HHH-9747 - Import initial reworking of transaction handling (based on JdbcSession work)

This commit is contained in:
Steve Ebersole 2015-04-24 13:34:42 -05:00
parent b476094d43
commit 148159fadc
44 changed files with 426 additions and 460 deletions

View File

@ -0,0 +1,50 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2015, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate;
/**
* Indicates the manner in which JDBC Connections should be acquired. Inverse to
* {@link org.hibernate.ConnectionReleaseMode}.
* <p/>
* NOTE : Not yet used. The only current behavior is the legacy behavior, which is
* {@link #AS_NEEDED}.
*
* @author Steve Ebersole
*/
public enum ConnectionAcquisitionMode {
/**
* The Connection will be acquired as soon as the Hibernate Session is opened. This
* also circumvents ConnectionReleaseMode, as the Connection will then be held until the
* Session is closed.
*/
IMMEDIATELY,
/**
* The legacy behavior. A Connection is only acquired when (if_) it is actually needed.
*/
AS_NEEDED,
/**
* Not sure yet tbh :)
*/
DEFAULT
}

View File

@ -27,7 +27,7 @@ import java.util.Locale;
/**
* Defines the various policies by which Hibernate might release its underlying
* JDBC connection.
* JDBC connection. Inverse of {@link ConnectionAcquisitionMode}.
*
* @author Steve Ebersole
*/

View File

@ -148,9 +148,4 @@ public class EmptyInterceptor implements Interceptor, Serializable {
@Override
public void onCollectionUpdate(Object collection, Serializable key) throws CallbackException {
}
@Override
public String inspect(String sql) {
return this.onPrepareStatement( sql );
}
}

View File

