remove deprecated operations of SessionBuilder
they've been deprecated since 5.2
This commit is contained in:
parent
9c37385cb9
commit
c44e0519b9
|
@ -150,38 +150,4 @@ public interface SessionBuilder<T extends SessionBuilder> {
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
T autoClose(boolean autoClose);
|
T autoClose(boolean autoClose);
|
||||||
|
|
||||||
/**
|
|
||||||
* Use a specific connection release mode for these session options.
|
|
||||||
*
|
|
||||||
* @param connectionReleaseMode The connection release mode to use.
|
|
||||||
*
|
|
||||||
* @return {@code this}, for method chaining
|
|
||||||
*
|
|
||||||
* @deprecated use {@link #connectionHandlingMode} instead
|
|
||||||
*/
|
|
||||||
@Deprecated(since = "5.2")
|
|
||||||
T connectionReleaseMode(ConnectionReleaseMode connectionReleaseMode);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should the session be automatically flushed during the "before completion"
|
|
||||||
* phase of transaction handling.
|
|
||||||
*
|
|
||||||
* @param flushBeforeCompletion Should the session be automatically flushed
|
|
||||||
*
|
|
||||||
* @return {@code this}, for method chaining
|
|
||||||
*
|
|
||||||
* @deprecated use {@link #flushMode(FlushMode)} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated(since = "5.2")
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
default T flushBeforeCompletion(boolean flushBeforeCompletion) {
|
|
||||||
if ( flushBeforeCompletion ) {
|
|
||||||
flushMode( FlushMode.ALWAYS );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
flushMode( FlushMode.MANUAL );
|
|
||||||
}
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,21 +79,6 @@ public interface SharedSessionBuilder<T extends SharedSessionBuilder> extends Se
|
||||||
*/
|
*/
|
||||||
T autoClose();
|
T autoClose();
|
||||||
|
|
||||||
/**
|
|
||||||
* Signifies that the flushBeforeCompletion flag from the original session should be used to create the new session.
|
|
||||||
*
|
|
||||||
* @return {@code this}, for method chaining
|
|
||||||
*
|
|
||||||
* @deprecated use {@link #flushMode()} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated(since = "5.2")
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
default T flushBeforeCompletion() {
|
|
||||||
flushMode();
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
// overrides to maintain binary compatibility
|
// overrides to maintain binary compatibility
|
||||||
|
|
||||||
|
@ -106,23 +91,9 @@ public interface SharedSessionBuilder<T extends SharedSessionBuilder> extends Se
|
||||||
@Override
|
@Override
|
||||||
T connection(Connection connection);
|
T connection(Connection connection);
|
||||||
|
|
||||||
@Override
|
|
||||||
T connectionReleaseMode(ConnectionReleaseMode connectionReleaseMode);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
T autoJoinTransactions(boolean autoJoinTransactions);
|
T autoJoinTransactions(boolean autoJoinTransactions);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
T autoClose(boolean autoClose);
|
T autoClose(boolean autoClose);
|
||||||
|
|
||||||
@Override @SuppressWarnings("unchecked")
|
|
||||||
default T flushBeforeCompletion(boolean flushBeforeCompletion) {
|
|
||||||
if ( flushBeforeCompletion ) {
|
|
||||||
flushMode( FlushMode.ALWAYS );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
flushMode( FlushMode.MANUAL );
|
|
||||||
}
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ package org.hibernate.boot.internal;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import org.hibernate.ConnectionReleaseMode;
|
|
||||||
import org.hibernate.CustomEntityDirtinessStrategy;
|
import org.hibernate.CustomEntityDirtinessStrategy;
|
||||||
import org.hibernate.EntityNameResolver;
|
import org.hibernate.EntityNameResolver;
|
||||||
import org.hibernate.Interceptor;
|
import org.hibernate.Interceptor;
|
||||||
|
|
|
@ -1096,11 +1096,6 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
||||||
this.checkNullability = enabled;
|
this.checkNullability = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ConnectionReleaseMode getConnectionReleaseMode() {
|
|
||||||
return getPhysicalConnectionHandlingMode().getReleaseMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doesConnectionProviderDisableAutoCommit() {
|
public boolean doesConnectionProviderDisableAutoCommit() {
|
||||||
return connectionProviderDisablesAutoCommit;
|
return connectionProviderDisablesAutoCommit;
|
||||||
|
|
|
@ -319,12 +319,6 @@ public class AbstractDelegatingSessionFactoryOptions implements SessionFactoryOp
|
||||||
return delegate.doesConnectionProviderDisableAutoCommit();
|
return delegate.doesConnectionProviderDisableAutoCommit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public ConnectionReleaseMode getConnectionReleaseMode() {
|
|
||||||
return delegate.getConnectionReleaseMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCommentsEnabled() {
|
public boolean isCommentsEnabled() {
|
||||||
return delegate.isCommentsEnabled();
|
return delegate.isCommentsEnabled();
|
||||||
|
|
|
@ -9,7 +9,6 @@ package org.hibernate.boot.spi;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import org.hibernate.ConnectionReleaseMode;
|
|
||||||
import org.hibernate.CustomEntityDirtinessStrategy;
|
import org.hibernate.CustomEntityDirtinessStrategy;
|
||||||
import org.hibernate.EntityNameResolver;
|
import org.hibernate.EntityNameResolver;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
|
@ -214,12 +213,6 @@ public interface SessionFactoryOptions extends QueryEngineOptions {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #getPhysicalConnectionHandlingMode()} instead
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
ConnectionReleaseMode getConnectionReleaseMode();
|
|
||||||
|
|
||||||
boolean isCommentsEnabled();
|
boolean isCommentsEnabled();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.cfg;
|
package org.hibernate.cfg;
|
||||||
|
|
||||||
import org.hibernate.ConnectionReleaseMode;
|
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.SchemaAutoTooling;
|
import org.hibernate.boot.SchemaAutoTooling;
|
||||||
import org.hibernate.boot.model.naming.Identifier;
|
import org.hibernate.boot.model.naming.Identifier;
|
||||||
|
@ -96,7 +95,7 @@ public final class Settings {
|
||||||
LOG.debugf( "Scrollable result sets: %s", enabledDisabled( sessionFactoryOptions.isScrollableResultSetsEnabled() ) );
|
LOG.debugf( "Scrollable result sets: %s", enabledDisabled( sessionFactoryOptions.isScrollableResultSetsEnabled() ) );
|
||||||
LOG.debugf( "JDBC3 getGeneratedKeys(): %s", enabledDisabled( sessionFactoryOptions.isGetGeneratedKeysEnabled() ) );
|
LOG.debugf( "JDBC3 getGeneratedKeys(): %s", enabledDisabled( sessionFactoryOptions.isGetGeneratedKeysEnabled() ) );
|
||||||
LOG.debugf( "JDBC result set fetch size: %s", sessionFactoryOptions.getJdbcFetchSize() );
|
LOG.debugf( "JDBC result set fetch size: %s", sessionFactoryOptions.getJdbcFetchSize() );
|
||||||
LOG.debugf( "Connection release mode: %s", sessionFactoryOptions.getConnectionReleaseMode() );
|
LOG.debugf( "Connection handling mode: %s", sessionFactoryOptions.getPhysicalConnectionHandlingMode() );
|
||||||
LOG.debugf( "Generate SQL with comments: %s", enabledDisabled( sessionFactoryOptions.isCommentsEnabled() ) );
|
LOG.debugf( "Generate SQL with comments: %s", enabledDisabled( sessionFactoryOptions.isCommentsEnabled() ) );
|
||||||
|
|
||||||
LOG.debugf( "JPA compliance - query : %s", enabledDisabled( sessionFactoryOptions.getJpaCompliance().isJpaQueryComplianceEnabled() ) );
|
LOG.debugf( "JPA compliance - query : %s", enabledDisabled( sessionFactoryOptions.getJpaCompliance().isJpaQueryComplianceEnabled() ) );
|
||||||
|
@ -271,10 +270,6 @@ public final class Settings {
|
||||||
return sessionFactoryOptions.isGetGeneratedKeysEnabled();
|
return sessionFactoryOptions.isGetGeneratedKeysEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionReleaseMode getConnectionReleaseMode() {
|
|
||||||
return sessionFactoryOptions.getConnectionReleaseMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCommentsEnabled() {
|
public boolean isCommentsEnabled() {
|
||||||
return sessionFactoryOptions.isCommentsEnabled();
|
return sessionFactoryOptions.isCommentsEnabled();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import jakarta.transaction.Synchronization;
|
||||||
import jakarta.transaction.Transaction;
|
import jakarta.transaction.Transaction;
|
||||||
import jakarta.transaction.TransactionManager;
|
import jakarta.transaction.TransactionManager;
|
||||||
|
|
||||||
import org.hibernate.ConnectionReleaseMode;
|
import org.hibernate.FlushMode;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.context.spi.AbstractCurrentSessionContext;
|
import org.hibernate.context.spi.AbstractCurrentSessionContext;
|
||||||
|
@ -21,6 +21,7 @@ import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
|
||||||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
|
|
||||||
|
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,7 +38,7 @@ import org.jboss.logging.Logger;
|
||||||
* meaning that the session will be automatically flushed and closed as part of the lifecycle of the
|
* meaning that the session will be automatically flushed and closed as part of the lifecycle of the
|
||||||
* JTA transaction with which it is associated. Additionally, it will be configured to aggressively
|
* JTA transaction with which it is associated. Additionally, it will be configured to aggressively
|
||||||
* release JDBC connections after each statement is executed. These settings are governed by the
|
* release JDBC connections after each statement is executed. These settings are governed by the
|
||||||
* {@link #isAutoFlushEnabled()}, {@link #isAutoCloseEnabled()}, and {@link #getConnectionReleaseMode()}
|
* {@link #isAutoFlushEnabled()}, {@link #isAutoCloseEnabled()}, and {@link #getConnectionHandlingMode()}
|
||||||
* methods; these are provided (along with the {@link #buildOrObtainSession()} method) for easier
|
* methods; these are provided (along with the {@link #buildOrObtainSession()} method) for easier
|
||||||
* subclassing for custom JTA-based session tracking logic (like maybe long-session semantics).
|
* subclassing for custom JTA-based session tracking logic (like maybe long-session semantics).
|
||||||
*
|
*
|
||||||
|
@ -49,7 +50,7 @@ public class JTASessionContext extends AbstractCurrentSessionContext {
|
||||||
JTASessionContext.class.getName()
|
JTASessionContext.class.getName()
|
||||||
);
|
);
|
||||||
|
|
||||||
private transient Map<Object, Session> currentSessionMap = new ConcurrentHashMap<>();
|
private transient final Map<Object, Session> currentSessionMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a JTASessionContext
|
* Constructs a JTASessionContext
|
||||||
|
@ -102,8 +103,8 @@ public class JTASessionContext extends AbstractCurrentSessionContext {
|
||||||
try {
|
try {
|
||||||
currentSession.close();
|
currentSession.close();
|
||||||
}
|
}
|
||||||
catch ( Throwable ignore ) {
|
catch ( Throwable e ) {
|
||||||
LOG.debug( "Unable to release generated current-session on failed synchronization registration", ignore );
|
LOG.debug( "Unable to release generated current-session on failed synchronization registration", e );
|
||||||
}
|
}
|
||||||
throw new HibernateException( "Unable to register cleanup Synchronization with TransactionManager" );
|
throw new HibernateException( "Unable to register cleanup Synchronization with TransactionManager" );
|
||||||
}
|
}
|
||||||
|
@ -138,8 +139,8 @@ public class JTASessionContext extends AbstractCurrentSessionContext {
|
||||||
protected Session buildOrObtainSession() {
|
protected Session buildOrObtainSession() {
|
||||||
return baseSessionBuilder()
|
return baseSessionBuilder()
|
||||||
.autoClose( isAutoCloseEnabled() )
|
.autoClose( isAutoCloseEnabled() )
|
||||||
.connectionReleaseMode( getConnectionReleaseMode() )
|
.connectionHandlingMode( getConnectionHandlingMode() )
|
||||||
.flushBeforeCompletion( isAutoFlushEnabled() )
|
.flushMode( isAutoFlushEnabled() ? FlushMode.AUTO : FlushMode.MANUAL )
|
||||||
.openSession();
|
.openSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,16 +167,16 @@ public class JTASessionContext extends AbstractCurrentSessionContext {
|
||||||
*
|
*
|
||||||
* @return The connection release mode for any built sessions.
|
* @return The connection release mode for any built sessions.
|
||||||
*/
|
*/
|
||||||
protected ConnectionReleaseMode getConnectionReleaseMode() {
|
protected PhysicalConnectionHandlingMode getConnectionHandlingMode() {
|
||||||
return ConnectionReleaseMode.AFTER_STATEMENT;
|
return PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JTA transaction sync used for cleanup of the internal session map.
|
* JTA transaction sync used for cleanup of the internal session map.
|
||||||
*/
|
*/
|
||||||
protected static class CleanupSync implements Synchronization {
|
protected static class CleanupSync implements Synchronization {
|
||||||
private Object transactionIdentifier;
|
private final Object transactionIdentifier;
|
||||||
private JTASessionContext context;
|
private final JTASessionContext context;
|
||||||
|
|
||||||
public CleanupSync(Object transactionIdentifier, JTASessionContext context) {
|
public CleanupSync(Object transactionIdentifier, JTASessionContext context) {
|
||||||
this.transactionIdentifier = transactionIdentifier;
|
this.transactionIdentifier = transactionIdentifier;
|
||||||
|
|
|
@ -19,7 +19,7 @@ import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import jakarta.transaction.Synchronization;
|
import jakarta.transaction.Synchronization;
|
||||||
|
|
||||||
import org.hibernate.ConnectionReleaseMode;
|
import org.hibernate.FlushMode;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
|
@ -30,6 +30,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.event.spi.EventSource;
|
import org.hibernate.event.spi.EventSource;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
|
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
|
||||||
import org.hibernate.resource.transaction.spi.TransactionStatus;
|
import org.hibernate.resource.transaction.spi.TransactionStatus;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
@ -44,14 +45,14 @@ import org.jboss.logging.Logger;
|
||||||
* sessions generated here are unusable until after {@link Session#beginTransaction()} has been
|
* sessions generated here are unusable until after {@link Session#beginTransaction()} has been
|
||||||
* called. If {@code close()} is called on a session managed by this class, it will be automatically
|
* called. If {@code close()} is called on a session managed by this class, it will be automatically
|
||||||
* unbound.
|
* unbound.
|
||||||
*
|
* <p>
|
||||||
* Additionally, the static {@link #bind} and {@link #unbind} methods are provided to allow application
|
* Additionally, the static {@link #bind} and {@link #unbind} methods are provided to allow application
|
||||||
* code to explicitly control opening and closing of these sessions. This, with some from of interception,
|
* code to explicitly control opening and closing of these sessions. This, with some from of interception,
|
||||||
* is the preferred approach. It also allows easy framework integration and one possible approach for
|
* is the preferred approach. It also allows easy framework integration and one possible approach for
|
||||||
* implementing long-sessions.
|
* implementing long-sessions.
|
||||||
*
|
* <p>
|
||||||
* The {@link #buildOrObtainSession}, {@link #isAutoCloseEnabled}, {@link #isAutoFlushEnabled},
|
* The {@link #buildOrObtainSession}, {@link #isAutoCloseEnabled}, {@link #isAutoFlushEnabled},
|
||||||
* {@link #getConnectionReleaseMode}, and {@link #buildCleanupSynch} methods are all provided to allow easy
|
* {@link #getConnectionHandlingMode}, and {@link #buildCleanupSynch} methods are all provided to allow easy
|
||||||
* subclassing (for long-running session scenarios, for example).
|
* subclassing (for long-running session scenarios, for example).
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
@ -63,7 +64,7 @@ public class ThreadLocalSessionContext extends AbstractCurrentSessionContext {
|
||||||
ThreadLocalSessionContext.class.getName()
|
ThreadLocalSessionContext.class.getName()
|
||||||
);
|
);
|
||||||
|
|
||||||
private static final Class[] SESSION_PROXY_INTERFACES = new Class[] {
|
private static final Class<?>[] SESSION_PROXY_INTERFACES = new Class<?>[] {
|
||||||
Session.class,
|
Session.class,
|
||||||
SessionImplementor.class,
|
SessionImplementor.class,
|
||||||
EventSource.class,
|
EventSource.class,
|
||||||
|
@ -110,10 +111,7 @@ public class ThreadLocalSessionContext extends AbstractCurrentSessionContext {
|
||||||
private boolean needsWrapping(Session session) {
|
private boolean needsWrapping(Session session) {
|
||||||
// try to make sure we don't wrap an already wrapped session
|
// try to make sure we don't wrap an already wrapped session
|
||||||
if ( Proxy.isProxyClass( session.getClass() ) ) {
|
if ( Proxy.isProxyClass( session.getClass() ) ) {
|
||||||
final InvocationHandler invocationHandler = Proxy.getInvocationHandler( session );
|
return !( Proxy.getInvocationHandler(session) instanceof TransactionProtectionWrapper );
|
||||||
if ( TransactionProtectionWrapper.class.isInstance( invocationHandler ) ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -139,8 +137,8 @@ public class ThreadLocalSessionContext extends AbstractCurrentSessionContext {
|
||||||
protected Session buildOrObtainSession() {
|
protected Session buildOrObtainSession() {
|
||||||
return baseSessionBuilder()
|
return baseSessionBuilder()
|
||||||
.autoClose( isAutoCloseEnabled() )
|
.autoClose( isAutoCloseEnabled() )
|
||||||
.connectionReleaseMode( getConnectionReleaseMode() )
|
.connectionHandlingMode( getConnectionHandlingMode() )
|
||||||
.flushBeforeCompletion( isAutoFlushEnabled() )
|
.flushMode( isAutoFlushEnabled() ? FlushMode.AUTO : FlushMode.MANUAL )
|
||||||
.openSession();
|
.openSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,8 +169,8 @@ public class ThreadLocalSessionContext extends AbstractCurrentSessionContext {
|
||||||
*
|
*
|
||||||
* @return The connection release mode for any built sessions.
|
* @return The connection release mode for any built sessions.
|
||||||
*/
|
*/
|
||||||
protected ConnectionReleaseMode getConnectionReleaseMode() {
|
protected PhysicalConnectionHandlingMode getConnectionHandlingMode() {
|
||||||
return factory().getSessionFactoryOptions().getPhysicalConnectionHandlingMode().getReleaseMode();
|
return factory().getSessionFactoryOptions().getPhysicalConnectionHandlingMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Session wrap(Session session) {
|
protected Session wrap(Session session) {
|
||||||
|
@ -230,7 +228,7 @@ public class ThreadLocalSessionContext extends AbstractCurrentSessionContext {
|
||||||
* @return The session which was unbound.
|
* @return The session which was unbound.
|
||||||
*/
|
*/
|
||||||
public static Session unbind(SessionFactory factory) {
|
public static Session unbind(SessionFactory factory) {
|
||||||
return doUnbind( factory, true );
|
return doUnbind( factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Session existingSession(SessionFactory factory) {
|
private static Session existingSession(SessionFactory factory) {
|
||||||
|
@ -241,16 +239,15 @@ public class ThreadLocalSessionContext extends AbstractCurrentSessionContext {
|
||||||
return CONTEXT_TL.get();
|
return CONTEXT_TL.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked"})
|
|
||||||
private static void doBind(Session session, SessionFactory factory) {
|
private static void doBind(Session session, SessionFactory factory) {
|
||||||
Session orphanedPreviousSession = sessionMap().put( factory, session );
|
Session orphanedPreviousSession = sessionMap().put( factory, session );
|
||||||
terminateOrphanedSession( orphanedPreviousSession );
|
terminateOrphanedSession( orphanedPreviousSession );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Session doUnbind(SessionFactory factory, boolean releaseMapIfEmpty) {
|
private static Session doUnbind(SessionFactory factory) {
|
||||||
final Map<SessionFactory, Session> sessionMap = sessionMap();
|
final Map<SessionFactory, Session> sessionMap = sessionMap();
|
||||||
final Session session = sessionMap.remove( factory );
|
final Session session = sessionMap.remove( factory );
|
||||||
if ( releaseMapIfEmpty && sessionMap.isEmpty() ) {
|
if ( sessionMap.isEmpty() ) {
|
||||||
//Do not use set(null) as it would prevent the initialValue to be invoked again in case of need.
|
//Do not use set(null) as it would prevent the initialValue to be invoked again in case of need.
|
||||||
CONTEXT_TL.remove();
|
CONTEXT_TL.remove();
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ package org.hibernate.engine.spi;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import org.hibernate.ConnectionReleaseMode;
|
|
||||||
import org.hibernate.FlushMode;
|
import org.hibernate.FlushMode;
|
||||||
import org.hibernate.Interceptor;
|
import org.hibernate.Interceptor;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
|
@ -71,13 +70,6 @@ public abstract class AbstractDelegatingSessionBuilder<T extends SessionBuilder>
|
||||||
return getThis();
|
return getThis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
|
||||||
public T connectionReleaseMode(ConnectionReleaseMode connectionReleaseMode) {
|
|
||||||
delegate.connectionReleaseMode( connectionReleaseMode );
|
|
||||||
return getThis();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T autoJoinTransactions(boolean autoJoinTransactions) {
|
public T autoJoinTransactions(boolean autoJoinTransactions) {
|
||||||
delegate.autoJoinTransactions( autoJoinTransactions );
|
delegate.autoJoinTransactions( autoJoinTransactions );
|
||||||
|
@ -90,13 +82,6 @@ public abstract class AbstractDelegatingSessionBuilder<T extends SessionBuilder>
|
||||||
return getThis();
|
return getThis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
|
||||||
public T flushBeforeCompletion(boolean flushBeforeCompletion) {
|
|
||||||
delegate.flushBeforeCompletion( flushBeforeCompletion );
|
|
||||||
return getThis();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T tenantIdentifier(String tenantIdentifier) {
|
public T tenantIdentifier(String tenantIdentifier) {
|
||||||
delegate.tenantIdentifier( tenantIdentifier );
|
delegate.tenantIdentifier( tenantIdentifier );
|
||||||
|
|
|
@ -9,7 +9,6 @@ package org.hibernate.engine.spi;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import org.hibernate.ConnectionReleaseMode;
|
|
||||||
import org.hibernate.FlushMode;
|
import org.hibernate.FlushMode;
|
||||||
import org.hibernate.Interceptor;
|
import org.hibernate.Interceptor;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
|
@ -25,7 +24,6 @@ import org.hibernate.resource.jdbc.spi.StatementInspector;
|
||||||
* @author Gunnar Morling
|
* @author Gunnar Morling
|
||||||
* @author Guillaume Smet
|
* @author Guillaume Smet
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public abstract class AbstractDelegatingSharedSessionBuilder<T extends SharedSessionBuilder> implements SharedSessionBuilder<T> {
|
public abstract class AbstractDelegatingSharedSessionBuilder<T extends SharedSessionBuilder> implements SharedSessionBuilder<T> {
|
||||||
|
|
||||||
private final SharedSessionBuilder delegate;
|
private final SharedSessionBuilder delegate;
|
||||||
|
@ -60,8 +58,7 @@ public abstract class AbstractDelegatingSharedSessionBuilder<T extends SharedSes
|
||||||
return getThis();
|
return getThis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@Override @Deprecated(since = "6.0")
|
||||||
@Override
|
|
||||||
public T connectionReleaseMode() {
|
public T connectionReleaseMode() {
|
||||||
delegate.connectionReleaseMode();
|
delegate.connectionReleaseMode();
|
||||||
return getThis();
|
return getThis();
|
||||||
|
@ -85,13 +82,6 @@ public abstract class AbstractDelegatingSharedSessionBuilder<T extends SharedSes
|
||||||
return getThis();
|
return getThis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
|
||||||
public T flushBeforeCompletion() {
|
|
||||||
delegate.flushBeforeCompletion();
|
|
||||||
return getThis();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T interceptor(Interceptor interceptor) {
|
public T interceptor(Interceptor interceptor) {
|
||||||
delegate.interceptor( interceptor );
|
delegate.interceptor( interceptor );
|
||||||
|
@ -116,13 +106,6 @@ public abstract class AbstractDelegatingSharedSessionBuilder<T extends SharedSes
|
||||||
return getThis();
|
return getThis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
|
||||||
public T connectionReleaseMode(ConnectionReleaseMode connectionReleaseMode) {
|
|
||||||
delegate.connectionReleaseMode( connectionReleaseMode );
|
|
||||||
return getThis();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T autoJoinTransactions(boolean autoJoinTransactions) {
|
public T autoJoinTransactions(boolean autoJoinTransactions) {
|
||||||
delegate.autoJoinTransactions( autoJoinTransactions );
|
delegate.autoJoinTransactions( autoJoinTransactions );
|
||||||
|
@ -135,13 +118,6 @@ public abstract class AbstractDelegatingSharedSessionBuilder<T extends SharedSes
|
||||||
return getThis();
|
return getThis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
|
||||||
public T flushBeforeCompletion(boolean flushBeforeCompletion) {
|
|
||||||
delegate.flushBeforeCompletion( flushBeforeCompletion );
|
|
||||||
return getThis();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T tenantIdentifier(String tenantIdentifier) {
|
public T tenantIdentifier(String tenantIdentifier) {
|
||||||
delegate.tenantIdentifier( tenantIdentifier );
|
delegate.tenantIdentifier( tenantIdentifier );
|
||||||
|
|
|
@ -33,8 +33,6 @@ import jakarta.persistence.PersistenceUnitUtil;
|
||||||
import jakarta.persistence.Query;
|
import jakarta.persistence.Query;
|
||||||
import jakarta.persistence.SynchronizationType;
|
import jakarta.persistence.SynchronizationType;
|
||||||
|
|
||||||
import org.hibernate.ConnectionAcquisitionMode;
|
|
||||||
import org.hibernate.ConnectionReleaseMode;
|
|
||||||
import org.hibernate.CustomEntityDirtinessStrategy;
|
import org.hibernate.CustomEntityDirtinessStrategy;
|
||||||
import org.hibernate.EmptyInterceptor;
|
import org.hibernate.EmptyInterceptor;
|
||||||
import org.hibernate.EntityNameResolver;
|
import org.hibernate.EntityNameResolver;
|
||||||
|
@ -1298,20 +1296,6 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
|
||||||
return (T) this;
|
return (T) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public T connectionReleaseMode(ConnectionReleaseMode connectionReleaseMode) {
|
|
||||||
// NOTE : Legacy behavior (when only ConnectionReleaseMode was exposed) was to always acquire a
|
|
||||||
// Connection using ConnectionAcquisitionMode.AS_NEEDED.
|
|
||||||
|
|
||||||
final PhysicalConnectionHandlingMode handlingMode = PhysicalConnectionHandlingMode.interpret(
|
|
||||||
ConnectionAcquisitionMode.AS_NEEDED,
|
|
||||||
connectionReleaseMode
|
|
||||||
);
|
|
||||||
connectionHandlingMode( handlingMode );
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public T connectionHandlingMode(PhysicalConnectionHandlingMode connectionHandlingMode) {
|
public T connectionHandlingMode(PhysicalConnectionHandlingMode connectionHandlingMode) {
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.hibernate.CacheMode;
|
import org.hibernate.CacheMode;
|
||||||
|
import org.hibernate.ConnectionAcquisitionMode;
|
||||||
import org.hibernate.Filter;
|
import org.hibernate.Filter;
|
||||||
import org.hibernate.FlushMode;
|
import org.hibernate.FlushMode;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
|
@ -123,6 +124,7 @@ import org.hibernate.proxy.LazyInitializer;
|
||||||
import org.hibernate.query.Query;
|
import org.hibernate.query.Query;
|
||||||
import org.hibernate.query.SelectionQuery;
|
import org.hibernate.query.SelectionQuery;
|
||||||
import org.hibernate.query.UnknownSqlResultSetMappingException;
|
import org.hibernate.query.UnknownSqlResultSetMappingException;
|
||||||
|
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
|
||||||
import org.hibernate.resource.transaction.TransactionRequiredForJoinException;
|
import org.hibernate.resource.transaction.TransactionRequiredForJoinException;
|
||||||
import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl;
|
import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl;
|
||||||
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
|
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
|
||||||
|
@ -2001,8 +2003,13 @@ public class SessionImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated(since = "6.0")
|
||||||
public T connectionReleaseMode() {
|
public T connectionReleaseMode() {
|
||||||
return connectionReleaseMode( session.getJdbcCoordinator().getLogicalConnection().getConnectionHandlingMode().getReleaseMode() );
|
final PhysicalConnectionHandlingMode handlingMode = PhysicalConnectionHandlingMode.interpret(
|
||||||
|
ConnectionAcquisitionMode.AS_NEEDED,
|
||||||
|
session.getJdbcCoordinator().getLogicalConnection().getConnectionHandlingMode().getReleaseMode()
|
||||||
|
);
|
||||||
|
return connectionHandlingMode( handlingMode );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -161,7 +161,7 @@ public class SessionWithSharedConnectionTest {
|
||||||
|
|
||||||
Session secondSession = session.sessionWithOptions()
|
Session secondSession = session.sessionWithOptions()
|
||||||
.transactionContext()
|
.transactionContext()
|
||||||
.flushBeforeCompletion( true )
|
// .flushBeforeCompletion( true )
|
||||||
.autoClose( true )
|
.autoClose( true )
|
||||||
.openSession();
|
.openSession();
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ public class SessionWithSharedConnectionTest {
|
||||||
|
|
||||||
session = scope.getSessionFactory().openSession();
|
session = scope.getSessionFactory().openSession();
|
||||||
session.getTransaction().begin();
|
session.getTransaction().begin();
|
||||||
IrrelevantEntity it = (IrrelevantEntity) session.byId( IrrelevantEntity.class ).load( id );
|
IrrelevantEntity it = session.byId( IrrelevantEntity.class ).load( id );
|
||||||
assertNotNull( it );
|
assertNotNull( it );
|
||||||
session.delete( it );
|
session.delete( it );
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
|
@ -220,7 +220,7 @@ public class SessionWithSharedConnectionTest {
|
||||||
//open secondary session to also insert an entity
|
//open secondary session to also insert an entity
|
||||||
Session secondSession = session.sessionWithOptions()
|
Session secondSession = session.sessionWithOptions()
|
||||||
.connection()
|
.connection()
|
||||||
.flushBeforeCompletion( true )
|
// .flushBeforeCompletion( true )
|
||||||
.autoClose( true )
|
.autoClose( true )
|
||||||
.openSession();
|
.openSession();
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ public class SessionWithSharedConnectionTest {
|
||||||
//open secondary session with managed options
|
//open secondary session with managed options
|
||||||
Session secondarySession = session.sessionWithOptions()
|
Session secondarySession = session.sessionWithOptions()
|
||||||
.connection()
|
.connection()
|
||||||
.flushBeforeCompletion( true )
|
// .flushBeforeCompletion( true )
|
||||||
.autoClose( true )
|
.autoClose( true )
|
||||||
.openSession();
|
.openSession();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue