HHH-16630 Refactor code to avoid frequent lookup of Service MutationExecutorService

This commit is contained in:
Sanne Grinovero 2023-05-18 12:47:49 +01:00 committed by Andrea Boriero
parent af86f96f27
commit 9a255a1798
12 changed files with 36 additions and 28 deletions

View File

@ -21,6 +21,7 @@ import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.batch.spi.BatchBuilder;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider;
import org.hibernate.engine.jdbc.mutation.spi.MutationExecutorService;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.event.service.spi.EventListenerGroup;
@ -180,6 +181,7 @@ public final class FastSessionServices {
private final ConnectionObserverStatsBridge defaultJdbcObservers;
private final FormatMapper jsonFormatMapper;
private final FormatMapper xmlFormatMapper;
private final MutationExecutorService mutationExecutorService;
FastSessionServices(SessionFactoryImplementor sessionFactory) {
Objects.requireNonNull( sessionFactory );
@ -235,6 +237,7 @@ public final class FastSessionServices {
this.defaultJdbcBatchSize = sessionFactoryOptions.getJdbcBatchSize();
this.requiresMultiTenantConnectionProvider = sessionFactory.getSessionFactoryOptions().isMultiTenancyEnabled();
this.parameterMarkerStrategy = serviceRegistry.getService( ParameterMarkerStrategy.class );
this.mutationExecutorService = serviceRegistry.getService( MutationExecutorService.class );
//Some "hot" services:
this.connectionProvider = requiresMultiTenantConnectionProvider
@ -399,4 +402,9 @@ public final class FastSessionServices {
}
return xmlFormatMapper;
}
public MutationExecutorService getMutationExecutorService() {
return mutationExecutorService;
}
}

View File

@ -226,8 +226,8 @@ public class OneToManyPersister extends AbstractCollectionPersister {
assert NullnessHelper.areAllNonNull( updateRowOperation, updateRowValues, updateRowRestrictions );
final MutationExecutorService mutationExecutorService = getFactory()
.getServiceRegistry()
.getService( MutationExecutorService.class );
.getFastSessionServices()
.getMutationExecutorService();
final MutationExecutor mutationExecutor = mutationExecutorService.createExecutor(
() -> new BasicBatchKey( getNavigableRole() + "#INDEX" ),
new MutationOperationGroupSingle( MutationType.UPDATE, this, updateRowOperation ),

View File

@ -68,8 +68,8 @@ public class DeleteRowsCoordinatorStandard implements DeleteRowsCoordinator {
final MutationExecutorService mutationExecutorService = session
.getFactory()
.getServiceRegistry()
.getService( MutationExecutorService.class );
.getFastSessionServices()
.getMutationExecutorService();
final MutationExecutor mutationExecutor = mutationExecutorService.createExecutor(
() -> batchKey,
operationGroup,

View File

@ -65,8 +65,8 @@ public class DeleteRowsCoordinatorTablePerSubclass implements DeleteRowsCoordina
final MutationExecutorService mutationExecutorService = session
.getFactory()
.getServiceRegistry()
.getService( MutationExecutorService.class );
.getFastSessionServices()
.getMutationExecutorService();
final PluralAttributeMapping pluralAttribute = mutationTarget.getTargetPart();
final CollectionPersister collectionDescriptor = pluralAttribute.getCollectionDescriptor();

View File

@ -77,8 +77,8 @@ public class InsertRowsCoordinatorStandard implements InsertRowsCoordinator {
final MutationExecutorService mutationExecutorService = session
.getFactory()
.getServiceRegistry()
.getService( MutationExecutorService.class );
.getFastSessionServices()
.getMutationExecutorService();
final MutationExecutor mutationExecutor = mutationExecutorService.createExecutor(
() -> batchKey,
operationGroup,

View File

@ -72,8 +72,8 @@ public class InsertRowsCoordinatorTablePerSubclass implements InsertRowsCoordina
final MutationExecutorService mutationExecutorService = session
.getFactory()
.getServiceRegistry()
.getService( MutationExecutorService.class );
.getFastSessionServices()
.getMutationExecutorService();
final Iterator<?> entries = collection.entries( collectionDescriptor );
collection.preInsert( collectionDescriptor );

View File

@ -86,8 +86,8 @@ public class RemoveCoordinatorStandard implements RemoveCoordinator {
final MutationExecutorService mutationExecutorService = session
.getFactory()
.getServiceRegistry()
.getService( MutationExecutorService.class );
.getFastSessionServices()
.getMutationExecutorService();
final MutationExecutor mutationExecutor = mutationExecutorService.createExecutor(
() -> batchKey,
operationGroup,

View File

@ -78,8 +78,8 @@ public class RemoveCoordinatorTablePerSubclass implements RemoveCoordinator {
final MutationExecutorService mutationExecutorService = session
.getFactory()
.getServiceRegistry()
.getService( MutationExecutorService.class );
.getFastSessionServices()
.getMutationExecutorService();
final ForeignKeyDescriptor fkDescriptor = mutationTarget.getTargetPart().getKeyDescriptor();
for ( MutationOperationGroupSingle operationGroup : operationGroups ) {

View File

@ -63,8 +63,8 @@ public class UpdateRowsCoordinatorOneToMany extends AbstractUpdateRowsCoordinato
final MutationOperationGroupSingle operationGroup = resolveDeleteGroup();
final MutationExecutorService mutationExecutorService = session
.getFactory()
.getServiceRegistry()
.getService( MutationExecutorService.class );
.getFastSessionServices()
.getMutationExecutorService();
final MutationExecutor mutationExecutor = mutationExecutorService.createExecutor(
() -> new BasicBatchKey( getMutationTarget().getRolePath() + "#UPDATE-DELETE" ),
operationGroup,
@ -124,8 +124,8 @@ public class UpdateRowsCoordinatorOneToMany extends AbstractUpdateRowsCoordinato
final MutationOperationGroupSingle operationGroup = resolveInsertGroup();
final MutationExecutorService mutationExecutorService = session
.getFactory()
.getServiceRegistry()
.getService( MutationExecutorService.class );
.getFastSessionServices()
.getMutationExecutorService();
final MutationExecutor mutationExecutor = mutationExecutorService.createExecutor(
() -> new BasicBatchKey( getMutationTarget().getRolePath() + "#UPDATE-INSERT" ),
operationGroup,

View File

@ -50,8 +50,8 @@ public class UpdateRowsCoordinatorStandard extends AbstractUpdateRowsCoordinator
final MutationExecutorService mutationExecutorService = session
.getFactory()
.getServiceRegistry()
.getService( MutationExecutorService.class );
.getFastSessionServices()
.getMutationExecutorService();
final MutationExecutor mutationExecutor = mutationExecutorService.createExecutor(
() -> new BasicBatchKey( getMutationTarget().getRolePath() + "#UPDATE" ),
operationGroup,

View File

@ -66,8 +66,8 @@ public class UpdateRowsCoordinatorTablePerSubclass extends AbstractUpdateRowsCoo
final MutationExecutorService mutationExecutorService = session
.getFactory()
.getServiceRegistry()
.getService( MutationExecutorService.class );
.getFastSessionServices()
.getMutationExecutorService();
final MutationExecutor[] executors = new MutationExecutor[deleteSubclassEntries.length];
try {
@ -159,8 +159,8 @@ public class UpdateRowsCoordinatorTablePerSubclass extends AbstractUpdateRowsCoo
final MutationExecutorService mutationExecutorService = session
.getFactory()
.getServiceRegistry()
.getService( MutationExecutorService.class );
.getFastSessionServices()
.getMutationExecutorService();
final MutationExecutor[] executors = new MutationExecutor[insertSubclassEntries.length];
try {

View File

@ -976,15 +976,15 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple
private MutationExecutor executor(SharedSessionContractImplementor session, MutationOperationGroup group, boolean dynamicUpdate) {
return session.getSessionFactory()
.getServiceRegistry()
.getService( MutationExecutorService.class )
.getFastSessionServices()
.getMutationExecutorService()
.createExecutor( resolveBatchKeyAccess( dynamicUpdate, session ), group, session );
}
private MutationExecutor updateVersionExecutor(SharedSessionContractImplementor session, MutationOperationGroup group, boolean dynamicUpdate) {
return session.getSessionFactory()
.getServiceRegistry()
.getService( MutationExecutorService.class )
.getFastSessionServices()
.getMutationExecutorService()
.createExecutor( resolveUpdateVersionBatchKeyAccess( dynamicUpdate, session ), group, session );
}