HHH-10664 - Prep 6.0 feature branch - merge hibernate-entitymanager into hibernate-core (continued fixing of hibernate-core test failures)

This commit is contained in:
Steve Ebersole 2016-04-26 09:56:45 -05:00
parent 34b439223e
commit 76bac3268a
65 changed files with 595 additions and 654 deletions

View File

@ -424,7 +424,8 @@ Should we prefer using the `org.hibernate.engine.transaction.jta.platform.spi.Jt
|`hibernate.transaction.auto_close_session` |`true` or `false` (default value) |Causes the session to be closed during the after completion phase of the transaction. If possible, use built-in and automatic session context management instead. |`hibernate.transaction.auto_close_session` |`true` or `false` (default value) |Causes the session to be closed during the after completion phase of the transaction. If possible, use built-in and automatic session context management instead.
|`hibernate.transaction.coordinator_class` | a| |`hibernate.transaction.coordinator_class` | a|
Names the implementation of `org.hibernate.resource.transaction.TransactionCoordinatorBuilder` to use for creating `org.hibernate.resource.transaction.TransactionCoordinator` instances. Names the implementation of `org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder` to use for creating
`org.hibernate.resource.transaction.spi.TransactionCoordinator` instances.
Can be Can be

View File

@ -20,7 +20,8 @@ This documentation largely treats the physical and logic notions of a transactio
Hibernate uses the JDBC API for persistence. In the world of Java there are two well-defined mechanism for dealing with transactions in JDBC: JDBC itself and JTA. Hibernate uses the JDBC API for persistence. In the world of Java there are two well-defined mechanism for dealing with transactions in JDBC: JDBC itself and JTA.
Hibernate supports both mechanisms for integrating with transactions and allowing applications to manage physical transactions. Hibernate supports both mechanisms for integrating with transactions and allowing applications to manage physical transactions.
Transaction handling per `Session` is handled by the `org.hibernate.resource.transaction.TransactionCoordinator` contract, which are built by the `org.hibernate.resource.transaction.TransactionCoordinatorBuilder` service. Transaction handling per `Session` is handled by the `org.hibernate.resource.transaction.spi.TransactionCoordinator` contract,
which are built by the `org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder` service.
`TransactionCoordinatorBuilder` represents a strategy for dealing with transactions whereas TransactionCoordinator represents one instance of that strategy related to a Session. `TransactionCoordinatorBuilder` represents a strategy for dealing with transactions whereas TransactionCoordinator represents one instance of that strategy related to a Session.
Which `TransactionCoordinatorBuilder` implementation to use is defined by the `hibernate.transaction.coordinator_class` setting. Which `TransactionCoordinatorBuilder` implementation to use is defined by the `hibernate.transaction.coordinator_class` setting.

View File

@ -444,9 +444,9 @@
<section> <section>
<title>TransactionCoordinatorBuilder</title> <title>TransactionCoordinatorBuilder</title>
<para> <para>
<interfacename>org.hibernate.resource.transaction.TransactionCoordinatorBuilder</interfacename> <interfacename>org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder</interfacename>
is used by Hibernate to integrate with and underlying transaction system. It is responsible for is used by Hibernate to integrate with and underlying transaction system. It is responsible for
building <interfacename>org.hibernate.resource.transaction.TransactionCoordinator</interfacename> building <interfacename>org.hibernate.resource.transaction.spi.TransactionCoordinator</interfacename>
instances for use by each Hibernate Session. instances for use by each Hibernate Session.
</para> </para>
</section> </section>

View File

@ -410,8 +410,8 @@
<title>Transaction configuration</title> <title>Transaction configuration</title>
<para> <para>
Transaction handling per Session is handled by the <interfacename>org.hibernate.resource.transaction.TransactionCoordinator</interfacename> Transaction handling per Session is handled by the <interfacename>org.hibernate.resource.transaction.spi.TransactionCoordinator</interfacename>
contract, which are built by the <interfacename>org.hibernate.resource.transaction.TransactionCoordinatorBuilder</interfacename> contract, which are built by the <interfacename>org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder</interfacename>
service. TransactionCoordinatorBuilder represents a strategy for dealing with transactions whereas service. TransactionCoordinatorBuilder represents a strategy for dealing with transactions whereas
TransactionCoordinator represents one instance of that strategy related to a Session. Which TransactionCoordinator represents one instance of that strategy related to a Session. Which
TransactionCoordinatorBuilder implementation to use is defined by the <literal>hibernate.transaction.coordinator_class</literal> TransactionCoordinatorBuilder implementation to use is defined by the <literal>hibernate.transaction.coordinator_class</literal>

View File

@ -52,8 +52,8 @@
<para> <para>
Transaction handling per Session is handled by the Transaction handling per Session is handled by the
<interfacename>org.hibernate.resource.transaction.TransactionCoordinator</interfacename> contract, which <interfacename>org.hibernate.resource.transaction.spi.TransactionCoordinator</interfacename> contract, which
are built by the <interfacename>org.hibernate.resource.transaction.TransactionCoordinatorBuilder</interfacename> are built by the <interfacename>org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder</interfacename>
service. TransactionCoordinatorBuilder represents a strategy for dealing with transactions whereas service. TransactionCoordinatorBuilder represents a strategy for dealing with transactions whereas
TransactionCoordinator represents one instance of that strategy related to a Session. Which TransactionCoordinator represents one instance of that strategy related to a Session. Which
TransactionCoordinatorBuilder implementation to use is defined by the TransactionCoordinatorBuilder implementation to use is defined by the

View File

@ -6,6 +6,8 @@
*/ */
package org.hibernate; package org.hibernate;
import org.hibernate.internal.util.StringHelper;
/** /**
* Indicates the manner in which JDBC Connections should be acquired. Inverse to * Indicates the manner in which JDBC Connections should be acquired. Inverse to
* {@link org.hibernate.ConnectionReleaseMode}. * {@link org.hibernate.ConnectionReleaseMode}.
@ -32,4 +34,21 @@ public enum ConnectionAcquisitionMode {
return AS_NEEDED; return AS_NEEDED;
} }
public static ConnectionAcquisitionMode interpret(Object setting) {
if ( setting == null ) {
return null;
}
if ( setting instanceof ConnectionAcquisitionMode ) {
return (ConnectionAcquisitionMode) setting;
}
final String value = setting.toString();
if ( StringHelper.isEmpty( value ) ) {
return null;
}
return interpret( value );
}
} }

View File

@ -8,6 +8,8 @@ package org.hibernate;
import java.util.Locale; import java.util.Locale;
import org.hibernate.internal.util.StringHelper;
/** /**
* Defines the various policies by which Hibernate might release its underlying * Defines the various policies by which Hibernate might release its underlying
* JDBC connection. Inverse of {@link ConnectionAcquisitionMode}. * JDBC connection. Inverse of {@link ConnectionAcquisitionMode}.
@ -48,4 +50,26 @@ public enum ConnectionReleaseMode{
public static ConnectionReleaseMode parse(final String name) { public static ConnectionReleaseMode parse(final String name) {
return ConnectionReleaseMode.valueOf( name.toUpperCase(Locale.ROOT) ); return ConnectionReleaseMode.valueOf( name.toUpperCase(Locale.ROOT) );
} }
public static ConnectionReleaseMode interpret(Object setting) {
if ( setting == null ) {
return null;
}
if ( setting instanceof ConnectionReleaseMode ) {
return (ConnectionReleaseMode) setting;
}
final String value = setting.toString();
if ( StringHelper.isEmpty( value ) ) {
return null;
}
// here we disregard "auto"
if ( value.equalsIgnoreCase( "auto" ) ) {
return null;
}
return parse( value );
}
} }

View File

@ -7,7 +7,6 @@
package org.hibernate; package org.hibernate;
import java.sql.Connection; import java.sql.Connection;
import javax.persistence.spi.PersistenceUnitTransactionType;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.jdbc.spi.StatementInspector; import org.hibernate.resource.jdbc.spi.StatementInspector;
@ -92,30 +91,62 @@ public interface SessionBuilder<T extends SessionBuilder> {
* @param autoJoinTransactions Should JTA transactions be automatically joined * @param autoJoinTransactions Should JTA transactions be automatically joined
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*
* @see javax.persistence.SynchronizationType#SYNCHRONIZED
*/ */
T autoJoinTransactions(boolean autoJoinTransactions); T autoJoinTransactions(boolean autoJoinTransactions);
/** /**
* Should the session be automatically closed afterQuery transaction completion. * Should the session be automatically closed after transaction completion?
* *
* @param autoClose Should the session be automatically closed * @param autoClose Should the session be automatically closed
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
* *
* @deprecated Only integrations can specify autoClosing behavior of individual sessions. See * @see javax.persistence.PersistenceContextType
* {@link org.hibernate.engine.spi.SessionOwner}
*/ */
@Deprecated
T autoClose(boolean autoClose); T autoClose(boolean autoClose);
/**
* Should the session be automatically cleared on a failed transaction?
*
* @param autoClear Whether the Session should be automatically cleared
*
* @return {@code this}, for method chaining
*/
T autoClear(boolean autoClear);
/**
* Specify the initial FlushMode to use for the opened Session
*
* @param flushMode The initial FlushMode to use for the opened Session
*
* @return {@code this}, for method chaining
*
* @see javax.persistence.PersistenceContextType
*/
T flushMode(FlushMode flushMode);
/** /**
* Should the session be automatically flushed during the "beforeQuery completion" phase of transaction handling. * Should the session be automatically flushed during the "beforeQuery completion" phase of transaction handling.
* *
* @param flushBeforeCompletion Should the session be automatically flushed * @param flushBeforeCompletion Should the session be automatically flushed
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*
* @deprecated (since 5.2) use {@link #flushMode(FlushMode)} instead.
*/ */
T flushBeforeCompletion(boolean flushBeforeCompletion); @Deprecated
@SuppressWarnings("unchecked")
default T flushBeforeCompletion(boolean flushBeforeCompletion) {
if ( flushBeforeCompletion ) {
flushMode( FlushMode.ALWAYS );
}
else {
flushMode( FlushMode.MANUAL );
}
return (T) this;
}
/** /**
* Define the tenant identifier to be associated with the opened session. * Define the tenant identifier to be associated with the opened session.
@ -143,6 +174,4 @@ public interface SessionBuilder<T extends SessionBuilder> {
*/ */
T clearEventListeners(); T clearEventListeners();
T persistenceUnitTransactionType(PersistenceUnitTransactionType persistenceUnitTransactionType);
} }

View File

@ -63,21 +63,31 @@ public interface SharedSessionBuilder<T extends SharedSessionBuilder> extends Se
*/ */
T autoJoinTransactions(); T autoJoinTransactions();
/**
* Signifies that the FlushMode from the original session should be used to create the new session.
*
* @return {@code this}, for method chaining
*/
T flushMode();
/** /**
* Signifies that the autoClose flag from the original session should be used to create the new session. * Signifies that the autoClose flag from the original session should be used to create the new session.
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*
* @deprecated For same reasons as {@link SessionBuilder#autoClose(boolean)} was deprecated. However, shared
* session builders can use {@link #autoClose(boolean)} since they do not "inherit" the owner.
*/ */
@Deprecated
T autoClose(); T autoClose();
/** /**
* Signifies that the flushBeforeCompletion flag from the original session should be used to create the new session. * Signifies that the flushBeforeCompletion flag from the original session should be used to create the new session.
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*
* @deprecated (since 5.2) use {@link #flushMode()} instead.
*/ */
T flushBeforeCompletion(); @Deprecated
@SuppressWarnings("unchecked")
default T flushBeforeCompletion() {
flushMode();
return (T) this;
}
} }

View File

@ -46,12 +46,13 @@ import org.hibernate.engine.jdbc.env.spi.ExtractedDatabaseMetaData;
import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy; import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
import org.hibernate.internal.SessionFactoryImpl; import org.hibernate.internal.SessionFactoryImpl;
import org.hibernate.internal.log.DeprecationLogger;
import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.loader.BatchFetchStyle; import org.hibernate.loader.BatchFetchStyle;
import org.hibernate.proxy.EntityNotFoundDelegate; import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.jdbc.spi.StatementInspector; import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder; import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.tuple.entity.EntityTuplizer; import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.tuple.entity.EntityTuplizerFactory; import org.hibernate.tuple.entity.EntityTuplizerFactory;
@ -66,6 +67,7 @@ import static org.hibernate.cfg.AvailableSettings.BATCH_FETCH_STYLE;
import static org.hibernate.cfg.AvailableSettings.BATCH_VERSIONED_DATA; import static org.hibernate.cfg.AvailableSettings.BATCH_VERSIONED_DATA;
import static org.hibernate.cfg.AvailableSettings.CACHE_REGION_PREFIX; import static org.hibernate.cfg.AvailableSettings.CACHE_REGION_PREFIX;
import static org.hibernate.cfg.AvailableSettings.CHECK_NULLABILITY; import static org.hibernate.cfg.AvailableSettings.CHECK_NULLABILITY;
import static org.hibernate.cfg.AvailableSettings.CONNECTION_HANDLING;
import static org.hibernate.cfg.AvailableSettings.CUSTOM_ENTITY_DIRTINESS_STRATEGY; import static org.hibernate.cfg.AvailableSettings.CUSTOM_ENTITY_DIRTINESS_STRATEGY;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_BATCH_FETCH_SIZE; import static org.hibernate.cfg.AvailableSettings.DEFAULT_BATCH_FETCH_SIZE;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_ENTITY_MODE; import static org.hibernate.cfg.AvailableSettings.DEFAULT_ENTITY_MODE;
@ -587,7 +589,7 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement
true true
); );
this.flushBeforeCompletionEnabled = cfgService.getSetting( FLUSH_BEFORE_COMPLETION, BOOLEAN, false ); this.flushBeforeCompletionEnabled = cfgService.getSetting( FLUSH_BEFORE_COMPLETION, BOOLEAN, true );
this.autoCloseSessionEnabled = cfgService.getSetting( AUTO_CLOSE_SESSION, BOOLEAN, false ); this.autoCloseSessionEnabled = cfgService.getSetting( AUTO_CLOSE_SESSION, BOOLEAN, false );
this.statisticsEnabled = cfgService.getSetting( GENERATE_STATISTICS, BOOLEAN, false ); this.statisticsEnabled = cfgService.getSetting( GENERATE_STATISTICS, BOOLEAN, false );
@ -730,36 +732,73 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement
); );
this.jdbcFetchSize = ConfigurationHelper.getInteger( STATEMENT_FETCH_SIZE, configurationSettings ); this.jdbcFetchSize = ConfigurationHelper.getInteger( STATEMENT_FETCH_SIZE, configurationSettings );
final ConnectionAcquisitionMode connectionAcquisitionMode = ConnectionAcquisitionMode.interpret( this.connectionHandlingMode = interpretConnectionHandlingMode( configurationSettings, serviceRegistry );
ConfigurationHelper.getString(
ACQUIRE_CONNECTIONS,
configurationSettings,
ConnectionAcquisitionMode.AS_NEEDED.name()
)
);
final ConnectionReleaseMode connectionReleaseMode;
final String releaseModeName = ConfigurationHelper.getString( RELEASE_CONNECTIONS, configurationSettings, "auto" );
if ( "auto".equals( releaseModeName ) ) {
// nothing was specified (or someone happened to configure the "magic" value)
if ( connectionAcquisitionMode == ConnectionAcquisitionMode.IMMEDIATELY ) {
connectionReleaseMode = ConnectionReleaseMode.ON_CLOSE;
}
else {
connectionReleaseMode = serviceRegistry.getService( TransactionCoordinatorBuilder.class )
.getDefaultConnectionReleaseMode();
}
}
else {
connectionReleaseMode = ConnectionReleaseMode.parse( releaseModeName );
}
this.connectionHandlingMode = PhysicalConnectionHandlingMode.interpret( connectionAcquisitionMode, connectionReleaseMode );
this.commentsEnabled = ConfigurationHelper.getBoolean( USE_SQL_COMMENTS, configurationSettings ); this.commentsEnabled = ConfigurationHelper.getBoolean( USE_SQL_COMMENTS, configurationSettings );
this.preferUserTransaction = ConfigurationHelper.getBoolean( PREFER_USER_TRANSACTION, configurationSettings, false ); this.preferUserTransaction = ConfigurationHelper.getBoolean( PREFER_USER_TRANSACTION, configurationSettings, false );
} }
private PhysicalConnectionHandlingMode interpretConnectionHandlingMode(
Map configurationSettings,
StandardServiceRegistry serviceRegistry) {
final PhysicalConnectionHandlingMode specifiedHandlingMode = PhysicalConnectionHandlingMode.interpret(
configurationSettings.get( CONNECTION_HANDLING )
);
if ( specifiedHandlingMode != null ) {
return specifiedHandlingMode;
}
final TransactionCoordinatorBuilder transactionCoordinatorBuilder = serviceRegistry.getService( TransactionCoordinatorBuilder.class );
// see if the deprecated ConnectionAcquisitionMode/ConnectionReleaseMode were used..
final ConnectionAcquisitionMode specifiedAcquisitionMode = ConnectionAcquisitionMode.interpret(
configurationSettings.get( ACQUIRE_CONNECTIONS )
);
final ConnectionReleaseMode specifiedReleaseMode = ConnectionReleaseMode.interpret(
configurationSettings.get( RELEASE_CONNECTIONS )
);
if ( specifiedAcquisitionMode != null || specifiedReleaseMode != null ) {
return interpretConnectionHandlingMode( specifiedAcquisitionMode, specifiedReleaseMode, configurationSettings, transactionCoordinatorBuilder );
}
return transactionCoordinatorBuilder.getDefaultConnectionHandlingMode();
}
@Deprecated
private PhysicalConnectionHandlingMode interpretConnectionHandlingMode(
ConnectionAcquisitionMode specifiedAcquisitionMode,
ConnectionReleaseMode specifiedReleaseMode,
Map configurationSettings,
TransactionCoordinatorBuilder transactionCoordinatorBuilder) {
DeprecationLogger.DEPRECATION_LOGGER.logUseOfDeprecatedConnectionHandlingSettings();
final ConnectionAcquisitionMode effectiveAcquisitionMode = specifiedAcquisitionMode == null
? ConnectionAcquisitionMode.AS_NEEDED
: specifiedAcquisitionMode;
final ConnectionReleaseMode effectiveReleaseMode;
if ( specifiedReleaseMode == null ) {
// check the actual setting. If we get in here it *should* be "auto" or null
final String releaseModeName = ConfigurationHelper.getString( RELEASE_CONNECTIONS, configurationSettings, "auto" );
assert "auto".equalsIgnoreCase( releaseModeName );
// nothing was specified (or someone happened to configure the "magic" value)
if ( effectiveAcquisitionMode == ConnectionAcquisitionMode.IMMEDIATELY ) {
effectiveReleaseMode = ConnectionReleaseMode.ON_CLOSE;
}
else {
effectiveReleaseMode = transactionCoordinatorBuilder.getDefaultConnectionReleaseMode();
}
}
else {
effectiveReleaseMode = specifiedReleaseMode;
}
return PhysicalConnectionHandlingMode.interpret( effectiveAcquisitionMode, effectiveReleaseMode );
}
@Override @Override
public StandardServiceRegistry getServiceRegistry() { public StandardServiceRegistry getServiceRegistry() {
return serviceRegistry; return serviceRegistry;

View File

@ -86,9 +86,9 @@ import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
import org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy; import org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy;
import org.hibernate.hql.spi.id.local.LocalTemporaryTableBulkIdStrategy; import org.hibernate.hql.spi.id.local.LocalTemporaryTableBulkIdStrategy;
import org.hibernate.hql.spi.id.persistent.PersistentTableBulkIdStrategy; import org.hibernate.hql.spi.id.persistent.PersistentTableBulkIdStrategy;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl; import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl;
import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl; import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;

View File

@ -8,6 +8,8 @@ package org.hibernate.cfg;
import org.hibernate.boot.MetadataBuilder; import org.hibernate.boot.MetadataBuilder;
import org.hibernate.query.internal.ParameterMetadataImpl; import org.hibernate.query.internal.ParameterMetadataImpl;
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.tool.schema.SourceType; import org.hibernate.tool.schema.SourceType;
/** /**
@ -357,8 +359,8 @@ public interface AvailableSettings {
String SCHEMA_MANAGEMENT_TOOL = "hibernate.schema_management_tool"; String SCHEMA_MANAGEMENT_TOOL = "hibernate.schema_management_tool";
/** /**
* Names the implementation of {@link org.hibernate.resource.transaction.TransactionCoordinatorBuilder} to use for * Names the implementation of {@link TransactionCoordinatorBuilder} to use for
* creating {@link org.hibernate.resource.transaction.TransactionCoordinator} instances. * creating {@link TransactionCoordinator} instances.
* <p/> * <p/>
* Can be<ul> * Can be<ul>
* <li>TransactionCoordinatorBuilder instance</li> * <li>TransactionCoordinatorBuilder instance</li>
@ -706,7 +708,10 @@ public interface AvailableSettings {
* @see org.hibernate.ConnectionAcquisitionMode * @see org.hibernate.ConnectionAcquisitionMode
* *
* @since 5.1 * @since 5.1
*
* @deprecated (since 5.2) use {@link #CONNECTION_HANDLING} instead
*/ */
@Deprecated
String ACQUIRE_CONNECTIONS = "hibernate.connection.acquisition_mode"; String ACQUIRE_CONNECTIONS = "hibernate.connection.acquisition_mode";
/** /**
@ -714,9 +719,22 @@ public interface AvailableSettings {
* this or {@link #ACQUIRE_CONNECTIONS}, not both * this or {@link #ACQUIRE_CONNECTIONS}, not both
* *
* @see org.hibernate.ConnectionReleaseMode * @see org.hibernate.ConnectionReleaseMode
*
* @deprecated (since 5.2) use {@link #CONNECTION_HANDLING} instead
*/ */
@Deprecated
String RELEASE_CONNECTIONS = "hibernate.connection.release_mode"; String RELEASE_CONNECTIONS = "hibernate.connection.release_mode";
/**
* Specifies how Hibernate should manage JDBC connections in terms of acquiring and releasing.
* Supersedes {@link #ACQUIRE_CONNECTIONS} and {@link #RELEASE_CONNECTIONS}
*
* @see org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode
*
* @since 5.2
*/
String CONNECTION_HANDLING = "hibernate.connection.handling_mode";
/** /**
* Context scoping impl for {@link org.hibernate.SessionFactory#getCurrentSession()} processing. * Context scoping impl for {@link org.hibernate.SessionFactory#getCurrentSession()} processing.
*/ */

View File

@ -484,6 +484,7 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator {
* *
* @throws IOException Trouble accessing the stream * @throws IOException Trouble accessing the stream
*/ */
@Override
public void serialize(ObjectOutputStream oos) throws IOException { public void serialize(ObjectOutputStream oos) throws IOException {
if ( ! isReadyForSerialization() ) { if ( ! isReadyForSerialization() ) {
throw new HibernateException( "Cannot serialize Session while connected" ); throw new HibernateException( "Cannot serialize Session while connected" );

View File

@ -6,6 +6,8 @@
*/ */
package org.hibernate.engine.jdbc.spi; package org.hibernate.engine.jdbc.spi;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable; import java.io.Serializable;
import java.sql.Connection; import java.sql.Connection;
import java.sql.Statement; import java.sql.Statement;
@ -190,4 +192,7 @@ public interface JdbcCoordinator extends Serializable, TransactionCoordinatorOwn
default ResourceRegistry getResourceRegistry() { default ResourceRegistry getResourceRegistry() {
return getLogicalConnection().getResourceRegistry(); return getLogicalConnection().getResourceRegistry();
} }
void serialize(ObjectOutputStream objectOutputStream) throws IOException;
} }

View File

@ -19,14 +19,12 @@ import javax.persistence.FlushModeType;
import javax.persistence.LockModeType; import javax.persistence.LockModeType;
import javax.persistence.PersistenceException; import javax.persistence.PersistenceException;
import javax.persistence.StoredProcedureQuery; import javax.persistence.StoredProcedureQuery;
import javax.persistence.SynchronizationType;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaDelete; import javax.persistence.criteria.CriteriaDelete;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.CriteriaUpdate; import javax.persistence.criteria.CriteriaUpdate;
import javax.persistence.criteria.Selection; import javax.persistence.criteria.Selection;
import javax.persistence.metamodel.Metamodel; import javax.persistence.metamodel.Metamodel;
import javax.persistence.spi.PersistenceUnitTransactionType;
import org.hibernate.CacheMode; import org.hibernate.CacheMode;
import org.hibernate.Criteria; import org.hibernate.Criteria;
@ -65,7 +63,7 @@ import org.hibernate.procedure.ProcedureCall;
import org.hibernate.query.spi.NativeQueryImplementor; import org.hibernate.query.spi.NativeQueryImplementor;
import org.hibernate.query.spi.QueryImplementor; import org.hibernate.query.spi.QueryImplementor;
import org.hibernate.resource.jdbc.spi.JdbcSessionContext; import org.hibernate.resource.jdbc.spi.JdbcSessionContext;
import org.hibernate.resource.transaction.TransactionCoordinator; import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.hibernate.stat.SessionStatistics; import org.hibernate.stat.SessionStatistics;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor; import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
@ -142,11 +140,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
delegate.setAutoClear( enabled ); delegate.setAutoClear( enabled );
} }
@Override
public void disableTransactionAutoJoin() {
delegate.disableTransactionAutoJoin();
}
@Override @Override
public boolean isTransactionInProgress() { public boolean isTransactionInProgress() {
return delegate.isTransactionInProgress(); return delegate.isTransactionInProgress();
@ -1116,16 +1109,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
delegate.addEventListeners( listeners ); delegate.addEventListeners( listeners );
} }
@Override
public PersistenceUnitTransactionType getTransactionType() {
return delegate.getTransactionType();
}
@Override
public SynchronizationType getSynchronizationType() {
return delegate.getSynchronizationType();
}
@Override @Override
public boolean isFlushBeforeCompletionEnabled() { public boolean isFlushBeforeCompletionEnabled() {
return delegate.isFlushBeforeCompletionEnabled(); return delegate.isFlushBeforeCompletionEnabled();

View File

@ -9,12 +9,10 @@ package org.hibernate.engine.spi;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.persistence.SynchronizationType;
import javax.persistence.criteria.CriteriaDelete; import javax.persistence.criteria.CriteriaDelete;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.CriteriaUpdate; import javax.persistence.criteria.CriteriaUpdate;
import javax.persistence.criteria.Selection; import javax.persistence.criteria.Selection;
import javax.persistence.spi.PersistenceUnitTransactionType;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.Session; import org.hibernate.Session;
@ -22,6 +20,8 @@ import org.hibernate.jpa.spi.HibernateEntityManagerImplementor;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.query.spi.NativeQueryImplementor; import org.hibernate.query.spi.NativeQueryImplementor;
import org.hibernate.query.spi.QueryImplementor; import org.hibernate.query.spi.QueryImplementor;
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
/** /**
* Defines the "internal contract" for {@link Session} and other parts of Hibernate such as * Defines the "internal contract" for {@link Session} and other parts of Hibernate such as
@ -34,8 +34,8 @@ import org.hibernate.query.spi.QueryImplementor;
* {@link org.hibernate.resource.jdbc.spi.JdbcSessionContext} delegate * {@link org.hibernate.resource.jdbc.spi.JdbcSessionContext} delegate
* </li> * </li>
* <li> * <li>
* {@link org.hibernate.resource.transaction.TransactionCoordinatorBuilder.TransactionCoordinatorOptions} * {@link TransactionCoordinatorBuilder.Options}
* to drive the creation of the {@link org.hibernate.resource.transaction.TransactionCoordinator} delegate * to drive the creation of the {@link TransactionCoordinator} delegate
* </li> * </li>
* <li> * <li>
* {@link org.hibernate.engine.jdbc.LobCreationContext} to act as the context for JDBC LOB instance creation * {@link org.hibernate.engine.jdbc.LobCreationContext} to act as the context for JDBC LOB instance creation
@ -54,13 +54,14 @@ import org.hibernate.query.spi.QueryImplementor;
*/ */
public interface SessionImplementor public interface SessionImplementor
extends Session, SharedSessionContractImplementor, HibernateEntityManagerImplementor { extends Session, SharedSessionContractImplementor, HibernateEntityManagerImplementor {
PersistenceUnitTransactionType getTransactionType();
SynchronizationType getSynchronizationType();
@Override @Override
SessionFactoryImplementor getSessionFactory(); SessionFactoryImplementor getSessionFactory();
// todo : isFlushBeforeCompletionEnabled is based on another value (SynchronizationType?), find usages of this and replace with that /**
* @deprecated (since 5.2) use {@link #getHibernateFlushMode()} instead.
*/
@Deprecated
boolean isFlushBeforeCompletionEnabled(); boolean isFlushBeforeCompletionEnabled();
ActionQueue getActionQueue(); ActionQueue getActionQueue();

View File

@ -33,7 +33,9 @@ import org.hibernate.loader.custom.CustomQuery;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.query.spi.QueryProducerImplementor; import org.hibernate.query.spi.QueryProducerImplementor;
import org.hibernate.resource.jdbc.spi.JdbcSessionOwner; import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder.TransactionCoordinatorOptions; import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder.Options;
import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.WrapperOptions;
/** /**
@ -48,10 +50,10 @@ import org.hibernate.type.descriptor.WrapperOptions;
* Can therefor be used to construct a JdbcCoordinator, which (for now) models a "JDBC session" * Can therefor be used to construct a JdbcCoordinator, which (for now) models a "JDBC session"
* </li> * </li>
* <li> * <li>
* {@link org.hibernate.resource.transaction.TransactionCoordinatorBuilder.TransactionCoordinatorOptions} * {@link Options}
* to drive the creation of the {@link org.hibernate.resource.transaction.TransactionCoordinator} delegate. * to drive the creation of the {@link TransactionCoordinator} delegate.
* This allows it to be passed along to * This allows it to be passed along to
* {@link org.hibernate.resource.transaction.TransactionCoordinatorBuilder#buildTransactionCoordinator} * {@link TransactionCoordinatorBuilder#buildTransactionCoordinator}
* </li> * </li>
* <li> * <li>
* {@link org.hibernate.engine.jdbc.LobCreationContext} to act as the context for JDBC LOB instance creation * {@link org.hibernate.engine.jdbc.LobCreationContext} to act as the context for JDBC LOB instance creation
@ -66,7 +68,7 @@ import org.hibernate.type.descriptor.WrapperOptions;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public interface SharedSessionContractImplementor public interface SharedSessionContractImplementor
extends SharedSessionContract, JdbcSessionOwner, TransactionCoordinatorOptions, LobCreationContext, WrapperOptions, QueryProducerImplementor, Serializable { extends SharedSessionContract, JdbcSessionOwner, Options, LobCreationContext, WrapperOptions, QueryProducerImplementor {
// todo : this is the shared contract between Session and StatelessSession, but it defines methods that StatelessSession does not implement // todo : this is the shared contract between Session and StatelessSession, but it defines methods that StatelessSession does not implement
// (it just throws UnsupportedOperationException). To me it seems like it is better to properly isolate those methods // (it just throws UnsupportedOperationException). To me it seems like it is better to properly isolate those methods
@ -196,19 +198,6 @@ public interface SharedSessionContractImplementor
*/ */
long getTimestamp(); long getTimestamp();
/**
* Disable automatic transaction joining. The really only has any effect for CMT transactions. The default
* Hibernate behavior is to auto join any active JTA transaction (register {@link javax.transaction.Synchronization}).
* JPA however defines an explicit join transaction operation.
* <p/>
* See javax.persistence.EntityManager#joinTransaction
*
* @deprecated (since 5.2) (1) this is not supported in StatelessSession and (2) this is based
* on SynchronizationType and in Session hierarchy we should just leverage {@link SessionImplementor#getSynchronizationType()}
*/
@Deprecated
void disableTransactionAutoJoin();
/** /**
* Does this <tt>Session</tt> have an active Hibernate transaction * Does this <tt>Session</tt> have an active Hibernate transaction
* or is there a JTA transaction in progress? * or is there a JTA transaction in progress?

View File

@ -12,12 +12,12 @@ import org.hibernate.HibernateException;
import org.hibernate.TransactionException; import org.hibernate.TransactionException;
import org.hibernate.engine.transaction.spi.TransactionImplementor; import org.hibernate.engine.transaction.spi.TransactionImplementor;
import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreLogging;
import org.hibernate.resource.transaction.TransactionCoordinator; import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.hibernate.resource.transaction.spi.TransactionStatus; import org.hibernate.resource.transaction.spi.TransactionStatus;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import static org.hibernate.resource.transaction.TransactionCoordinator.TransactionDriver; import static org.hibernate.resource.transaction.spi.TransactionCoordinator.TransactionDriver;
/** /**
* @author Andrea Boriero * @author Andrea Boriero

View File

@ -12,7 +12,7 @@ import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.event.spi.EventSource; import org.hibernate.event.spi.EventSource;
import org.hibernate.resource.jdbc.spi.JdbcSessionOwner; import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder.TransactionCoordinatorOptions; import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder.Options;
import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.WrapperOptions;
/** /**
@ -22,7 +22,8 @@ import org.hibernate.type.descriptor.WrapperOptions;
*/ */
public abstract class AbstractSessionImpl public abstract class AbstractSessionImpl
extends AbstractSharedSessionContract extends AbstractSharedSessionContract
implements Serializable, SharedSessionContractImplementor, JdbcSessionOwner, SessionImplementor, EventSource, TransactionCoordinatorOptions, WrapperOptions { implements Serializable, SharedSessionContractImplementor, JdbcSessionOwner, SessionImplementor, EventSource,
Options, WrapperOptions {
private static final CoreMessageLogger log = CoreLogging.messageLogger( AbstractSessionImpl.class ); private static final CoreMessageLogger log = CoreLogging.messageLogger( AbstractSessionImpl.class );
@ -30,7 +31,4 @@ public abstract class AbstractSessionImpl
super( factory, options ); super( factory, options );
} }
@Override
public abstract boolean shouldAutoJoinTransaction();
} }

View File

@ -20,13 +20,10 @@ import javax.persistence.LockTimeoutException;
import javax.persistence.NoResultException; import javax.persistence.NoResultException;
import javax.persistence.NonUniqueResultException; import javax.persistence.NonUniqueResultException;
import javax.persistence.OptimisticLockException; import javax.persistence.OptimisticLockException;
import javax.persistence.PersistenceContextType;
import javax.persistence.PersistenceException; import javax.persistence.PersistenceException;
import javax.persistence.PessimisticLockException; import javax.persistence.PessimisticLockException;
import javax.persistence.QueryTimeoutException; import javax.persistence.QueryTimeoutException;
import javax.persistence.SynchronizationType;
import javax.persistence.Tuple; import javax.persistence.Tuple;
import javax.persistence.spi.PersistenceUnitTransactionType;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.CacheMode; import org.hibernate.CacheMode;
@ -96,11 +93,10 @@ import org.hibernate.query.internal.QueryImpl;
import org.hibernate.query.spi.NativeQueryImplementor; import org.hibernate.query.spi.NativeQueryImplementor;
import org.hibernate.query.spi.QueryImplementor; import org.hibernate.query.spi.QueryImplementor;
import org.hibernate.resource.jdbc.spi.JdbcSessionContext; import org.hibernate.resource.jdbc.spi.JdbcSessionContext;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.jdbc.spi.StatementInspector; import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.resource.transaction.TransactionCoordinator;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
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.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.spi.TransactionStatus; import org.hibernate.resource.transaction.spi.TransactionStatus;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor; import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
@ -126,36 +122,28 @@ import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
public abstract class AbstractSharedSessionContract implements SharedSessionContractImplementor { public abstract class AbstractSharedSessionContract implements SharedSessionContractImplementor {
private static final EntityManagerMessageLogger log = HEMLogging.messageLogger( SessionImpl.class ); private static final EntityManagerMessageLogger log = HEMLogging.messageLogger( SessionImpl.class );
private final SessionFactoryImpl factory; private transient SessionFactoryImpl factory;
private final String tenantIdentifier; private final String tenantIdentifier;
private final UUID sessionIdentifier; private final UUID sessionIdentifier;
// todo : (5.2) review synchronizationType, persistenceContextType, transactionType usage
private transient PhysicalConnectionHandlingMode connectionHandlingMode;
// SynchronizationType -> should we auto enlist in transactions
private transient SynchronizationType synchronizationType;
// PersistenceUnitTransactionType -> what type of TransactionCoordinator(Builder) to use;
// according to JPA should technically also disallow access to Transaction object for
// JTA environments
private transient PersistenceUnitTransactionType transactionType;
// PersistenceContextType -> influences FlushMode and 'autoClose'
private transient PersistenceContextType persistenceContextType;
private final boolean isTransactionCoordinatorShared; private final boolean isTransactionCoordinatorShared;
private final TransactionCoordinator transactionCoordinator;
private final JdbcCoordinator jdbcCoordinator;
private final Interceptor interceptor; private final Interceptor interceptor;
private final JdbcSessionContext jdbcSessionContext;
private final EntityNameResolver entityNameResolver;
private FlushMode flushMode; private FlushMode flushMode;
private boolean autoJoinTransactions;
private CacheMode cacheMode; private CacheMode cacheMode;
private boolean closed; private boolean closed;
// transient & non-final for Serialization purposes - ugh
private transient SessionEventListenerManagerImpl sessionEventsManager = new SessionEventListenerManagerImpl(); private transient SessionEventListenerManagerImpl sessionEventsManager = new SessionEventListenerManagerImpl();
private transient EntityNameResolver entityNameResolver;
private transient JdbcConnectionAccess jdbcConnectionAccess; private transient JdbcConnectionAccess jdbcConnectionAccess;
private transient JdbcSessionContext jdbcSessionContext;
private transient JdbcCoordinator jdbcCoordinator;
private transient TransactionImplementor currentHibernateTransaction; private transient TransactionImplementor currentHibernateTransaction;
private transient TransactionCoordinator transactionCoordinator;
private transient Boolean useStreamForLobBinding; private transient Boolean useStreamForLobBinding;
private transient long timestamp; private transient long timestamp;
@ -164,9 +152,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
this.sessionIdentifier = StandardRandomStrategy.INSTANCE.generateUUID( null ); this.sessionIdentifier = StandardRandomStrategy.INSTANCE.generateUUID( null );
this.timestamp = factory.getCache().getRegionFactory().nextTimestamp(); this.timestamp = factory.getCache().getRegionFactory().nextTimestamp();
this.transactionType = options.getPersistenceUnitTransactionType(); this.flushMode = options.getInitialSessionFlushMode();
this.synchronizationType = options.getSynchronizationType();
this.persistenceContextType = PersistenceContextType.TRANSACTION;
this.tenantIdentifier = options.getTenantIdentifier(); this.tenantIdentifier = options.getTenantIdentifier();
if ( MultiTenancyStrategy.NONE == factory.getSettings().getMultiTenancyStrategy() ) { if ( MultiTenancyStrategy.NONE == factory.getSettings().getMultiTenancyStrategy() ) {
@ -201,11 +187,12 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
// todo : "wrap" the transaction to no-op cmmit/rollback attempts? // todo : "wrap" the transaction to no-op cmmit/rollback attempts?
this.currentHibernateTransaction = sharedOptions.getTransaction(); this.currentHibernateTransaction = sharedOptions.getTransaction();
if ( sharedOptions.getSynchronizationType() != null ) { if ( sharedOptions.shouldAutoJoinTransactions() ) {
log.debug( log.debug(
"Session creation specified 'autoJoinTransactions', which is invalid in conjunction " + "Session creation specified 'autoJoinTransactions', which is invalid in conjunction " +
"with sharing JDBC connection between sessions; ignoring" "with sharing JDBC connection between sessions; ignoring"
); );
autoJoinTransactions = false;
} }
if ( sharedOptions.getPhysicalConnectionHandlingMode() != this.jdbcCoordinator.getLogicalConnection().getConnectionHandlingMode() ) { if ( sharedOptions.getPhysicalConnectionHandlingMode() != this.jdbcCoordinator.getLogicalConnection().getConnectionHandlingMode() ) {
log.debug( log.debug(
@ -218,6 +205,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
} }
else { else {
this.isTransactionCoordinatorShared = false; this.isTransactionCoordinatorShared = false;
this.autoJoinTransactions = options.shouldAutoJoinTransactions();
this.jdbcCoordinator = new JdbcCoordinatorImpl( options.getConnection(), this ); this.jdbcCoordinator = new JdbcCoordinatorImpl( options.getConnection(), this );
this.transactionCoordinator = factory.getServiceRegistry() this.transactionCoordinator = factory.getServiceRegistry()
@ -232,6 +220,11 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
protected void addSharedSessionTransactionObserver(TransactionCoordinator transactionCoordinator) { protected void addSharedSessionTransactionObserver(TransactionCoordinator transactionCoordinator) {
} }
@Override
public boolean shouldAutoJoinTransaction() {
return autoJoinTransactions;
}
private Interceptor interpret(Interceptor interceptor) { private Interceptor interpret(Interceptor interceptor) {
return interceptor == null ? EmptyInterceptor.INSTANCE : interceptor; return interceptor == null ? EmptyInterceptor.INSTANCE : interceptor;
} }
@ -290,24 +283,6 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
return tenantIdentifier; return tenantIdentifier;
} }
public SynchronizationType getSynchronizationType() {
return synchronizationType;
}
public PersistenceUnitTransactionType getTransactionType() {
return transactionType;
}
public PersistenceContextType getPersistenceContextType() {
return persistenceContextType;
}
@Override
public void disableTransactionAutoJoin() {
checkOpen();
synchronizationType = SynchronizationType.UNSYNCHRONIZED;
}
@Override @Override
public long getTimestamp() { public long getTimestamp() {
return timestamp; return timestamp;
@ -1170,7 +1145,8 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
return scrollCustomQuery( getNativeQueryPlan( spec ).getCustomQuery(), queryParameters ); return scrollCustomQuery( getNativeQueryPlan( spec ).getCustomQuery(), queryParameters );
} }
protected void writeObject(ObjectOutputStream oos) throws IOException { @SuppressWarnings("unused")
private void writeObject(ObjectOutputStream oos) throws IOException {
log.trace( "Serializing " + getClass().getSimpleName() + " [" ); log.trace( "Serializing " + getClass().getSimpleName() + " [" );
if ( !jdbcCoordinator.isReadyForSerialization() ) { if ( !jdbcCoordinator.isReadyForSerialization() ) {
@ -1179,6 +1155,10 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
throw new IllegalStateException( "Cannot serialize " + getClass().getSimpleName() + " [" + getSessionIdentifier() + "] while connected" ); throw new IllegalStateException( "Cannot serialize " + getClass().getSimpleName() + " [" + getSessionIdentifier() + "] while connected" );
} }
if ( isTransactionCoordinatorShared ) {
throw new IllegalStateException( "Cannot serialize " + getClass().getSimpleName() + " [" + getSessionIdentifier() + "] as it has a shared TransactionCoordinator" );
}
// todo : (5.2) come back and review serialization plan... // todo : (5.2) come back and review serialization plan...
// this was done quickly during initial HEM consolidation into CORE and is likely not perfect :) // this was done quickly during initial HEM consolidation into CORE and is likely not perfect :)
// //
@ -1190,10 +1170,14 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Step 2 :: write transient state... // Step 2 :: write transient state...
// -- none that we want to serialize atm (see concurrent access discussion) // -- see concurrent access discussion
factory.serialize( oos );
oos.writeObject( jdbcSessionContext.getStatementInspector() );
jdbcCoordinator.serialize( oos );
} }
protected void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException, SQLException { private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException, SQLException {
log.trace( "Deserializing " + getClass().getSimpleName() ); log.trace( "Deserializing " + getClass().getSimpleName() );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -1202,7 +1186,16 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Step 2 :: read back transient state... // Step 2 :: read back transient state...
// -- again none, see above // -- see above
factory = SessionFactoryImpl.deserialize( ois );
jdbcSessionContext = new JdbcSessionContextImpl( this, (StatementInspector) ois.readObject() );
jdbcCoordinator = JdbcCoordinatorImpl.deserialize( ois, this );
this.transactionCoordinator = factory.getServiceRegistry()
.getService( TransactionCoordinatorBuilder.class )
.buildTransactionCoordinator( jdbcCoordinator, this );
entityNameResolver = new CoordinatingEntityNameResolver( factory, interceptor );
} }
} }

View File

@ -7,9 +7,8 @@
package org.hibernate.internal; package org.hibernate.internal;
import java.sql.Connection; import java.sql.Connection;
import javax.persistence.SynchronizationType;
import javax.persistence.spi.PersistenceUnitTransactionType;
import org.hibernate.FlushMode;
import org.hibernate.Interceptor; import org.hibernate.Interceptor;
import org.hibernate.engine.spi.SessionOwner; import org.hibernate.engine.spi.SessionOwner;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
@ -25,22 +24,13 @@ public interface SessionCreationOptions {
// todo : (5.2) review this. intended as a consolidation of the options needed to create a Session // todo : (5.2) review this. intended as a consolidation of the options needed to create a Session
// comes from building a Session and a EntityManager // comes from building a Session and a EntityManager
/** boolean shouldAutoJoinTransactions();
* Access to the SessionOwner, which defines the contract for things that can wrap a Session
*
* @return The SessionOwner
*
* @deprecated since 6.0 SessionOwner is no longer pertinent due to the
* hibernate-entitymanager -> hibernate-core consolidation
*/
@Deprecated
SessionOwner getSessionOwner();
ExceptionMapper getExceptionMapper(); FlushMode getInitialSessionFlushMode();
AfterCompletionAction getAfterCompletionAction(); boolean shouldAutoClose();
ManagedFlushChecker getManagedFlushChecker(); boolean shouldAutoClear();
Connection getConnection(); Connection getConnection();
@ -52,15 +42,25 @@ public interface SessionCreationOptions {
String getTenantIdentifier(); String getTenantIdentifier();
PersistenceUnitTransactionType getPersistenceUnitTransactionType();
SynchronizationType getSynchronizationType(); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// deprecations
boolean isClearStateOnCloseEnabled(); /**
* Access to the SessionOwner, which defines the contract for things that can wrap a Session
*
* @return The SessionOwner
*
* @deprecated (since 5,2) SessionOwner is no longer pertinent due to the
* hibernate-entitymanager -> hibernate-core consolidation
*/
@Deprecated
SessionOwner getSessionOwner();
boolean isFlushBeforeCompletionEnabled(); ExceptionMapper getExceptionMapper();
AfterCompletionAction getAfterCompletionAction();
ManagedFlushChecker getManagedFlushChecker();
// not sure of these are needed
// boolean isAutoCloseSessionEnabled();
// PersistenceContextType getPersistenceContextType();
} }

View File

@ -23,7 +23,7 @@ import java.util.concurrent.ConcurrentMap;
import javax.naming.Reference; import javax.naming.Reference;
import javax.naming.StringRefAddr; import javax.naming.StringRefAddr;
import javax.persistence.EntityGraph; import javax.persistence.EntityGraph;
import javax.persistence.EntityManager; import javax.persistence.PersistenceContextType;
import javax.persistence.PersistenceUnitUtil; import javax.persistence.PersistenceUnitUtil;
import javax.persistence.Query; import javax.persistence.Query;
import javax.persistence.SynchronizationType; import javax.persistence.SynchronizationType;
@ -36,6 +36,7 @@ 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;
import org.hibernate.FlushMode;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.Interceptor; import org.hibernate.Interceptor;
import org.hibernate.MappingException; import org.hibernate.MappingException;
@ -107,6 +108,7 @@ import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.resource.transaction.backend.jta.internal.synchronization.AfterCompletionAction; import org.hibernate.resource.transaction.backend.jta.internal.synchronization.AfterCompletionAction;
import org.hibernate.resource.transaction.backend.jta.internal.synchronization.ExceptionMapper; import org.hibernate.resource.transaction.backend.jta.internal.synchronization.ExceptionMapper;
import org.hibernate.resource.transaction.backend.jta.internal.synchronization.ManagedFlushChecker; import org.hibernate.resource.transaction.backend.jta.internal.synchronization.ManagedFlushChecker;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.secure.spi.GrantedPermission; import org.hibernate.secure.spi.GrantedPermission;
import org.hibernate.secure.spi.JaccPermissionDeclarations; import org.hibernate.secure.spi.JaccPermissionDeclarations;
import org.hibernate.secure.spi.JaccService; import org.hibernate.secure.spi.JaccService;
@ -553,24 +555,60 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
return null; return null;
} }
// todo : (5.2) review synchronizationType, persistenceContextType, transactionType usage
// SynchronizationType -> should we auto enlist in transactions
private transient SynchronizationType synchronizationType;
// PersistenceContextType -> influences FlushMode and 'autoClose'
private transient PersistenceContextType persistenceContextType;
@Override @Override
public EntityManager createEntityManager() { public Session createEntityManager() {
return null; return buildEntityManager( SynchronizationType.SYNCHRONIZED, Collections.emptyMap() );
}
private Session buildEntityManager(SynchronizationType synchronizationType, Map map) {
SessionBuilderImplementor builder = withOptions();
if ( synchronizationType == SynchronizationType.SYNCHRONIZED ) {
builder.autoJoinTransactions( true );
}
else {
builder.autoJoinTransactions( false );
}
return builder.openSession();
} }
@Override @Override
public EntityManager createEntityManager(Map map) { public Session createEntityManager(Map map) {
return null; return buildEntityManager( SynchronizationType.SYNCHRONIZED, map );
} }
@Override @Override
public EntityManager createEntityManager(SynchronizationType synchronizationType) { public Session createEntityManager(SynchronizationType synchronizationType) {
return null; errorIfResourceLocalDueToExplicitSynchronizationType();
return buildEntityManager( synchronizationType, Collections.emptyMap() );
}
private void errorIfResourceLocalDueToExplicitSynchronizationType() {
// JPA requires that we throw IllegalStateException in cases where:
// 1) the PersistenceUnitTransactionType (TransactionCoordinator) is non-JTA
// 2) an explicit SynchronizationType is specified
if ( !getServiceRegistry().getService( TransactionCoordinatorBuilder.class ).isJta() ) {
throw new IllegalStateException(
"Illegal attempt to specify a SynchronizationType when building an EntityManager from a " +
"EntityManagerFactory defined as RESOURCE_LOCAL (as opposed to JTA)"
);
}
} }
@Override @Override
public EntityManager createEntityManager(SynchronizationType synchronizationType, Map map) { public Session createEntityManager(SynchronizationType synchronizationType, Map map) {
return null; errorIfResourceLocalDueToExplicitSynchronizationType();
return buildEntityManager( synchronizationType, map );
} }
@Override @Override
@ -884,9 +922,10 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
private StatementInspector statementInspector; private StatementInspector statementInspector;
private Connection connection; private Connection connection;
private PhysicalConnectionHandlingMode connectionHandlingMode; private PhysicalConnectionHandlingMode connectionHandlingMode;
private boolean autoClose;
private boolean autoJoinTransactions = true; private boolean autoJoinTransactions = true;
private boolean flushBeforeCompletion; private FlushMode flushMode;
private boolean autoClose;
private boolean autoClear;
private String tenantIdentifier; private String tenantIdentifier;
private List<SessionEventListener> listeners; private List<SessionEventListener> listeners;
@ -902,7 +941,9 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
this.statementInspector = sessionFactory.getSessionFactoryOptions().getStatementInspector(); this.statementInspector = sessionFactory.getSessionFactoryOptions().getStatementInspector();
this.connectionHandlingMode = sessionFactory.getSessionFactoryOptions().getPhysicalConnectionHandlingMode(); this.connectionHandlingMode = sessionFactory.getSessionFactoryOptions().getPhysicalConnectionHandlingMode();
this.autoClose = sessionFactory.getSessionFactoryOptions().isAutoCloseSessionEnabled(); this.autoClose = sessionFactory.getSessionFactoryOptions().isAutoCloseSessionEnabled();
this.flushBeforeCompletion = sessionFactory.getSessionFactoryOptions().isFlushBeforeCompletionEnabled(); this.flushMode = sessionFactory.getSessionFactoryOptions().isFlushBeforeCompletionEnabled()
? FlushMode.AUTO
: FlushMode.MANUAL;
if ( sessionFactory.getCurrentTenantIdentifierResolver() != null ) { if ( sessionFactory.getCurrentTenantIdentifierResolver() != null ) {
tenantIdentifier = sessionFactory.getCurrentTenantIdentifierResolver().resolveCurrentTenantIdentifier(); tenantIdentifier = sessionFactory.getCurrentTenantIdentifierResolver().resolveCurrentTenantIdentifier();
@ -952,6 +993,26 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
: null; : null;
} }
@Override
public boolean shouldAutoJoinTransactions() {
return autoJoinTransactions;
}
@Override
public FlushMode getInitialSessionFlushMode() {
return flushMode;
}
@Override
public boolean shouldAutoClose() {
return autoClose;
}
@Override
public boolean shouldAutoClear() {
return autoClear;
}
@Override @Override
public Connection getConnection() { public Connection getConnection() {
return connection; return connection;
@ -995,26 +1056,6 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
return tenantIdentifier; return tenantIdentifier;
} }
@Override
public PersistenceUnitTransactionType getPersistenceUnitTransactionType() {
return persistenceUnitTransactionType;
}
@Override
public SynchronizationType getSynchronizationType() {
return autoJoinTransactions ? SynchronizationType.SYNCHRONIZED : SynchronizationType.UNSYNCHRONIZED;
}
@Override
public boolean isClearStateOnCloseEnabled() {
return autoClose;
}
@Override
public boolean isFlushBeforeCompletionEnabled() {
return flushBeforeCompletion;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// SessionBuilder // SessionBuilder
@ -1103,8 +1144,15 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public T flushBeforeCompletion(boolean flushBeforeCompletion) { public T autoClear(boolean autoClear) {
this.flushBeforeCompletion = flushBeforeCompletion; this.autoClear = autoClear;
return (T) this;
}
@Override
@SuppressWarnings("unchecked")
public T flushMode(FlushMode flushMode) {
this.flushMode = flushMode;
return (T) this; return (T) this;
} }
@ -1128,13 +1176,6 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
listeners.clear(); listeners.clear();
return (T) this; return (T) this;
} }
@Override
@SuppressWarnings("unchecked")
public T persistenceUnitTransactionType(PersistenceUnitTransactionType persistenceUnitTransactionType) {
this.persistenceUnitTransactionType = persistenceUnitTransactionType;
return (T) this;
}
} }
public static class StatelessSessionBuilderImpl implements StatelessSessionBuilder, SessionCreationOptions { public static class StatelessSessionBuilderImpl implements StatelessSessionBuilder, SessionCreationOptions {
@ -1168,23 +1209,23 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
} }
@Override @Override
public SessionOwner getSessionOwner() { public boolean shouldAutoJoinTransactions() {
return null; return true;
} }
@Override @Override
public ExceptionMapper getExceptionMapper() { public FlushMode getInitialSessionFlushMode() {
return null; return FlushMode.ALWAYS;
} }
@Override @Override
public AfterCompletionAction getAfterCompletionAction() { public boolean shouldAutoClose() {
return null; return false;
} }
@Override @Override
public ManagedFlushChecker getManagedFlushChecker() { public boolean shouldAutoClear() {
return null; return false;
} }
@Override @Override
@ -1227,23 +1268,23 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
} }
@Override @Override
public PersistenceUnitTransactionType getPersistenceUnitTransactionType() { public SessionOwner getSessionOwner() {
return null; return null;
} }
@Override @Override
public SynchronizationType getSynchronizationType() { public ExceptionMapper getExceptionMapper() {
return null; return null;
} }
@Override @Override
public boolean isClearStateOnCloseEnabled() { public AfterCompletionAction getAfterCompletionAction() {
return false; return null;
} }
@Override @Override
public boolean isFlushBeforeCompletionEnabled() { public ManagedFlushChecker getManagedFlushChecker() {
return false; return null;
} }
} }

View File

@ -39,13 +39,11 @@ import javax.persistence.LockTimeoutException;
import javax.persistence.NoResultException; import javax.persistence.NoResultException;
import javax.persistence.NonUniqueResultException; import javax.persistence.NonUniqueResultException;
import javax.persistence.OptimisticLockException; import javax.persistence.OptimisticLockException;
import javax.persistence.PersistenceContextType;
import javax.persistence.PersistenceException; import javax.persistence.PersistenceException;
import javax.persistence.PessimisticLockException; import javax.persistence.PessimisticLockException;
import javax.persistence.PessimisticLockScope; import javax.persistence.PessimisticLockScope;
import javax.persistence.QueryTimeoutException; import javax.persistence.QueryTimeoutException;
import javax.persistence.StoredProcedureQuery; import javax.persistence.StoredProcedureQuery;
import javax.persistence.SynchronizationType;
import javax.persistence.TransactionRequiredException; import javax.persistence.TransactionRequiredException;
import javax.persistence.Tuple; import javax.persistence.Tuple;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
@ -53,17 +51,13 @@ import javax.persistence.criteria.CriteriaDelete;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.CriteriaUpdate; import javax.persistence.criteria.CriteriaUpdate;
import javax.persistence.criteria.Selection; import javax.persistence.criteria.Selection;
import javax.persistence.spi.PersistenceUnitTransactionType;
import org.hibernate.CacheMode; import org.hibernate.CacheMode;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.Criteria; import org.hibernate.Criteria;
import org.hibernate.EmptyInterceptor;
import org.hibernate.Filter; import org.hibernate.Filter;
import org.hibernate.FlushMode; import org.hibernate.FlushMode;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.IdentifierLoadAccess; import org.hibernate.IdentifierLoadAccess;
import org.hibernate.Interceptor;
import org.hibernate.LobHelper; import org.hibernate.LobHelper;
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.LockOptions; import org.hibernate.LockOptions;
@ -188,14 +182,12 @@ import org.hibernate.query.criteria.internal.expression.CompoundSelectionImpl;
import org.hibernate.query.internal.CollectionFilterImpl; import org.hibernate.query.internal.CollectionFilterImpl;
import org.hibernate.query.procedure.internal.StoredProcedureQueryImpl; import org.hibernate.query.procedure.internal.StoredProcedureQueryImpl;
import org.hibernate.query.spi.QueryImplementor; import org.hibernate.query.spi.QueryImplementor;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.resource.transaction.TransactionCoordinator;
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.backend.jta.internal.synchronization.AfterCompletionAction; import org.hibernate.resource.transaction.backend.jta.internal.synchronization.AfterCompletionAction;
import org.hibernate.resource.transaction.backend.jta.internal.synchronization.ExceptionMapper; import org.hibernate.resource.transaction.backend.jta.internal.synchronization.ExceptionMapper;
import org.hibernate.resource.transaction.backend.jta.internal.synchronization.ManagedFlushChecker; import org.hibernate.resource.transaction.backend.jta.internal.synchronization.ManagedFlushChecker;
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.hibernate.resource.transaction.spi.TransactionStatus; import org.hibernate.resource.transaction.spi.TransactionStatus;
import org.hibernate.stat.SessionStatistics; import org.hibernate.stat.SessionStatistics;
import org.hibernate.stat.internal.SessionStatisticsImpl; import org.hibernate.stat.internal.SessionStatisticsImpl;
@ -204,7 +196,6 @@ import static org.hibernate.cfg.AvailableSettings.JPA_LOCK_SCOPE;
import static org.hibernate.cfg.AvailableSettings.JPA_LOCK_TIMEOUT; import static org.hibernate.cfg.AvailableSettings.JPA_LOCK_TIMEOUT;
import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE; import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE;
import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_STORE_MODE; import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_STORE_MODE;
import static org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION;
/** /**
* Concrete implementation of a Session. * Concrete implementation of a Session.
@ -247,25 +238,21 @@ public final class SessionImpl
private transient LoadQueryInfluencers loadQueryInfluencers; private transient LoadQueryInfluencers loadQueryInfluencers;
// todo : (5.2) HEM always initialized this. Is that really needed?
private LockOptions lockOptions = new LockOptions();
private transient boolean autoClear;
private transient boolean autoClose;
private transient int dontFlushFromFind;
private transient ExceptionMapper exceptionMapper; private transient ExceptionMapper exceptionMapper;
private transient ManagedFlushChecker managedFlushChecker; private transient ManagedFlushChecker managedFlushChecker;
private transient AfterCompletionAction afterCompletionAction; private transient AfterCompletionAction afterCompletionAction;
// todo : (5.2) HEM always initialized this. Is that really needed?
private LockOptions lockOptions = new LockOptions();
// todo : (5.2) are these still really needed?
private transient boolean autoClear; //for EJB3
private transient boolean flushBeforeCompletionEnabled;
private transient boolean autoCloseSessionEnabled;
private transient int dontFlushFromFind;
private transient LoadEvent loadEvent; //cached LoadEvent instance private transient LoadEvent loadEvent; //cached LoadEvent instance
public SessionImpl(SessionFactoryImpl factory, SessionCreationOptions options) { public SessionImpl(SessionFactoryImpl factory, SessionCreationOptions options) {
super( factory, options ); super( factory, options );
@ -275,49 +262,17 @@ public final class SessionImpl
this.sessionOwner = options.getSessionOwner(); this.sessionOwner = options.getSessionOwner();
initializeFromSessionOwner( sessionOwner ); initializeFromSessionOwner( sessionOwner );
this.autoClear = options.isClearStateOnCloseEnabled(); this.autoClear = options.shouldAutoClear();
this.flushBeforeCompletionEnabled = options.isFlushBeforeCompletionEnabled(); this.autoClose = options.shouldAutoClose();
if ( options instanceof SharedSessionCreationOptions && ( (SharedSessionCreationOptions) options ).isTransactionCoordinatorShared() ) { if ( options instanceof SharedSessionCreationOptions && ( (SharedSessionCreationOptions) options ).isTransactionCoordinatorShared() ) {
final SharedSessionCreationOptions sharedOptions = (SharedSessionCreationOptions) options; final SharedSessionCreationOptions sharedOptions = (SharedSessionCreationOptions) options;
if ( sharedOptions.getTransactionCompletionProcesses() != null ) { if ( sharedOptions.getTransactionCompletionProcesses() != null ) {
actionQueue.setTransactionCompletionProcesses( sharedOptions.getTransactionCompletionProcesses(), true ); actionQueue.setTransactionCompletionProcesses( sharedOptions.getTransactionCompletionProcesses(), true );
} }
getTransactionCoordinator().addObserver(
new TransactionObserver() {
@Override
public void afterBegin() {
log.tracef( "TransactionObserver#afterBegin on Session [%s]", getSessionIdentifier() );
}
@Override
public void beforeCompletion() {
log.tracef( "TransactionObserver#beforeCompletion on Session [%s]", getSessionIdentifier() );
if ( isOpen() && flushBeforeCompletionEnabled ) {
SessionImpl.this.managedFlush();
}
actionQueue.beforeTransactionCompletion();
try {
getInterceptor().beforeTransactionCompletion( getTransaction() );
}
catch (Throwable t) {
log.exceptionInBeforeTransactionCompletionInterceptor( t );
}
}
@Override
public void afterCompletion(boolean successful, boolean delayed) {
log.tracef( "TransactionObserver#afterCompletion(%s, %s) on Session [%s]", successful, delayed, getSessionIdentifier() );
afterTransactionCompletion( successful, delayed );
}
}
);
} }
else { else {
this.autoCloseSessionEnabled = getPersistenceContextType() == PersistenceContextType.TRANSACTION this.autoClose = options.shouldAutoClose();
&& factory.getSessionFactoryOptions().isAutoCloseSessionEnabled();
} }
loadQueryInfluencers = new LoadQueryInfluencers( factory ); loadQueryInfluencers = new LoadQueryInfluencers( factory );
@ -337,41 +292,6 @@ public final class SessionImpl
} }
} }
private PhysicalConnectionHandlingMode interpret(
Connection userSuppliedConnection,
PhysicalConnectionHandlingMode connectionHandlingMode) {
if ( userSuppliedConnection != null ) {
return DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION;
}
if ( connectionHandlingMode == null ) {
connectionHandlingMode = getFactory().getSessionFactoryOptions().getPhysicalConnectionHandlingMode();
}
if ( connectionHandlingMode.getReleaseMode() == ConnectionReleaseMode.AFTER_STATEMENT ) {
if ( !getJdbcConnectionAccess().supportsAggressiveRelease() ) {
log.debug( "Connection provider reports to not support aggressive release; overriding" );
return PhysicalConnectionHandlingMode.interpret(
connectionHandlingMode.getAcquisitionMode(),
ConnectionReleaseMode.AFTER_TRANSACTION
);
}
}
return connectionHandlingMode;
}
private Interceptor interpret(Interceptor interceptor) {
return interceptor == null ? EmptyInterceptor.INSTANCE : interceptor;
}
private StatementInspector interpret(StatementInspector statementInspector) {
if ( statementInspector == null ) {
return (StatementInspector) sql -> getInterceptor().onPrepareStatement( sql );
}
return statementInspector;
}
private void setDefaultProperties() { private void setDefaultProperties() {
properties.putIfAbsent( AvailableSettings.FLUSH_MODE, getHibernateFlushMode() ); properties.putIfAbsent( AvailableSettings.FLUSH_MODE, getHibernateFlushMode() );
properties.putIfAbsent( JPA_LOCK_SCOPE, PessimisticLockScope.EXTENDED.name() ); properties.putIfAbsent( JPA_LOCK_SCOPE, PessimisticLockScope.EXTENDED.name() );
@ -414,144 +334,6 @@ public final class SessionImpl
return determineCacheStoreMode( properties ); return determineCacheStoreMode( properties );
} }
// /**
// * Constructor used for openSession(...) processing, as well as construction
// * of sessions for getCurrentSession().
// *
// * @param connection The user-supplied connection to use for this session.
// * @param factory The factory from which this session was obtained
// * @param transactionCoordinator The transaction coordinator to use, may be null to indicate that a new transaction
// * coordinator should get created.
// * @param autoJoinTransactions Should the session automatically join JTA transactions?
// * @param timestamp The timestamp for this session
// * @param interceptor The interceptor to be applied to this session
// * @param flushBeforeCompletionEnabled Should we auto flush beforeQuery completion of transaction
// * @param autoCloseSessionEnabled Should we auto close afterQuery completion of transaction
// * @param connectionReleaseMode The mode by which we should release JDBC connections.
// * @param tenantIdentifier The tenant identifier to use. May be null
// */
// SessionImpl(
// final Connection connection,
// final SessionFactoryImpl factory,
// final SessionOwner sessionOwner,
// final TransactionCoordinator transactionCoordinator,
// final JdbcCoordinatorImpl jdbcCoordinator,
// final Transaction transaction,
// final ActionQueue.TransactionCompletionProcesses transactionCompletionProcesses,
// final boolean autoJoinTransactions,
// final long timestamp,
// final Interceptor interceptor,
// final StatementInspector statementInspector,
// final boolean flushBeforeCompletionEnabled,
// final boolean autoCloseSessionEnabled,
// final ConnectionReleaseMode connectionReleaseMode,
// final String tenantIdentifier) {
// super( factory, tenantIdentifier );
// this.timestamp = timestamp;
// this.sessionOwner = sessionOwner;
// this.interceptor = interceptor == null ? EmptyInterceptor.INSTANCE : interceptor;
// this.actionQueue = new ActionQueue( this );
// this.persistenceContext = new StatefulPersistenceContext( this );
//
// this.autoCloseSessionEnabled = autoCloseSessionEnabled;
// this.flushBeforeCompletionEnabled = flushBeforeCompletionEnabled;
//
// initializeFromSessionOwner( sessionOwner );
//
// if ( statementInspector == null ) {
// this.statementInspector = new StatementInspector() {
// @Override
// @SuppressWarnings("deprecation")
// public String inspect(String sql) {
// return SessionImpl.this.interceptor.onPrepareStatement( sql );
// }
// };
// }
// else {
// this.statementInspector = statementInspector;
// }
// this.jdbcSessionContext = new JdbcSessionContextImpl( factory, this.statementInspector );
//
// if ( transactionCoordinator == null ) {
// this.isTransactionCoordinatorShared = false;
// this.connectionReleaseMode = connectionReleaseMode;
// this.autoJoinTransactions = autoJoinTransactions;
//
// this.jdbcCoordinator = new JdbcCoordinatorImpl( connection, this );
// this.transactionCoordinator = getTransactionCoordinatorBuilder().buildTransactionCoordinator(
// this.jdbcCoordinator,
// this
// );
// this.currentHibernateTransaction = getTransaction();
// }
// else {
// if ( connection != null ) {
// throw new SessionException( "Cannot simultaneously share transaction context and specify connection" );
// }
// this.transactionCoordinator = transactionCoordinator;
// this.jdbcCoordinator = jdbcCoordinator;
// this.currentHibernateTransaction = transaction;
// this.isTransactionCoordinatorShared = true;
// this.autoJoinTransactions = false;
// if ( transactionCompletionProcesses != null ) {
// actionQueue.setTransactionCompletionProcesses( transactionCompletionProcesses, true );
// }
// if ( autoJoinTransactions ) {
// log.debug(
// "Session creation specified 'autoJoinTransactions', which is invalid in conjunction " +
// "with sharing JDBC connection between sessions; ignoring"
// );
// }
// if ( connectionReleaseMode != this.jdbcCoordinator.getConnectionReleaseMode() ) {
// log.debug(
// "Session creation specified 'getConnectionReleaseMode', which is invalid in conjunction " +
// "with sharing JDBC connection between sessions; ignoring"
// );
// }
// this.connectionReleaseMode = this.jdbcCoordinator.getConnectionReleaseMode();
//
// transactionObserver = new TransactionObserver() {
// @Override
// public void afterBegin() {
// }
//
// @Override
// public void beforeCompletion() {
// if ( isOpen() && flushBeforeCompletionEnabled ) {
// SessionImpl.this.managedFlush();
// }
// actionQueue.beforeTransactionCompletion();
// try {
// SessionImpl.this.interceptor.beforeTransactionCompletion( currentHibernateTransaction );
// }
// catch (Throwable t) {
// log.exceptionInBeforeTransactionCompletionInterceptor( t );
// }
// }
//
// @Override
// public void afterCompletion(boolean successful, boolean delayed) {
// afterTransactionCompletion( successful, delayed );
// if ( !isClosed() && autoCloseSessionEnabled ) {
// managedClose();
// }
// }
// };
//
// transactionCoordinator.addObserver( transactionObserver );
// }
//
// loadQueryInfluencers = new LoadQueryInfluencers( factory );
//
// if ( factory.getStatistics().isStatisticsEnabled() ) {
// factory.getStatistics().openSession();
// }
//
// if ( TRACE_ENABLED ) {
// log.tracef( "Opened session at timestamp: %s", timestamp );
// }
//
// }
private void initializeFromSessionOwner(SessionOwner sessionOwner) { private void initializeFromSessionOwner(SessionOwner sessionOwner) {
if ( sessionOwner != null ) { if ( sessionOwner != null ) {
@ -658,12 +440,7 @@ public final class SessionImpl
@Override @Override
public boolean isAutoCloseSessionEnabled() { public boolean isAutoCloseSessionEnabled() {
return autoCloseSessionEnabled; return autoClose;
}
@Override
public boolean shouldAutoJoinTransaction() {
return getSynchronizationType() == SynchronizationType.SYNCHRONIZED;
} }
@Override @Override
@ -708,6 +485,9 @@ public final class SessionImpl
return sessionOwner.shouldAutoCloseSession(); return sessionOwner.shouldAutoCloseSession();
} }
else { else {
// JPA technically requires that this be a PersistentUnityTransactionType#JTA to work,
// but we do not assert that here...
//return isAutoCloseSessionEnabled() && getTransactionCoordinator().getTransactionCoordinatorBuilder().isJta();
return isAutoCloseSessionEnabled(); return isAutoCloseSessionEnabled();
} }
} }
@ -2480,7 +2260,11 @@ public final class SessionImpl
public void afterTransactionCompletion(boolean successful, boolean delayed) { public void afterTransactionCompletion(boolean successful, boolean delayed) {
log.tracef( "SessionImpl#afterTransactionCompletion(successful=%s, delayed=%s)", successful, delayed ); log.tracef( "SessionImpl#afterTransactionCompletion(successful=%s, delayed=%s)", successful, delayed );
afterCompletionAction.doAction( successful, this ); if ( !isClosed() ) {
if ( !successful && autoClear ) {
clear();
}
}
persistenceContext.afterTransactionCompletion(); persistenceContext.afterTransactionCompletion();
actionQueue.afterTransactionCompletion( successful ); actionQueue.afterTransactionCompletion( successful );
@ -2503,20 +2287,6 @@ public final class SessionImpl
managedClose(); managedClose();
} }
} }
if ( autoClear ) {
internalClear();
}
}
@Override
public PersistenceUnitTransactionType getTransactionType() {
return super.getTransactionType();
}
@Override
public SynchronizationType getSynchronizationType() {
return super.getSynchronizationType();
} }
private static class LobHelperImpl implements LobHelper { private static class LobHelperImpl implements LobHelper {
@ -2614,13 +2384,13 @@ public final class SessionImpl
} }
@Override @Override
public T autoClose() { public T flushMode() {
return autoClose( session.autoCloseSessionEnabled ); return flushMode( session.getHibernateFlushMode() );
} }
@Override @Override
public T flushBeforeCompletion() { public T autoClose() {
return flushBeforeCompletion( session.flushBeforeCompletionEnabled ); return autoClose( session.autoClose );
} }
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -2717,7 +2487,7 @@ public final class SessionImpl
@Override @Override
public void beforeCompletion() { public void beforeCompletion() {
if ( isOpen() && flushBeforeCompletionEnabled ) { if ( isOpen() && getHibernateFlushMode() != FlushMode.MANUAL ) {
managedFlush(); managedFlush();
} }
actionQueue.beforeTransactionCompletion(); actionQueue.beforeTransactionCompletion();
@ -2732,7 +2502,7 @@ public final class SessionImpl
@Override @Override
public void afterCompletion(boolean successful, boolean delayed) { public void afterCompletion(boolean successful, boolean delayed) {
afterTransactionCompletion( successful, delayed ); afterTransactionCompletion( successful, delayed );
if ( !isClosed() && autoCloseSessionEnabled ) { if ( !isClosed() && autoClose ) {
managedClose(); managedClose();
} }
} }
@ -3221,9 +2991,12 @@ public final class SessionImpl
@Override @Override
public void flushBeforeTransactionCompletion() { public void flushBeforeTransactionCompletion() {
boolean flush = isTransactionFlushable() && managedFlushChecker.shouldDoManagedFlush( this ); final boolean doFlush = ! isClosed()
&& isTransactionFlushable()
&& getHibernateFlushMode() != FlushMode.MANUAL;
try { try {
if ( flush ) { if ( doFlush ) {
managedFlush(); managedFlush();
} }
} }
@ -3243,7 +3016,7 @@ public final class SessionImpl
@Override @Override
public boolean isFlushBeforeCompletionEnabled() { public boolean isFlushBeforeCompletionEnabled() {
return flushBeforeCompletionEnabled; return getHibernateFlushMode() != FlushMode.MANUAL;
} }
private static final AfterCompletionAction STANDARD_AFTER_COMPLETION_ACTION = (AfterCompletionAction) (successful, session) -> { private static final AfterCompletionAction STANDARD_AFTER_COMPLETION_ACTION = (AfterCompletionAction) (successful, session) -> {
@ -3254,13 +3027,10 @@ public final class SessionImpl
public static class ManagedFlushCheckerStandardImpl implements ManagedFlushChecker { public static class ManagedFlushCheckerStandardImpl implements ManagedFlushChecker {
@Override @Override
public boolean shouldDoManagedFlush(SessionImplementor session) { public boolean shouldDoManagedFlush(SessionImplementor session) {
final FlushMode flushMode = session.getHibernateFlushMode(); if ( session.isClosed() ) {
final boolean isFlushModeNever = flushMode == FlushMode.MANUAL; return false;
return ( !isFlushModeNever && }
!session.isFlushBeforeCompletionEnabled() ) || return session.getHibernateFlushMode() != FlushMode.MANUAL;
!session.isClosed()
&& !isFlushModeNever
&& session.isFlushBeforeCompletionEnabled();
} }
} }
@ -4001,7 +3771,7 @@ public final class SessionImpl
} }
private void joinTransaction(boolean explicitRequest) { private void joinTransaction(boolean explicitRequest) {
if ( getTransactionType() != PersistenceUnitTransactionType.JTA ) { if ( !getTransactionCoordinator().getTransactionCoordinatorBuilder().isJta() ) {
if ( explicitRequest ) { if ( explicitRequest ) {
log.callingJoinTransactionOnNonJtaEntityManager(); log.callingJoinTransactionOnNonJtaEntityManager();
} }
@ -4104,12 +3874,9 @@ public final class SessionImpl
* *
* @throws IOException Indicates a general IO stream exception * @throws IOException Indicates a general IO stream exception
*/ */
@Override private void writeObject(ObjectOutputStream oos) throws IOException {
protected void writeObject(ObjectOutputStream oos) throws IOException {
log.tracef( "Serializing Session [%s]", getSessionIdentifier() ); log.tracef( "Serializing Session [%s]", getSessionIdentifier() );
super.writeObject( oos );
oos.defaultWriteObject(); oos.defaultWriteObject();
persistenceContext.serialize( oos ); persistenceContext.serialize( oos );
@ -4126,12 +3893,9 @@ public final class SessionImpl
* @throws IOException Indicates a general IO stream exception * @throws IOException Indicates a general IO stream exception
* @throws ClassNotFoundException Indicates a class resolution issue * @throws ClassNotFoundException Indicates a class resolution issue
*/ */
@Override private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException, SQLException {
protected void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException, SQLException {
log.tracef( "Deserializing Session [%s]", getSessionIdentifier() ); log.tracef( "Deserializing Session [%s]", getSessionIdentifier() );
super.readObject( ois );
ois.defaultReadObject(); ois.defaultReadObject();
persistenceContext = StatefulPersistenceContext.deserialize( ois, this ); persistenceContext = StatefulPersistenceContext.deserialize( ois, this );

View File

@ -9,7 +9,7 @@ package org.hibernate.internal;
import org.hibernate.engine.jdbc.spi.JdbcCoordinator; import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
import org.hibernate.engine.spi.ActionQueue; import org.hibernate.engine.spi.ActionQueue;
import org.hibernate.engine.transaction.spi.TransactionImplementor; import org.hibernate.engine.transaction.spi.TransactionImplementor;
import org.hibernate.resource.transaction.TransactionCoordinator; import org.hibernate.resource.transaction.spi.TransactionCoordinator;
/** /**
* An extension of SessionCreationOptions for cases where the Session to be created shares * An extension of SessionCreationOptions for cases where the Session to be created shares

View File

@ -425,12 +425,6 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public void disableTransactionAutoJoin() {
throw new UnsupportedOperationException();
}
@Override @Override
protected Object load(String entityName, Serializable identifier) { protected Object load(String entityName, Serializable identifier) {
return null; return null;

View File

@ -230,4 +230,12 @@ public interface DeprecationLogger extends BasicLogger {
value = "Hibernate's legacy org.hibernate.Criteria API is deprecated; use the JPA javax.persistence.criteria.CriteriaQuery instead" value = "Hibernate's legacy org.hibernate.Criteria API is deprecated; use the JPA javax.persistence.criteria.CriteriaQuery instead"
) )
void deprecatedLegacyCriteria(); void deprecatedLegacyCriteria();
@LogMessage(level = WARN)
@Message(
id = 90000023,
value = "Encountered use of deprecated Connection handling settings [hibernate.connection.acquisition_mode]" +
"or [hibernate.connection.release_mode]; use [hibernate.connection.handling_mode] instead"
)
void logUseOfDeprecatedConnectionHandlingSettings();
} }

View File

@ -6,8 +6,6 @@
*/ */
package org.hibernate.jpa.internal; package org.hibernate.jpa.internal;
import javax.persistence.spi.PersistenceUnitTransactionType;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.resource.transaction.backend.jta.internal.synchronization.AfterCompletionAction; import org.hibernate.resource.transaction.backend.jta.internal.synchronization.AfterCompletionAction;
@ -31,7 +29,7 @@ public class AfterCompletionActionLegacyJpaImpl implements AfterCompletionAction
return; return;
} }
if ( !successful && session.getTransactionType() == PersistenceUnitTransactionType.JTA ) { if ( !successful && session.getTransactionCoordinator().getTransactionCoordinatorBuilder().isJta() ) {
session.clear(); session.clear();
} }
} }

View File

@ -21,21 +21,21 @@ public interface LogicalConnection {
* @return {@code true} if still open ({@link #close} has not been called yet); {@code false} if not open * @return {@code true} if still open ({@link #close} has not been called yet); {@code false} if not open
* (({@link #close} has been called). * (({@link #close} has been called).
*/ */
public boolean isOpen(); boolean isOpen();
/** /**
* Closes the JdbcSession, making it inactive and forcing release of any held resources * Closes the JdbcSession, making it inactive and forcing release of any held resources
* *
* @return Legacy :( Returns the JDBC Connection *if* the user passed in a Connection originally. * @return Legacy :( Returns the JDBC Connection *if* the user passed in a Connection originally.
*/ */
public Connection close(); Connection close();
/** /**
* Is this JdbcSession currently physically connected (meaning does it currently hold a JDBC Connection)? * Is this JdbcSession currently physically connected (meaning does it currently hold a JDBC Connection)?
* *
* @return {@code true} if the JdbcSession currently hold a JDBC Connection; {@code false} if it does not. * @return {@code true} if the JdbcSession currently hold a JDBC Connection; {@code false} if it does not.
*/ */
public boolean isPhysicallyConnected(); boolean isPhysicallyConnected();
/** /**
* Provides access to the registry of JDBC resources associated with this LogicalConnection. * Provides access to the registry of JDBC resources associated with this LogicalConnection.
@ -44,6 +44,6 @@ public interface LogicalConnection {
* *
* @throws org.hibernate.ResourceClosedException if the LogicalConnection is closed * @throws org.hibernate.ResourceClosedException if the LogicalConnection is closed
*/ */
public ResourceRegistry getResourceRegistry(); ResourceRegistry getResourceRegistry();
} }

View File

@ -23,9 +23,9 @@ public interface ResourceRegistry {
* *
* @return True if the registry does have registered resources; false otherwise. * @return True if the registry does have registered resources; false otherwise.
*/ */
public boolean hasRegisteredResources(); boolean hasRegisteredResources();
public void releaseResources(); void releaseResources();
/** /**
* Register a JDBC statement. * Register a JDBC statement.
@ -34,14 +34,14 @@ public interface ResourceRegistry {
* @param cancelable Is the statement being registered capable of being cancelled? In other words, * @param cancelable Is the statement being registered capable of being cancelled? In other words,
* should we register it to be the target of subsequent {@link #cancelLastQuery()} calls? * should we register it to be the target of subsequent {@link #cancelLastQuery()} calls?
*/ */
public void register(Statement statement, boolean cancelable); void register(Statement statement, boolean cancelable);
/** /**
* Release a previously registered statement. * Release a previously registered statement.
* *
* @param statement The statement to release. * @param statement The statement to release.
*/ */
public void release(Statement statement); void release(Statement statement);
/** /**
* Register a JDBC result set. * Register a JDBC result set.
@ -53,7 +53,7 @@ public interface ResourceRegistry {
* @param resultSet The result set to register. * @param resultSet The result set to register.
* @param statement Statement from which {@link java.sql.ResultSet} has been generated. * @param statement Statement from which {@link java.sql.ResultSet} has been generated.
*/ */
public void register(ResultSet resultSet, Statement statement); void register(ResultSet resultSet, Statement statement);
/** /**
* Release a previously registered result set. * Release a previously registered result set.
@ -61,17 +61,17 @@ public interface ResourceRegistry {
* @param resultSet The result set to release. * @param resultSet The result set to release.
* @param statement Statement from which {@link java.sql.ResultSet} has been generated. * @param statement Statement from which {@link java.sql.ResultSet} has been generated.
*/ */
public void release(ResultSet resultSet, Statement statement); void release(ResultSet resultSet, Statement statement);
public void register(Blob blob); void register(Blob blob);
public void release(Blob blob); void release(Blob blob);
public void register(Clob clob); void register(Clob clob);
public void release(Clob clob); void release(Clob clob);
public void register(NClob nclob); void register(NClob nclob);
public void release(NClob nclob); void release(NClob nclob);
public void cancelLastQuery(); void cancelLastQuery();
} }

View File

@ -7,7 +7,7 @@
package org.hibernate.resource.jdbc.spi; package org.hibernate.resource.jdbc.spi;
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
import org.hibernate.resource.transaction.TransactionCoordinator; import org.hibernate.resource.transaction.spi.TransactionCoordinator;
/** /**
* Contract for something that controls a JdbcSessionContext. The name comes from the * Contract for something that controls a JdbcSessionContext. The name comes from the

View File

@ -6,8 +6,11 @@
*/ */
package org.hibernate.resource.jdbc.spi; package org.hibernate.resource.jdbc.spi;
import java.util.Locale;
import org.hibernate.ConnectionAcquisitionMode; import org.hibernate.ConnectionAcquisitionMode;
import org.hibernate.ConnectionReleaseMode; import org.hibernate.ConnectionReleaseMode;
import org.hibernate.internal.util.StringHelper;
import static org.hibernate.ConnectionAcquisitionMode.AS_NEEDED; import static org.hibernate.ConnectionAcquisitionMode.AS_NEEDED;
import static org.hibernate.ConnectionAcquisitionMode.IMMEDIATELY; import static org.hibernate.ConnectionAcquisitionMode.IMMEDIATELY;
@ -62,6 +65,23 @@ public enum PhysicalConnectionHandlingMode {
return releaseMode; return releaseMode;
} }
public static PhysicalConnectionHandlingMode interpret(Object setting) {
if ( setting == null ) {
return null;
}
if ( setting instanceof PhysicalConnectionHandlingMode ) {
return (PhysicalConnectionHandlingMode) setting;
}
final String value = setting.toString();
if ( StringHelper.isEmpty( value ) ) {
return null;
}
return PhysicalConnectionHandlingMode.valueOf( value.toUpperCase( Locale.ROOT ) );
}
public static PhysicalConnectionHandlingMode interpret( public static PhysicalConnectionHandlingMode interpret(
ConnectionAcquisitionMode acquisitionMode, ConnectionAcquisitionMode acquisitionMode,
ConnectionReleaseMode releaseMode) { ConnectionReleaseMode releaseMode) {

View File

@ -7,6 +7,7 @@
package org.hibernate.resource.transaction; package org.hibernate.resource.transaction;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
/** /**
* Indicates a call to {@link TransactionCoordinator#explicitJoin()} that requires an * Indicates a call to {@link TransactionCoordinator#explicitJoin()} that requires an

View File

@ -6,12 +6,11 @@
*/ */
package org.hibernate.resource.transaction.backend.jdbc.internal; package org.hibernate.resource.transaction.backend.jdbc.internal;
import org.hibernate.ConnectionAcquisitionMode;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.resource.transaction.TransactionCoordinator; import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransactionAccess; import org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransactionAccess;
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner; import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner;
/** /**
@ -28,7 +27,7 @@ public class JdbcResourceLocalTransactionCoordinatorBuilderImpl implements Trans
public static final JdbcResourceLocalTransactionCoordinatorBuilderImpl INSTANCE = new JdbcResourceLocalTransactionCoordinatorBuilderImpl(); public static final JdbcResourceLocalTransactionCoordinatorBuilderImpl INSTANCE = new JdbcResourceLocalTransactionCoordinatorBuilderImpl();
@Override @Override
public TransactionCoordinator buildTransactionCoordinator(TransactionCoordinatorOwner owner, TransactionCoordinatorOptions options) { public TransactionCoordinator buildTransactionCoordinator(TransactionCoordinatorOwner owner, Options options) {
if ( owner instanceof JdbcResourceTransactionAccess ) { if ( owner instanceof JdbcResourceTransactionAccess ) {
return new JdbcResourceLocalTransactionCoordinatorImpl( this, owner, (JdbcResourceTransactionAccess) owner ); return new JdbcResourceLocalTransactionCoordinatorImpl( this, owner, (JdbcResourceTransactionAccess) owner );
} }
@ -44,12 +43,7 @@ public class JdbcResourceLocalTransactionCoordinatorBuilderImpl implements Trans
} }
@Override @Override
public ConnectionReleaseMode getDefaultConnectionReleaseMode() { public PhysicalConnectionHandlingMode getDefaultConnectionHandlingMode() {
return ConnectionReleaseMode.AFTER_TRANSACTION; return PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION;
}
@Override
public ConnectionAcquisitionMode getDefaultConnectionAcquisitionMode() {
return ConnectionAcquisitionMode.AS_NEEDED;
} }
} }

View File

@ -16,12 +16,12 @@ import org.hibernate.engine.transaction.spi.IsolationDelegate;
import org.hibernate.engine.transaction.spi.TransactionObserver; import org.hibernate.engine.transaction.spi.TransactionObserver;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.resource.jdbc.spi.JdbcSessionOwner; import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;
import org.hibernate.resource.transaction.SynchronizationRegistry;
import org.hibernate.resource.transaction.TransactionCoordinator;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransaction; import org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransaction;
import org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransactionAccess; import org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransactionAccess;
import org.hibernate.resource.transaction.internal.SynchronizationRegistryStandardImpl; import org.hibernate.resource.transaction.internal.SynchronizationRegistryStandardImpl;
import org.hibernate.resource.transaction.spi.SynchronizationRegistry;
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner; import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner;
import org.hibernate.resource.transaction.spi.TransactionStatus; import org.hibernate.resource.transaction.spi.TransactionStatus;

View File

@ -6,10 +6,9 @@
*/ */
package org.hibernate.resource.transaction.backend.jta.internal; package org.hibernate.resource.transaction.backend.jta.internal;
import org.hibernate.ConnectionAcquisitionMode; import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.ConnectionReleaseMode; import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.hibernate.resource.transaction.TransactionCoordinator; import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner; import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner;
/** /**
@ -21,7 +20,7 @@ public class JtaTransactionCoordinatorBuilderImpl implements TransactionCoordina
public static final String SHORT_NAME = "jta"; public static final String SHORT_NAME = "jta";
@Override @Override
public TransactionCoordinator buildTransactionCoordinator(TransactionCoordinatorOwner owner, TransactionCoordinatorOptions options) { public TransactionCoordinator buildTransactionCoordinator(TransactionCoordinatorOwner owner, Options options) {
return new JtaTransactionCoordinatorImpl( return new JtaTransactionCoordinatorImpl(
this, this,
owner, owner,
@ -35,12 +34,8 @@ public class JtaTransactionCoordinatorBuilderImpl implements TransactionCoordina
} }
@Override @Override
public ConnectionReleaseMode getDefaultConnectionReleaseMode() { public PhysicalConnectionHandlingMode getDefaultConnectionHandlingMode() {
return ConnectionReleaseMode.AFTER_STATEMENT; // todo : I want to change this to PhysicalConnectionHandlingMode#IMMEDIATE_ACQUISITION_AND_HOLD
} return PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT;
@Override
public ConnectionAcquisitionMode getDefaultConnectionAcquisitionMode() {
return ConnectionAcquisitionMode.AS_NEEDED;
} }
} }

View File

@ -21,9 +21,6 @@ import org.hibernate.engine.transaction.spi.IsolationDelegate;
import org.hibernate.engine.transaction.spi.TransactionObserver; import org.hibernate.engine.transaction.spi.TransactionObserver;
import org.hibernate.resource.jdbc.spi.JdbcSessionContext; import org.hibernate.resource.jdbc.spi.JdbcSessionContext;
import org.hibernate.resource.jdbc.spi.JdbcSessionOwner; import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;
import org.hibernate.resource.transaction.SynchronizationRegistry;
import org.hibernate.resource.transaction.TransactionCoordinator;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.TransactionRequiredForJoinException; import org.hibernate.resource.transaction.TransactionRequiredForJoinException;
import org.hibernate.resource.transaction.backend.jta.internal.synchronization.RegisteredSynchronization; import org.hibernate.resource.transaction.backend.jta.internal.synchronization.RegisteredSynchronization;
import org.hibernate.resource.transaction.backend.jta.internal.synchronization.SynchronizationCallbackCoordinator; import org.hibernate.resource.transaction.backend.jta.internal.synchronization.SynchronizationCallbackCoordinator;
@ -31,6 +28,9 @@ import org.hibernate.resource.transaction.backend.jta.internal.synchronization.S
import org.hibernate.resource.transaction.backend.jta.internal.synchronization.SynchronizationCallbackCoordinatorTrackingImpl; import org.hibernate.resource.transaction.backend.jta.internal.synchronization.SynchronizationCallbackCoordinatorTrackingImpl;
import org.hibernate.resource.transaction.backend.jta.internal.synchronization.SynchronizationCallbackTarget; import org.hibernate.resource.transaction.backend.jta.internal.synchronization.SynchronizationCallbackTarget;
import org.hibernate.resource.transaction.internal.SynchronizationRegistryStandardImpl; import org.hibernate.resource.transaction.internal.SynchronizationRegistryStandardImpl;
import org.hibernate.resource.transaction.spi.SynchronizationRegistry;
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner; import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner;
import org.hibernate.resource.transaction.spi.TransactionStatus; import org.hibernate.resource.transaction.spi.TransactionStatus;

View File

@ -16,7 +16,11 @@ import org.hibernate.engine.spi.SessionImplementor;
* {@link javax.transaction.Synchronization} registered by Hibernate with the underlying JTA platform. * {@link javax.transaction.Synchronization} registered by Hibernate with the underlying JTA platform.
* *
* @author Steve Ebersole * @author Steve Ebersole
*
* @deprecated (since 5.2) - probably getting removed in 5.2 as well. This was an SPI contract
* intended for HEM that is no longer needed.
*/ */
@Deprecated
public interface AfterCompletionAction extends Serializable { public interface AfterCompletionAction extends Serializable {
void doAction(boolean successful, SessionImplementor session); void doAction(boolean successful, SessionImplementor session);
} }

View File

@ -16,7 +16,10 @@ import org.hibernate.engine.spi.SessionImplementor;
* through the sister strategy {@link ExceptionMapper}. * through the sister strategy {@link ExceptionMapper}.
* *
* @author Steve Ebersole * @author Steve Ebersole
*
* @deprecated (since 5.2) no longer needed since integrating HEM into hibernate-core.
*/ */
@Deprecated
public interface ManagedFlushChecker extends Serializable { public interface ManagedFlushChecker extends Serializable {
/** /**
* Check whether we should perform the managed flush * Check whether we should perform the managed flush

View File

@ -12,12 +12,10 @@ import org.hibernate.boot.registry.StandardServiceInitiator;
import org.hibernate.boot.registry.selector.spi.StrategySelector; import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.internal.log.DeprecationLogger; import org.hibernate.internal.log.DeprecationLogger;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl; import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.jboss.logging.Logger;
/** /**
* StandardServiceInitiator for initiating the TransactionCoordinatorBuilder service. * StandardServiceInitiator for initiating the TransactionCoordinatorBuilder service.
* *

View File

@ -7,10 +7,10 @@
/** /**
* Defines the resource-level transaction capabilities of Hibernate, which revolves around the * Defines the resource-level transaction capabilities of Hibernate, which revolves around the
* {@link org.hibernate.resource.transaction.TransactionCoordinator} contract. * {@link org.hibernate.resource.transaction.spi.TransactionCoordinator} contract.
* <p/> * <p/>
* TransactionCoordinator instances can be obtained from * TransactionCoordinator instances can be obtained from
* {@link org.hibernate.resource.transaction.TransactionCoordinatorBuilder}, which is a Service * {@link org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder}, which is a Service
* and available from the StandardServiceRegistry * and available from the StandardServiceRegistry
* <p/> * <p/>
* A few terms/concepts to keep in mind here... * A few terms/concepts to keep in mind here...
@ -20,7 +20,7 @@
* The local transaction is the idea of transactionality exposed to the application (as * The local transaction is the idea of transactionality exposed to the application (as
* {@link org.hibernate.Transaction}) as a means to control the underlying transaction. That * {@link org.hibernate.Transaction}) as a means to control the underlying transaction. That
* control flows from the {@link org.hibernate.Transaction} into the TransactionCoordinator * control flows from the {@link org.hibernate.Transaction} into the TransactionCoordinator
* through the {@link org.hibernate.resource.transaction.TransactionCoordinator.TransactionDriver} it exposes. * through the {@link org.hibernate.resource.transaction.spi.TransactionCoordinator.TransactionDriver} it exposes.
* *
* <h2>Physical transaction</h2> * <h2>Physical transaction</h2>
* *
@ -42,7 +42,7 @@
* The Hibernate transaction api allows the application itself to register JTA Synchronization * The Hibernate transaction api allows the application itself to register JTA Synchronization
* objects with the TransactionCoordinator. These local Synchronizations work in all transaction * objects with the TransactionCoordinator. These local Synchronizations work in all transaction
* environments. See {@link org.hibernate.Transaction#registerSynchronization} and * environments. See {@link org.hibernate.Transaction#registerSynchronization} and
* {@link org.hibernate.resource.transaction.SynchronizationRegistry} for additional details. * {@link org.hibernate.resource.transaction.spi.SynchronizationRegistry} for additional details.
* *
*/ */
package org.hibernate.resource.transaction; package org.hibernate.resource.transaction;

View File

@ -4,11 +4,13 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.resource.transaction; package org.hibernate.resource.transaction.spi;
import java.io.Serializable; import java.io.Serializable;
import javax.transaction.Synchronization; import javax.transaction.Synchronization;
import org.hibernate.resource.transaction.NullSynchronizationException;
/** /**
* Manages a registry of (local) JTA {@link Synchronization} instances * Manages a registry of (local) JTA {@link Synchronization} instances
* *

View File

@ -6,8 +6,6 @@
*/ */
package org.hibernate.resource.transaction.spi; package org.hibernate.resource.transaction.spi;
import org.hibernate.resource.transaction.SynchronizationRegistry;
/** /**
* SPI contract for SynchronizationRegistry implementors. * SPI contract for SynchronizationRegistry implementors.
* *

View File

@ -4,11 +4,10 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.resource.transaction; package org.hibernate.resource.transaction.spi;
import org.hibernate.engine.transaction.spi.IsolationDelegate; import org.hibernate.engine.transaction.spi.IsolationDelegate;
import org.hibernate.engine.transaction.spi.TransactionObserver; import org.hibernate.engine.transaction.spi.TransactionObserver;
import org.hibernate.resource.transaction.spi.TransactionStatus;
/** /**
* Models the coordination of all transaction related flows. * Models the coordination of all transaction related flows.

View File

@ -4,13 +4,12 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.resource.transaction; package org.hibernate.resource.transaction.spi;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner;
import org.hibernate.service.Service;
import org.hibernate.ConnectionAcquisitionMode; import org.hibernate.ConnectionAcquisitionMode;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.service.Service;
/** /**
* Builder for TransactionCoordinator instances * Builder for TransactionCoordinator instances
@ -21,7 +20,7 @@ public interface TransactionCoordinatorBuilder extends Service {
/** /**
* Access to options to are specific to each TransactionCoordinator instance * Access to options to are specific to each TransactionCoordinator instance
*/ */
static interface TransactionCoordinatorOptions { static interface Options {
/** /**
* Indicates whether an active transaction should be automatically joined. Only relevant * Indicates whether an active transaction should be automatically joined. Only relevant
* for JTA-based TransactionCoordinator instances. * for JTA-based TransactionCoordinator instances.
@ -32,11 +31,25 @@ public interface TransactionCoordinatorBuilder extends Service {
boolean shouldAutoJoinTransaction(); boolean shouldAutoJoinTransaction();
} }
TransactionCoordinator buildTransactionCoordinator(TransactionCoordinatorOwner owner, TransactionCoordinatorOptions options); TransactionCoordinator buildTransactionCoordinator(TransactionCoordinatorOwner owner, Options options);
boolean isJta(); boolean isJta();
ConnectionReleaseMode getDefaultConnectionReleaseMode(); PhysicalConnectionHandlingMode getDefaultConnectionHandlingMode();
ConnectionAcquisitionMode getDefaultConnectionAcquisitionMode(); /**
* @deprecated (since 5.2) Use {@link #getDefaultConnectionHandlingMode} instead
*/
@Deprecated
default ConnectionAcquisitionMode getDefaultConnectionAcquisitionMode() {
return getDefaultConnectionHandlingMode().getAcquisitionMode();
}
/**
* @deprecated (since 5.2) Use {@link #getDefaultConnectionHandlingMode} instead
*/
@Deprecated
default ConnectionReleaseMode getDefaultConnectionReleaseMode() {
return getDefaultConnectionHandlingMode().getReleaseMode();
}
} }

View File

@ -24,7 +24,9 @@ import org.hibernate.testing.RequiresDialect;
public class BasicConnectionProviderTest extends ConnectionManagementTestCase { public class BasicConnectionProviderTest extends ConnectionManagementTestCase {
@Override @Override
protected Session getSessionUnderTest() { protected Session getSessionUnderTest() {
return openSession(); Session session = openSession();
session.beginTransaction();
return session;
} }
@Override @Override

View File

@ -54,7 +54,7 @@ public class ThreadLocalCurrentSessionTest extends ConnectionManagementTestCase
long initialCount = sessionFactory().getStatistics().getSessionCloseCount(); long initialCount = sessionFactory().getStatistics().getSessionCloseCount();
session.getTransaction().commit(); session.getTransaction().commit();
long subsequentCount = sessionFactory().getStatistics().getSessionCloseCount(); long subsequentCount = sessionFactory().getStatistics().getSessionCloseCount();
assertEquals( "Session still open afterQuery commit", initialCount + 1, subsequentCount ); assertEquals( "Session still open after commit", initialCount + 1, subsequentCount );
// also make sure it was cleaned up from the internal ThreadLocal... // also make sure it was cleaned up from the internal ThreadLocal...
assertFalse( "session still bound to internal ThreadLocal", TestableThreadLocalContext.hasBind() ); assertFalse( "session still bound to internal ThreadLocal", TestableThreadLocalContext.hasBind() );
} }
@ -90,7 +90,7 @@ public class ThreadLocalCurrentSessionTest extends ConnectionManagementTestCase
Session session = sessionFactory().getCurrentSession(); Session session = sessionFactory().getCurrentSession();
session.beginTransaction(); session.beginTransaction();
session.getTransaction().commit(); session.getTransaction().commit();
assertFalse( "session open afterQuery txn completion", session.isOpen() ); assertFalse( "session open after txn completion", session.isOpen() );
assertFalse( "session still bound afterQuery txn completion", TestableThreadLocalContext.isSessionBound( session ) ); assertFalse( "session still bound afterQuery txn completion", TestableThreadLocalContext.isSessionBound( session ) );
Session session2 = sessionFactory().getCurrentSession(); Session session2 = sessionFactory().getCurrentSession();

View File

@ -6,11 +6,6 @@
*/ */
package org.hibernate.test.jdbc.internal; package org.hibernate.test.jdbc.internal;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.Statement; import java.sql.Statement;
@ -28,13 +23,16 @@ import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.jdbc.Expectation; import org.hibernate.jdbc.Expectation;
import org.hibernate.jdbc.Expectations; import org.hibernate.jdbc.Expectations;
import org.hibernate.resource.jdbc.spi.LogicalConnectionImplementor; import org.hibernate.resource.jdbc.spi.LogicalConnectionImplementor;
import org.hibernate.resource.transaction.TransactionCoordinator;
import org.hibernate.test.common.JournalingBatchObserver;
import org.hibernate.test.common.JournalingTransactionObserver;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.test.common.JournalingBatchObserver;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
* @author Brett Meyer * @author Brett Meyer

View File

@ -8,13 +8,12 @@ package org.hibernate.test.resource.transaction;
import java.util.Collections; import java.util.Collections;
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl; import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl; import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl;
import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl; import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl;
import org.hibernate.resource.transaction.internal.TransactionCoordinatorBuilderInitiator; import org.hibernate.resource.transaction.internal.TransactionCoordinatorBuilderInitiator;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.After; import org.junit.After;

View File

@ -6,13 +6,10 @@
*/ */
package org.hibernate.test.resource.transaction.jdbc; package org.hibernate.test.resource.transaction.jdbc;
import javax.transaction.Synchronization;
import org.hibernate.HibernateException;
import org.hibernate.TransactionException; import org.hibernate.TransactionException;
import org.hibernate.resource.transaction.TransactionCoordinator;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl; import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl;
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.spi.TransactionStatus; import org.hibernate.resource.transaction.spi.TransactionStatus;
import org.hibernate.test.resource.common.SynchronizationCollectorImpl; import org.hibernate.test.resource.common.SynchronizationCollectorImpl;
@ -34,7 +31,7 @@ public class BasicJdbcTransactionTests {
final TransactionCoordinator transactionCoordinator = transactionCoordinatorBuilder.buildTransactionCoordinator( final TransactionCoordinator transactionCoordinator = transactionCoordinatorBuilder.buildTransactionCoordinator(
owner, owner,
new TransactionCoordinatorBuilder.TransactionCoordinatorOptions() { new TransactionCoordinatorBuilder.Options() {
@Override @Override
public boolean shouldAutoJoinTransaction() { public boolean shouldAutoJoinTransaction() {
return false; return false;
@ -66,7 +63,7 @@ public class BasicJdbcTransactionTests {
final TransactionCoordinator transactionCoordinator = transactionCoordinatorBuilder.buildTransactionCoordinator( final TransactionCoordinator transactionCoordinator = transactionCoordinatorBuilder.buildTransactionCoordinator(
owner, owner,
new TransactionCoordinatorBuilder.TransactionCoordinatorOptions() { new TransactionCoordinatorBuilder.Options() {
@Override @Override
public boolean shouldAutoJoinTransaction() { public boolean shouldAutoJoinTransaction() {
return false; return false;
@ -101,7 +98,7 @@ public class BasicJdbcTransactionTests {
final TransactionCoordinator transactionCoordinator = transactionCoordinatorBuilder.buildTransactionCoordinator( final TransactionCoordinator transactionCoordinator = transactionCoordinatorBuilder.buildTransactionCoordinator(
owner, owner,
new TransactionCoordinatorBuilder.TransactionCoordinatorOptions() { new TransactionCoordinatorBuilder.Options() {
@Override @Override
public boolean shouldAutoJoinTransaction() { public boolean shouldAutoJoinTransaction() {
return false; return false;

View File

@ -6,10 +6,10 @@
*/ */
package org.hibernate.test.resource.transaction.jta; package org.hibernate.test.resource.transaction.jta;
import org.hibernate.resource.transaction.TransactionCoordinator;
import org.hibernate.resource.transaction.backend.jta.internal.JtaPlatformInaccessibleException; import org.hibernate.resource.transaction.backend.jta.internal.JtaPlatformInaccessibleException;
import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl; import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl;
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.junit.Test; import org.junit.Test;

View File

@ -6,13 +6,14 @@
*/ */
package org.hibernate.cache.infinispan.access; package org.hibernate.cache.infinispan.access;
import java.util.UUID;
import org.hibernate.cache.infinispan.util.FutureUpdate; import org.hibernate.cache.infinispan.util.FutureUpdate;
import org.hibernate.cache.infinispan.util.InfinispanMessageLogger; import org.hibernate.cache.infinispan.util.InfinispanMessageLogger;
import org.hibernate.cache.infinispan.util.InvocationAfterCompletion; import org.hibernate.cache.infinispan.util.InvocationAfterCompletion;
import org.hibernate.resource.transaction.TransactionCoordinator; import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.infinispan.AdvancedCache;
import java.util.UUID; import org.infinispan.AdvancedCache;
/** /**
* @author Radim Vansa &lt;rvansa@redhat.com&gt; * @author Radim Vansa &lt;rvansa@redhat.com&gt;

View File

@ -17,7 +17,7 @@ import org.hibernate.cache.infinispan.util.VersionedEntry;
import org.hibernate.cache.spi.access.SoftLock; import org.hibernate.cache.spi.access.SoftLock;
import org.hibernate.cache.spi.entry.CacheEntry; import org.hibernate.cache.spi.entry.CacheEntry;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.resource.transaction.TransactionCoordinator; import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.infinispan.AdvancedCache; import org.infinispan.AdvancedCache;
import org.infinispan.configuration.cache.Configuration; import org.infinispan.configuration.cache.Configuration;

View File

@ -14,7 +14,7 @@ import org.hibernate.cache.CacheException;
import org.hibernate.cache.infinispan.impl.BaseRegion; import org.hibernate.cache.infinispan.impl.BaseRegion;
import org.hibernate.cache.spi.access.SoftLock; import org.hibernate.cache.spi.access.SoftLock;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.resource.transaction.TransactionCoordinator; import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.hibernate.resource.transaction.spi.TransactionStatus; import org.hibernate.resource.transaction.spi.TransactionStatus;
/** /**

View File

@ -23,7 +23,7 @@ import org.hibernate.cache.infinispan.util.CacheCommandInitializer;
import org.hibernate.cache.infinispan.util.InfinispanMessageLogger; import org.hibernate.cache.infinispan.util.InfinispanMessageLogger;
import org.hibernate.cache.spi.RegionFactory; import org.hibernate.cache.spi.RegionFactory;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.resource.transaction.TransactionCoordinator; import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.infinispan.AdvancedCache; import org.infinispan.AdvancedCache;
import org.infinispan.configuration.cache.CacheMode; import org.infinispan.configuration.cache.CacheMode;

View File

@ -6,13 +6,14 @@
*/ */
package org.hibernate.cache.infinispan.access; package org.hibernate.cache.infinispan.access;
import java.util.concurrent.TimeUnit;
import org.hibernate.cache.infinispan.impl.BaseTransactionalDataRegion; import org.hibernate.cache.infinispan.impl.BaseTransactionalDataRegion;
import org.hibernate.cache.infinispan.util.InvocationAfterCompletion; import org.hibernate.cache.infinispan.util.InvocationAfterCompletion;
import org.hibernate.cache.infinispan.util.VersionedEntry; import org.hibernate.cache.infinispan.util.VersionedEntry;
import org.hibernate.resource.transaction.TransactionCoordinator; import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.infinispan.AdvancedCache;
import java.util.concurrent.TimeUnit; import org.infinispan.AdvancedCache;
/** /**
* @author Radim Vansa &lt;rvansa@redhat.com&gt; * @author Radim Vansa &lt;rvansa@redhat.com&gt;

View File

@ -17,7 +17,7 @@ import org.hibernate.cache.infinispan.util.Tombstone;
import org.hibernate.cache.infinispan.util.TombstoneUpdate; import org.hibernate.cache.infinispan.util.TombstoneUpdate;
import org.hibernate.cache.spi.access.SoftLock; import org.hibernate.cache.spi.access.SoftLock;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.resource.transaction.TransactionCoordinator; import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.infinispan.AdvancedCache; import org.infinispan.AdvancedCache;
import org.infinispan.configuration.cache.Configuration; import org.infinispan.configuration.cache.Configuration;

View File

@ -6,14 +6,15 @@
*/ */
package org.hibernate.cache.infinispan.access; package org.hibernate.cache.infinispan.access;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.hibernate.cache.infinispan.impl.BaseTransactionalDataRegion; import org.hibernate.cache.infinispan.impl.BaseTransactionalDataRegion;
import org.hibernate.cache.infinispan.util.InvocationAfterCompletion; import org.hibernate.cache.infinispan.util.InvocationAfterCompletion;
import org.hibernate.cache.infinispan.util.Tombstone; import org.hibernate.cache.infinispan.util.Tombstone;
import org.hibernate.resource.transaction.TransactionCoordinator; import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.infinispan.AdvancedCache;
import java.util.UUID; import org.infinispan.AdvancedCache;
import java.util.concurrent.TimeUnit;
/** /**
* @author Radim Vansa &lt;rvansa@redhat.com&gt; * @author Radim Vansa &lt;rvansa@redhat.com&gt;

View File

@ -6,6 +6,10 @@
*/ */
package org.hibernate.cache.infinispan.query; package org.hibernate.cache.infinispan.query;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.transaction.Transaction; import javax.transaction.Transaction;
import javax.transaction.TransactionManager; import javax.transaction.TransactionManager;
@ -17,17 +21,13 @@ import org.hibernate.cache.infinispan.util.InfinispanMessageLogger;
import org.hibernate.cache.infinispan.util.InvocationAfterCompletion; import org.hibernate.cache.infinispan.util.InvocationAfterCompletion;
import org.hibernate.cache.spi.QueryResultsRegion; import org.hibernate.cache.spi.QueryResultsRegion;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.resource.transaction.TransactionCoordinator; import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.infinispan.AdvancedCache; import org.infinispan.AdvancedCache;
import org.infinispan.configuration.cache.TransactionConfiguration; import org.infinispan.configuration.cache.TransactionConfiguration;
import org.infinispan.context.Flag; import org.infinispan.context.Flag;
import org.infinispan.transaction.TransactionMode; import org.infinispan.transaction.TransactionMode;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/** /**
* Region for caching query results. * Region for caching query results.
* *

View File

@ -6,17 +6,17 @@
*/ */
package org.hibernate.cache.infinispan.util; package org.hibernate.cache.infinispan.util;
import org.hibernate.HibernateException; import java.sql.Connection;
import org.hibernate.jdbc.WorkExecutor; import java.sql.SQLException;
import org.hibernate.jdbc.WorkExecutorVisitable;
import org.hibernate.resource.transaction.TransactionCoordinator;
import org.infinispan.AdvancedCache;
import javax.transaction.Status; import javax.transaction.Status;
import javax.transaction.Synchronization; import javax.transaction.Synchronization;
import java.sql.Connection; import org.hibernate.HibernateException;
import java.sql.SQLException; import org.hibernate.jdbc.WorkExecutor;
import org.hibernate.jdbc.WorkExecutorVisitable;
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.infinispan.AdvancedCache;
/** /**
* @author Radim Vansa &lt;rvansa@redhat.com&gt; * @author Radim Vansa &lt;rvansa@redhat.com&gt;

View File

@ -25,9 +25,9 @@ import org.hibernate.engine.transaction.internal.TransactionImpl;
import org.hibernate.internal.util.compare.ComparableComparator; import org.hibernate.internal.util.compare.ComparableComparator;
import org.hibernate.resource.jdbc.spi.JdbcSessionContext; import org.hibernate.resource.jdbc.spi.JdbcSessionContext;
import org.hibernate.resource.jdbc.spi.JdbcSessionOwner; import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;
import org.hibernate.resource.transaction.TransactionCoordinator;
import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl; import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl;
import org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransactionAccess; import org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransactionAccess;
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner; import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;

View File

@ -24,24 +24,24 @@ import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.mapping.RootClass; import org.hibernate.mapping.RootClass;
import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.SimpleValue;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl; import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl;
import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl; import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.testing.BeforeClassOnce;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.hibernate.testing.junit4.CustomParameterized;
import org.hibernate.test.cache.infinispan.tm.JtaPlatformImpl;
import org.hibernate.test.cache.infinispan.tm.XaConnectionProvider; import org.hibernate.test.cache.infinispan.tm.XaConnectionProvider;
import org.hibernate.test.cache.infinispan.util.InfinispanTestingSetup; import org.hibernate.test.cache.infinispan.util.InfinispanTestingSetup;
import org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory; import org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory;
import org.hibernate.test.cache.infinispan.util.TxUtil; import org.hibernate.test.cache.infinispan.util.TxUtil;
import org.hibernate.testing.BeforeClassOnce;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.hibernate.test.cache.infinispan.tm.JtaPlatformImpl;
import org.hibernate.testing.junit4.CustomParameterized;
import org.infinispan.configuration.cache.CacheMode;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
import org.infinispan.configuration.cache.CacheMode;
/** /**
* @author Galder Zamarreño * @author Galder Zamarreño
* @since 3.5 * @since 3.5

View File

@ -18,12 +18,11 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cache.infinispan.util.InfinispanMessageLogger; import org.hibernate.cache.infinispan.util.InfinispanMessageLogger;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl; import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.test.cache.infinispan.functional.AbstractFunctionalTest; import org.hibernate.test.cache.infinispan.functional.AbstractFunctionalTest;
import org.hibernate.test.cache.infinispan.util.InfinispanTestingSetup; import org.hibernate.test.cache.infinispan.util.InfinispanTestingSetup;
import org.hibernate.test.cache.infinispan.util.TxUtil; import org.hibernate.test.cache.infinispan.util.TxUtil;
import org.junit.ClassRule; import org.junit.ClassRule;

View File

@ -1,28 +1,28 @@
package org.hibernate.test.cache.infinispan.util; package org.hibernate.test.cache.infinispan.util;
import java.sql.Connection;
import java.sql.SQLException;
import javax.transaction.RollbackException;
import javax.transaction.Status;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper; import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
import org.hibernate.engine.transaction.spi.IsolationDelegate; import org.hibernate.engine.transaction.spi.IsolationDelegate;
import org.hibernate.engine.transaction.spi.TransactionObserver; import org.hibernate.engine.transaction.spi.TransactionObserver;
import org.hibernate.resource.transaction.SynchronizationRegistry;
import org.hibernate.resource.transaction.TransactionCoordinator;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.backend.jta.internal.JtaIsolationDelegate; import org.hibernate.resource.transaction.backend.jta.internal.JtaIsolationDelegate;
import org.hibernate.resource.transaction.backend.jta.internal.StatusTranslator; import org.hibernate.resource.transaction.backend.jta.internal.StatusTranslator;
import org.hibernate.resource.transaction.spi.SynchronizationRegistry;
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.spi.TransactionStatus; import org.hibernate.resource.transaction.spi.TransactionStatus;
import org.infinispan.transaction.tm.BatchModeTransactionManager; import org.infinispan.transaction.tm.BatchModeTransactionManager;
import org.infinispan.transaction.tm.DummyTransaction; import org.infinispan.transaction.tm.DummyTransaction;
import javax.transaction.RollbackException;
import javax.transaction.Status;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
import java.sql.Connection;
import java.sql.SQLException;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;

View File

@ -35,7 +35,7 @@ import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.jdbc.AbstractReturningWork; import org.hibernate.jdbc.AbstractReturningWork;
import org.hibernate.jdbc.Work; import org.hibernate.jdbc.Work;
import org.hibernate.resource.transaction.TransactionCoordinator; import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.hibernate.testing.AfterClassOnce; import org.hibernate.testing.AfterClassOnce;
import org.hibernate.testing.BeforeClassOnce; import org.hibernate.testing.BeforeClassOnce;

View File

@ -42,7 +42,7 @@ import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.mapping.RootClass; import org.hibernate.mapping.RootClass;
import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.SimpleValue;
import org.hibernate.resource.transaction.TransactionCoordinator; import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.hibernate.type.BlobType; import org.hibernate.type.BlobType;
import org.hibernate.type.ClobType; import org.hibernate.type.ClobType;
import org.hibernate.type.NClobType; import org.hibernate.type.NClobType;