Skip to content

Commit d083326

Browse files
committed
work on the new session builder infrastructure
and fix a big bug in tx/connection sharing between stateful and stateless sessions!
1 parent c0a94fc commit d083326

19 files changed

+116
-114
lines changed

hibernate-core/src/main/java/org/hibernate/SessionBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public interface SessionBuilder extends CommonBuilder {
169169
*
170170
* @return {@code this}, for method chaining
171171
*/
172+
@Override
172173
SessionBuilder jdbcTimeZone(TimeZone timeZone);
173174

174175
/**

hibernate-core/src/main/java/org/hibernate/SharedSessionBuilder.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ public interface SharedSessionBuilder extends SessionBuilder, CommonSharedBuilde
7171
@Override
7272
SharedSessionBuilder statementInspector(UnaryOperator<String> operator);
7373

74+
@Override
75+
SharedSessionBuilder statementInspector();
76+
77+
@Override
78+
SharedSessionBuilder noStatementInspector();
79+
7480
@Override @Deprecated
7581
SharedSessionBuilder connectionHandlingMode(PhysicalConnectionHandlingMode mode);
7682

hibernate-core/src/main/java/org/hibernate/SharedStatelessSessionBuilder.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import org.hibernate.engine.creation.CommonSharedBuilder;
88

9+
import java.sql.Connection;
10+
import java.util.TimeZone;
911
import java.util.function.UnaryOperator;
1012

1113
/**
@@ -21,7 +23,7 @@
2123
* @author Steve Ebersole
2224
*/
2325
@Incubating
24-
public interface SharedStatelessSessionBuilder extends CommonSharedBuilder {
26+
public interface SharedStatelessSessionBuilder extends StatelessSessionBuilder, CommonSharedBuilder {
2527
/**
2628
* Open the stateless session.
2729
*/
@@ -55,4 +57,13 @@ public interface SharedStatelessSessionBuilder extends CommonSharedBuilder {
5557

5658
@Override
5759
SharedStatelessSessionBuilder initialCacheMode(CacheMode cacheMode);
60+
61+
@Override
62+
SharedStatelessSessionBuilder connection(Connection connection);
63+
64+
@Override
65+
SharedStatelessSessionBuilder connectionHandling(ConnectionAcquisitionMode acquisitionMode, ConnectionReleaseMode releaseMode);
66+
67+
@Override
68+
SharedStatelessSessionBuilder jdbcTimeZone(TimeZone timeZone);
5869
}

hibernate-core/src/main/java/org/hibernate/StatelessSession.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@
7979
* @author Gavin King
8080
*/
8181
public interface StatelessSession extends SharedSessionContract {
82-
/**
83-
* Close the stateless session and release the JDBC connection.
84-
*/
85-
void close();
8682

8783
/**
8884
* Insert a record.

hibernate-core/src/main/java/org/hibernate/StatelessSessionBuilder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package org.hibernate;
66

77
import java.sql.Connection;
8+
import java.util.TimeZone;
89
import java.util.function.UnaryOperator;
910

1011
import org.hibernate.engine.creation.CommonBuilder;
@@ -43,6 +44,9 @@ public interface StatelessSessionBuilder extends CommonBuilder {
4344
@Override
4445
StatelessSessionBuilder statementInspector(UnaryOperator<String> operator);
4546

47+
@Override
48+
StatelessSessionBuilder jdbcTimeZone(TimeZone timeZone);
49+
4650
/**
4751
* Define the tenant identifier to be associated with the opened session.
4852
*

hibernate-core/src/main/java/org/hibernate/engine/creation/CommonBuilder.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.hibernate.StatelessSession;
1616

1717
import java.sql.Connection;
18+
import java.util.TimeZone;
1819
import java.util.function.UnaryOperator;
1920

2021
/**
@@ -157,4 +158,12 @@ public interface CommonBuilder {
157158
* @see SharedSessionContract#getCacheMode()
158159
*/
159160
CommonBuilder initialCacheMode(CacheMode cacheMode);
161+
162+
/**
163+
* Specify the {@linkplain org.hibernate.cfg.JdbcSettings#JDBC_TIME_ZONE
164+
* JDBC time zone} for the session.
165+
*
166+
* @return {@code this}, for method chaining
167+
*/
168+
CommonBuilder jdbcTimeZone(TimeZone timeZone);
160169
}

hibernate-core/src/main/java/org/hibernate/engine/creation/CommonSharedBuilder.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
package org.hibernate.engine.creation;
66

77
import org.hibernate.CacheMode;
8+
import org.hibernate.ConnectionAcquisitionMode;
9+
import org.hibernate.ConnectionReleaseMode;
810
import org.hibernate.Incubating;
911
import org.hibernate.Interceptor;
1012
import org.hibernate.Session;
1113
import org.hibernate.StatelessSession;
1214

15+
import java.sql.Connection;
16+
import java.util.TimeZone;
1317
import java.util.function.UnaryOperator;
1418

1519
/**
@@ -48,6 +52,7 @@ public interface CommonSharedBuilder extends CommonBuilder {
4852
* Signifies that no SQL {@linkplain org.hibernate.resource.jdbc.spi.StatementInspector statement inspector}
4953
* should be used.
5054
*/
55+
@Override
5156
CommonSharedBuilder noStatementInspector();
5257

5358
@Override
@@ -67,4 +72,13 @@ public interface CommonSharedBuilder extends CommonBuilder {
6772

6873
@Override
6974
CommonSharedBuilder tenantIdentifier(Object tenantIdentifier);
75+
76+
@Override
77+
CommonBuilder connection(Connection connection);
78+
79+
@Override
80+
CommonSharedBuilder connectionHandling(ConnectionAcquisitionMode acquisitionMode, ConnectionReleaseMode releaseMode);
81+
82+
@Override
83+
CommonSharedBuilder jdbcTimeZone(TimeZone timeZone);
7084
}

hibernate-core/src/main/java/org/hibernate/engine/creation/internal/AbstractCommonBuilder.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.hibernate.resource.jdbc.spi.StatementInspector;
1616

1717
import java.sql.Connection;
18+
import java.util.TimeZone;
1819
import java.util.function.UnaryOperator;
1920

2021
/**
@@ -33,13 +34,15 @@ public abstract class AbstractCommonBuilder<T extends CommonBuilder> implements
3334
protected Object tenantIdentifier;
3435
protected boolean readOnly;
3536
protected CacheMode cacheMode;
37+
protected TimeZone jdbcTimeZone;
3638

3739
public AbstractCommonBuilder(SessionFactoryImplementor factory) {
3840
sessionFactory = factory;
3941
final var options = factory.getSessionFactoryOptions();
4042
statementInspector = options.getStatementInspector();
4143
cacheMode = options.getInitialSessionCacheMode();
4244
connectionHandlingMode = options.getPhysicalConnectionHandlingMode();
45+
jdbcTimeZone = options.getJdbcTimeZone();
4346
tenantIdentifier = factory.resolveTenantIdentifier();
4447
}
4548

@@ -143,4 +146,10 @@ public T noStatementInspector() {
143146
this.statementInspector = null;
144147
return getThis();
145148
}
149+
150+
@Override
151+
public T jdbcTimeZone(TimeZone timeZone) {
152+
jdbcTimeZone = timeZone;
153+
return getThis();
154+
}
146155
}

hibernate-core/src/main/java/org/hibernate/engine/creation/internal/CommonSharedSessionCreationOptions.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
import org.hibernate.Interceptor;
99
import org.hibernate.Transaction;
1010
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
11+
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
1112
import org.hibernate.resource.jdbc.spi.StatementInspector;
1213
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
1314

15+
import java.util.TimeZone;
16+
17+
1418
/**
1519
* Creation options for shared {@linkplain org.hibernate.engine.spi.SessionImplementor stateful}
1620
* and {@linkplain org.hibernate.engine.spi.StatelessSessionImplementor stateless} sessions.
@@ -34,8 +38,12 @@ public interface CommonSharedSessionCreationOptions {
3438

3539
CacheMode getInitialCacheMode();
3640

41+
PhysicalConnectionHandlingMode getPhysicalConnectionHandlingMode();
42+
3743
boolean isTransactionCoordinatorShared();
3844
TransactionCoordinator getTransactionCoordinator();
3945
JdbcCoordinator getJdbcCoordinator();
4046
Transaction getTransaction();
47+
48+
TimeZone getJdbcTimeZone();
4149
}

hibernate-core/src/main/java/org/hibernate/engine/creation/internal/SessionBuilderImpl.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public abstract class SessionBuilderImpl
3838
private boolean autoClose;
3939
private boolean autoClear;
4040
private boolean identifierRollback;
41-
private TimeZone jdbcTimeZone;
4241
private FlushMode flushMode;
4342

4443
private final int defaultBatchFetchSize;
@@ -55,7 +54,6 @@ public SessionBuilderImpl(SessionFactoryImplementor sessionFactory) {
5554
final var options = sessionFactory.getSessionFactoryOptions();
5655
autoClose = options.isAutoCloseSessionEnabled();
5756
identifierRollback = options.isIdentifierRollbackEnabled();
58-
jdbcTimeZone = options.getJdbcTimeZone();
5957
defaultBatchFetchSize = options.getDefaultBatchFetchSize();
6058
subselectFetchEnabled = options.isSubselectFetchEnabled();
6159
}
@@ -119,13 +117,6 @@ public PhysicalConnectionHandlingMode getPhysicalConnectionHandlingMode() {
119117
return connectionHandlingMode;
120118
}
121119

122-
@Override
123-
public String getTenantIdentifier() {
124-
return tenantIdentifier != null
125-
? sessionFactory.getTenantIdentifierJavaType().toString( tenantIdentifier )
126-
: null;
127-
}
128-
129120
@Override
130121
public Object getTenantIdentifierValue() {
131122
return tenantIdentifier;
@@ -241,10 +232,4 @@ public SessionBuilderImplementor clearEventListeners() {
241232
}
242233
return this;
243234
}
244-
245-
@Override
246-
public SessionBuilderImplementor jdbcTimeZone(TimeZone timeZone) {
247-
jdbcTimeZone = timeZone;
248-
return this;
249-
}
250235
}

0 commit comments

Comments
 (0)