Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,12 @@ public SessionFactoryOptionsBuilder(StandardServiceRegistry serviceRegistry, Boo

// we cannot use context.getConfigurationService() here because it might be missing some settings
// (the StandardServiceRegistry passed in here does not need to be the bootstrap service registry)
final ConfigurationService configurationService = serviceRegistry.requireService( ConfigurationService.class );
final var configurationService = serviceRegistry.requireService( ConfigurationService.class );

final StrategySelector strategySelector = serviceRegistry.requireService( StrategySelector.class );
final JdbcServices jdbcServices = serviceRegistry.requireService( JdbcServices.class );
final var strategySelector = serviceRegistry.requireService( StrategySelector.class );
final var jdbcServices = serviceRegistry.requireService( JdbcServices.class );

final Dialect dialect = jdbcServices.getJdbcEnvironment().getDialect();
final var dialect = jdbcServices.getJdbcEnvironment().getDialect();

final Map<String,Object> settings = new HashMap<>();
settings.putAll( map( dialect.getDefaultProperties() ) );
Expand Down Expand Up @@ -601,6 +601,12 @@ private static boolean disallowBatchUpdates(Dialect dialect, ExtractedDatabaseMe
return dialectAnswer != null ? !dialectAnswer : !meta.supportsBatchUpdates();
}

private static boolean hasStrategyConstructorSignature(Class<?>[] parameterTypes) {
return parameterTypes.length == 2
&& parameterTypes[0] == EntityMappingType.class
&& parameterTypes[1] == RuntimeModelCreationContext.class;
}

@SuppressWarnings("unchecked")
private SqmMultiTableMutationStrategy resolveSqmMutationStrategy(
String strategyName,
Expand Down Expand Up @@ -631,7 +637,7 @@ private SqmMultiTableMutationStrategy resolveSqmMutationStrategy(
else if ( parameterTypes.length == 0 ) {
emptyConstructor = constructor;
}
else if ( parameterTypes.length == 2 && parameterTypes[0] == EntityMappingType.class && parameterTypes[1] == RuntimeModelCreationContext.class ) {
else if ( hasStrategyConstructorSignature( parameterTypes ) ) {
entityBasedConstructor = (Constructor<SqmMultiTableMutationStrategy>) declaredConstructor;
}
}
Expand All @@ -649,13 +655,12 @@ else if ( emptyConstructor != null ) {
}
catch (Exception e) {
throw new StrategySelectionException(
"Could not instantiate named strategy class [" +
strategyClass.getName() + "]",
"Could not instantiate named strategy class [" + strategyClass.getName() + "]",
e
);
}
throw new IllegalArgumentException(
"Cannot instantiate the class [" + strategyClass.getName() + "] because it does not have a constructor that accepts a dialect or an empty constructor" );
throw new IllegalArgumentException( "Cannot instantiate the class [" + strategyClass.getName()
+ "] because it does not have a constructor that accepts a dialect or an empty constructor" );
}
else {
return null;
Expand All @@ -668,19 +673,16 @@ else if ( emptyConstructor != null ) {
private Constructor<SqmMultiTableMutationStrategy> resolveSqmMutationStrategyConstructor(
String strategyName,
StrategySelector strategySelector) {
if ( strategyName == null ) {
return null;
}

Class<? extends SqmMultiTableMutationStrategy> strategyClass =
strategySelector.selectStrategyImplementor( SqmMultiTableMutationStrategy.class, strategyName );
for ( Constructor<?> declaredConstructor : strategyClass.getDeclaredConstructors() ) {
final Class<?>[] parameterTypes = declaredConstructor.getParameterTypes();
if ( parameterTypes.length == 2 && parameterTypes[0] == EntityMappingType.class && parameterTypes[1] == RuntimeModelCreationContext.class ) {
return (Constructor<SqmMultiTableMutationStrategy>) declaredConstructor;
if ( strategyName != null ) {
final var strategyClass =
strategySelector.selectStrategyImplementor( SqmMultiTableMutationStrategy.class, strategyName );
for ( var declaredConstructor : strategyClass.getDeclaredConstructors() ) {
final var parameterTypes = declaredConstructor.getParameterTypes();
if ( hasStrategyConstructorSignature( parameterTypes ) ) {
return (Constructor<SqmMultiTableMutationStrategy>) declaredConstructor;
}
}
}

return null;
}

Expand Down Expand Up @@ -714,7 +716,7 @@ private SqmMultiTableInsertStrategy resolveSqmInsertStrategy(
else if ( parameterTypes.length == 0 ) {
emptyConstructor = constructor;
}
else if ( parameterTypes.length == 2 && parameterTypes[0] == EntityMappingType.class && parameterTypes[1] == RuntimeModelCreationContext.class ) {
else if ( hasStrategyConstructorSignature( parameterTypes ) ) {
entityBasedConstructor = (Constructor<SqmMultiTableInsertStrategy>) declaredConstructor;
}
}
Expand Down Expand Up @@ -751,19 +753,16 @@ else if ( emptyConstructor != null ) {
private Constructor<SqmMultiTableInsertStrategy> resolveSqmInsertStrategyConstructor(
String strategyName,
StrategySelector strategySelector) {
if ( strategyName == null ) {
return null;
}

Class<? extends SqmMultiTableInsertStrategy> strategyClass =
strategySelector.selectStrategyImplementor( SqmMultiTableInsertStrategy.class, strategyName );
for ( Constructor<?> declaredConstructor : strategyClass.getDeclaredConstructors() ) {
final Class<?>[] parameterTypes = declaredConstructor.getParameterTypes();
if ( parameterTypes.length == 2 && parameterTypes[0] == EntityMappingType.class && parameterTypes[1] == RuntimeModelCreationContext.class ) {
return (Constructor<SqmMultiTableInsertStrategy>) declaredConstructor;
if ( strategyName != null ) {
final var strategyClass =
strategySelector.selectStrategyImplementor( SqmMultiTableInsertStrategy.class, strategyName );
for ( var declaredConstructor : strategyClass.getDeclaredConstructors() ) {
final var parameterTypes = declaredConstructor.getParameterTypes();
if ( hasStrategyConstructorSignature( parameterTypes ) ) {
return (Constructor<SqmMultiTableInsertStrategy>) declaredConstructor;
}
}
}

return null;
}

Expand Down Expand Up @@ -844,7 +843,7 @@ private static Supplier<? extends Interceptor> interceptorSupplier(Class<? exten
private PhysicalConnectionHandlingMode interpretConnectionHandlingMode(
Map<String,Object> configurationSettings,
StandardServiceRegistry serviceRegistry) {
final PhysicalConnectionHandlingMode specifiedHandlingMode =
final var specifiedHandlingMode =
PhysicalConnectionHandlingMode.interpret( configurationSettings.get( CONNECTION_HANDLING ) );
return specifiedHandlingMode != null
? specifiedHandlingMode
Expand Down Expand Up @@ -995,7 +994,8 @@ public SqmMultiTableMutationStrategy resolveCustomSqmMultiTableMutationStrategy(
}
catch (Exception e) {
throw new StrategySelectionException(
String.format( "Could not instantiate named strategy class [%s]", sqmMultiTableMutationStrategyConstructor.getDeclaringClass().getName() ),
String.format( "Could not instantiate named strategy class [%s]",
sqmMultiTableMutationStrategyConstructor.getDeclaringClass().getName() ),
e
);
}
Expand All @@ -1011,7 +1011,8 @@ public SqmMultiTableInsertStrategy resolveCustomSqmMultiTableInsertStrategy(Enti
}
catch (Exception e) {
throw new StrategySelectionException(
String.format( "Could not instantiate named strategy class [%s]", sqmMultiTableInsertStrategyConstructor.getDeclaringClass().getName() ),
String.format( "Could not instantiate named strategy class [%s]",
sqmMultiTableInsertStrategyConstructor.getDeclaringClass().getName() ),
e
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6129,7 +6129,7 @@ else if ( literal instanceof Period period ) {
appender.appendSql( '(' );
}
boolean first = true;
for ( java.time.temporal.TemporalUnit unit : literal.getUnits() ) {
for ( var unit : literal.getUnits() ) {
final long value = literal.get( unit );
if ( value != 0 ) {
if ( first ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;
import javax.naming.Reference;
import javax.naming.StringRefAddr;
Expand Down Expand Up @@ -83,14 +82,11 @@
import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.jpa.internal.ExceptionMapperLegacyJpaImpl;
import org.hibernate.jpa.internal.PersistenceUnitUtilImpl;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.GeneratorSettings;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.RootClass;
import org.hibernate.metamodel.MappingMetamodel;
import org.hibernate.metamodel.RepresentationMode;
import org.hibernate.metamodel.internal.RuntimeMetamodelsImpl;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl;
import org.hibernate.metamodel.model.domain.spi.JpaMetamodelImplementor;
Expand Down Expand Up @@ -254,23 +250,23 @@ public SessionFactoryImpl(

jpaPersistenceUnitUtil = new PersistenceUnitUtilImpl( this );

for ( SessionFactoryObserver sessionFactoryObserver : options.getSessionFactoryObservers() ) {
for ( var sessionFactoryObserver : options.getSessionFactoryObservers() ) {
observer.addObserver( sessionFactoryObserver );
}

filters = new HashMap<>( bootMetamodel.getFilterDefinitions() );

final FilterDefinition tenantFilter = filters.get( TenantIdBinder.FILTER_NAME );
final var tenantFilter = filters.get( TenantIdBinder.FILTER_NAME );
if ( tenantFilter == null ) {
tenantIdentifierJavaType = options.getDefaultTenantIdentifierJavaType();
}
else {
final JdbcMapping jdbcMapping = tenantFilter.getParameterJdbcMapping( TenantIdBinder.PARAMETER_NAME );
final var jdbcMapping = tenantFilter.getParameterJdbcMapping( TenantIdBinder.PARAMETER_NAME );
assert jdbcMapping != null;
//noinspection unchecked
tenantIdentifierJavaType = jdbcMapping.getJavaTypeDescriptor();
}
for ( Map.Entry<String, FilterDefinition> filterEntry : filters.entrySet() ) {
for ( var filterEntry : filters.entrySet() ) {
if ( filterEntry.getValue().isAutoEnabled() ) {
autoEnabledFilters.add( filterEntry.getValue() );
}
Expand All @@ -283,7 +279,7 @@ public SessionFactoryImpl(
classLoaderService = serviceRegistry.requireService( ClassLoaderService.class );
jdbcValuesMappingProducerProvider = serviceRegistry.requireService( JdbcValuesMappingProducerProvider.class );

final IntegratorObserver integratorObserver = new IntegratorObserver();
final var integratorObserver = new IntegratorObserver();
observer.addObserver( integratorObserver );
try {
integrate( bootMetamodel, bootstrapContext, integratorObserver );
Expand All @@ -294,7 +290,7 @@ public SessionFactoryImpl(
primeSecondLevelCacheRegions( bootMetamodel );

// create the empty runtime metamodels object
final RuntimeMetamodelsImpl runtimeMetamodelsImpl = new RuntimeMetamodelsImpl( typeConfiguration );
final var runtimeMetamodelsImpl = new RuntimeMetamodelsImpl( typeConfiguration );
runtimeMetamodels = runtimeMetamodelsImpl;

// we build this before creating the runtime metamodels
Expand All @@ -305,7 +301,7 @@ public SessionFactoryImpl(
sqlTranslationEngine = new SqlTranslationEngineImpl( this, typeConfiguration, fetchProfiles );

// now actually create the mapping and JPA metamodels
final MappingMetamodelImpl mappingMetamodelImpl = new MappingMetamodelImpl( typeConfiguration, serviceRegistry );
final var mappingMetamodelImpl = new MappingMetamodelImpl( typeConfiguration, serviceRegistry );
runtimeMetamodelsImpl.setMappingMetamodel( mappingMetamodelImpl );
mappingMetamodelImpl.finishInitialization(
new ModelCreationContext( bootstrapContext, bootMetamodel, mappingMetamodelImpl, typeConfiguration ) );
Expand Down Expand Up @@ -432,22 +428,22 @@ class IntegratorObserver implements SessionFactoryObserver {
private final ArrayList<Integrator> integrators = new ArrayList<>();
@Override
public void sessionFactoryClosed(SessionFactory factory) {
for ( Integrator integrator : integrators ) {
for ( var integrator : integrators ) {
integrator.disintegrate( SessionFactoryImpl.this, SessionFactoryImpl.this.serviceRegistry );
}
integrators.clear();
}
}

private void integrate(MetadataImplementor bootMetamodel, BootstrapContext bootstrapContext, IntegratorObserver integratorObserver) {
for ( Integrator integrator : serviceRegistry.requireService( IntegratorService.class ).getIntegrators() ) {
for ( var integrator : serviceRegistry.requireService( IntegratorService.class ).getIntegrators() ) {
integrator.integrate( bootMetamodel, bootstrapContext, this );
integratorObserver.integrators.add( integrator );
}
}

private void disintegrate(Exception startupException, IntegratorObserver integratorObserver) {
for ( Integrator integrator : integratorObserver.integrators ) {
for ( var integrator : integratorObserver.integrators ) {
try {
integrator.disintegrate( this, serviceRegistry );
}
Expand Down Expand Up @@ -483,10 +479,9 @@ private void primeSecondLevelCacheRegions(MetadataImplementor mappingMetadata) {
// TODO: ultimately this code can be made more efficient when we have
// a better intrinsic understanding of the hierarchy as a whole

for ( PersistentClass bootEntityDescriptor : mappingMetadata.getEntityBindings() ) {
for ( var bootEntityDescriptor : mappingMetadata.getEntityBindings() ) {
final AccessType accessType =
AccessType.fromExternalName( bootEntityDescriptor.getCacheConcurrencyStrategy() );

if ( accessType != null ) {
if ( bootEntityDescriptor.isCached() ) {
regionConfigBuilders.computeIfAbsent(
Expand All @@ -508,8 +503,9 @@ private void primeSecondLevelCacheRegions(MetadataImplementor mappingMetadata) {
}
}

for ( Collection collection : mappingMetadata.getCollectionBindings() ) {
final AccessType accessType = AccessType.fromExternalName( collection.getCacheConcurrencyStrategy() );
for ( var collection : mappingMetadata.getCollectionBindings() ) {
final AccessType accessType =
AccessType.fromExternalName( collection.getCacheConcurrencyStrategy() );
if ( accessType != null ) {
regionConfigBuilders.computeIfAbsent(
collection.getCacheRegionName(),
Expand All @@ -525,7 +521,7 @@ private void primeSecondLevelCacheRegions(MetadataImplementor mappingMetadata) {
}
else {
regionConfigs = new HashSet<>();
for ( DomainDataRegionConfigImpl.Builder builder : regionConfigBuilders.values() ) {
for ( var builder : regionConfigBuilders.values() ) {
regionConfigs.add( builder.build() );
}
}
Expand Down Expand Up @@ -735,12 +731,12 @@ public boolean isOpen() {

@Override
public RootGraph<Map<String, ?>> createGraphForDynamicEntity(String entityName) {
final EntityDomainType<?> entity = getJpaMetamodel().entity( entityName );
final var entity = getJpaMetamodel().entity( entityName );
if ( entity.getRepresentationMode() != RepresentationMode.MAP ) {
throw new IllegalArgumentException( "Entity '" + entityName + "' is not a dynamic entity" );
}
@SuppressWarnings("unchecked") //Safe, because we just checked
final EntityDomainType<Map<String, ?>> dynamicEntity = (EntityDomainType<Map<String, ?>>) entity;
final var dynamicEntity = (EntityDomainType<Map<String, ?>>) entity;
return new RootGraphImpl<>( null, dynamicEntity );
}

Expand Down Expand Up @@ -1108,7 +1104,7 @@ public static Interceptor configuredInterceptor(Interceptor interceptor, boolean
}

// then check the Session-scoped interceptor prototype
final Supplier<? extends Interceptor> statelessInterceptorImplementorSupplier =
final var statelessInterceptorImplementorSupplier =
options.getStatelessInterceptorImplementorSupplier();
if ( statelessInterceptorImplementorSupplier != null ) {
return statelessInterceptorImplementorSupplier.get();
Expand Down