diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractCompositeIdentifierMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractCompositeIdentifierMapping.java index b4503e75b4b9..0a1ac0b12589 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractCompositeIdentifierMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractCompositeIdentifierMapping.java @@ -11,15 +11,10 @@ import org.hibernate.engine.FetchTiming; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.metamodel.mapping.AttributeMapping; import org.hibernate.metamodel.mapping.CompositeIdentifierMapping; import org.hibernate.metamodel.mapping.EmbeddableMappingType; -import org.hibernate.metamodel.mapping.EntityIdentifierMapping; import org.hibernate.metamodel.mapping.EntityMappingType; -import org.hibernate.metamodel.mapping.ForeignKeyDescriptor; import org.hibernate.metamodel.mapping.ModelPart; -import org.hibernate.metamodel.mapping.SelectableMappings; import org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess; import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping; import org.hibernate.metamodel.model.domain.NavigableRole; @@ -30,12 +25,10 @@ import org.hibernate.sql.ast.spi.SqlAliasBase; import org.hibernate.sql.ast.spi.SqlAstCreationState; import org.hibernate.sql.ast.tree.expression.ColumnReference; -import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.ast.tree.expression.SqlTuple; import org.hibernate.sql.ast.tree.from.StandardVirtualTableGroup; import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.sql.ast.tree.from.TableGroupJoin; -import org.hibernate.sql.ast.tree.from.TableReference; import org.hibernate.sql.ast.tree.predicate.Predicate; import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultCreationState; @@ -48,6 +41,8 @@ import org.checkerframework.checker.nullness.qual.Nullable; +import static org.hibernate.internal.util.collections.CollectionHelper.arrayList; + /** * Base implementation for composite identifier mappings * @@ -66,7 +61,9 @@ public AbstractCompositeIdentifierMapping( EntityMappingType entityMapping, String tableExpression, MappingModelCreationProcess creationProcess) { - this.navigableRole = entityMapping.getNavigableRole().appendContainer( EntityIdentifierMapping.ID_ROLE_NAME ); + this.navigableRole = + entityMapping.getNavigableRole() + .appendContainer( ID_ROLE_NAME ); this.entityMapping = entityMapping; this.tableExpression = tableExpression; this.sessionFactory = creationProcess.getCreationContext().getSessionFactory(); @@ -135,8 +132,8 @@ public TableGroupJoin createTableGroupJoin( boolean fetched, boolean addsPredicate, SqlAstCreationState creationState) { - final SqlAstJoinType joinType = determineSqlJoinType( lhs, requestedJoinType, fetched ); - final TableGroup tableGroup = createRootTableGroupJoin( + final var joinType = determineSqlJoinType( lhs, requestedJoinType, fetched ); + final var tableGroup = createRootTableGroupJoin( navigablePath, lhs, explicitSourceAlias, @@ -146,7 +143,6 @@ public TableGroupJoin createTableGroupJoin( null, creationState ); - return new TableGroupJoin( navigablePath, joinType, tableGroup, null ); } @@ -184,26 +180,24 @@ public int forEachJdbcValue( JdbcValuesBiConsumer valuesConsumer, SharedSessionContractImplementor session) { int span = 0; - final EmbeddableMappingType embeddableTypeDescriptor = getEmbeddableTypeDescriptor(); + final var embeddableTypeDescriptor = getEmbeddableTypeDescriptor(); final int size = embeddableTypeDescriptor.getNumberOfAttributeMappings(); if ( value == null ) { for ( int i = 0; i < size; i++ ) { - final AttributeMapping attributeMapping = embeddableTypeDescriptor.getAttributeMapping( i ); + final var attributeMapping = embeddableTypeDescriptor.getAttributeMapping( i ); span += attributeMapping.forEachJdbcValue( null, span + offset, x, y, valuesConsumer, session ); } } else { for ( int i = 0; i < size; i++ ) { - final AttributeMapping attributeMapping = embeddableTypeDescriptor.getAttributeMapping( i ); - final Object o = embeddableTypeDescriptor.getValue( value, i ); + final var attributeMapping = embeddableTypeDescriptor.getAttributeMapping( i ); + final Object object = embeddableTypeDescriptor.getValue( value, i ); if ( attributeMapping instanceof ToOneAttributeMapping toOneAttributeMapping ) { - final ForeignKeyDescriptor fkDescriptor = toOneAttributeMapping.getForeignKeyDescriptor(); - final Object identifier = fkDescriptor.getAssociationKeyFromSide( - o, - toOneAttributeMapping.getSideNature().inverse(), - session - ); - span += fkDescriptor.forEachJdbcValue( + final var foreignKeyDescriptor = toOneAttributeMapping.getForeignKeyDescriptor(); + final var inverse = toOneAttributeMapping.getSideNature().inverse(); + final Object identifier = + foreignKeyDescriptor.getAssociationKeyFromSide( object, inverse, session ); + span += foreignKeyDescriptor.forEachJdbcValue( identifier, span + offset, x, @@ -213,7 +207,7 @@ public int forEachJdbcValue( ); } else { - span += attributeMapping.forEachJdbcValue( o, span + offset, x, y, valuesConsumer, session ); + span += attributeMapping.forEachJdbcValue( object, span + offset, x, y, valuesConsumer, session ); } } } @@ -226,22 +220,22 @@ public SqlTuple toSqlExpression( Clause clause, SqmToSqlAstConverter walker, SqlAstCreationState sqlAstCreationState) { - final SelectableMappings selectableMappings = getEmbeddableTypeDescriptor(); - final List columnReferences = CollectionHelper.arrayList( selectableMappings.getJdbcTypeCount() ); - final NavigablePath navigablePath = tableGroup.getNavigablePath().append( getNavigableRole().getNavigableName() ); - final TableReference defaultTableReference = tableGroup.resolveTableReference( navigablePath, getContainingTableExpression() ); + final List columnReferences = arrayList( getEmbeddableTypeDescriptor().getJdbcTypeCount() ); + final var navigablePath = tableGroup.getNavigablePath().append( getNavigableRole().getNavigableName() ); + final var defaultTableReference = tableGroup.resolveTableReference( navigablePath, getContainingTableExpression() ); getEmbeddableTypeDescriptor().forEachSelectable( (columnIndex, selection) -> { - final TableReference tableReference = getContainingTableExpression().equals( selection.getContainingTableExpression() ) - ? defaultTableReference - : tableGroup.resolveTableReference( navigablePath, selection.getContainingTableExpression() ); - final Expression columnReference = sqlAstCreationState.getSqlExpressionResolver() - .resolveSqlExpression( tableReference, selection ); - + final String containingTableExpression = selection.getContainingTableExpression(); + final var tableReference = + getContainingTableExpression().equals( containingTableExpression ) + ? defaultTableReference + : tableGroup.resolveTableReference( navigablePath, containingTableExpression ); + final var columnReference = + sqlAstCreationState.getSqlExpressionResolver() + .resolveSqlExpression( tableReference, selection ); columnReferences.add( (ColumnReference) columnReference ); } ); - return new SqlTuple( columnReferences, this ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractDynamicMapInstantiator.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractDynamicMapInstantiator.java index 68631f9011a7..b6ea007c4541 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractDynamicMapInstantiator.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractDynamicMapInstantiator.java @@ -33,8 +33,8 @@ public String getRoleName() { @Override public boolean isInstance(Object object) { return object instanceof Map map - && isSameRole( (String) map.get( TYPE_KEY ) ); - // todo (6.0) : should this be an exception if there is no TYPE_KEY + // TODO: should this be an exception if there is no TYPE_KEY + && roleName.equals( map.get( TYPE_KEY ) ); } protected boolean isSameRole(String type) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractEntityInstantiatorPojo.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractEntityInstantiatorPojo.java index a5efe315377b..e829644f5c1c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractEntityInstantiatorPojo.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractEntityInstantiatorPojo.java @@ -6,6 +6,7 @@ import org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor; +import org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor.EntityRelatedState; import org.hibernate.mapping.PersistentClass; import org.hibernate.metamodel.spi.EntityInstantiator; import org.hibernate.persister.entity.EntityPersister; @@ -23,7 +24,7 @@ public abstract class AbstractEntityInstantiatorPojo extends AbstractPojoInstant private final Class proxyInterface; private final boolean applyBytecodeInterception; - private final LazyAttributeLoadingInterceptor.EntityRelatedState loadingInterceptorState; + private final EntityRelatedState loadingInterceptorState; public AbstractEntityInstantiatorPojo( EntityPersister persister, @@ -34,17 +35,15 @@ public AbstractEntityInstantiatorPojo( //TODO this PojoEntityInstantiator appears to not be reused ?! applyBytecodeInterception = isPersistentAttributeInterceptableType( persistentClass.getMappedClass() ); - if ( applyBytecodeInterception ) { - loadingInterceptorState = new LazyAttributeLoadingInterceptor.EntityRelatedState( - persister.getEntityName(), - persister.getBytecodeEnhancementMetadata() - .getLazyAttributesMetadata() - .getLazyAttributeNames() - ); - } - else { - loadingInterceptorState = null; - } + loadingInterceptorState = + applyBytecodeInterception + ? new EntityRelatedState( + persister.getEntityName(), + persister.getBytecodeEnhancementMetadata() + .getLazyAttributesMetadata() + .getLazyAttributeNames() + ) + : null; } protected Object applyInterception(Object entity) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/BaseAttributeMetadata.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/BaseAttributeMetadata.java index 951c818d3003..cb71194d3941 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/BaseAttributeMetadata.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/BaseAttributeMetadata.java @@ -33,26 +33,27 @@ protected BaseAttributeMetadata( this.ownerType = ownerType; this.member = member; this.attributeClassification = attributeClassification; + //noinspection unchecked + javaType = (Class) declaredType( propertyMapping, member ); + } - final Class declaredType; - + private static Class declaredType(Property propertyMapping, Member member) { if ( member == null ) { // assume we have a MAP entity-mode "class" - declaredType = propertyMapping.getType().getReturnedClass(); + return propertyMapping.getType().getReturnedClass(); } else if ( member instanceof Field field ) { - declaredType = field.getType(); + return field.getType(); } else if ( member instanceof Method method ) { - declaredType = method.getReturnType(); + return method.getReturnType(); } else if ( member instanceof MapMember mapMember ) { - declaredType = mapMember.getType(); + return mapMember.getType(); } else { throw new IllegalArgumentException( "Cannot determine java-type from given member [" + member + "]" ); } - this.javaType = declaredType; } public String getName() { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorDynamicMap.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorDynamicMap.java index 243f86c2ce40..b66760bf778c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorDynamicMap.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorDynamicMap.java @@ -31,9 +31,9 @@ public EmbeddableInstantiatorDynamicMap( @Override public Object instantiate(ValueAccess valuesAccess) { final Map dataMap = generateDataMap(); - final Object[] values = valuesAccess == null ? null : valuesAccess.getValues(); + final var values = valuesAccess == null ? null : valuesAccess.getValues(); if ( values != null ) { - final EmbeddableMappingType mappingType = runtimeDescriptorAccess.get(); + final var mappingType = runtimeDescriptorAccess.get(); mappingType.setValues( dataMap, values ); } return dataMap; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoIndirecting.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoIndirecting.java index bf1872efc626..4b02422129a0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoIndirecting.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoIndirecting.java @@ -39,8 +39,8 @@ public static EmbeddableInstantiatorPojoIndirecting of( @Override public Object instantiate(ValueAccess valuesAccess) { try { - final Object[] originalValues = valuesAccess.getValues(); - final Object[] values = new Object[originalValues.length]; + final var originalValues = valuesAccess.getValues(); + final var values = new Object[originalValues.length]; for ( int i = 0; i < values.length; i++ ) { values[i] = originalValues[index[i]]; } @@ -61,8 +61,8 @@ public EmbeddableInstantiatorPojoIndirectingWithGap(Constructor constructor, @Override public Object instantiate(ValueAccess valuesAccess) { try { - final Object[] originalValues = valuesAccess.getValues(); - final Object[] values = new Object[index.length]; + final var originalValues = valuesAccess.getValues(); + final var values = new Object[index.length]; for ( int i = 0; i < values.length; i++ ) { final int index = this.index[i]; if ( index >= 0 ) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoOptimized.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoOptimized.java index 91fe79c36325..40c72aeabeae 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoOptimized.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoOptimized.java @@ -31,8 +31,8 @@ public EmbeddableInstantiatorPojoOptimized( @Override public Object instantiate(ValueAccess valuesAccess) { final Object embeddable = instantiationOptimizer.newInstance(); - final EmbeddableMappingType embeddableMapping = embeddableMappingAccess.get(); - final Object[] values = valuesAccess.getValues(); + final var embeddableMapping = embeddableMappingAccess.get(); + final var values = valuesAccess.getValues(); if ( values != null ) { embeddableMapping.setValues( embeddable, values ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoStandard.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoStandard.java index 1d08d3c23cc1..f6218d5565c8 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoStandard.java @@ -52,7 +52,7 @@ public Object instantiate(ValueAccess valuesAccess) { } try { - final Object[] values = valuesAccess == null ? null : valuesAccess.getValues(); + final var values = valuesAccess == null ? null : valuesAccess.getValues(); final Object instance = constructor.newInstance(); if ( values != null ) { // At this point, createEmptyCompositesEnabled is always true. diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorProxied.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorProxied.java index 8b2bc41f2299..bb9c1893df24 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorProxied.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorProxied.java @@ -30,7 +30,7 @@ public EmbeddableInstantiatorProxied( @Override public Object instantiate(ValueAccess valuesAccess) { final Object proxy = factory.getProxy(); - final Object[] values = valuesAccess == null ? null : valuesAccess.getValues(); + final var values = valuesAccess == null ? null : valuesAccess.getValues(); if ( values != null ) { embeddableMappingAccess.get().setValues( proxy, values ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorRecordIndirecting.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorRecordIndirecting.java index 8d005539b3c7..aa323b43c8d5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorRecordIndirecting.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorRecordIndirecting.java @@ -36,8 +36,8 @@ public Object instantiate(ValueAccess valuesAccess) { } try { - final Object[] originalValues = valuesAccess.getValues(); - final Object[] values = new Object[originalValues.length]; + final var originalValues = valuesAccess.getValues(); + final var values = new Object[originalValues.length]; for ( int i = 0; i < values.length; i++ ) { values[i] = originalValues[index[i]]; } @@ -62,8 +62,8 @@ public Object instantiate(ValueAccess valuesAccess) { } try { - final Object[] originalValues = valuesAccess.getValues(); - final Object[] values = new Object[index.length]; + final var originalValues = valuesAccess.getValues(); + final var values = new Object[index.length]; for ( int i = 0; i < values.length; i++ ) { final int index = this.index[i]; if ( index >= 0 ) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorRecordStandard.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorRecordStandard.java index f9ea0a94a936..3fe5796bfbe0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorRecordStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorRecordStandard.java @@ -22,8 +22,7 @@ public class EmbeddableInstantiatorRecordStandard extends AbstractPojoInstantiat public EmbeddableInstantiatorRecordStandard(Class javaType) { super( javaType ); - final Class[] componentTypes = getRecordComponentTypes( javaType ); - this.constructor = getConstructorOrNull( javaType, componentTypes ); + constructor = getConstructorOrNull( javaType, getRecordComponentTypes( javaType ) ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableRepresentationStrategyPojo.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableRepresentationStrategyPojo.java index 1778361bd67f..ff64b3d31b40 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableRepresentationStrategyPojo.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableRepresentationStrategyPojo.java @@ -4,7 +4,6 @@ */ package org.hibernate.metamodel.internal; -import java.util.Collection; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Locale; @@ -12,7 +11,6 @@ import java.util.function.Supplier; import org.hibernate.HibernateException; -import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.selector.spi.StrategySelector; import org.hibernate.bytecode.spi.BytecodeProvider; import org.hibernate.bytecode.spi.ProxyFactoryFactory; @@ -63,7 +61,7 @@ public EmbeddableRepresentationStrategyPojo( final var subclassesByName = getSubclassesByName( bootDescriptor, creationContext ); boolean foundCustomAccessor = false; for ( int i = 0; i < bootDescriptor.getProperties().size(); i++ ) { - final Property property = bootDescriptor.getProperty( i ); + final var property = bootDescriptor.getProperty( i ); final Class embeddableClass; if ( subclassesByName != null ) { final var subclass = subclassesByName.get( bootDescriptor.getPropertyDeclaringClass( property ) ); @@ -127,13 +125,10 @@ private static JavaType resolveEmbeddableJavaType( CompositeUserType compositeUserType, RuntimeModelCreationContext creationContext) { final var javaTypeRegistry = creationContext.getTypeConfiguration().getJavaTypeRegistry(); - if ( compositeUserType == null ) { - return javaTypeRegistry.getDescriptor( bootDescriptor.getComponentClass() ); - } - else { - return javaTypeRegistry.resolveDescriptor( compositeUserType.returnedClass(), - () -> new CompositeUserTypeJavaTypeWrapper<>( compositeUserType ) ); - } + return compositeUserType == null + ? javaTypeRegistry.getDescriptor( bootDescriptor.getComponentClass() ) + : javaTypeRegistry.resolveDescriptor( compositeUserType.returnedClass(), + () -> new CompositeUserTypeJavaTypeWrapper<>( compositeUserType ) ); } private static EmbeddableInstantiator determineInstantiator( @@ -149,8 +144,7 @@ private static EmbeddableInstantiator determineInstantiator( reflectionOptimizer.getInstantiationOptimizer() ); } - - if ( bootDescriptor.isEmbedded() && isAbstractClass( embeddableClass ) ) { + else if ( bootDescriptor.isEmbedded() && isAbstractClass( embeddableClass ) ) { return new EmbeddableInstantiatorProxied( embeddableClass, runtimeDescriptorAccess, @@ -158,8 +152,9 @@ private static EmbeddableInstantiator determineInstantiator( .buildBasicProxyFactory( embeddableClass ) ); } - - return new EmbeddableInstantiatorPojoStandard( embeddableClass, runtimeDescriptorAccess ); + else { + return new EmbeddableInstantiatorPojoStandard( embeddableClass, runtimeDescriptorAccess ); + } } private static ProxyFactoryFactory getProxyFactoryFactory(RuntimeModelCreationContext creationContext) { @@ -168,21 +163,21 @@ private static ProxyFactoryFactory getProxyFactoryFactory(RuntimeModelCreationCo } private PropertyAccess buildPropertyAccess( - Property bootAttributeDescriptor, + Property property, Class embeddableClass, boolean requireSetters) { - final var strategy = propertyAccessStrategy( bootAttributeDescriptor, embeddableClass, strategySelector ); + final var strategy = propertyAccessStrategy( property, embeddableClass, strategySelector ); if ( strategy == null ) { throw new HibernateException( String.format( Locale.ROOT, "Could not resolve PropertyAccess for attribute `%s#%s`", getEmbeddableJavaType().getTypeName(), - bootAttributeDescriptor.getName() + property.getName() ) ); } - return strategy.buildPropertyAccess( embeddableClass, bootAttributeDescriptor.getName(), requireSetters ); + return strategy.buildPropertyAccess( embeddableClass, property.getName(), requireSetters ); } private static ReflectionOptimizer buildReflectionOptimizer( @@ -196,7 +191,7 @@ private static ReflectionOptimizer buildReflectionOptimizer( && !bootDescriptor.isPolymorphic() ) { final Map propertyAccessMap = new LinkedHashMap<>(); int i = 0; - for ( Property property : bootDescriptor.getProperties() ) { + for ( var property : bootDescriptor.getProperties() ) { propertyAccessMap.put( property.getName(), propertyAccesses[i] ); i++; } @@ -214,11 +209,11 @@ private static Map> getSubclassesByName( Component bootDescriptor, RuntimeModelCreationContext creationContext) { if ( bootDescriptor.isPolymorphic() ) { - final Collection subclassNames = bootDescriptor.getDiscriminatorValues().values(); + final var subclassNames = bootDescriptor.getDiscriminatorValues().values(); final Map> result = new HashMap<>( subclassNames.size() ); - final ClassLoaderService classLoaderService = creationContext.getBootstrapContext().getClassLoaderService(); + final var classLoaderService = creationContext.getBootstrapContext().getClassLoaderService(); for ( final String subclassName : subclassNames ) { - final Class embeddableClass = + final var embeddableClass = subclassName.equals( bootDescriptor.getComponentClassName() ) ? bootDescriptor.getComponentClass() : classLoaderService.classForName( subclassName ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityInstantiatorDynamicMap.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityInstantiatorDynamicMap.java index 0daf9a30a6bf..4b25f577d620 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityInstantiatorDynamicMap.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityInstantiatorDynamicMap.java @@ -27,8 +27,8 @@ public EntityInstantiatorDynamicMap(PersistentClass bootDescriptor) { super( bootDescriptor.getEntityName() ); entityRoleNames.add( getRoleName() ); if ( bootDescriptor.hasSubclasses() ) { - for ( PersistentClass subclassInfo : bootDescriptor.getSubclassClosure() ) { - entityRoleNames.add( subclassInfo.getEntityName() ); + for ( var subclass : bootDescriptor.getSubclassClosure() ) { + entityRoleNames.add( subclass.getEntityName() ); } } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityRepresentationStrategyMap.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityRepresentationStrategyMap.java index 5abb3c3e86a4..331000a7ea6f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityRepresentationStrategyMap.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityRepresentationStrategyMap.java @@ -49,7 +49,7 @@ public EntityRepresentationStrategyMap( private static ProxyFactory createProxyFactory(PersistentClass bootType) { try { - ProxyFactory proxyFactory = new MapProxyFactory(); + final var proxyFactory = new MapProxyFactory(); proxyFactory.postInstantiate( bootType.getEntityName(), null, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityRepresentationStrategyPojoStandard.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityRepresentationStrategyPojoStandard.java index 5e0baa9879b7..9c607329b999 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityRepresentationStrategyPojoStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityRepresentationStrategyPojoStandard.java @@ -153,7 +153,7 @@ private ProxyFactory resolveProxyFactory( private Map buildPropertyAccessMap(PersistentClass bootDescriptor) { final Map propertyAccessMap = new LinkedHashMap<>(); - for ( Property property : bootDescriptor.getPropertyClosure() ) { + for ( var property : bootDescriptor.getPropertyClosure() ) { propertyAccessMap.put( property.getName(), makePropertyAccess( property ) ); } return propertyAccessMap; @@ -187,7 +187,7 @@ private ProxyFactory createProxyFactory( final Method idGetterMethod; final Method idSetterMethod; try { - for ( Property property : bootDescriptor.getProperties() ) { + for ( var property : bootDescriptor.getProperties() ) { validateGetterSetterMethodProxyability( "Getter", property.getGetter( clazz ).getMethod() ); validateGetterSetterMethodProxyability( "Setter", @@ -251,8 +251,8 @@ private static Set> proxyInterfaces( } for ( var subclass : bootDescriptor.getSubclasses() ) { - final Class subclassProxy = subclass.getProxyInterface(); - final Class subclassClass = subclass.getMappedClass(); + final var subclassProxy = subclass.getProxyInterface(); + final var subclassClass = subclass.getMappedClass(); if ( subclassProxy != null && !subclassClass.equals( subclassProxy ) ) { if ( !subclassProxy.isInterface() ) { throw new MappingException( "proxy must be either an interface, or the class itself: " diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/FullNameImplicitDiscriminatorStrategy.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/FullNameImplicitDiscriminatorStrategy.java index bb313d27e5ee..982f7b55c3df 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/FullNameImplicitDiscriminatorStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/FullNameImplicitDiscriminatorStrategy.java @@ -9,7 +9,6 @@ import org.hibernate.metamodel.model.domain.NavigableRole; import org.hibernate.metamodel.spi.ImplicitDiscriminatorStrategy; import org.hibernate.metamodel.spi.MappingMetamodelImplementor; -import org.hibernate.persister.entity.EntityPersister; /** * ImplicitDiscriminatorStrategy implementation using entity {@linkplain EntityMappingType#getEntityName() full-names}. @@ -27,7 +26,7 @@ public Object toDiscriminatorValue(EntityMappingType entityMapping, NavigableRol @Override public EntityMappingType toEntityMapping(Object discriminatorValue, NavigableRole discriminatorRole, MappingMetamodelImplementor mappingModel) { if ( discriminatorValue instanceof String assumedEntityName ) { - final EntityPersister persister = mappingModel.findEntityDescriptor( assumedEntityName ); + final var persister = mappingModel.findEntityDescriptor( assumedEntityName ); if ( persister != null ) { return persister; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/InjectionHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/InjectionHelper.java index ff7a1d509c03..42362ca95b24 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/InjectionHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/InjectionHelper.java @@ -7,7 +7,6 @@ import org.hibernate.AssertionFailure; import org.hibernate.boot.model.NamedEntityGraphDefinition; import org.hibernate.boot.query.NamedQueryDefinition; -import org.hibernate.internal.util.ReflectHelper; import org.hibernate.metamodel.model.domain.spi.JpaMetamodelImplementor; import java.lang.reflect.Field; @@ -16,6 +15,7 @@ import static java.lang.Character.isJavaIdentifierPart; import static java.lang.reflect.Modifier.isPublic; import static org.hibernate.internal.CoreMessageLogger.CORE_LOGGER; +import static org.hibernate.internal.util.ReflectHelper.ensureAccessibility; public class InjectionHelper { @@ -50,7 +50,7 @@ public static void injectTypedQueryReference(NamedQueryDefinition definition, } public static String javaIdentifier(String name) { - final StringBuilder result = new StringBuilder(); + final var result = new StringBuilder(); int position = 0; while ( position < name.length() ) { final int codePoint = name.codePointAt( position ); @@ -70,7 +70,7 @@ public static void injectField( : metamodelClass.getDeclaredField( name ); try { if ( !isPublic( metamodelClass.getModifiers() ) ) { - ReflectHelper.ensureAccessibility( field ); + ensureAccessibility( field ); } field.set( null, model); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/JpaMetamodelPopulationSetting.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/JpaMetamodelPopulationSetting.java index 9af807ecaf9a..793cb409704e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/JpaMetamodelPopulationSetting.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/JpaMetamodelPopulationSetting.java @@ -7,8 +7,8 @@ import java.util.Locale; import java.util.Map; -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.internal.util.config.ConfigurationHelper; +import static org.hibernate.cfg.MappingSettings.JPA_METAMODEL_POPULATION; +import static org.hibernate.internal.util.config.ConfigurationHelper.getString; /** * @author Steve Ebersole @@ -27,11 +27,6 @@ public static JpaMetamodelPopulationSetting parse(String setting) { } public static JpaMetamodelPopulationSetting determineJpaMetaModelPopulationSetting(Map settings) { - String setting = ConfigurationHelper.getString( - AvailableSettings.JPA_METAMODEL_POPULATION, - settings, - "ignoreUnsupported" - ); - return JpaMetamodelPopulationSetting.parse( setting ); + return parse( getString( JPA_METAMODEL_POPULATION, settings, "ignoreUnsupported" ) ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/JpaStaticMetamodelPopulationSetting.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/JpaStaticMetamodelPopulationSetting.java index 9190cc51c39c..b277c7641e71 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/JpaStaticMetamodelPopulationSetting.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/JpaStaticMetamodelPopulationSetting.java @@ -7,9 +7,8 @@ import java.util.Locale; import java.util.Map; -import org.hibernate.internal.util.config.ConfigurationHelper; - import static org.hibernate.cfg.MappingSettings.STATIC_METAMODEL_POPULATION; +import static org.hibernate.internal.util.config.ConfigurationHelper.getString; /** * Enumerated setting used to control whether Hibernate looks for and populates @@ -43,15 +42,8 @@ public static JpaStaticMetamodelPopulationSetting parse(String setting) { } public static JpaStaticMetamodelPopulationSetting determineJpaStaticMetaModelPopulationSetting( - Map configurationValues) { - return parse( determineSetting( configurationValues ) ); + Map settings) { + return parse( getString( STATIC_METAMODEL_POPULATION, settings, "skipUnsupported" ) ); } - private static String determineSetting(Map configurationValues) { - return ConfigurationHelper.getString( - STATIC_METAMODEL_POPULATION, - configurationValues, - "skipUnsupported" - ); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/ManagedTypeRepresentationResolverStandard.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/ManagedTypeRepresentationResolverStandard.java index adbc05228f76..26f37c0d4618 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/ManagedTypeRepresentationResolverStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/ManagedTypeRepresentationResolverStandard.java @@ -55,8 +55,8 @@ public EmbeddableRepresentationStrategy resolveStrategy( Supplier runtimeDescriptorAccess, RuntimeModelCreationContext creationContext) { - final CompositeUserType compositeUserType = getCompositeUserType( bootDescriptor, creationContext ); - final EmbeddableInstantiator customInstantiator = + final var compositeUserType = getCompositeUserType( bootDescriptor, creationContext ); + final var customInstantiator = getCustomInstantiator( bootDescriptor, creationContext, compositeUserType ); if ( bootDescriptor.getComponentClassName() == null ) { // i.e. RepresentationMode.MAP; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java index 49ad7bed16b7..74a55651cf2c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java @@ -173,7 +173,7 @@ public Map, MappedSuperclassDomainType> getMappedSuperclassTypeMap() } public void registerEntityType(PersistentClass persistentClass, EntityTypeImpl entityType) { - final Class javaType = entityType.getJavaType(); + final var javaType = entityType.getJavaType(); if ( javaType != null && javaType != Map.class ) { entityTypes.put( javaType, entityType ); } @@ -186,7 +186,7 @@ public void registerEntityType(PersistentClass persistentClass, EntityTypeImpl< public void registerEmbeddableType( EmbeddableDomainType embeddableType, Component bootDescriptor) { - final var javaType = embeddableType.getJavaType(); + final var javaType = embeddableType.getJavaType(); assert javaType != null; assert !Map.class.isAssignableFrom( javaType ); embeddablesToProcess.computeIfAbsent( javaType, k -> new ArrayList<>( 1 ) ) @@ -264,10 +264,10 @@ public Map> getIdentifiableTypesByName() { if ( property.getValue() instanceof Component component && component.isGeneric() ) { // This is an embeddable property that uses generics, we have to retrieve the generic // component previously registered and create the concrete attribute - final Component genericComponent = + final var genericComponent = runtimeModelCreationContext.getMetadata() .getGenericComponent( component.getComponentClass() ); - final Property genericProperty = property.copy(); + final var genericProperty = property.copy(); genericProperty.setValue( genericComponent ); genericProperty.setGeneric( true ); final var attribute = factoryFunction.apply( entityType, genericProperty ); @@ -308,7 +308,7 @@ public void wrapUp() { applyVersionAttribute( persistentClass, jpaMapping ); applyGenericProperties( persistentClass, jpaMapping ); - for ( Property property : persistentClass.getDeclaredProperties() ) { + for ( var property : persistentClass.getDeclaredProperties() ) { if ( property.getValue() == persistentClass.getIdentifierMapper() ) { // property represents special handling for id-class mappings but we have already // accounted for the embedded property mappings in #applyIdMetadata && @@ -345,7 +345,7 @@ else if ( mapping instanceof MappedSuperclass mappedSuperclass ) { applyVersionAttribute( mappedSuperclass, jpaType ); // applyNaturalIdAttribute( safeMapping, jpaType ); - for ( Property property : mappedSuperclass.getDeclaredProperties() ) { + for ( var property : mappedSuperclass.getDeclaredProperties() ) { if ( isIdentifierProperty( property, mappedSuperclass ) ) { // property represents special handling for id-class mappings but we have already // accounted for the embedded property mappings in #applyIdMetadata && @@ -387,8 +387,8 @@ else if ( mappedSuperclass.isVersioned() && property == mappedSuperclass.getVers embeddablesToProcess.clear(); for ( var embeddable : processingEmbeddables ) { - final Component component = componentByEmbeddable.get( embeddable ); - for ( Property property : component.getProperties() ) { + final var component = componentByEmbeddable.get( embeddable ); + for ( var property : component.getProperties() ) { if ( !component.isPolymorphic() || embeddable.getTypeName().equals( component.getPropertyDeclaringClass( property ) ) ) { addAttribute( embeddable, property, component ); @@ -410,7 +410,7 @@ else if ( mappedSuperclass.isVersioned() && property == mappedSuperclass.getVers } private static boolean isIdentifierProperty(Property property, MappedSuperclass mappedSuperclass) { - final Component identifierMapper = mappedSuperclass.getIdentifierMapper(); + final var identifierMapper = mappedSuperclass.getIdentifierMapper(); return identifierMapper != null && ArrayHelper.contains( identifierMapper.getPropertyNames(), property.getName() ); } @@ -418,7 +418,7 @@ private static boolean isIdentifierProperty(Property property, MappedSuperclass private void addAttribute(EmbeddableDomainType embeddable, Property property, Component component) { final var attribute = buildAttribute( embeddable, property); if ( attribute != null ) { - final Property superclassProperty = + final var superclassProperty = getMappedSuperclassProperty( property.getName(), component.getMappedSuperclass() ); if ( superclassProperty != null && superclassProperty.isGeneric() ) { @@ -453,8 +453,8 @@ private void addAttribute(ManagedDomainType type, PersistentAttribute) attribute.getValueGraphType(); - final Component component = componentByEmbeddable.get( embeddableDomainType ); - for ( Property property : component.getProperties() ) { + final var component = componentByEmbeddable.get( embeddableDomainType ); + for ( var property : component.getProperties() ) { final var subAttribute = buildAttribute( embeddableDomainType, property ); if ( subAttribute != null ) { inFlightAccess.addAttribute( subAttribute ); @@ -475,7 +475,7 @@ private void applyIdMetadata(PersistentClass persistentClass, IdentifiableDo if ( persistentClass.hasIdentifierProperty() ) { final var managedType = (ManagedDomainType) identifiableType; final var attributeContainer = (AttributeContainer) managedType; - final Property declaredIdentifierProperty = persistentClass.getDeclaredIdentifierProperty(); + final var declaredIdentifierProperty = persistentClass.getDeclaredIdentifierProperty(); if ( declaredIdentifierProperty != null ) { final var idAttribute = (SingularPersistentAttribute) @@ -484,7 +484,7 @@ private void applyIdMetadata(PersistentClass persistentClass, IdentifiableDo attributeContainer.getInFlightAccess().applyIdAttribute( idAttribute ); } else { - final Property superclassIdentifier = getMappedSuperclassIdentifier( persistentClass ); + final var superclassIdentifier = getMappedSuperclassIdentifier( persistentClass ); if ( superclassIdentifier != null && superclassIdentifier.isGeneric() ) { // If the superclass identifier is generic, we have to build the attribute to register the concrete type final var concreteIdentifier = @@ -511,7 +511,7 @@ private void applyIdAttributes( final List cidProperties; final int propertySpan; final EmbeddableTypeImpl idClassType; - final Component identifierMapper = persistentClass.getIdentifierMapper(); + final var identifierMapper = persistentClass.getIdentifierMapper(); if ( identifierMapper != null ) { cidProperties = identifierMapper.getProperties(); propertySpan = identifierMapper.getPropertySpan(); @@ -593,7 +593,7 @@ private EmbeddableTypeImpl embeddableType(Component idClassComponent, Cla @SuppressWarnings("unchecked") private MappedSuperclassDomainType getMappedSuperclassDomainType(Component idClassComponent) { - final MappedSuperclass mappedSuperclass = idClassComponent.getMappedSuperclass(); + final var mappedSuperclass = idClassComponent.getMappedSuperclass(); return mappedSuperclass == null ? null : (MappedSuperclassDomainType) locateMappedSuperclassType( mappedSuperclass ); @@ -622,7 +622,7 @@ else if ( mappingType.getIdentifierMapper() != null ) { } private void applyVersionAttribute(PersistentClass persistentClass, EntityDomainType jpaEntityType) { - final Property declaredVersion = persistentClass.getDeclaredVersion(); + final var declaredVersion = persistentClass.getDeclaredVersion(); if ( declaredVersion != null ) { final var managedType = (ManagedDomainType) jpaEntityType; final var attributeContainer = (AttributeContainer) managedType; @@ -632,7 +632,7 @@ private void applyVersionAttribute(PersistentClass persistentClass, EntityDo } private void applyVersionAttribute(MappedSuperclass mappingType, MappedSuperclassDomainType jpaMappingType) { - final Property declaredVersion = mappingType.getDeclaredVersion(); + final var declaredVersion = mappingType.getDeclaredVersion(); if ( declaredVersion != null ) { final var managedType = (ManagedDomainType) jpaMappingType; final var attributeContainer = (AttributeContainer) managedType; @@ -644,9 +644,9 @@ private void applyVersionAttribute(MappedSuperclass mappingType, MappedSuper private void applyGenericProperties(PersistentClass persistentClass, EntityDomainType entityType) { var mappedSuperclass = getMappedSuperclass( persistentClass ); while ( mappedSuperclass != null ) { - for ( Property superclassProperty : mappedSuperclass.getDeclaredProperties() ) { + for ( var superclassProperty : mappedSuperclass.getDeclaredProperties() ) { if ( superclassProperty.isGeneric() ) { - final Property property = persistentClass.getProperty( superclassProperty.getName() ); + final var property = persistentClass.getProperty( superclassProperty.getName() ); final var managedType = (ManagedDomainType) entityType; final var attributeContainer = (AttributeContainer) managedType; attributeContainer.getInFlightAccess() @@ -680,13 +680,13 @@ private Property getMappedSuperclassProperty(String propertyName, MappedSupercla return null; } - for ( Property property : mappedSuperclass.getDeclaredProperties() ) { + for ( var property : mappedSuperclass.getDeclaredProperties() ) { if ( property.getName().equals( propertyName ) ) { return property; } } - final Property property = + final var property = getMappedSuperclassProperty( propertyName, mappedSuperclass.getSuperMappedSuperclass() ); if ( property != null ) { @@ -705,17 +705,17 @@ private Property getMappedSuperclassProperty(String propertyName, MappedSupercla CORE_LOGGER.trace( "Building old-school composite identifier [" + ownerType.getJavaType().getName() + ']' ); } final Set> attributes = new HashSet<>(); - for ( Property property : properties ) { + for ( var property : properties ) { attributes.add( buildIdAttribute( ownerType, property ) ); } return attributes; } private void populateStaticMetamodel(ManagedDomainType managedType, Set processedMetamodelClassName) { - final Class managedTypeClass = managedType.getJavaType(); + final var managedTypeClass = managedType.getJavaType(); if ( managedTypeClass != null // can be null for MAP entity mode, so skip... && processedMetamodelClassName.add( metamodelClassName( managedType ) ) ) { - final Class metamodelClass = metamodelClass( managedType ); + final var metamodelClass = metamodelClass( managedType ); if ( metamodelClass != null ) { registerAttributes( metamodelClass, managedType ); injectManagedType( managedType, metamodelClass ); @@ -821,7 +821,7 @@ public void pushEntityWorkedOn(PersistentClass persistentClass) { } public void popEntityWorkedOn(PersistentClass persistentClass) { - final PersistentClass stackTop = stackOfPersistentClassesBeingProcessed.remove( + final var stackTop = stackOfPersistentClassesBeingProcessed.remove( stackOfPersistentClassesBeingProcessed.size() - 1 ); if ( stackTop != persistentClass ) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/PluralAttributeMetadataImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/PluralAttributeMetadataImpl.java index ad3758e30352..2bf9f28aeee7 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/PluralAttributeMetadataImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/PluralAttributeMetadataImpl.java @@ -19,6 +19,17 @@ import org.hibernate.metamodel.ValueClassification; import org.hibernate.metamodel.model.domain.ManagedDomainType; +import static org.hibernate.metamodel.CollectionClassification.BAG; +import static org.hibernate.metamodel.CollectionClassification.ID_BAG; +import static org.hibernate.metamodel.CollectionClassification.LIST; +import static org.hibernate.metamodel.CollectionClassification.MAP; +import static org.hibernate.metamodel.CollectionClassification.ORDERED_MAP; +import static org.hibernate.metamodel.CollectionClassification.ORDERED_SET; +import static org.hibernate.metamodel.CollectionClassification.SET; +import static org.hibernate.metamodel.CollectionClassification.SORTED_MAP; +import static org.hibernate.metamodel.CollectionClassification.SORTED_SET; +import static org.hibernate.metamodel.internal.AttributeFactory.getSignatureType; + /** * @author Steve Ebersole */ @@ -26,8 +37,6 @@ class PluralAttributeMetadataImpl extends BaseAttributeMetadata implements PluralAttributeMetadata { private final CollectionClassification collectionClassification; - private final AttributeClassification elementClassification; - private final AttributeClassification listIndexOrMapKeyClassification; private final Class elementJavaType; private final Class keyJavaType; private final ValueContext elementValueContext; @@ -41,43 +50,17 @@ class PluralAttributeMetadataImpl AttributeClassification elementClassification, AttributeClassification listIndexOrMapKeyClassification) { super( propertyMapping, ownerType, member, attributeClassification ); - this.collectionClassification = determineCollectionType( getJavaType(), propertyMapping ); - this.elementClassification = elementClassification; - this.listIndexOrMapKeyClassification = listIndexOrMapKeyClassification; - - final var signatureType = AttributeFactory.getSignatureType( member ); - switch ( collectionClassification ) { - case MAP: - case SORTED_MAP: - case ORDERED_MAP: { - keyJavaType = signatureType != null - ? getClassFromGenericArgument( signatureType.getActualTypeArguments()[0] ) - : Object.class; - elementJavaType = signatureType != null - ? getClassFromGenericArgument( signatureType.getActualTypeArguments()[1] ) - : Object.class; - break; - } - case ARRAY: - case LIST: { - keyJavaType = Integer.class; - elementJavaType = signatureType != null - ? getClassFromGenericArgument( signatureType.getActualTypeArguments()[0] ) - : Object.class; - break; - } - default: { - elementJavaType = signatureType != null - ? getClassFromGenericArgument( signatureType.getActualTypeArguments()[0] ) - : Object.class; - keyJavaType = null; - } - } + + collectionClassification = determineCollectionType( getJavaType(), propertyMapping ); + + final var signatureType = getSignatureType( member ); + keyJavaType = getKeyJavaType( signatureType ); + elementJavaType = getElementJavaType( signatureType ); elementValueContext = new ValueContext() { @Override public Value getHibernateValue() { - return ( (Collection) getPropertyMapping().getValue() ).getElement(); + return ( (Collection) propertyMapping.getValue() ).getElement(); } @Override @@ -87,7 +70,7 @@ public Class getJpaBindableType() { @Override public ValueClassification getValueClassification() { - return toValueClassification(PluralAttributeMetadataImpl.this.elementClassification); + return toValueClassification( elementClassification ); } @Override @@ -101,7 +84,7 @@ public AttributeMetadata getAttributeMetadata() { keyValueContext = new ValueContext() { @Override public Value getHibernateValue() { - return ( (Map) getPropertyMapping().getValue() ).getIndex(); + return ( (Map) propertyMapping.getValue() ).getIndex(); } @Override @@ -111,7 +94,7 @@ public Class getJpaBindableType() { @Override public ValueClassification getValueClassification() { - return toValueClassification(PluralAttributeMetadataImpl.this.listIndexOrMapKeyClassification); + return toValueClassification( listIndexOrMapKeyClassification ); } @Override @@ -125,6 +108,30 @@ public AttributeMetadata getAttributeMetadata() { } } + private Class getElementJavaType(ParameterizedType signatureType) { + return switch ( collectionClassification ) { + case MAP, SORTED_MAP, ORDERED_MAP -> + signatureType == null + ? Object.class + : getClassFromGenericArgument( signatureType.getActualTypeArguments()[1] ); + case SET, SORTED_SET, ORDERED_SET, ARRAY, LIST, BAG, ID_BAG -> + signatureType == null + ? Object.class + : getClassFromGenericArgument( signatureType.getActualTypeArguments()[0] ); + }; + } + + private Class getKeyJavaType(ParameterizedType signatureType) { + return switch ( collectionClassification ) { + case ARRAY, LIST -> Integer.class; + case MAP, SORTED_MAP, ORDERED_MAP -> + signatureType == null + ? Object.class + : getClassFromGenericArgument( signatureType.getActualTypeArguments()[0] ); + default -> null; + }; + } + private static ValueClassification toValueClassification(AttributeClassification classification) { return switch ( classification ) { case EMBEDDED -> ValueClassification.EMBEDDABLE; @@ -138,15 +145,15 @@ private Class getClassFromGenericArgument(java.lang.reflect.Type type) { return clazz; } else if ( type instanceof TypeVariable typeVariable ) { - final java.lang.reflect.Type upperBound = typeVariable.getBounds()[0]; + final var upperBound = typeVariable.getBounds()[0]; return getClassFromGenericArgument( upperBound ); } else if ( type instanceof ParameterizedType parameterizedType ) { - final java.lang.reflect.Type rawType = parameterizedType.getRawType(); + final var rawType = parameterizedType.getRawType(); return getClassFromGenericArgument( rawType ); } else if ( type instanceof WildcardType wildcardType ) { - final java.lang.reflect.Type upperBound = wildcardType.getUpperBounds()[0]; + final var upperBound = wildcardType.getUpperBounds()[0]; return getClassFromGenericArgument( upperBound ); } else { @@ -159,38 +166,34 @@ else if ( type instanceof WildcardType wildcardType ) { public static CollectionClassification determineCollectionType(Class javaType, Property property) { final var collection = (Collection) property.getValue(); - if ( java.util.List.class.isAssignableFrom( javaType ) ) { - return CollectionClassification.LIST; + return LIST; } else if ( java.util.Set.class.isAssignableFrom( javaType ) ) { if ( collection.isSorted() ) { - return CollectionClassification.SORTED_SET; + return SORTED_SET; } - - if ( collection.hasOrder() ) { - return CollectionClassification.ORDERED_SET; + else if ( collection.hasOrder() ) { + return ORDERED_SET; + } + else { + return SET; } - - return CollectionClassification.SET; } else if ( java.util.Map.class.isAssignableFrom( javaType ) ) { if ( collection.isSorted() ) { - return CollectionClassification.SORTED_MAP; + return SORTED_MAP; } - - if ( collection.hasOrder() ) { - return CollectionClassification.ORDERED_MAP; + else if ( collection.hasOrder() ) { + return ORDERED_MAP; + } + else { + return MAP; } - - return CollectionClassification.MAP; } else if ( java.util.Collection.class.isAssignableFrom( javaType ) ) { - if ( collection.isIdentified() ) { - return CollectionClassification.ID_BAG; - } + return collection.isIdentified() ? ID_BAG : BAG; - return CollectionClassification.BAG; } else if ( javaType.isArray() ) { return CollectionClassification.ARRAY; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/PropertyAccessHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/PropertyAccessHelper.java index 2a902ad311ed..1c97512dfac8 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/PropertyAccessHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/PropertyAccessHelper.java @@ -20,7 +20,7 @@ static PropertyAccessStrategy propertyAccessStrategy( Property bootAttributeDescriptor, Class mappedClass, StrategySelector strategySelector) { - final PropertyAccessStrategy strategy = bootAttributeDescriptor.getPropertyAccessStrategy( mappedClass ); + final var strategy = bootAttributeDescriptor.getPropertyAccessStrategy( mappedClass ); if ( strategy != null ) { return strategy; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/ShortNameImplicitDiscriminatorStrategy.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/ShortNameImplicitDiscriminatorStrategy.java index bd513a8d89dc..a5a210c47832 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/ShortNameImplicitDiscriminatorStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/ShortNameImplicitDiscriminatorStrategy.java @@ -27,7 +27,7 @@ public Object toDiscriminatorValue(EntityMappingType entityMapping, NavigableRol public EntityMappingType toEntityMapping(Object discriminatorValue, NavigableRole discriminatorRole, MappingMetamodelImplementor mappingModel) { if ( discriminatorValue instanceof String assumedEntityName ) { final String importedName = mappingModel.getImportedName( assumedEntityName ); - final EntityMappingType entityMapping = mappingModel.findEntityDescriptor( importedName ); + final var entityMapping = mappingModel.findEntityDescriptor( importedName ); if ( entityMapping != null ) { return entityMapping; }