@ -53,7 +53,7 @@ import org.hibernate.type.Type;
*
* @author Gavin King
*/
public interface Interceptor extends StatementInspector {
public interface Interceptor {
/**
* Called just before an object is initialized. The interceptor may change the <tt>state</tt>, which will
* be propagated to the persistent object. Note that when this method is called, <tt>entity</tt> will be
@ -273,6 +273,10 @@ public interface Interceptor extends StatementInspector {
* Called when sql string is being prepared.
* @param sql sql to be prepared
* @return original or modified sql
*
* @deprecated Supply a {@link org.hibernate.resource.jdbc.spi.StatementInspector} instead, if you wish
* to inspect and alter SQL statements.
*/
@Deprecated
public String onPrepareStatement(String sql);
}

View File

@ -25,6 +25,8 @@ package org.hibernate;
import java.sql.Connection;
import org.hibernate.resource.jdbc.spi.StatementInspector;
/**
* Represents a consolidation of all session creation options into a builder style delegate.
*
@ -60,6 +62,15 @@ public interface SessionBuilder {
*/
public SessionBuilder noInterceptor();
/**
* Applies a specific StatementInspector to the session options.
*
* @param statementInspector The StatementInspector to use.
*
* @return {@code this}, for method chaining
*/
public SessionBuilder statementInspector(StatementInspector statementInspector);
/**
* Adds a specific connection to the session options.
*

View File

@ -40,6 +40,7 @@ import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
import org.hibernate.loader.BatchFetchStyle;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.tuple.entity.EntityTuplizerFactory;
@ -142,6 +143,18 @@ public interface SessionFactoryBuilder {
*/
public SessionFactoryBuilder applyInterceptor(Interceptor interceptor);
/**
* Names a StatementInspector to be applied to the SessionFactory, which in turn means it will be used by all
* Sessions unless one is explicitly specified in {@link org.hibernate.SessionBuilder#statementInspector}
*
* @param statementInspector The StatementInspector
*
* @return {@code this}, for method chaining
*
* @see org.hibernate.cfg.AvailableSettings#STATEMENT_INSPECTOR
*/
public SessionFactoryBuilder applyStatementInspector(StatementInspector statementInspector);
/**
* Specifies one or more observers to be applied to the SessionFactory. Can be called multiple times to add
* additional observers.
@ -365,19 +378,30 @@ public interface SessionFactoryBuilder {
public SessionFactoryBuilder applyCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver resolver);
/**
* Should we track JTA transactions to attempt to detect timeouts?
* If using the built-in Hibernate JTA-based TransactionCoordinator/Builder, should it track JTA
* transactions by thread in an attempt to detect timeouts?
*
* @param enabled {@code true} indicates we should track by thread; {@code false} indicates not
*
* @return {@code this}, for method chaining
*
* @see org.hibernate.cfg.AvailableSettings#JTA_TRACK_BY_THREAD
*
* @deprecated This should be replaced by new TransactionCoordinator work...
*/
@Deprecated
public SessionFactoryBuilder applyJtaTrackingByThread(boolean enabled);
/**
* If using the built-in Hibernate JTA-based TransactionCoordinator/Builder, should it prefer to use
* {@link javax.transaction.UserTransaction} over {@link javax.transaction.Transaction}?
*
* @param preferUserTransactions {@code true} indicates we should prefer {@link javax.transaction.UserTransaction};
* {@code false} indicates we should prefer {@link javax.transaction.Transaction}
*
* @return {@code this}, for method chaining
*
* @see org.hibernate.cfg.AvailableSettings#PREFER_USER_TRANSACTION
*/
public SessionFactoryBuilder applyPreferUserTransactions(boolean preferUserTransactions);
/**
* Apply query substitutions to use in HQL queries. Note, this is a legacy feature and almost always
* never needed anymore...

View File

@ -65,6 +65,7 @@ import org.hibernate.internal.SessionFactoryImpl;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.loader.BatchFetchStyle;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.tuple.entity.EntityTuplizer;
@ -102,6 +103,7 @@ import static org.hibernate.cfg.AvailableSettings.SESSION_FACTORY_NAME;
import static org.hibernate.cfg.AvailableSettings.SESSION_FACTORY_NAME_IS_JNDI;
import static org.hibernate.cfg.AvailableSettings.STATEMENT_BATCH_SIZE;
import static org.hibernate.cfg.AvailableSettings.STATEMENT_FETCH_SIZE;
import static org.hibernate.cfg.AvailableSettings.STATEMENT_INSPECTOR;
import static org.hibernate.cfg.AvailableSettings.USE_DIRECT_REFERENCE_CACHE_ENTRIES;
import static org.hibernate.cfg.AvailableSettings.USE_GET_GENERATED_KEYS;
import static org.hibernate.cfg.AvailableSettings.USE_IDENTIFIER_ROLLBACK;
@ -172,6 +174,18 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement
return this;
}
@Override
public SessionFactoryBuilder applyJtaTrackingByThread(boolean enabled) {
this.options.jtaTrackByThread = enabled;
return this;
}
@Override
public SessionFactoryBuilder applyPreferUserTransactions(boolean preferUserTransactions) {
this.options.preferUserTransaction = preferUserTransactions;
return this;
}
@Override
public SessionFactoryBuilder applyStatisticsSupport(boolean enabled) {
this.options.statisticsEnabled = enabled;
@ -190,13 +204,18 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement
return this;
}
@Override
public SessionFactoryBuilder applyStatementInspector(StatementInspector statementInspector) {
this.options.statementInspector = statementInspector;
return this;
}
@Override
public SessionFactoryBuilder applyCustomEntityDirtinessStrategy(CustomEntityDirtinessStrategy strategy) {
this.options.customEntityDirtinessStrategy = strategy;
return this;
}
@Override
public SessionFactoryBuilder addEntityNameResolver(EntityNameResolver... entityNameResolvers) {
this.options.entityNameResolvers.addAll( Arrays.asList( entityNameResolvers ) );
@ -307,12 +326,6 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement
return this;
}
@Override
public SessionFactoryBuilder applyJtaTrackingByThread(boolean enabled) {
this.options.jtaTrackByThread = enabled;
return this;
}
@Override
@SuppressWarnings("unchecked")
public SessionFactoryBuilder applyQuerySubstitutions(Map substitutions) {
@ -473,9 +486,14 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement
private boolean flushBeforeCompletionEnabled;
private boolean autoCloseSessionEnabled;
// (JTA) transaction handling
private boolean jtaTrackByThread;
private boolean preferUserTransaction;
// Statistics/Interceptor/observers
private boolean statisticsEnabled;
private Interceptor interceptor;
private StatementInspector statementInspector;
private List<SessionFactoryObserver> sessionFactoryObserverList = new ArrayList<SessionFactoryObserver>();
private BaselineSessionEventsListenerBuilder baselineSessionEventsListenerBuilder; // not exposed on builder atm
@ -501,9 +519,6 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement
private MultiTenancyStrategy multiTenancyStrategy;
private CurrentTenantIdentifierResolver currentTenantIdentifierResolver;
// JTA timeout detection
private boolean jtaTrackByThread;
// Queries
private Map querySubstitutions;
private boolean strictJpaQueryLanguageCompliance;
@ -533,7 +548,6 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement
private boolean wrapResultSetsEnabled;
private Map<String, SQLFunction> sqlFunctions;
private boolean preferUserTransaction;
public SessionFactoryOptionsStateStandardImpl(StandardServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry;
@ -569,6 +583,11 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement
configurationSettings.get( INTERCEPTOR ),
EmptyInterceptor.INSTANCE
);
this.statementInspector = strategySelector.resolveStrategy(
StatementInspector.class,
configurationSettings.get( STATEMENT_INSPECTOR )
);
// todo : expose this from builder?
final String autoSessionEventsListenerName = (String) configurationSettings.get(
AUTO_SESSION_EVENTS_LISTENER
@ -742,6 +761,11 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement
return interceptor == null ? EmptyInterceptor.INSTANCE : interceptor;
}
@Override
public StatementInspector getStatementInspector() {
return statementInspector;
}
@Override
public SessionFactoryObserver[] getSessionFactoryObservers() {
return sessionFactoryObserverList.toArray( new SessionFactoryObserver[ sessionFactoryObserverList.size() ] );
@ -1003,6 +1027,11 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement
return options.getInterceptor();
}
@Override
public StatementInspector getStatementInspector() {
return options.getStatementInspector();
}
@Override
public SessionFactoryObserver[] getSessionFactoryObservers() {
return options.getSessionFactoryObservers();
@ -1212,4 +1241,9 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement
public Map<String, SQLFunction> getCustomSqlFunctionMap() {
return options.getCustomSqlFunctionMap();
}
@Override
public boolean isPreferUserTransaction() {
return options.isPreferUserTransaction();
}
}

View File

@ -44,6 +44,7 @@ import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
import org.hibernate.loader.BatchFetchStyle;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.tuple.entity.EntityTuplizerFactory;
/**
@ -66,9 +67,14 @@ public class SessionFactoryOptionsImpl implements SessionFactoryOptions {
private final boolean flushBeforeCompletionEnabled;
private final boolean autoCloseSessionEnabled;
// transaction handling
private final boolean jtaTrackByThread;
private final boolean preferUserTransaction;
// Statistics/Interceptor/observers
private final boolean statisticsEnabled;
private final Interceptor interceptor;
private final StatementInspector statementInspector;
private final SessionFactoryObserver[] sessionFactoryObserverList;
private final BaselineSessionEventsListenerBuilder baselineSessionEventsListenerBuilder; // not exposed on builder atm
@ -94,9 +100,6 @@ public class SessionFactoryOptionsImpl implements SessionFactoryOptions {
private final MultiTenancyStrategy multiTenancyStrategy;
private final CurrentTenantIdentifierResolver currentTenantIdentifierResolver;
// JTA timeout detection
private final boolean jtaTrackByThread;
// Queries
private final Map querySubstitutions;
private final boolean strictJpaQueryLanguageCompliance;
@ -127,7 +130,6 @@ public class SessionFactoryOptionsImpl implements SessionFactoryOptions {
private final Map<String, SQLFunction> sqlFunctions;
public SessionFactoryOptionsImpl(SessionFactoryOptionsState state) {
this.serviceRegistry = state.getServiceRegistry();
@ -140,8 +142,12 @@ public class SessionFactoryOptionsImpl implements SessionFactoryOptions {
this.flushBeforeCompletionEnabled = state.isFlushBeforeCompletionEnabled();
this.autoCloseSessionEnabled = state.isAutoCloseSessionEnabled();
this.jtaTrackByThread = state.isJtaTrackByThread();
this.preferUserTransaction = state.isPreferUserTransaction();
this.statisticsEnabled = state.isStatisticsEnabled();
this.interceptor = state.getInterceptor();
this.statementInspector = state.getStatementInspector();
this.sessionFactoryObserverList = state.getSessionFactoryObservers();
this.baselineSessionEventsListenerBuilder = state.getBaselineSessionEventsListenerBuilder();
@ -165,8 +171,6 @@ public class SessionFactoryOptionsImpl implements SessionFactoryOptions {
this.multiTenancyStrategy = state.getMultiTenancyStrategy();
this.currentTenantIdentifierResolver = state.getCurrentTenantIdentifierResolver();
this.jtaTrackByThread = state.isJtaTrackByThread();
this.querySubstitutions = state.getQuerySubstitutions();
this.strictJpaQueryLanguageCompliance = state.isStrictJpaQueryLanguageCompliance();
this.namedQueryStartupCheckingEnabled = state.isNamedQueryStartupCheckingEnabled();
@ -239,6 +243,11 @@ public class SessionFactoryOptionsImpl implements SessionFactoryOptions {
return interceptor;
}
@Override
public StatementInspector getStatementInspector() {
return statementInspector;
}
@Override
public BaselineSessionEventsListenerBuilder getBaselineSessionEventsListenerBuilder() {
return baselineSessionEventsListenerBuilder;
@ -452,4 +461,9 @@ public class SessionFactoryOptionsImpl implements SessionFactoryOptions {
public void setCheckNullability(boolean enabled) {
this.checkNullability = enabled;
}
@Override
public boolean isPreferUserTransaction() {
return preferUserTransaction;
}
}

View File

@ -43,6 +43,7 @@ import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
import org.hibernate.loader.BatchFetchStyle;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.tuple.entity.EntityTuplizerFactory;
/**
@ -69,6 +70,8 @@ public interface SessionFactoryOptionsState {
public Interceptor getInterceptor();
public StatementInspector getStatementInspector();
public SessionFactoryObserver[] getSessionFactoryObservers();
public BaselineSessionEventsListenerBuilder getBaselineSessionEventsListenerBuilder();
@ -152,4 +155,6 @@ public interface SessionFactoryOptionsState {
public EntityNotFoundDelegate getEntityNotFoundDelegate();
public Map<String, SQLFunction> getCustomSqlFunctionMap();
public boolean isPreferUserTransaction();
}

View File

@ -97,6 +97,9 @@ import org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy;
import org.hibernate.hql.spi.id.local.LocalTemporaryTableBulkIdStrategy;
import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
import org.hibernate.hql.spi.id.persistent.PersistentTableBulkIdStrategy;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl;
import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl;
import org.jboss.logging.Logger;
@ -161,7 +164,7 @@ public class StrategySelectorBuilder {
// build the baseline...
addDialects( strategySelector );
addJtaPlatforms( strategySelector );
// addTransactionFactories( strategySelector );
addTransactionCoordinatorBuilders( strategySelector );
addMultiTableBulkIdStrategies( strategySelector );
addEntityCopyObserverStrategies( strategySelector );
@ -351,16 +354,18 @@ public class StrategySelectorBuilder {
}
}
// private void addTransactionFactories(StrategySelectorImpl strategySelector) {
// strategySelector.registerStrategyImplementor( TransactionFactory.class, JdbcTransactionFactory.SHORT_NAME, JdbcTransactionFactory.class );
// strategySelector.registerStrategyImplementor( TransactionFactory.class, "org.hibernate.transaction.JDBCTransactionFactory", JdbcTransactionFactory.class );
//
// strategySelector.registerStrategyImplementor( TransactionFactory.class, JtaTransactionFactory.SHORT_NAME, JtaTransactionFactory.class );
// strategySelector.registerStrategyImplementor( TransactionFactory.class, "org.hibernate.transaction.JTATransactionFactory", JtaTransactionFactory.class );
//
// strategySelector.registerStrategyImplementor( TransactionFactory.class, CMTTransactionFactory.SHORT_NAME, CMTTransactionFactory.class );
// strategySelector.registerStrategyImplementor( TransactionFactory.class, "org.hibernate.transaction.CMTTransactionFactory", CMTTransactionFactory.class );
// }
private void addTransactionCoordinatorBuilders(StrategySelectorImpl strategySelector) {
strategySelector.registerStrategyImplementor(
TransactionCoordinatorBuilder.class,
JdbcResourceLocalTransactionCoordinatorBuilderImpl.SHORT_NAME,
JdbcResourceLocalTransactionCoordinatorBuilderImpl.class
);
strategySelector.registerStrategyImplementor(
TransactionCoordinatorBuilder.class,
JtaTransactionCoordinatorBuilderImpl.SHORT_NAME,
JtaTransactionCoordinatorBuilderImpl.class
);
}
private void addMultiTableBulkIdStrategies(StrategySelectorImpl strategySelector) {
strategySelector.registerStrategyImplementor(

View File

@ -43,6 +43,7 @@ import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
import org.hibernate.loader.BatchFetchStyle;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.tuple.entity.EntityTuplizerFactory;
/**
@ -93,6 +94,8 @@ public interface SessionFactoryOptions {
*/
public Interceptor getInterceptor();
public StatementInspector getStatementInspector();
public SessionFactoryObserver[] getSessionFactoryObservers();
public BaselineSessionEventsListenerBuilder getBaselineSessionEventsListenerBuilder();

View File

@ -283,7 +283,15 @@ public interface AvailableSettings {
/**
* Names the implementation of {@link org.hibernate.resource.transaction.TransactionCoordinatorBuilder} to use for
* creating {@link org.hibernate.resource.transaction.TransactionCoordinator} instances
* creating {@link org.hibernate.resource.transaction.TransactionCoordinator} instances.
* <p/>
* Can be<ul>
* <li>TransactionCoordinatorBuilder instance</li>
* <li>TransactionCoordinatorBuilder implementation {@link Class} reference</li>
* <li>TransactionCoordinatorBuilder implementation class name (FQN)</li>
* </ul>
*
* @since 5.0
*/
String TRANSACTION_COORDINATOR_STRATEGY = "hibernate.transaction.coordinator_class";
@ -291,10 +299,20 @@ public interface AvailableSettings {
* Names the {@link org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform} implementation to use for integrating
* with {@literal JTA} systems. Can reference either a {@link org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform}
* instance or the name of the {@link org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform} implementation class
*
* @since 4.0
*/
String JTA_PLATFORM = "hibernate.transaction.jta.platform";
/**
* Used to specify if using {@link javax.transaction.UserTransaction} class to use for JTA transaction management.
*
* Default is <code>false</code>
*
* @since 5.0
*/
String PREFER_USER_TRANSACTION = "hibernate.jta.prefer_user_transaction";
/**
* Names the {@link org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformResolver} implementation to use.
* @since 4.3
@ -661,6 +679,18 @@ public interface AvailableSettings {
*/
String INTERCEPTOR = "hibernate.session_factory.interceptor";
/**
* Names a {@link org.hibernate.resource.jdbc.spi.StatementInspector} implementation to be applied to
* the {@link org.hibernate.SessionFactory}. Can reference<ul>
* <li>StatementInspector instance</li>
* <li>StatementInspector implementation {@link Class} reference</li>
* <li>StatementInspector implementation class name (FQN)</li>
* </ul>
*
* @since 5.0
*/
String STATEMENT_INSPECTOR = "hibernate.session_factory.statement_inspector";
String ENABLE_LAZY_LOAD_NO_TRANS = "hibernate.enable_lazy_load_no_trans";
String HQL_BULK_ID_STRATEGY = "hibernate.hql.bulk_id_strategy";
@ -807,13 +837,4 @@ public interface AvailableSettings {
* annotations (combined with {@code orm.xml} mappings).
*/
String ARTIFACT_PROCESSING_ORDER = "hibernate.mapping.precedence";
/**
* Used to specify if using {@link javax.transaction.UserTransaction} class to use for JTA transaction management.
*
* Default is <code>false</code>
*
* @since 5.0
*/
String PREFER_USER_TRANSACTION = "hibernate.jta.prefer_user_transaction";
}

View File

@ -61,7 +61,7 @@ import org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl;
import org.hibernate.resource.jdbc.internal.LogicalConnectionProvidedImpl;
import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;
import org.hibernate.resource.jdbc.spi.LogicalConnectionImplementor;
import org.hibernate.resource.transaction.backend.store.spi.DataStoreTransaction;
import org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransaction;
/**
* Standard Hibernate implementation of {@link JdbcCoordinator}
@ -517,7 +517,7 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator {
}
@Override
public DataStoreTransaction getResourceLocalTransaction() {
public JdbcResourceTransaction getResourceLocalTransaction() {
return logicalConnection.getPhysicalJdbcTransaction();
}

View File

@ -171,10 +171,12 @@ class StatementPreparerImpl implements StatementPreparer {
private abstract class StatementPreparationTemplate {
protected final String sql;
protected StatementPreparationTemplate(String sql) {
this.sql = jdbcCoordinator.getJdbcSessionOwner().getJdbcSessionContext().getStatementInspector().inspect(
sql
);
protected StatementPreparationTemplate(String incomingSql) {
final String inspectedSql = jdbcCoordinator.getJdbcSessionOwner()
.getJdbcSessionContext()
.getStatementInspector()
.inspect( incomingSql );
this.sql = inspectedSql == null ? incomingSql : inspectedSql;
}
public PreparedStatement prepareStatement() {

View File

@ -33,8 +33,7 @@ import org.hibernate.engine.jdbc.batch.spi.BatchKey;
import org.hibernate.jdbc.WorkExecutorVisitable;
import org.hibernate.resource.jdbc.ResourceRegistry;
import org.hibernate.resource.jdbc.spi.LogicalConnectionImplementor;
import org.hibernate.resource.transaction.TransactionCoordinator;
import org.hibernate.resource.transaction.backend.store.spi.DataStoreTransactionAccess;
import org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransactionAccess;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner;
/**
@ -43,7 +42,7 @@ import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner;
* @author Steve Ebersole
* @author Brett Meyer
*/
public interface JdbcCoordinator extends Serializable, TransactionCoordinatorOwner, DataStoreTransactionAccess {
public interface JdbcCoordinator extends Serializable, TransactionCoordinatorOwner, JdbcResourceTransactionAccess {
// /**
// * Retrieve the transaction coordinator associated with this JDBC coordinator.
// *

View File

@ -30,6 +30,7 @@ import org.hibernate.Interceptor;
import org.hibernate.Session;
import org.hibernate.SessionBuilder;
import org.hibernate.SessionEventListener;
import org.hibernate.resource.jdbc.spi.StatementInspector;
/**
* Base class for {@link SessionBuilder} implementations that wish to implement only parts of that contract themselves
@ -60,6 +61,11 @@ public class ForwardingSessionBuilder implements SessionBuilder {
return delegate.noInterceptor();
}
@Override
public SessionBuilder statementInspector(StatementInspector statementInspector) {
return delegate.statementInspector( statementInspector );
}
@Override
public SessionBuilder connection(Connection connection) {
return delegate.connection(connection);

View File

@ -31,6 +31,7 @@ import org.hibernate.Session;
import org.hibernate.SessionBuilder;
import org.hibernate.SessionEventListener;
import org.hibernate.SharedSessionBuilder;
import org.hibernate.resource.jdbc.spi.StatementInspector;
/**
* Base class for {@link SharedSessionBuilder} implementations that wish to implement only parts of that contract
@ -96,6 +97,11 @@ public class ForwardingSharedSessionBuilder implements SharedSessionBuilder {
return delegate.noInterceptor();
}
@Override
public SessionBuilder statementInspector(StatementInspector statementInspector) {
return delegate.statementInspector( statementInspector );
}
@Override
public SharedSessionBuilder connection(Connection connection) {
return delegate.connection(connection);

View File

@ -24,8 +24,6 @@
package org.hibernate.hql.spi.id.global;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.spi.MetadataBuildingOptions;
@ -43,7 +41,6 @@ import org.hibernate.hql.internal.ast.tree.FromElement;
import org.hibernate.hql.internal.ast.tree.UpdateStatement;
import org.hibernate.hql.spi.id.AbstractMultiTableBulkIdStrategyImpl;
import org.hibernate.hql.spi.id.IdTableHelper;
import org.hibernate.hql.spi.id.IdTableInfo;
import org.hibernate.hql.spi.id.IdTableSupport;
import org.hibernate.hql.spi.id.IdTableSupportStandardImpl;
import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
@ -188,13 +185,13 @@ public class GlobalTemporaryTableBulkIdStrategy
final String sql = "delete from " + tableName;
PreparedStatement ps = null;
try {
ps = session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( sql, false );
session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( ps );
ps = session.getJdbcCoordinator().getStatementPreparer().prepareStatement( sql, false );
session.getJdbcCoordinator().getResultSetReturn().executeUpdate( ps );
}
finally {
if ( ps != null ) {
try {
session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
session.getJdbcCoordinator().getResourceRegistry().release( ps );
}
catch( Throwable ignore ) {
// ignore

View File

@ -60,14 +60,14 @@ public class Helper {
try {
PreparedStatement ps = null;
try {
ps = session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( sql, false );
ps = session.getJdbcCoordinator().getStatementPreparer().prepareStatement( sql, false );
bindSessionIdentifier( ps, session, 1 );
session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( ps );
session.getJdbcCoordinator().getResultSetReturn().executeUpdate( ps );
}
finally {
if ( ps != null ) {
try {
session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
session.getJdbcCoordinator().getResourceRegistry().release( ps );
}
catch( Throwable ignore ) {
// ignore

View File

@ -30,6 +30,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.hibernate.ConnectionAcquisitionMode;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
@ -41,8 +42,8 @@ import org.hibernate.SessionEventListener;
import org.hibernate.SessionException;
import org.hibernate.SharedSessionContract;
import org.hibernate.Transaction;
import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.cache.spi.CacheKey;
import org.hibernate.cfg.Settings;
import org.hibernate.engine.jdbc.LobCreationContext;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
@ -71,7 +72,7 @@ import org.hibernate.resource.jdbc.spi.JdbcSessionContext;
import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.TransactionCoordinatorJtaBuilder;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder.TransactionCoordinatorOptions;
import org.hibernate.resource.transaction.spi.TransactionStatus;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.Type;
@ -82,7 +83,7 @@ import org.hibernate.type.Type;
* @author Gavin King
*/
public abstract class AbstractSessionImpl
implements Serializable, SharedSessionContract, SessionImplementor, JdbcSessionOwner {
implements Serializable, SharedSessionContract, SessionImplementor, JdbcSessionOwner, TransactionCoordinatorOptions {
protected transient SessionFactoryImpl factory;
private final String tenantIdentifier;
private boolean closed;
@ -108,6 +109,7 @@ public abstract class AbstractSessionImpl
return factory;
}
@Override
public abstract boolean shouldAutoJoinTransaction();
@Override
@ -482,6 +484,10 @@ public abstract class AbstractSessionImpl
this.inspector = inspector;
this.serviceRegistry = sessionFactory.getServiceRegistry();
this.jdbcObserver = new JdbcObserverImpl();
if ( inspector == null ) {
throw new IllegalArgumentException( "StatementInspector cannot be null" );
}
}
@Override
@ -506,7 +512,7 @@ public abstract class AbstractSessionImpl
@Override
public ConnectionAcquisitionMode getConnectionAcquisitionMode() {
return null;
return ConnectionAcquisitionMode.DEFAULT;
}
@Override
@ -529,8 +535,8 @@ public abstract class AbstractSessionImpl
return this.serviceRegistry;
}
private final Settings settings() {
return this.sessionFactory.getSettings();
private SessionFactoryOptions settings() {
return this.sessionFactory.getSessionFactoryOptions();
}
}
@ -603,20 +609,7 @@ public abstract class AbstractSessionImpl
@Override
public TransactionCoordinatorBuilder getTransactionCoordinatorBuilder() {
TransactionCoordinatorBuilder transactionCoordinatorBuilder = factory.getServiceRegistry()
.getService( TransactionCoordinatorBuilder.class );
if ( transactionCoordinatorBuilder instanceof TransactionCoordinatorJtaBuilder ) {
((TransactionCoordinatorJtaBuilder) transactionCoordinatorBuilder).setJtaPlatform(
factory.getSettings()
.getJtaPlatform()
).setAutoJoinTransactions( shouldAutoJoinTransaction() ).setPerformJtaThreadTracking(
factory.getSettings()
.isJtaTrackByThread()
).setPreferUserTransactions( factory.getSettings().isPreferUserTransaction() );
}
return transactionCoordinatorBuilder;
return factory.getServiceRegistry().getService( TransactionCoordinatorBuilder.class );
}
}

View File

@ -137,6 +137,7 @@ import org.hibernate.persister.entity.Queryable;
import org.hibernate.persister.spi.PersisterCreationContext;
import org.hibernate.persister.spi.PersisterFactory;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.resource.transaction.TransactionCoordinator;
import org.hibernate.secure.spi.GrantedPermission;
import org.hibernate.secure.spi.JaccPermissionDeclarations;
@ -1195,6 +1196,7 @@ public final class SessionFactoryImpl
private final SessionFactoryImpl sessionFactory;
private SessionOwner sessionOwner;
private Interceptor interceptor;
private StatementInspector statementInspector;
private Connection connection;
private ConnectionReleaseMode connectionReleaseMode;
private boolean autoClose;
@ -1210,6 +1212,7 @@ public final class SessionFactoryImpl
// set up default builder values...
this.interceptor = sessionFactory.getInterceptor();
this.statementInspector = sessionFactory.getSessionFactoryOptions().getStatementInspector();
this.connectionReleaseMode = settings.getConnectionReleaseMode();
this.autoClose = settings.isAutoCloseSessionEnabled();
this.flushBeforeCompletion = settings.isFlushBeforeCompletionEnabled();
@ -1251,6 +1254,7 @@ public final class SessionFactoryImpl
autoJoinTransactions,
sessionFactory.settings.getRegionFactory().nextTimestamp(),
interceptor,
statementInspector,
flushBeforeCompletion,
autoClose,
connectionReleaseMode,
@ -1282,6 +1286,12 @@ public final class SessionFactoryImpl
return this;
}
@Override
public SessionBuilder statementInspector(StatementInspector statementInspector) {
this.statementInspector = statementInspector;
return this;
}
@Override
public SessionBuilder connection(Connection connection) {
this.connection = connection;

View File

@ -202,6 +202,7 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
private transient TransactionCoordinator transactionCoordinator;
private transient JdbcCoordinatorImpl jdbcCoordinator;
private transient Interceptor interceptor;
private StatementInspector statementInspector;
private transient EntityNameResolver entityNameResolver = new CoordinatingEntityNameResolver();
private transient ConnectionReleaseMode connectionReleaseMode;
@ -251,6 +252,7 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
final boolean autoJoinTransactions,
final long timestamp,
final Interceptor interceptor,
final StatementInspector statementInspector,
final boolean flushBeforeCompletionEnabled,
final boolean autoCloseSessionEnabled,
final ConnectionReleaseMode connectionReleaseMode,
@ -264,7 +266,19 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
this.autoCloseSessionEnabled = autoCloseSessionEnabled;
this.flushBeforeCompletionEnabled = flushBeforeCompletionEnabled;
this.jdbcSessionContext = new JdbcSessionContextImpl( factory, getStatementInspector() );
if ( statementInspector == null ) {
this.statementInspector = new StatementInspector() {
@Override
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;
@ -272,7 +286,7 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
this.autoJoinTransactions = autoJoinTransactions;
this.jdbcCoordinator = new JdbcCoordinatorImpl( connection, this );
this.transactionCoordinator = getTransactionCoordinatorBuilder().buildTransactionCoordinator( this.jdbcCoordinator );
this.transactionCoordinator = getTransactionCoordinatorBuilder().buildTransactionCoordinator( this.jdbcCoordinator, this );
this.currentHibernateTransaction = getTransaction();
}
else {
@ -2155,12 +2169,12 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
interceptor = (Interceptor) ois.readObject();
factory = SessionFactoryImpl.deserialize( ois );
this.jdbcSessionContext = new JdbcSessionContextImpl( factory, interceptor );
this.jdbcSessionContext = new JdbcSessionContextImpl( factory, statementInspector );
sessionOwner = (SessionOwner) ois.readObject();
jdbcCoordinator = JdbcCoordinatorImpl.deserialize( ois, this );
this.transactionCoordinator = getTransactionCoordinatorBuilder().buildTransactionCoordinator( jdbcCoordinator );
this.transactionCoordinator = getTransactionCoordinatorBuilder().buildTransactionCoordinator( jdbcCoordinator, this );
persistenceContext = StatefulPersistenceContext.deserialize( ois, this );
actionQueue = ActionQueue.deserialize( ois, this );
@ -2232,10 +2246,6 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
return this.jdbcSessionContext;
}
private StatementInspector getStatementInspector() {
return this.interceptor;
}
@Override
public void beforeTransactionCompletion() {
LOG.trace( "before transaction completion" );
@ -2412,6 +2422,11 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
return (SharedSessionBuilder) super.noInterceptor();
}
@Override
public SharedSessionBuilder statementInspector(StatementInspector statementInspector) {
return (SharedSessionBuilder) super.statementInspector( statementInspector );
}
@Override
public SharedSessionBuilder connection(Connection connection) {
return (SharedSessionBuilder) super.connection( connection );

View File

@ -23,15 +23,13 @@
*/
package org.hibernate.internal;
import javax.transaction.SystemException;
import java.io.Serializable;
import java.sql.Connection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.jboss.logging.Logger;
import javax.transaction.SystemException;
import org.hibernate.CacheMode;
import org.hibernate.Criteria;
@ -73,16 +71,17 @@ import org.hibernate.persister.entity.OuterJoinLoadable;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.resource.jdbc.spi.JdbcSessionContext;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.resource.transaction.TransactionCoordinator;
import org.hibernate.resource.transaction.spi.TransactionStatus;
import org.hibernate.type.Type;
/**
* @author Gavin King
* @author Steve Ebersole
*/
public class StatelessSessionImpl extends AbstractSessionImpl implements StatelessSession {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, StatelessSessionImpl.class.getName());
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( StatelessSessionImpl.class );
private TransactionCoordinator transactionCoordinator;
@ -104,10 +103,18 @@ public class StatelessSessionImpl extends AbstractSessionImpl implements Statele
SessionFactoryImpl factory,
long timestamp) {
super( factory, tenantIdentifier );
this.jdbcSessionContext = new JdbcSessionContextImpl( factory, EmptyInterceptor.INSTANCE );
this.jdbcSessionContext = new JdbcSessionContextImpl(
factory,
new StatementInspector() {
@Override
public String inspect(String sql) {
return null;
}
}
);
this.jdbcCoordinator = new JdbcCoordinatorImpl( connection, this );
this.transactionCoordinator = getTransactionCoordinatorBuilder().buildTransactionCoordinator( jdbcCoordinator );
this.transactionCoordinator = getTransactionCoordinatorBuilder().buildTransactionCoordinator( jdbcCoordinator, this );
this.currentHibernateTransaction = getTransaction();
this.timestamp = timestamp;
}

View File

@ -8,6 +8,7 @@ import java.sql.SQLException;
import org.jboss.logging.Logger;
import org.hibernate.ConnectionAcquisitionMode;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.ResourceClosedException;
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
@ -53,7 +54,7 @@ public class LogicalConnectionManagedImpl extends AbstractLogicalConnectionImple
this.connectionReleaseMode = jdbcSessionContext.getConnectionReleaseMode();
this.resourceRegistry = resourceRegistry;
if ( jdbcSessionContext.getConnectionAcquisitionMode() == JdbcSessionContext.ConnectionAcquisitionMode.IMMEDIATELY ) {
if ( jdbcSessionContext.getConnectionAcquisitionMode() == ConnectionAcquisitionMode.IMMEDIATELY ) {
if ( jdbcSessionContext.getConnectionReleaseMode() != ConnectionReleaseMode.ON_CLOSE ) {
throw new IllegalStateException(
"Illegal combination of ConnectionAcquisitionMode#IMMEDIATELY with !ConnectionReleaseMode.ON_CLOSE"

View File

@ -23,10 +23,8 @@
*/
package org.hibernate.resource.jdbc.spi;
import org.hibernate.ConnectionAcquisitionMode;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.service.ServiceRegistry;
@ -55,10 +53,4 @@ public interface JdbcSessionContext {
public SessionFactoryImplementor getSessionFactory();
public ServiceRegistry getServiceRegistry();
public static enum ConnectionAcquisitionMode {
IMMEDIATELY,
AS_NEEDED,
DEFAULT
}
}

View File

@ -23,12 +23,12 @@
*/
package org.hibernate.resource.jdbc.spi;
import org.hibernate.resource.transaction.backend.store.spi.DataStoreTransaction;
import org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransaction;
/**
* Provides access to manage "transactionality" via the JDBC Connection
*
* @author Steve Ebersole
*/
public interface PhysicalJdbcTransaction extends DataStoreTransaction {
public interface PhysicalJdbcTransaction extends JdbcResourceTransaction {
}

View File

@ -23,12 +23,14 @@
*/
package org.hibernate.resource.jdbc.spi;
import java.io.Serializable;
/**
* Contract to allow inspection (and swapping) of SQL to be prepared
*
* @author Steve Ebersole
*/
public interface StatementInspector {
public interface StatementInspector extends Serializable {
/**
* Inspect the given SQL, possibly returning a different SQL to be used instead. Note that returning {@code null}
* is interpreted as returning the same SQL as was passed.

View File

@ -24,12 +24,10 @@
package org.hibernate.resource.transaction;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.resource.jdbc.spi.JdbcSessionContext;
import org.hibernate.resource.transaction.TransactionCoordinator;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner;
import org.hibernate.service.Service;
import static org.hibernate.resource.jdbc.spi.JdbcSessionContext.ConnectionAcquisitionMode;
import org.hibernate.ConnectionAcquisitionMode;
/**
* Builder for TransactionCoordinator instances
@ -37,7 +35,21 @@ import static org.hibernate.resource.jdbc.spi.JdbcSessionContext.ConnectionAcqui
* @author Steve Ebersole
*/
public interface TransactionCoordinatorBuilder extends Service {
public TransactionCoordinator buildTransactionCoordinator(TransactionCoordinatorOwner owner);
/**
* Access to options to are specific to each TransactionCoordinator instance
*/
public static interface TransactionCoordinatorOptions {
/**
* Indicates whether an active transaction should be automatically joined. Only relevant
* for JTA-based TransactionCoordinator instances.
*
* @return {@code true} indicates the active transaction should be auto joined; {@code false}
* indicates it should not (until {@link TransactionCoordinator#explicitJoin} is called).
*/
public boolean shouldAutoJoinTransaction();
}
public TransactionCoordinator buildTransactionCoordinator(TransactionCoordinatorOwner owner, TransactionCoordinatorOptions options);
public boolean isJta();

View File

@ -1,64 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.resource.transaction;
import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl;
import org.hibernate.resource.transaction.backend.store.internal.ResourceLocalTransactionCoordinatorBuilderImpl;
/**
* Factory for obtaining instances of standard TransactionCoordinatorBuilder implementations
*
* @author Steve Ebersole
*/
public class TransactionCoordinatorBuilderFactory {
/**
* Singleton access
*/
public static final TransactionCoordinatorBuilderFactory INSTANCE = new TransactionCoordinatorBuilderFactory();
/**
* Private constructor for the factory
*/
private TransactionCoordinatorBuilderFactory() {
}
/**
* Obtain a TransactionCoordinatorBuilder specific to resource-local environments
*
* @return The resource-local specific TransactionCoordinatorBuilder
*/
public TransactionCoordinatorResourceLocalBuilder forResourceLocal() {
return new ResourceLocalTransactionCoordinatorBuilderImpl();
}
/**
* Obtain a TransactionCoordinatorBuilder specific to JTA environments
*
* @return The JTA specific TransactionCoordinatorBuilder
*/
public TransactionCoordinatorJtaBuilder forJta() {
return new JtaTransactionCoordinatorBuilderImpl();
}
}

View File

@ -1,77 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.resource.transaction;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
/**
* A builder of TransactionCoordinator instances intended for use in JTA environments.
*
* @author Steve Ebersole
*/
public interface TransactionCoordinatorJtaBuilder extends TransactionCoordinatorBuilder {
/**
* Specifies the JtaPlatform to use.
*
* @param jtaPlatform The JtaPlatform to use.
*
* @return {@code this}, for method chaining
*/
public TransactionCoordinatorJtaBuilder setJtaPlatform(JtaPlatform jtaPlatform);
/**
* Should JTA transactions be automatically joined? Or should we wait for (JPA-style) explicit joining? The
* default is to auto-join ({@code true}).
*
* @param autoJoinTransactions {@code true} (default) indicates that JTA transactions should be auto joined;
* {@code false} indicated we should wait for an explicit join
*
* @return {@code this}, for method chaining
*/
public TransactionCoordinatorJtaBuilder setAutoJoinTransactions(boolean autoJoinTransactions);
/**
* Should we prefer to use UserTransactions (over TransactionManager) for managing transactions (mainly for calling
* begin, commit, rollback)? We will try both, this controls which to check first. The default is to prefer
* accessing the TransactionManager
*
* @param preferUserTransactions {@code true} indicates to look for UserTransactions first; {@code false} (the
* default) indicates to looks for the TransactionManager first,
*
* @return {@code this}, for method chaining
*/
public TransactionCoordinatorJtaBuilder setPreferUserTransactions(boolean preferUserTransactions);
/**
* Should we track threads in order to protect against the JTA system calling us from a different thread? This
* might often be the case for JTA systems which implement timeout rollbacks from separate "reaper" threads. The
* default is to track threads.
*
* @param performJtaThreadTracking {@code true} (the default) indicates that the thread should be tracked;
* {@code false} indicates it should not.
*
* @return {@code this}, for method chaining
*/
public TransactionCoordinatorJtaBuilder setPerformJtaThreadTracking(boolean performJtaThreadTracking);
}

View File

@ -1,51 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.resource.transaction;
import org.hibernate.resource.transaction.backend.store.spi.DataStoreTransactionAccess;
/**
* A builder of TransactionCoordinator instances intended for use in resource-local mode (non-JTA transactions local
* to the underlying data store).
* <p/>
* NOTE : Ideally I'd love to specialize the {@link #buildTransactionCoordinator(org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner)}
* method here to only accept TransactionCoordinatorOwner arguments that are specifically
* {@link org.hibernate.resource.transaction.backend.store.spi.DataStoreTransactionAccess} instances. Not sure how to
* best achieve that. For now we just cast and let the exception happen, but directing the user via the contract
* would be MUCH preferable.
*
* @author Steve Ebersole
*/
public interface TransactionCoordinatorResourceLocalBuilder extends TransactionCoordinatorBuilder {
/**
* Provides the TransactionCoordinator we are building with access to the ResourceLocalTransaction used to control
* transactions.
* <p/>
* An alternative is for the owner passed to {@link #buildTransactionCoordinator} to implement the
* ResourceLocalTransactionAccess contract.
*
* @param dataStoreTransactionAccess Access
*/
public void setResourceLocalTransactionAccess(DataStoreTransactionAccess dataStoreTransactionAccess);
}

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.resource.transaction.backend.store.internal;
package org.hibernate.resource.transaction.backend.jdbc.internal;
import java.sql.Connection;
import java.sql.SQLException;

View File

@ -21,40 +21,33 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.resource.transaction.backend.store.internal;
package org.hibernate.resource.transaction.backend.jdbc.internal;
import org.hibernate.ConnectionAcquisitionMode;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.HibernateException;
import org.hibernate.resource.jdbc.spi.JdbcSessionContext;
import org.hibernate.resource.transaction.TransactionCoordinator;
import org.hibernate.resource.transaction.backend.store.spi.DataStoreTransactionAccess;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransactionAccess;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner;
import org.hibernate.resource.transaction.TransactionCoordinatorResourceLocalBuilder;
import static org.hibernate.resource.jdbc.spi.JdbcSessionContext.ConnectionAcquisitionMode;
/**
* Concrete builder for resource-local TransactionCoordinator instances.
*
* @author Steve Ebersole
*/
public class ResourceLocalTransactionCoordinatorBuilderImpl implements TransactionCoordinatorResourceLocalBuilder {
private DataStoreTransactionAccess providedDataStoreTransactionAccess;
public class JdbcResourceLocalTransactionCoordinatorBuilderImpl implements TransactionCoordinatorBuilder {
public static final String SHORT_NAME = "jdbc";
/**
* Singleton access
*/
public static final JdbcResourceLocalTransactionCoordinatorBuilderImpl INSTANCE = new JdbcResourceLocalTransactionCoordinatorBuilderImpl();
@Override
public void setResourceLocalTransactionAccess(DataStoreTransactionAccess dataStoreTransactionAccess) {
this.providedDataStoreTransactionAccess = dataStoreTransactionAccess;
}
@Override
public TransactionCoordinator buildTransactionCoordinator(TransactionCoordinatorOwner owner) {
if ( providedDataStoreTransactionAccess != null ) {
return new ResourceLocalTransactionCoordinatorImpl( this, owner, providedDataStoreTransactionAccess );
}
else {
if ( owner instanceof DataStoreTransactionAccess ) {
return new ResourceLocalTransactionCoordinatorImpl( this, owner, (DataStoreTransactionAccess) owner );
}
public TransactionCoordinator buildTransactionCoordinator(TransactionCoordinatorOwner owner, TransactionCoordinatorOptions options) {
if ( owner instanceof JdbcResourceTransactionAccess ) {
return new JdbcResourceLocalTransactionCoordinatorImpl( this, owner, (JdbcResourceTransactionAccess) owner );
}
throw new HibernateException(
@ -74,6 +67,6 @@ public class ResourceLocalTransactionCoordinatorBuilderImpl implements Transacti
@Override
public ConnectionAcquisitionMode getDefaultConnectionAcquisitionMode() {
return null;
return ConnectionAcquisitionMode.DEFAULT;
}
}

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.resource.transaction.backend.store.internal;
package org.hibernate.resource.transaction.backend.jdbc.internal;
import javax.transaction.Status;
@ -36,8 +36,8 @@ 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.store.spi.DataStoreTransaction;
import org.hibernate.resource.transaction.backend.store.spi.DataStoreTransactionAccess;
import org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransaction;
import org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransactionAccess;
import org.hibernate.resource.transaction.internal.SynchronizationRegistryStandardImpl;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner;
import org.hibernate.resource.transaction.spi.TransactionStatus;
@ -45,17 +45,18 @@ import org.hibernate.resource.transaction.spi.TransactionStatus;
import static org.hibernate.internal.CoreLogging.messageLogger;
/**
* An implementation of TransactionCoordinator based on managing a transaction through the data-store
* specific ResourceLocalTransaction.
* An implementation of TransactionCoordinator based on managing a transaction through the JDBC Connection
* via {@link org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransaction}
*
* @author Steve Ebersole
* @see org.hibernate.resource.transaction.backend.store.spi.DataStoreTransaction
*
* @see org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransaction
*/
public class ResourceLocalTransactionCoordinatorImpl implements TransactionCoordinator {
private static final CoreMessageLogger log = messageLogger( ResourceLocalTransactionCoordinatorImpl.class );
public class JdbcResourceLocalTransactionCoordinatorImpl implements TransactionCoordinator {
private static final CoreMessageLogger log = messageLogger( JdbcResourceLocalTransactionCoordinatorImpl.class );
private final TransactionCoordinatorBuilder transactionCoordinatorBuilder;
private final DataStoreTransactionAccess dataStoreTransactionAccess;
private final JdbcResourceTransactionAccess jdbcResourceTransactionAccess;
private final TransactionCoordinatorOwner transactionCoordinatorOwner;
private final SynchronizationRegistryStandardImpl synchronizationRegistry = new SynchronizationRegistryStandardImpl();
@ -71,13 +72,13 @@ public class ResourceLocalTransactionCoordinatorImpl implements TransactionCoord
*
* @param owner The transactionCoordinatorOwner
*/
ResourceLocalTransactionCoordinatorImpl(
JdbcResourceLocalTransactionCoordinatorImpl(
TransactionCoordinatorBuilder transactionCoordinatorBuilder,
TransactionCoordinatorOwner owner,
DataStoreTransactionAccess dataStoreTransactionAccess) {
JdbcResourceTransactionAccess jdbcResourceTransactionAccess) {
this.observers = new ArrayList<TransactionObserver>();
this.transactionCoordinatorBuilder = transactionCoordinatorBuilder;
this.dataStoreTransactionAccess = dataStoreTransactionAccess;
this.jdbcResourceTransactionAccess = jdbcResourceTransactionAccess;
this.transactionCoordinatorOwner = owner;
}
@ -87,7 +88,7 @@ public class ResourceLocalTransactionCoordinatorImpl implements TransactionCoord
// coordinator. We lazily build it as we invalidate each delegate after each transaction (a delegate is
// valid for just one transaction)
if ( physicalTransactionDelegate == null ) {
physicalTransactionDelegate = new TransactionDriverControlImpl( dataStoreTransactionAccess.getResourceLocalTransaction() );
physicalTransactionDelegate = new TransactionDriverControlImpl( jdbcResourceTransactionAccess.getResourceLocalTransaction() );
}
return physicalTransactionDelegate;
}
@ -200,12 +201,12 @@ public class ResourceLocalTransactionCoordinatorImpl implements TransactionCoord
* transaction via the JDBC Connection.
*/
public class TransactionDriverControlImpl implements LocalInflow {
private final DataStoreTransaction dataStoreTransaction;
private final JdbcResourceTransaction jdbcResourceTransaction;
private boolean invalid;
public TransactionDriverControlImpl(DataStoreTransaction dataStoreTransaction) {
public TransactionDriverControlImpl(JdbcResourceTransaction jdbcResourceTransaction) {
super();
this.dataStoreTransaction = dataStoreTransaction;
this.jdbcResourceTransaction = jdbcResourceTransaction;
}
protected void invalidate() {
@ -216,8 +217,8 @@ public class ResourceLocalTransactionCoordinatorImpl implements TransactionCoord
public void begin() {
errorIfInvalid();
dataStoreTransaction.begin();
ResourceLocalTransactionCoordinatorImpl.this.afterBeginCallback();
jdbcResourceTransaction.begin();
JdbcResourceLocalTransactionCoordinatorImpl.this.afterBeginCallback();
}
protected void errorIfInvalid() {
@ -228,20 +229,20 @@ public class ResourceLocalTransactionCoordinatorImpl implements TransactionCoord
@Override
public void commit() {
ResourceLocalTransactionCoordinatorImpl.this.beforeCompletionCallback();
dataStoreTransaction.commit();
ResourceLocalTransactionCoordinatorImpl.this.afterCompletionCallback( true );
JdbcResourceLocalTransactionCoordinatorImpl.this.beforeCompletionCallback();
jdbcResourceTransaction.commit();
JdbcResourceLocalTransactionCoordinatorImpl.this.afterCompletionCallback( true );
}
@Override
public void rollback() {
dataStoreTransaction.rollback();
ResourceLocalTransactionCoordinatorImpl.this.afterCompletionCallback( false );
jdbcResourceTransaction.rollback();
JdbcResourceLocalTransactionCoordinatorImpl.this.afterCompletionCallback( false );
}
@Override
public TransactionStatus getStatus() {
return dataStoreTransaction.getStatus();
return jdbcResourceTransaction.getStatus();
}
@Override

View File

@ -28,11 +28,11 @@
* correlates to the JDBC notion of a transaction, which (unfortunately) is
* not modeled by an actual contract. Instead JDBC models transaction control
* via its Connection contract. Here we use
* {@link org.hibernate.resource.transaction.backend.store.spi.DataStoreTransaction}
* {@link org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransaction}
* as the encapsulation for conceptual JDBC transaction. It also helps isolate the
* {@link org.hibernate.resource.transaction} and {@link org.hibernate.resource.jdbc}
* packages from circularity. Lastly it does somewhat allow for potentially abstracting
* non-JDBC data stores into this transaction handling utilizing its data store specific
* transaction mechanism.
*/
package org.hibernate.resource.transaction.backend.store;
package org.hibernate.resource.transaction.backend.jdbc;

View File

@ -21,16 +21,16 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.resource.transaction.backend.store.spi;
package org.hibernate.resource.transaction.backend.jdbc.spi;
import org.hibernate.resource.transaction.spi.TransactionStatus;
/**
* Models access to the resource transaction of the underlying data store (JDBC).
* Models access to the resource transaction of the underlying JDBC resource.
*
* @author Steve Ebersole
*/
public interface DataStoreTransaction {
public interface JdbcResourceTransaction {
/**
* Begin the resource transaction
*/

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.resource.transaction.backend.store.spi;
package org.hibernate.resource.transaction.backend.jdbc.spi;
/**
* Provides access to DataStoreTransaction (JDBC transaction stand-in) for use in building resource-local
@ -29,12 +29,12 @@ package org.hibernate.resource.transaction.backend.store.spi;
*
* @author Steve Ebersole
*/
public interface DataStoreTransactionAccess {
public interface JdbcResourceTransactionAccess {
/**
* Provides access to the resource local transaction of this data store, which is used by the TransactionCoordinator
* to manage transactions against the data store when not using JTA.
*
* @return The resource-local transaction
*/
public DataStoreTransaction getResourceLocalTransaction();
public JdbcResourceTransaction getResourceLocalTransaction();
}

View File

@ -23,61 +23,26 @@
*/
package org.hibernate.resource.transaction.backend.jta.internal;
import org.hibernate.ConnectionAcquisitionMode;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
import org.hibernate.resource.jdbc.spi.JdbcSessionContext;
import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;
import org.hibernate.resource.transaction.TransactionCoordinatorJtaBuilder;
import org.hibernate.resource.transaction.TransactionCoordinator;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner;
import static org.hibernate.resource.jdbc.spi.JdbcSessionContext.*;
/**
* Concrete builder for JTA-based TransactionCoordinator instances.
*
* @author Steve Ebersole
*/
public class JtaTransactionCoordinatorBuilderImpl implements TransactionCoordinatorJtaBuilder {
private JtaPlatform jtaPlatform;
private boolean autoJoinTransactions = true;
private boolean preferUserTransactions;
private boolean performJtaThreadTracking = true;
private JdbcSessionOwner sessionOwner;
public class JtaTransactionCoordinatorBuilderImpl implements TransactionCoordinatorBuilder {
public static final String SHORT_NAME = "jta";
@Override
public TransactionCoordinatorJtaBuilder setJtaPlatform(JtaPlatform jtaPlatform) {
this.jtaPlatform = jtaPlatform;
return this;
}
@Override
public TransactionCoordinatorJtaBuilder setAutoJoinTransactions(boolean autoJoinTransactions) {
this.autoJoinTransactions = autoJoinTransactions;
return this;
}
@Override
public TransactionCoordinatorJtaBuilder setPreferUserTransactions(boolean preferUserTransactions) {
this.preferUserTransactions = preferUserTransactions;
return this;
}
@Override
public TransactionCoordinatorJtaBuilder setPerformJtaThreadTracking(boolean performJtaThreadTracking) {
this.performJtaThreadTracking = performJtaThreadTracking;
return this;
}
@Override
public TransactionCoordinator buildTransactionCoordinator(TransactionCoordinatorOwner owner) {
public TransactionCoordinator buildTransactionCoordinator(TransactionCoordinatorOwner owner, TransactionCoordinatorOptions options) {
return new JtaTransactionCoordinatorImpl(
this,
owner,
jtaPlatform,
autoJoinTransactions,
preferUserTransactions,
performJtaThreadTracking
options.shouldAutoJoinTransaction()
);
}

View File

@ -1,19 +1,17 @@
package org.hibernate.resource.transaction.backend.jta.internal;
import java.util.ArrayList;
import java.util.List;
import javax.transaction.Status;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;
import java.util.ArrayList;
import java.util.List;
import org.jboss.logging.Logger;
import org.hibernate.TransactionException;
import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
import org.hibernate.engine.transaction.spi.IsolationDelegate;
import org.hibernate.engine.transaction.spi.TransactionObserver;
import org.hibernate.resource.jdbc.spi.JdbcSessionContext;
import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;
import org.hibernate.resource.transaction.SynchronizationRegistry;
import org.hibernate.resource.transaction.TransactionCoordinator;
@ -27,6 +25,8 @@ import org.hibernate.resource.transaction.internal.SynchronizationRegistryStanda
import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner;
import org.hibernate.resource.transaction.spi.TransactionStatus;
import org.jboss.logging.Logger;
import static org.hibernate.internal.CoreLogging.logger;
/**
@ -59,25 +59,24 @@ public class JtaTransactionCoordinatorImpl implements TransactionCoordinator, Sy
* builder.
*
* @param owner The transactionCoordinatorOwner
* @param jtaPlatform The JtaPlatform to use
* @param autoJoinTransactions Should JTA transactions be auto-joined? Or should we wait for explicit join calls?
* @param preferUserTransactions Should we prefer using UserTransaction, as opposed to TransactionManager?
* @param performJtaThreadTracking Should we perform thread tracking?
*/
JtaTransactionCoordinatorImpl(
TransactionCoordinatorBuilder transactionCoordinatorBuilder,
TransactionCoordinatorOwner owner,
JtaPlatform jtaPlatform,
boolean autoJoinTransactions,
boolean preferUserTransactions,
boolean performJtaThreadTracking) {
boolean autoJoinTransactions) {
this.observers = new ArrayList<TransactionObserver>();
this.transactionCoordinatorBuilder = transactionCoordinatorBuilder;
this.transactionCoordinatorOwner = owner;
this.jtaPlatform = jtaPlatform;
this.autoJoinTransactions = autoJoinTransactions;
this.preferUserTransactions = preferUserTransactions;
this.performJtaThreadTracking = performJtaThreadTracking;
final JdbcSessionContext jdbcSessionContext = owner.getJdbcSessionOwner().getJdbcSessionContext();
this.jtaPlatform = jdbcSessionContext.getServiceRegistry().getService( JtaPlatform.class );
final SessionFactoryOptions sessionFactoryOptions = jdbcSessionContext.getSessionFactory().getSessionFactoryOptions();
this.preferUserTransactions = sessionFactoryOptions.isPreferUserTransaction();
this.performJtaThreadTracking = sessionFactoryOptions.isJtaTrackByThread();
synchronizationRegistered = false;
@ -282,6 +281,10 @@ public class JtaTransactionCoordinatorImpl implements TransactionCoordinator, Sy
physicalTransactionDelegate.markRollbackOnly();
}
synchronizationRegistry.notifySynchronizationsBeforeTransactionCompletion();
for ( TransactionObserver observer : observers ) {
observer.beforeCompletion();
}
}
@Override
@ -291,6 +294,10 @@ public class JtaTransactionCoordinatorImpl implements TransactionCoordinator, Sy
transactionCoordinatorOwner.afterTransactionCompletion( successful );
for ( TransactionObserver observer : observers ) {
observer.afterCompletion( successful );
}
if ( physicalTransactionDelegate != null ) {
physicalTransactionDelegate.invalidate();
}

View File

@ -28,37 +28,31 @@ import java.util.Map;
import org.hibernate.boot.registry.StandardServiceInitiator;
import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilderFactory;
import org.hibernate.resource.transaction.TransactionCoordinatorJtaBuilder;
import org.hibernate.resource.transaction.backend.store.internal.ResourceLocalTransactionCoordinatorBuilderImpl;
import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl;
import org.hibernate.service.spi.ServiceRegistryImplementor;
/**
* StandardServiceInitiator for initiating the TransactionCoordinatorBuilder service.
*
* @author Andrea Boriero
* @author Steve Ebersole
*/
public class TransactionCoordinatorBuilderInitiator implements StandardServiceInitiator<TransactionCoordinatorBuilder> {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger(TransactionCoordinatorBuilderInitiator.class);
public static final TransactionCoordinatorBuilderInitiator INSTANCE = new TransactionCoordinatorBuilderInitiator();
/**
* Singleton access
*/
public static final TransactionCoordinatorBuilderInitiator INSTANCE = new TransactionCoordinatorBuilderInitiator();
@Override
public TransactionCoordinatorBuilder initiateService(
Map configurationValues, ServiceRegistryImplementor registry) {
public TransactionCoordinatorBuilder initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
final Object strategy = configurationValues.get( AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY );
if ( strategy == null ) {
return new ResourceLocalTransactionCoordinatorBuilderImpl() ;
}
// TransactionCoordinatorJtaBuilder transactionCoordinatorJtaBuilder = TransactionCoordinatorBuilderFactory.INSTANCE
// .forJta();
TransactionCoordinatorBuilder transactionCoordinatorBuilder = registry.getService( StrategySelector.class )
.resolveStrategy( TransactionCoordinatorBuilder.class, strategy );
return transactionCoordinatorBuilder;
return registry.getService( StrategySelector.class ).resolveDefaultableStrategy(
TransactionCoordinatorBuilder.class,
strategy,
JdbcResourceLocalTransactionCoordinatorBuilderImpl.INSTANCE
);
}
@Override

View File

@ -24,13 +24,12 @@
/**
* Defines the resource-level transaction capabilities of Hibernate, which revolves around the
* {@link org.hibernate.resource.transaction.TransactionCoordinator} contract. See
* {@link org.hibernate.resource.transaction.TransactionCoordinatorBuilder} and
* {@link org.hibernate.resource.transaction.TransactionCoordinatorBuilderFactory}
* for information on obtaining TransactionCoordinator instances.
*
* {@link org.hibernate.resource.transaction.TransactionCoordinator} contract.
* <p/>
* TransactionCoordinator instances can be obtained from
* {@link org.hibernate.resource.transaction.TransactionCoordinatorBuilder}, which is a Service
* and available from the StandardServiceRegistry
* <p/>
*
* A few terms/concepts to keep in mind here...
*
* <h2>Local transaction</h2>

View File

@ -91,8 +91,4 @@ public class DocumentInterceptor implements Interceptor {
public void onCollectionRemove(Object collection, Serializable key) throws CallbackException {}
public void onCollectionUpdate(Object collection, Serializable key) throws CallbackException {}
@Override
public String inspect(String sql) {
return sql;
}
}

View File

@ -112,9 +112,4 @@ public class DocumentInterceptor implements Interceptor {
public void onCollectionUpdate(Object collection, Serializable key) throws CallbackException {
}
@Override
public String inspect(String sql) {
return sql;
}
}

View File

@ -81,7 +81,7 @@ import org.hibernate.jpa.spi.IdentifierGeneratorStrategyProvider;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl;
import org.hibernate.resource.transaction.backend.store.internal.ResourceLocalTransactionCoordinatorBuilderImpl;
import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl;
import org.hibernate.secure.spi.GrantedPermission;
import org.hibernate.secure.spi.JaccPermissionDeclarations;
import org.hibernate.service.ServiceRegistry;
@ -560,7 +560,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
ssrBuilder.applySetting( Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class );
}
else if ( txnType == PersistenceUnitTransactionType.RESOURCE_LOCAL ) {
ssrBuilder.applySetting( Environment.TRANSACTION_COORDINATOR_STRATEGY, ResourceLocalTransactionCoordinatorBuilderImpl.class );
ssrBuilder.applySetting( Environment.TRANSACTION_COORDINATOR_STRATEGY, JdbcResourceLocalTransactionCoordinatorBuilderImpl.class );
}
}
}