HHH-14625 Avoid performing a ServiceRegistryLookup in JtaTransactionCoordinatorImpl constructor

This commit is contained in:
Sanne Grinovero 2021-08-09 16:09:34 +01:00 committed by Sanne Grinovero
parent 135361a6b8
commit fb0279e3a7
2 changed files with 18 additions and 4 deletions

View File

@ -6,11 +6,14 @@
*/
package org.hibernate.resource.transaction.backend.jta.internal;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.transaction.spi.DdlTransactionIsolator;
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner;
import org.hibernate.service.spi.ServiceRegistryAwareService;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.tool.schema.internal.exec.JdbcContext;
/**
@ -18,15 +21,19 @@ import org.hibernate.tool.schema.internal.exec.JdbcContext;
*
* @author Steve Ebersole
*/
public class JtaTransactionCoordinatorBuilderImpl implements TransactionCoordinatorBuilder {
public class JtaTransactionCoordinatorBuilderImpl implements TransactionCoordinatorBuilder, ServiceRegistryAwareService {
public static final String SHORT_NAME = "jta";
private JtaPlatform jtaPlatform;
@Override
public TransactionCoordinator buildTransactionCoordinator(TransactionCoordinatorOwner owner, Options options) {
return new JtaTransactionCoordinatorImpl(
this,
owner,
options.shouldAutoJoinTransaction()
options.shouldAutoJoinTransaction(),
jtaPlatform
);
}
@ -45,4 +52,10 @@ public class JtaTransactionCoordinatorBuilderImpl implements TransactionCoordina
public DdlTransactionIsolator buildDdlTransactionIsolator(JdbcContext jdbcContext) {
return new DdlTransactionIsolatorJtaImpl( jdbcContext );
}
@Override
public void injectServices(ServiceRegistryImplementor serviceRegistry) {
this.jtaPlatform = serviceRegistry.getService( JtaPlatform.class );
}
}

View File

@ -74,14 +74,15 @@ public class JtaTransactionCoordinatorImpl implements TransactionCoordinator, Sy
JtaTransactionCoordinatorImpl(
TransactionCoordinatorBuilder transactionCoordinatorBuilder,
TransactionCoordinatorOwner owner,
boolean autoJoinTransactions) {
boolean autoJoinTransactions,
JtaPlatform jtaPlatform) {
this.transactionCoordinatorBuilder = transactionCoordinatorBuilder;
this.transactionCoordinatorOwner = owner;
this.autoJoinTransactions = autoJoinTransactions;
final JdbcSessionContext jdbcSessionContext = owner.getJdbcSessionOwner().getJdbcSessionContext();
this.jtaPlatform = jdbcSessionContext.getServiceRegistry().getService( JtaPlatform.class );
this.jtaPlatform = jtaPlatform;
final SessionFactoryOptions sessionFactoryOptions = jdbcSessionContext.getSessionFactory().getSessionFactoryOptions();
this.preferUserTransactions = sessionFactoryOptions.isPreferUserTransaction();