HHH-16323 Ensure new service ParameterMarkerStrategy can be looked up efficiently

This commit is contained in:
Sanne Grinovero 2023-03-16 16:15:59 +00:00 committed by Steve Ebersole
parent 85f98d21f9
commit faf98a14af
5 changed files with 22 additions and 6 deletions

View File

@ -66,6 +66,7 @@ import org.hibernate.jpa.internal.util.ConfigurationHelper;
import org.hibernate.jpa.internal.util.LockOptionsHelper;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.sql.ast.spi.ParameterMarkerStrategy;
import org.hibernate.type.format.FormatMapper;
import jakarta.persistence.CacheRetrieveMode;
@ -171,6 +172,7 @@ public final class FastSessionServices {
public final EntityCopyObserverFactory entityCopyObserverFactory;
public final BatchBuilder batchBuilder;
public final Dialect dialect;
public final ParameterMarkerStrategy parameterMarkerStrategy;
//Private fields:
private final CacheStoreMode defaultCacheStoreMode;
@ -232,6 +234,7 @@ public final class FastSessionServices {
this.defaultTimeZoneStorageStrategy = sessionFactoryOptions.getDefaultTimeZoneStorageStrategy();
this.defaultJdbcBatchSize = sessionFactoryOptions.getJdbcBatchSize();
this.requiresMultiTenantConnectionProvider = sessionFactory.getSessionFactoryOptions().isMultiTenancyEnabled();
this.parameterMarkerStrategy = serviceRegistry.getService( ParameterMarkerStrategy.class );
//Some "hot" services:
this.connectionProvider = requiresMultiTenantConnectionProvider

View File

@ -29,7 +29,7 @@ public class Delete implements RestrictionRenderingContext {
private int parameterCount;
public Delete(SessionFactoryImplementor factory) {
this( factory.getServiceRegistry().getService( ParameterMarkerStrategy.class ) );
this( factory.getFastSessionServices().parameterMarkerStrategy );
}
public Delete(ParameterMarkerStrategy parameterMarkerStrategy) {

View File

@ -38,8 +38,8 @@ public class Insert {
public Insert(SessionFactoryImplementor sessionFactory) {
this(
sessionFactory.getJdbcServices().getDialect(),
sessionFactory.getServiceRegistry().getService( ParameterMarkerStrategy.class )
sessionFactory.getFastSessionServices().dialect,
sessionFactory.getFastSessionServices().parameterMarkerStrategy
);
}

View File

@ -18,6 +18,7 @@ import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.FastSessionServices;
import org.hibernate.sql.ast.spi.ParameterMarkerStrategy;
/**
@ -42,8 +43,20 @@ public class SimpleSelect implements RestrictionRenderingContext {
private int parameterCount;
public SimpleSelect(SessionFactoryImplementor factory) {
this.dialect = factory.getJdbcServices().getDialect();
this.parameterMarkerStrategy = factory.getServiceRegistry().getService( ParameterMarkerStrategy.class );
this.dialect = lookupDialect( factory );
this.parameterMarkerStrategy = lookupParameterMarkerStrategy( factory );
}
//A SimpleSelect constructor might be invoked before the FastSessionServices are defined
private static Dialect lookupDialect(final SessionFactoryImplementor factory) {
final FastSessionServices fastSessionServices = factory.getFastSessionServices();
return fastSessionServices != null ? fastSessionServices.dialect : factory.getJdbcServices().getDialect();
}
//A SimpleSelect constructor might be invoked before the FastSessionServices are defined
private static ParameterMarkerStrategy lookupParameterMarkerStrategy(final SessionFactoryImplementor factory) {
final FastSessionServices fastSessionServices = factory.getFastSessionServices();
return fastSessionServices != null ? fastSessionServices.parameterMarkerStrategy : factory.getServiceRegistry().getService( ParameterMarkerStrategy.class );
}
@Override

View File

@ -32,7 +32,7 @@ public class Update implements RestrictionRenderingContext {
private int parameterCount;
public Update(SessionFactoryImplementor factory) {
this( factory.getServiceRegistry().getService( ParameterMarkerStrategy.class ) );
this( factory.getFastSessionServices().parameterMarkerStrategy );
}
public Update(ParameterMarkerStrategy parameterMarkerStrategy) {