From 09299e1f417a193dabf0e020f33166522d67ccad Mon Sep 17 00:00:00 2001 From: Gavin King Date: Wed, 26 Jan 2022 21:42:16 +0100 Subject: [PATCH] get rid of the last iterators in the mapping package --- .../InFlightMetadataCollectorImpl.java | 28 ++++----- .../source/internal/hbm/ModelBinder.java | 32 +++++----- .../NaturalIdDataCachingConfigImpl.java | 8 +-- .../org/hibernate/cfg/AnnotationBinder.java | 17 ++---- .../hibernate/cfg/CollectionSecondPass.java | 3 +- .../CopyIdentifierComponentSecondPass.java | 4 +- .../hibernate/cfg/CreateKeySecondPass.java | 3 +- .../cfg/IdGeneratorResolverSecondPass.java | 3 +- .../cfg/JoinedSubclassFkSecondPass.java | 3 +- .../org/hibernate/cfg/OneToOneSecondPass.java | 9 ++- .../PkDrivenByDefaultMapsIdSecondPass.java | 4 +- .../hibernate/cfg/PropertyHolderBuilder.java | 3 +- .../hibernate/cfg/PropertyInferredData.java | 1 + .../cfg/SecondaryTableSecondPass.java | 10 ++-- .../cfg/SetBasicValueTypeSecondPass.java | 7 ++- .../cfg/SimpleToOneFkSecondPass.java | 3 +- .../org/hibernate/cfg/ToOneFkSecondPass.java | 6 +- ...VerifyFetchProfileReferenceSecondPass.java | 8 +-- .../hibernate/cfg/annotations/MapBinder.java | 9 ++- .../ResultsetMappingSecondPass.java | 53 +++++++--------- ...NullableDiscriminatorColumnSecondPass.java | 10 ++-- .../dialect/SpannerDialectTableExporter.java | 14 ++--- .../dialect/unique/UniqueDelegate.java | 8 +-- .../util/collections/IdentityMap.java | 2 +- .../jpa/event/internal/CallbacksFactory.java | 6 +- .../org/hibernate/mapping/BasicValue.java | 50 +++++++--------- .../org/hibernate/mapping/Constraint.java | 4 +- .../hibernate/mapping/DenormalizedTable.java | 22 +++---- .../org/hibernate/mapping/ForeignKey.java | 31 ++++------ .../hibernate/mapping/IndexedCollection.java | 5 +- .../java/org/hibernate/mapping/ManyToOne.java | 6 +- .../hibernate/mapping/MappedSuperclass.java | 29 ++++----- .../org/hibernate/mapping/MappingHelper.java | 7 +-- .../hibernate/mapping/PersistentClass.java | 60 +++++++++++++++---- .../org/hibernate/mapping/PrimaryKey.java | 8 +-- .../java/org/hibernate/mapping/RootClass.java | 11 ++-- .../mapping/SingleTableSubclass.java | 1 + .../java/org/hibernate/mapping/Subclass.java | 10 +++- .../java/org/hibernate/mapping/Table.java | 20 +++++-- .../EntityInstantiatorDynamicMap.java | 4 +- ...ityRepresentationStrategyPojoStandard.java | 4 +- .../metamodel/internal/MetadataContext.java | 9 +-- .../entity/AbstractEntityPersister.java | 4 +- .../entity/JoinedSubclassEntityPersister.java | 35 +++++------ .../entity/SingleTableEntityPersister.java | 19 +++--- .../entity/UnionSubclassEntityPersister.java | 20 +++---- .../StandardPersisterClassResolver.java | 19 +++--- .../proxy/pojo/ProxyFactoryHelper.java | 5 +- .../internal/AbstractSchemaMigrator.java | 21 ++----- .../internal/AbstractSchemaValidator.java | 5 +- .../schema/internal/SchemaCreatorImpl.java | 8 +-- .../schema/internal/SchemaDropperImpl.java | 5 +- .../internal/StandardTableExporter.java | 16 ++--- .../tuple/DynamicMapInstantiator.java | 5 +- .../tuple/entity/EntityMetamodel.java | 12 ++-- .../metadata/CollectionMappedByResolver.java | 9 +-- 56 files changed, 337 insertions(+), 381 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java index 110944ac0a..11012af669 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java @@ -1872,16 +1872,14 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector final MetadataBuildingContext buildingContext) throws MappingException { table.createForeignKeys(); - Iterator itr = table.getForeignKeyIterator(); - while ( itr.hasNext() ) { - final ForeignKey fk = (ForeignKey) itr.next(); - if ( !done.contains( fk ) ) { - done.add( fk ); - final String referencedEntityName = fk.getReferencedEntityName(); + for ( ForeignKey foreignKey : table.getForeignKeys().values() ) { + if ( !done.contains( foreignKey ) ) { + done.add( foreignKey ); + final String referencedEntityName = foreignKey.getReferencedEntityName(); if ( referencedEntityName == null ) { throw new MappingException( "An association from the table " + - fk.getTable().getName() + + foreignKey.getTable().getName() + " does not specify the referenced entity" ); } @@ -1891,7 +1889,7 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector if ( referencedClass == null ) { throw new MappingException( "An association from the table " + - fk.getTable().getName() + + foreignKey.getTable().getName() + " refers to an unmapped class: " + referencedEntityName ); @@ -1900,12 +1898,12 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector secondPassCompileForeignKeys( referencedClass.getSuperclass().getTable(), done, buildingContext ); } - fk.setReferencedTable( referencedClass.getTable() ); + foreignKey.setReferencedTable( referencedClass.getTable() ); Identifier nameIdentifier; ImplicitForeignKeyNameSource foreignKeyNameSource = new ImplicitForeignKeyNameSource() { - final List columnNames = extractColumnNames( fk.getColumns() ); + final List columnNames = extractColumnNames( foreignKey.getColumns() ); List referencedColumnNames = null; @Override @@ -1920,20 +1918,20 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector @Override public Identifier getReferencedTableName() { - return fk.getReferencedTable().getNameIdentifier(); + return foreignKey.getReferencedTable().getNameIdentifier(); } @Override public List getReferencedColumnNames() { if ( referencedColumnNames == null ) { - referencedColumnNames = extractColumnNames( fk.getReferencedColumns() ); + referencedColumnNames = extractColumnNames( foreignKey.getReferencedColumns() ); } return referencedColumnNames; } @Override public Identifier getUserProvidedIdentifier() { - return fk.getName() != null ? Identifier.toIdentifier( fk.getName() ) : null; + return foreignKey.getName() != null ? Identifier.toIdentifier( foreignKey.getName() ) : null; } @Override @@ -1944,9 +1942,9 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector nameIdentifier = getMetadataBuildingOptions().getImplicitNamingStrategy().determineForeignKeyName(foreignKeyNameSource); - fk.setName( nameIdentifier.render( getDatabase().getJdbcEnvironment().getDialect() ) ); + foreignKey.setName( nameIdentifier.render( getDatabase().getJdbcEnvironment().getDialect() ) ); - fk.alignColumns(); + foreignKey.alignColumns(); } } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java index 63d0cc81cc..851e609b33 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java @@ -1814,19 +1814,19 @@ public class ModelBinder { secondaryTableJoin.createForeignKey(); } } - - private List sortColumns(List primaryKeyColumnSources, KeyValue identifier) { - if ( primaryKeyColumnSources.size() == 1 || !identifier.getType().isComponentType() ) { - return primaryKeyColumnSources; - } - final ComponentType componentType = (ComponentType) identifier.getType(); - final List sortedColumnSource = new ArrayList<>( primaryKeyColumnSources.size() ); - final int[] originalPropertyOrder = componentType.getOriginalPropertyOrder(); - for ( int originalIndex : originalPropertyOrder ) { - sortedColumnSource.add( primaryKeyColumnSources.get( originalIndex ) ); - } - return sortedColumnSource; - } +// +// private List sortColumns(List primaryKeyColumnSources, KeyValue identifier) { +// if ( primaryKeyColumnSources.size() == 1 || !identifier.getType().isComponentType() ) { +// return primaryKeyColumnSources; +// } +// final ComponentType componentType = (ComponentType) identifier.getType(); +// final List sortedColumnSource = new ArrayList<>( primaryKeyColumnSources.size() ); +// final int[] originalPropertyOrder = componentType.getOriginalPropertyOrder(); +// for ( int originalIndex : originalPropertyOrder ) { +// sortedColumnSource.add( primaryKeyColumnSources.get( originalIndex ) ); +// } +// return sortedColumnSource; +// } private Property createEmbeddedAttribute( MappingDocument sourceDocument, @@ -3168,7 +3168,7 @@ public class ModelBinder { } @Override - public void doSecondPass(Map persistentClasses) throws org.hibernate.MappingException { + public void doSecondPass(Map persistentClasses) throws org.hibernate.MappingException { bindCollectionTable(); bindCollectionKey(); @@ -4108,7 +4108,7 @@ public class ModelBinder { } @Override - public void doSecondPass(Map persistentClasses) throws org.hibernate.MappingException { + public void doSecondPass(Map persistentClasses) throws org.hibernate.MappingException { if ( allColumnsNamed ) { relationalObjectBinder.bindColumnsAndFormulas( mappingDocument, @@ -4202,7 +4202,7 @@ public class ModelBinder { } @Override - public void doSecondPass(Map persistentClasses) throws org.hibernate.MappingException { + public void doSecondPass(Map persistentClasses) throws org.hibernate.MappingException { if ( referencedEntityAttributeName == null ) { manyToOneBinding.createForeignKey(); } diff --git a/hibernate-core/src/main/java/org/hibernate/cache/cfg/internal/NaturalIdDataCachingConfigImpl.java b/hibernate-core/src/main/java/org/hibernate/cache/cfg/internal/NaturalIdDataCachingConfigImpl.java index 7ed683e3ab..03e7c88556 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/cfg/internal/NaturalIdDataCachingConfigImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/cfg/internal/NaturalIdDataCachingConfigImpl.java @@ -6,8 +6,6 @@ */ package org.hibernate.cache.cfg.internal; -import java.util.Iterator; - import org.hibernate.cache.cfg.spi.NaturalIdDataCachingConfig; import org.hibernate.cache.spi.access.AccessType; import org.hibernate.mapping.Property; @@ -36,10 +34,8 @@ public class NaturalIdDataCachingConfigImpl } private boolean hasAnyMutableNaturalIdProps() { - final Iterator itr = rootEntityDescriptor.getDeclaredPropertyIterator(); - while ( itr.hasNext() ) { - final Property prop = (Property) itr.next(); - if ( prop.isNaturalIdentifier() && prop.isUpdateable() ) { + for ( Property property : rootEntityDescriptor.getDeclaredProperties() ) { + if ( property.isNaturalIdentifier() && property.isUpdateable() ) { return true; } } diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java index c1a420ebb8..3f15239f40 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java @@ -1617,17 +1617,12 @@ public final class AnnotationBinder { reflectionManager, entityClass, callbackType ) ); } - context.getMetadataCollector().addSecondPass( new SecondPass() { - @Override - public void doSecondPass(Map persistentClasses) throws MappingException { - for ( @SuppressWarnings("unchecked") Iterator propertyIterator = persistentClass.getDeclaredPropertyIterator(); - propertyIterator.hasNext(); ) { - Property property = propertyIterator.next(); - if ( property.isComposite() ) { - for ( CallbackType callbackType : CallbackType.values() ) { - property.addCallbackDefinitions( CallbackDefinitionResolverLegacyImpl.resolveEmbeddableCallbacks( - reflectionManager, persistentClass.getMappedClass(), property, callbackType ) ); - } + context.getMetadataCollector().addSecondPass( persistentClasses -> { + for ( Property property : persistentClass.getDeclaredProperties() ) { + if ( property.isComposite() ) { + for ( CallbackType callbackType : CallbackType.values() ) { + property.addCallbackDefinitions( CallbackDefinitionResolverLegacyImpl.resolveEmbeddableCallbacks( + reflectionManager, persistentClass.getMappedClass(), property, callbackType ) ); } } } diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/CollectionSecondPass.java b/hibernate-core/src/main/java/org/hibernate/cfg/CollectionSecondPass.java index be92c9239a..3bbde82486 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/CollectionSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/CollectionSecondPass.java @@ -16,6 +16,7 @@ import org.hibernate.internal.CoreMessageLogger; import org.hibernate.mapping.Collection; import org.hibernate.mapping.IndexedCollection; import org.hibernate.mapping.OneToMany; +import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Selectable; import org.hibernate.mapping.Value; @@ -44,7 +45,7 @@ public abstract class CollectionSecondPass implements SecondPass { this( buildingContext, collection, Collections.EMPTY_MAP ); } - public void doSecondPass(Map persistentClasses) + public void doSecondPass(Map persistentClasses) throws MappingException { if ( LOG.isDebugEnabled() ) { LOG.debugf( "Second pass for collection: %s", collection.getRole() ); diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/CopyIdentifierComponentSecondPass.java b/hibernate-core/src/main/java/org/hibernate/cfg/CopyIdentifierComponentSecondPass.java index a01a84d515..b335c07621 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/CopyIdentifierComponentSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/CopyIdentifierComponentSecondPass.java @@ -63,8 +63,8 @@ public class CopyIdentifierComponentSecondPass extends FkSecondPass { } @Override - public void doSecondPass(Map persistentClasses) throws MappingException { - PersistentClass referencedPersistentClass = (PersistentClass) persistentClasses.get( referencedEntityName ); + public void doSecondPass(Map persistentClasses) throws MappingException { + PersistentClass referencedPersistentClass = persistentClasses.get( referencedEntityName ); // TODO better error names if ( referencedPersistentClass == null ) { throw new AnnotationException( "Unknown entity name: " + referencedEntityName ); diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/CreateKeySecondPass.java b/hibernate-core/src/main/java/org/hibernate/cfg/CreateKeySecondPass.java index 913af57f9b..25a0c372c5 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/CreateKeySecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/CreateKeySecondPass.java @@ -9,6 +9,7 @@ import java.util.Map; import org.hibernate.MappingException; import org.hibernate.mapping.JoinedSubclass; +import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.RootClass; /** @@ -26,7 +27,7 @@ public class CreateKeySecondPass implements SecondPass { this.joinedSubClass = joinedSubClass; } - public void doSecondPass(Map persistentClasses) throws MappingException { + public void doSecondPass(Map persistentClasses) throws MappingException { if ( rootClass != null ) { rootClass.createPrimaryKey(); } diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/IdGeneratorResolverSecondPass.java b/hibernate-core/src/main/java/org/hibernate/cfg/IdGeneratorResolverSecondPass.java index 0799cc9272..e451873533 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/IdGeneratorResolverSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/IdGeneratorResolverSecondPass.java @@ -12,6 +12,7 @@ import org.hibernate.MappingException; import org.hibernate.annotations.common.reflection.XProperty; import org.hibernate.boot.model.IdentifierGeneratorDefinition; import org.hibernate.boot.spi.MetadataBuildingContext; +import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.SimpleValue; /** @@ -50,7 +51,7 @@ public class IdGeneratorResolverSecondPass implements SecondPass { } @Override - public void doSecondPass(Map idGeneratorDefinitionMap) throws MappingException { + public void doSecondPass(Map idGeneratorDefinitionMap) throws MappingException { BinderHelper.makeIdGenerator( id, idXProperty, generatorType, generatorName, buildingContext, localIdentifierGeneratorDefinition ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/JoinedSubclassFkSecondPass.java b/hibernate-core/src/main/java/org/hibernate/cfg/JoinedSubclassFkSecondPass.java index edd15d7c2a..eb7d133936 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/JoinedSubclassFkSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/JoinedSubclassFkSecondPass.java @@ -11,6 +11,7 @@ import org.hibernate.MappingException; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.cfg.annotations.TableBinder; import org.hibernate.mapping.JoinedSubclass; +import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.SimpleValue; /** @@ -39,7 +40,7 @@ public class JoinedSubclassFkSecondPass extends FkSecondPass { return true; } - public void doSecondPass(Map persistentClasses) throws MappingException { + public void doSecondPass(Map persistentClasses) throws MappingException { TableBinder.bindFk( entity.getSuperclass(), entity, columns, value, false, buildingContext ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java b/hibernate-core/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java index ca03ac283e..c002084c4b 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java @@ -76,7 +76,7 @@ public class OneToOneSecondPass implements SecondPass { } //TODO refactor this code, there is a lot of duplication in this method - public void doSecondPass(Map persistentClasses) throws MappingException { + public void doSecondPass(Map persistentClasses) throws MappingException { OneToOne value = new OneToOne( buildingContext, propertyHolder.getTable(), @@ -141,14 +141,13 @@ public class OneToOneSecondPass implements SecondPass { //no column associated since its a one to one propertyHolder.addProperty( prop, inferredData.getDeclaringClass() ); } - else { +// else { //this is a many to one with Formula - - } +// } } else { value.setMappedByProperty( mappedBy ); - PersistentClass otherSide = (PersistentClass) persistentClasses.get( value.getReferencedEntityName() ); + PersistentClass otherSide = persistentClasses.get( value.getReferencedEntityName() ); Property otherSideProperty; try { if ( otherSide == null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/PkDrivenByDefaultMapsIdSecondPass.java b/hibernate-core/src/main/java/org/hibernate/cfg/PkDrivenByDefaultMapsIdSecondPass.java index e9c72ba319..56221add63 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/PkDrivenByDefaultMapsIdSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/PkDrivenByDefaultMapsIdSecondPass.java @@ -41,8 +41,8 @@ public class PkDrivenByDefaultMapsIdSecondPass extends FkSecondPass { } @Override - public void doSecondPass(Map persistentClasses) throws MappingException { - PersistentClass referencedEntity = (PersistentClass) persistentClasses.get( referencedEntityName ); + public void doSecondPass(Map persistentClasses) throws MappingException { + PersistentClass referencedEntity = persistentClasses.get( referencedEntityName ); if ( referencedEntity == null ) { throw new AnnotationException( "Unknown entity name: " + referencedEntityName diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/PropertyHolderBuilder.java b/hibernate-core/src/main/java/org/hibernate/cfg/PropertyHolderBuilder.java index f8ec1d0022..0a0b788f1c 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/PropertyHolderBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/PropertyHolderBuilder.java @@ -5,6 +5,7 @@ * See the lgpl.txt file in the root directory or . */ package org.hibernate.cfg; + import java.util.Map; import org.hibernate.annotations.common.reflection.XClass; @@ -45,7 +46,7 @@ public final class PropertyHolderBuilder { * * @param component component to wrap * @param path component path - * @param context + * * @return PropertyHolder */ public static PropertyHolder buildPropertyHolder( diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/PropertyInferredData.java b/hibernate-core/src/main/java/org/hibernate/cfg/PropertyInferredData.java index 89743c41aa..059756d205 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/PropertyInferredData.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/PropertyInferredData.java @@ -5,6 +5,7 @@ * See the lgpl.txt file in the root directory or . */ package org.hibernate.cfg; + import jakarta.persistence.Access; import org.hibernate.MappingException; diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/SecondaryTableSecondPass.java b/hibernate-core/src/main/java/org/hibernate/cfg/SecondaryTableSecondPass.java index 9c7cbec1c2..783b4dd14e 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/SecondaryTableSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/SecondaryTableSecondPass.java @@ -5,19 +5,21 @@ * See the lgpl.txt file in the root directory or . */ package org.hibernate.cfg; + import java.util.Map; import org.hibernate.MappingException; import org.hibernate.annotations.common.reflection.XAnnotatedElement; import org.hibernate.cfg.annotations.EntityBinder; +import org.hibernate.mapping.PersistentClass; /** * @author Emmanuel Bernard */ public class SecondaryTableSecondPass implements SecondPass { - private EntityBinder entityBinder; - private PropertyHolder propertyHolder; - private XAnnotatedElement annotatedClass; + private final EntityBinder entityBinder; + private final PropertyHolder propertyHolder; + private final XAnnotatedElement annotatedClass; public SecondaryTableSecondPass(EntityBinder entityBinder, PropertyHolder propertyHolder, XAnnotatedElement annotatedClass) { this.entityBinder = entityBinder; @@ -25,7 +27,7 @@ public class SecondaryTableSecondPass implements SecondPass { this.annotatedClass = annotatedClass; } - public void doSecondPass(Map persistentClasses) throws MappingException { + public void doSecondPass(Map persistentClasses) throws MappingException { entityBinder.finalSecondaryTableBinding( propertyHolder ); } diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/SetBasicValueTypeSecondPass.java b/hibernate-core/src/main/java/org/hibernate/cfg/SetBasicValueTypeSecondPass.java index 33ddd7d791..e1835c59a1 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/SetBasicValueTypeSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/SetBasicValueTypeSecondPass.java @@ -10,18 +10,19 @@ import java.util.Map; import org.hibernate.MappingException; import org.hibernate.cfg.annotations.BasicValueBinder; +import org.hibernate.mapping.PersistentClass; /** * @author Sharath Reddy */ public class SetBasicValueTypeSecondPass implements SecondPass { - private final BasicValueBinder binder; + private final BasicValueBinder binder; - public SetBasicValueTypeSecondPass(BasicValueBinder val) { + public SetBasicValueTypeSecondPass(BasicValueBinder val) { binder = val; } - public void doSecondPass(Map persistentClasses) throws MappingException { + public void doSecondPass(Map persistentClasses) throws MappingException { binder.fillSimpleValue(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/SimpleToOneFkSecondPass.java b/hibernate-core/src/main/java/org/hibernate/cfg/SimpleToOneFkSecondPass.java index 7b66966a72..4efced5847 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/SimpleToOneFkSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/SimpleToOneFkSecondPass.java @@ -7,6 +7,7 @@ package org.hibernate.cfg; import org.hibernate.MappingException; +import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.ToOne; /** @@ -30,7 +31,7 @@ public class SimpleToOneFkSecondPass extends FkSecondPass { return false; } - public void doSecondPass(java.util.Map persistentClasses) throws MappingException { + public void doSecondPass(java.util.Map persistentClasses) throws MappingException { value.createForeignKey(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/ToOneFkSecondPass.java b/hibernate-core/src/main/java/org/hibernate/cfg/ToOneFkSecondPass.java index 323bf4930f..9881446753 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/ToOneFkSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/ToOneFkSecondPass.java @@ -6,8 +6,6 @@ */ package org.hibernate.cfg; -import java.util.Iterator; - import org.hibernate.AnnotationException; import org.hibernate.AssertionFailure; import org.hibernate.MappingException; @@ -88,10 +86,10 @@ public class ToOneFkSecondPass extends FkSecondPass { return false; } - public void doSecondPass(java.util.Map persistentClasses) throws MappingException { + public void doSecondPass(java.util.Map persistentClasses) throws MappingException { if ( value instanceof ManyToOne ) { ManyToOne manyToOne = (ManyToOne) value; - PersistentClass ref = (PersistentClass) persistentClasses.get( manyToOne.getReferencedEntityName() ); + PersistentClass ref = persistentClasses.get( manyToOne.getReferencedEntityName() ); if ( ref == null ) { throw new AnnotationException( "@OneToOne or @ManyToOne on " diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/VerifyFetchProfileReferenceSecondPass.java b/hibernate-core/src/main/java/org/hibernate/cfg/VerifyFetchProfileReferenceSecondPass.java index 8681e50a3d..22ce7accfa 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/VerifyFetchProfileReferenceSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/VerifyFetchProfileReferenceSecondPass.java @@ -18,9 +18,9 @@ import org.hibernate.mapping.PersistentClass; * @author Hardy Ferentschik */ public class VerifyFetchProfileReferenceSecondPass implements SecondPass { - private String fetchProfileName; - private FetchProfile.FetchOverride fetch; - private MetadataBuildingContext buildingContext; + private final String fetchProfileName; + private final FetchProfile.FetchOverride fetch; + private final MetadataBuildingContext buildingContext; public VerifyFetchProfileReferenceSecondPass( String fetchProfileName, @@ -31,7 +31,7 @@ public class VerifyFetchProfileReferenceSecondPass implements SecondPass { this.buildingContext = buildingContext; } - public void doSecondPass(Map persistentClasses) throws MappingException { + public void doSecondPass(Map persistentClasses) throws MappingException { org.hibernate.mapping.FetchProfile profile = buildingContext.getMetadataCollector().getFetchProfile( fetchProfileName ); diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/MapBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/MapBinder.java index 1f60f9157a..d919143af5 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/MapBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/MapBinder.java @@ -7,7 +7,7 @@ package org.hibernate.cfg.annotations; import java.util.HashMap; -import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.function.Supplier; @@ -129,7 +129,7 @@ public class MapBinder extends CollectionBinder { // check if the index column has been mapped by the associated entity to a property; // @MapKeyColumn only maps a column to the primary table for the one-to-many, so we only // need to check "un-joined" properties. - if ( !propertyIteratorContainsColumn( persistentClass.getUnjoinedPropertyIterator(), column ) ) { + if ( !propertiesContainColumn( persistentClass.getUnjoinedProperties(), column ) ) { // The index column is not mapped to an associated entity property so we can // safely make the index column nullable. column.setNullable( true ); @@ -138,9 +138,8 @@ public class MapBinder extends CollectionBinder { } } - private boolean propertyIteratorContainsColumn(Iterator propertyIterator, Column column) { - for (; propertyIterator.hasNext(); ) { - final Property property = propertyIterator.next(); + private boolean propertiesContainColumn(List properties, Column column) { + for ( Property property : properties ) { for ( Selectable selectable: property.getSelectables() ) { if ( column.equals( selectable ) ) { final Column iteratedColumn = (Column) selectable; diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/ResultsetMappingSecondPass.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/ResultsetMappingSecondPass.java index 04fa0f09fc..ddb1e7c422 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/ResultsetMappingSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/ResultsetMappingSecondPass.java @@ -6,29 +6,20 @@ */ package org.hibernate.cfg.annotations; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; import java.util.Map; import jakarta.persistence.SqlResultSetMapping; import org.hibernate.MappingException; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.cfg.QuerySecondPass; -import org.hibernate.internal.CoreLogging; -import org.hibernate.internal.CoreMessageLogger; -import org.hibernate.mapping.Component; import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.Property; -import org.hibernate.mapping.ToOne; -import org.hibernate.mapping.Value; import org.hibernate.boot.query.SqlResultSetMappingDescriptor; /** * @author Emmanuel Bernard */ public class ResultsetMappingSecondPass implements QuerySecondPass { - private static final CoreMessageLogger LOG = CoreLogging.messageLogger( ResultsetMappingSecondPass.class ); +// private static final CoreMessageLogger LOG = CoreLogging.messageLogger( ResultsetMappingSecondPass.class ); private final SqlResultSetMapping ann; private final MetadataBuildingContext context; @@ -41,7 +32,7 @@ public class ResultsetMappingSecondPass implements QuerySecondPass { } @Override - public void doSecondPass(Map persistentClasses) throws MappingException { + public void doSecondPass(Map persistentClasses) throws MappingException { if ( ann == null ) { return; } @@ -196,26 +187,26 @@ public class ResultsetMappingSecondPass implements QuerySecondPass { // context.getMetadataCollector().addResultSetMapping( definition ); // } } - - private String normalizeColumnQuoting(String name) { - return context.getMetadataCollector().getDatabase().toIdentifier( name ).render(); - } - - private List getFollowers(Iterator parentPropIter, String reducedName, String name) { - boolean hasFollowers = false; - List followers = new ArrayList<>(); - while ( parentPropIter.hasNext() ) { - String currentPropertyName = ( (Property) parentPropIter.next() ).getName(); - String currentName = reducedName + '.' + currentPropertyName; - if ( hasFollowers ) { - followers.add( currentName ); - } - if ( name.equals( currentName ) ) { - hasFollowers = true; - } - } - return followers; - } +// +// private String normalizeColumnQuoting(String name) { +// return context.getMetadataCollector().getDatabase().toIdentifier( name ).render(); +// } +// +// private List getFollowers(Iterator parentPropIter, String reducedName, String name) { +// boolean hasFollowers = false; +// List followers = new ArrayList<>(); +// while ( parentPropIter.hasNext() ) { +// String currentPropertyName = parentPropIter.next().getName(); +// String currentName = reducedName + '.' + currentPropertyName; +// if ( hasFollowers ) { +// followers.add( currentName ); +// } +// if ( name.equals( currentName ) ) { +// hasFollowers = true; +// } +// } +// return followers; +// } // // private Iterator getSubPropertyIterator(PersistentClass pc, String reducedName) { // Value value = pc.getRecursiveProperty( reducedName ).getValue(); diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/internal/NullableDiscriminatorColumnSecondPass.java b/hibernate-core/src/main/java/org/hibernate/cfg/internal/NullableDiscriminatorColumnSecondPass.java index 54e45ba4bd..d6428b8ca8 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/internal/NullableDiscriminatorColumnSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/internal/NullableDiscriminatorColumnSecondPass.java @@ -24,9 +24,8 @@ public class NullableDiscriminatorColumnSecondPass implements SecondPass { } @Override - @SuppressWarnings("rawtypes") - public void doSecondPass(Map persistentClasses) throws MappingException { - PersistentClass rootPersistenceClass = (PersistentClass) persistentClasses.get( rootEntityName ); + public void doSecondPass(Map persistentClasses) throws MappingException { + PersistentClass rootPersistenceClass = persistentClasses.get( rootEntityName ); if ( hasNullDiscriminatorValue( rootPersistenceClass ) ) { for ( Selectable selectable: rootPersistenceClass.getDiscriminator().getSelectables() ) { if ( selectable instanceof Column ) { @@ -40,9 +39,8 @@ public class NullableDiscriminatorColumnSecondPass implements SecondPass { if ( rootPersistenceClass.isDiscriminatorValueNull() ) { return true; } - Iterator subclassIterator = rootPersistenceClass.getSubclassIterator(); - while ( subclassIterator.hasNext() ) { - if ( subclassIterator.next().isDiscriminatorValueNull() ) { + for ( Subclass subclass : rootPersistenceClass.getSubclasses() ) { + if ( subclass.isDiscriminatorValueNull() ) { return true; } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SpannerDialectTableExporter.java b/hibernate-core/src/main/java/org/hibernate/dialect/SpannerDialectTableExporter.java index 0787b33c1e..994ac5755a 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SpannerDialectTableExporter.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SpannerDialectTableExporter.java @@ -56,10 +56,7 @@ class SpannerDialectTableExporter implements Exporter { } else if ( table.getForeignKeys().size() > 0 ) { // a table with no PK's but has FK's; often corresponds to element collection properties - keyColumns = new ArrayList<>(); - for (Iterator column = table.getColumnIterator(); column.hasNext();) { - keyColumns.add( column.next() ); - } + keyColumns = table.getColumns(); } else { // the case corresponding to a sequence-table that will only have 1 row. @@ -77,12 +74,11 @@ class SpannerDialectTableExporter implements Exporter
{ StringJoiner colsAndTypes = new StringJoiner( "," ); - for (Iterator column = table.getColumnIterator(); column.hasNext();) { - Column col = column.next(); + for ( Column column : table.getColumns() ) { String columnDeclaration = - col.getName() - + " " + col.getSqlType() - + ( col.isNullable() ? this.spannerDialect.getNullColumnString( col.getSqlType() ) : " not null" ); + column.getName() + + " " + column.getSqlType() + + ( column.isNullable() ? this.spannerDialect.getNullColumnString( column.getSqlType() ) : " not null" ); colsAndTypes.add( columnDeclaration ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/unique/UniqueDelegate.java b/hibernate-core/src/main/java/org/hibernate/dialect/unique/UniqueDelegate.java index 09fc675e92..a6d4505fba 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/unique/UniqueDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/unique/UniqueDelegate.java @@ -48,10 +48,10 @@ public interface UniqueDelegate { String getColumnDefinitionUniquenessFragment(Column column, SqlStringGenerationContext context); /** - * Get the fragment that can be used to apply unique constraints as part of table creation. The implementation - * should iterate over the {@link UniqueKey} instances for the given table (see - * {@link org.hibernate.mapping.Table#getUniqueKeyIterator()} and generate the whole fragment for all - * unique keys + * Get the fragment that can be used to apply unique constraints as part of table creation. The + * implementation should iterate over the {@link UniqueKey} instances for the given table (see + * {@link org.hibernate.mapping.Table#getUniqueKeyIterator()} and generate the whole fragment for + * all unique keys *

* Intended for Dialects which support unique constraint definitions, but just not in separate ALTER statements. * diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/IdentityMap.java b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/IdentityMap.java index 77d933b502..6a8a8c765f 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/IdentityMap.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/IdentityMap.java @@ -23,7 +23,7 @@ import java.util.function.Consumer; public final class IdentityMap implements Map { private final LinkedHashMap,V> map; - @SuppressWarnings( {"unchecked"}) + private transient Entry,V>[] entryArray = null; /** diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbacksFactory.java b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbacksFactory.java index dd4fd151bd..2869b1bbef 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbacksFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbacksFactory.java @@ -13,11 +13,9 @@ import java.util.Iterator; import java.util.List; import java.util.Set; -import org.hibernate.annotations.common.reflection.ReflectionManager; import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.jpa.event.spi.Callback; import org.hibernate.jpa.event.spi.CallbackDefinition; -import org.hibernate.jpa.event.spi.CallbackType; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; import org.hibernate.resource.beans.spi.ManagedBeanRegistry; @@ -68,9 +66,7 @@ public final class CallbacksFactory { registry.registerCallbacks( persistentClass.getMappedClass(), buildCallbacks( persistentClass.getCallbackDefinitions(), beanRegistry ) ); - for ( @SuppressWarnings("unchecked") Iterator propertyIterator = persistentClass.getDeclaredPropertyIterator(); - propertyIterator.hasNext(); ) { - final Property property = propertyIterator.next(); + for ( Property property : persistentClass.getDeclaredProperties() ) { registry.registerCallbacks( persistentClass.getMappedClass(), buildCallbacks( property.getCallbackDefinitions(), beanRegistry ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java b/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java index 3fdc13b214..93defed218 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java @@ -67,7 +67,6 @@ import static org.hibernate.mapping.MappingHelper.injectParameters; /** * @author Steve Ebersole */ -@SuppressWarnings({"unchecked", "rawtypes"}) public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resolvable { private static final CoreMessageLogger log = CoreLogging.messageLogger( BasicValue.class ); @@ -77,7 +76,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol // incoming "configuration" values private String explicitTypeName; - private Map explicitLocalTypeParams; + private Map explicitLocalTypeParams; private Function explicitJavaTypeAccess; private Function explicitJdbcTypeAccess; @@ -179,7 +178,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol @Override public long getColumnLength() { final Selectable column = getColumn(); - if ( column != null && column instanceof Column ) { + if ( column instanceof Column ) { final Long length = ( (Column) column ).getLength(); return length == null ? NO_COLUMN_LENGTH : length; } @@ -191,7 +190,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol @Override public int getColumnPrecision() { final Selectable column = getColumn(); - if ( column != null && column instanceof Column ) { + if ( column instanceof Column ) { final Integer length = ( (Column) column ).getPrecision(); return length == null ? NO_COLUMN_PRECISION : length; } @@ -203,7 +202,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol @Override public int getColumnScale() { final Selectable column = getColumn(); - if ( column != null && column instanceof Column ) { + if ( column instanceof Column ) { final Integer length = ( (Column) column ).getScale(); return length == null ? NO_COLUMN_SCALE : length; } @@ -240,13 +239,11 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol return; } - if ( column != null ) { - throw new IllegalStateException( - "BasicValue [" + ownerName + "." + propertyName + - "] already had column associated: `" + column.getText() + - "` -> `" + incomingColumn.getText() + "`" - ); - } + throw new IllegalStateException( + "BasicValue [" + ownerName + "." + propertyName + + "] already had column associated: `" + column.getText() + + "` -> `" + incomingColumn.getText() + "`" + ); } @Override @@ -386,12 +383,12 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol ); } - JavaType jtd = null; + JavaType jtd = null; // determine JavaType if we can if ( explicitJavaTypeAccess != null ) { - final BasicJavaType explicitJtd = explicitJavaTypeAccess.apply( typeConfiguration ); + final BasicJavaType explicitJtd = explicitJavaTypeAccess.apply( typeConfiguration ); if ( explicitJtd != null ) { jtd = explicitJtd; } @@ -407,7 +404,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol } if ( jtd == null ) { - final JavaType reflectedJtd = determineReflectedJavaType(); + final JavaType reflectedJtd = determineReflectedJavaType(); if ( reflectedJtd != null ) { jtd = reflectedJtd; } @@ -453,7 +450,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol } - private JavaType determineReflectedJavaType() { + private JavaType determineReflectedJavaType() { final java.lang.reflect.Type impliedJavaType; if ( resolvedJavaType != null ) { @@ -486,8 +483,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol } - @SuppressWarnings({"unchecked", "rawtypes"}) - private static Resolution interpretExplicitlyNamedType( + private static Resolution interpretExplicitlyNamedType( String name, EnumType enumerationStyle, Function implicitJavaTypeAccess, @@ -495,7 +491,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol Function explicitStdAccess, Function explicitMutabilityPlanAccess, ConverterDescriptor converterDescriptor, - Map localTypeParams, + Map localTypeParams, Consumer combinedParameterConsumer, JdbcTypeIndicators stdIndicators, TypeConfiguration typeConfiguration, @@ -539,7 +535,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol if ( name.startsWith( BasicTypeImpl.EXTERNALIZED_PREFIX ) ) { final BasicTypeImpl basicType = context.getBootstrapContext().resolveAdHocBasicType( name ); - return new NamedBasicTypeResolution( + return new NamedBasicTypeResolution<>( basicType.getJavaTypeDescriptor(), basicType, null, @@ -549,24 +545,24 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol } // see if it is a named basic type - final BasicType basicTypeByName = typeConfiguration.getBasicTypeRegistry().getRegisteredType( name ); + final BasicType basicTypeByName = typeConfiguration.getBasicTypeRegistry().getRegisteredType( name ); if ( basicTypeByName != null ) { - final BasicValueConverter valueConverter; + final BasicValueConverter valueConverter; final JavaType domainJtd; if ( converterDescriptor != null ) { valueConverter = converterDescriptor.createJpaAttributeConverter( converterCreationContext ); domainJtd = valueConverter.getDomainJavaType(); } else if ( basicTypeByName instanceof ConvertedBasicType ) { - final ConvertedBasicType convertedType = (ConvertedBasicType) basicTypeByName; - return new ConvertedBasicTypeResolution( convertedType, stdIndicators ); + final ConvertedBasicType convertedType = (ConvertedBasicType) basicTypeByName; + return new ConvertedBasicTypeResolution<>( convertedType, stdIndicators ); } else { valueConverter = null; domainJtd = basicTypeByName.getJavaTypeDescriptor(); } - return new NamedBasicTypeResolution( + return new NamedBasicTypeResolution<>( domainJtd, basicTypeByName, valueConverter, @@ -594,7 +590,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol // see if the name is a UserType or BasicType implementor class name final ClassLoaderService cls = typeConfiguration.getServiceRegistry().getService( ClassLoaderService.class ); try { - final Class typeNamedClass = cls.classForName( name ); + final Class typeNamedClass = cls.classForName( name ); // if there are no local config params, register an implicit TypeDefinition for this custom type . // later uses may find it and re-use its cacheable reference... @@ -670,7 +666,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol return typeConfiguration; } - public void setExplicitTypeParams(Map explicitLocalTypeParams) { + public void setExplicitTypeParams(Map explicitLocalTypeParams) { this.explicitLocalTypeParams = explicitLocalTypeParams; } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Constraint.java b/hibernate-core/src/main/java/org/hibernate/mapping/Constraint.java index e5b374dcf9..fc50d0ab82 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Constraint.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Constraint.java @@ -84,7 +84,8 @@ public abstract class Constraint implements RelationalModel, Exportable, Seriali if ( o instanceof Column ) { defensive.add( (Column) o ); } - //else: others might be Formula instances. They don't need to be part of the name generation. + // else: others might be Formula instances. + // They don't need to be part of the name generation. } return generateName( prefix, table, defensive.toArray( new Column[0] ) ); } @@ -156,6 +157,7 @@ public abstract class Constraint implements RelationalModel, Exportable, Seriali return columns.get( i ); } + @Deprecated(since = "6.0") public Iterator getColumnIterator() { return columns.iterator(); } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/DenormalizedTable.java b/hibernate-core/src/main/java/org/hibernate/mapping/DenormalizedTable.java index 0068916fc6..57ee9f819f 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/DenormalizedTable.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/DenormalizedTable.java @@ -60,19 +60,17 @@ public class DenormalizedTable extends Table { @Override public void createForeignKeys() { includedTable.createForeignKeys(); - Iterator iter = includedTable.getForeignKeyIterator(); - while ( iter.hasNext() ) { - ForeignKey fk = iter.next(); + for ( ForeignKey foreignKey : includedTable.getForeignKeys().values() ) { createForeignKey( Constraint.generateName( - fk.generatedConstraintNamePrefix(), + foreignKey.generatedConstraintNamePrefix(), this, - fk.getColumns() + foreignKey.getColumns() ), - fk.getColumns(), - fk.getReferencedEntityName(), - fk.getKeyDefinition(), - fk.getReferencedColumns() + foreignKey.getColumns(), + foreignKey.getReferencedEntityName(), + foreignKey.getKeyDefinition(), + foreignKey.getReferencedColumns() ); } } @@ -117,10 +115,8 @@ public class DenormalizedTable extends Table { @Override public Iterator getUniqueKeyIterator() { if ( !includedTable.isPhysicalTable() ) { - Iterator iter = includedTable.getUniqueKeyIterator(); - while ( iter.hasNext() ) { - UniqueKey uk = iter.next(); - createUniqueKey( uk.getColumns() ); + for ( UniqueKey uniqueKey : includedTable.getUniqueKeys().values() ) { + createUniqueKey( uniqueKey.getColumns() ); } } return getUniqueKeys().values().iterator(); diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/ForeignKey.java b/hibernate-core/src/main/java/org/hibernate/mapping/ForeignKey.java index b55fe223e6..40227945c7 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/ForeignKey.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/ForeignKey.java @@ -65,20 +65,14 @@ public class ForeignKey extends Constraint { String[] columnNames = new String[getColumnSpan()]; String[] referencedColumnNames = new String[getColumnSpan()]; - final Iterator referencedColumnItr; - if ( isReferenceToPrimaryKey() ) { - referencedColumnItr = referencedTable.getPrimaryKey().getColumnIterator(); - } - else { - referencedColumnItr = referencedColumns.iterator(); - } + final List referencedColumns = isReferenceToPrimaryKey() + ? referencedTable.getPrimaryKey().getColumns() + : this.referencedColumns; - Iterator columnItr = getColumnIterator(); - int i = 0; - while ( columnItr.hasNext() ) { - columnNames[i] = columnItr.next().getQuotedName( dialect ); - referencedColumnNames[i] = referencedColumnItr.next().getQuotedName( dialect ); - i++; + List columns = getColumns(); + for ( int i=0; i referencedColumnsIterator) { - while ( referencedColumnsIterator.hasNext() ) { - Selectable col = referencedColumnsIterator.next(); - if ( !col.isFormula() ) { - addReferencedColumn( (Column) col ); - } + public void addReferencedColumns(List referencedColumns) { + for (Column referencedColumn : referencedColumns) { +// if ( !referencedColumn.isFormula() ) { + addReferencedColumn( referencedColumn ); +// } } } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/IndexedCollection.java b/hibernate-core/src/main/java/org/hibernate/mapping/IndexedCollection.java index 4cad3c1dad..0a978f0df3 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/IndexedCollection.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/IndexedCollection.java @@ -6,7 +6,6 @@ */ package org.hibernate.mapping; -import java.util.Iterator; import java.util.function.Supplier; import org.hibernate.MappingException; @@ -76,7 +75,7 @@ public abstract class IndexedCollection extends Collection { } getCollectionTable().setPrimaryKey(pk); } - else { +// else { // don't create a unique key, 'cos some // databases don't like a UK on nullable // columns @@ -84,7 +83,7 @@ public abstract class IndexedCollection extends Collection { list.addAll( getKey().getConstraintColumns() ); list.addAll( getIndex().getConstraintColumns() ); getCollectionTable().createUniqueKey(list);*/ - } +// } } public void validate(Mapping mapping) throws MappingException { diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/ManyToOne.java b/hibernate-core/src/main/java/org/hibernate/mapping/ManyToOne.java index d3fbed32ea..65aa0cee2a 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/ManyToOne.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/ManyToOne.java @@ -7,12 +7,10 @@ package org.hibernate.mapping; import java.util.ArrayList; -import java.util.Iterator; import java.util.Map; import org.hibernate.MappingException; import org.hibernate.boot.spi.MetadataBuildingContext; -import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.type.EntityType; import org.hibernate.type.Type; @@ -64,11 +62,11 @@ public class ManyToOne extends ToOne { } } - public void createPropertyRefConstraints(Map persistentClasses) { + public void createPropertyRefConstraints(Map persistentClasses) { if (referencedPropertyName!=null) { // Ensure properties are sorted before we create a foreign key sortProperties(); - PersistentClass pc = (PersistentClass) persistentClasses.get(getReferencedEntityName() ); + PersistentClass pc = persistentClasses.get(getReferencedEntityName() ); Property property = pc.getReferencedProperty( getReferencedPropertyName() ); diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/MappedSuperclass.java b/hibernate-core/src/main/java/org/hibernate/mapping/MappedSuperclass.java index f09f25e897..a5668a153e 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/MappedSuperclass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/MappedSuperclass.java @@ -30,8 +30,8 @@ import java.util.List; public class MappedSuperclass { private final MappedSuperclass superMappedSuperclass; private final PersistentClass superPersistentClass; - private final List declaredProperties; - private Class mappedClass; + private final List declaredProperties; + private Class mappedClass; private Property identifierProperty; private Property version; private Component identifierMapper; @@ -39,7 +39,7 @@ public class MappedSuperclass { public MappedSuperclass(MappedSuperclass superMappedSuperclass, PersistentClass superPersistentClass) { this.superMappedSuperclass = superMappedSuperclass; this.superPersistentClass = superPersistentClass; - this.declaredProperties = new ArrayList(); + this.declaredProperties = new ArrayList<>(); } /** @@ -71,28 +71,32 @@ public class MappedSuperclass { return superPersistentClass; } - public Iterator getDeclaredPropertyIterator() { + @Deprecated(since = "6.0") + public Iterator getDeclaredPropertyIterator() { return declaredProperties.iterator(); } + public List getDeclaredProperties() { + return declaredProperties; + } + public void addDeclaredProperty(Property p) { //Do not add duplicate properties //TODO is it efficient enough? String name = p.getName(); - Iterator it = declaredProperties.iterator(); - while (it.hasNext()) { - if ( name.equals( ((Property)it.next()).getName() ) ) { + for (Property declaredProperty : declaredProperties) { + if ( name.equals( declaredProperty.getName() ) ) { return; } } declaredProperties.add(p); } - public Class getMappedClass() { + public Class getMappedClass() { return mappedClass; } - public void setMappedClass(Class mappedClass) { + public void setMappedClass(Class mappedClass) { this.mappedClass = mappedClass; } @@ -173,9 +177,7 @@ public class MappedSuperclass { * @return {@code true} if a property with that name exists; {@code false} if not */ public boolean hasProperty(String name) { - final Iterator itr = getDeclaredPropertyIterator(); - while ( itr.hasNext() ) { - final Property property = (Property) itr.next(); + for ( Property property : getDeclaredProperties() ) { if ( property.getName().equals( name ) ) { return true; } @@ -210,8 +212,7 @@ public class MappedSuperclass { return false; } - @SuppressWarnings( "unchecked" ) public void prepareForMappingModel() { - ( (List) declaredProperties ).sort( Comparator.comparing( Property::getName ) ); + declaredProperties.sort( Comparator.comparing( Property::getName ) ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/MappingHelper.java b/hibernate-core/src/main/java/org/hibernate/mapping/MappingHelper.java index 7df11d1d09..fb5f825ab9 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/MappingHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/MappingHelper.java @@ -67,12 +67,7 @@ public final class MappingHelper { public static void injectParameters(Object type, Properties parameters) { if ( type instanceof ParameterizedType ) { - if ( parameters == null ) { - ( (ParameterizedType) type ).setParameterValues( EMPTY_PROPERTIES ); - } - else { - ( (ParameterizedType) type ).setParameterValues( parameters ); - } + ( (ParameterizedType) type ).setParameterValues( parameters == null ? EMPTY_PROPERTIES : parameters ); } else if ( parameters != null && !parameters.isEmpty() ) { MappingModelCreationLogger.LOGGER.debugf( diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java b/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java index be263d5259..5e4e176cec 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java @@ -214,9 +214,25 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl } /** - * Iterate over subclasses in a special 'order', most derived subclasses - * first. + * Get the subclasses in a special 'order', most derived subclasses first. */ + public List getSubclasses() { + @SuppressWarnings("unchecked") + List[] iters = new List[subclasses.size() + 1]; + int i = 0; + for ( Subclass subclass : subclasses ) { + iters[i++] = subclass.getSubclasses(); + } + iters[i] = subclasses; + return new JoinedList<>( iters ); + } + + /** + * Iterate over subclasses in a special 'order', most derived subclasses first. + * + * @deprecated use {@link #getSubclasses()} + */ + @Deprecated(since = "6.0") public Iterator getSubclassIterator() { @SuppressWarnings("unchecked") Iterator[] iters = new Iterator[subclasses.size() + 1]; @@ -229,13 +245,21 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl return new JoinedIterator<>( iters ); } + public List getSubclassClosure() { + ArrayList> lists = new ArrayList<>(); + lists.add( List.of( this ) ); + for ( Subclass subclass : getSubclasses() ) { + lists.add( subclass.getSubclassClosure() ); + } + return new JoinedList<>( lists ); + } + + @Deprecated(since = "6.0") public Iterator getSubclassClosureIterator() { ArrayList> iters = new ArrayList<>(); iters.add( new SingletonIterator<>( this ) ); - Iterator iter = getSubclassIterator(); - while ( iter.hasNext() ) { - PersistentClass clazz = iter.next(); - iters.add( clazz.getSubclassClosureIterator() ); + for ( Subclass subclass : getSubclasses() ) { + iters.add( subclass.getSubclassClosureIterator() ); } return new JoinedIterator<>( iters ); } @@ -244,8 +268,8 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl return getRootTable(); } - public Iterator getDirectSubclasses() { - return subclasses.iterator(); + public List getDirectSubclasses() { + return subclasses; } @Override @@ -328,6 +352,9 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl @Deprecated(since = "6.0") public abstract Iterator

getTableClosureIterator(); + public abstract List getKeyClosure(); + + @Deprecated(since = "6.0") public abstract Iterator getKeyClosureIterator(); protected void addSubclassProperty(Property prop) { @@ -783,7 +810,10 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl * defined in superclasses of the mapping inheritance are not included. * * @return An iterator over the "normal" properties. + * + * @deprecated use {@link #getProperties()} */ + @Deprecated(since = "6.0") public Iterator getPropertyIterator() { ArrayList> iterators = new ArrayList<>(); iterators.add( properties.iterator() ); @@ -1006,6 +1036,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl return getUnjoinedProperties(); } + @Deprecated(since = "6.0") protected Iterator getDiscriminatorColumnIterator() { return Collections.emptyIterator(); } @@ -1113,11 +1144,20 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl } // The following methods are added to support @MappedSuperclass in the metamodel + public List getDeclaredProperties() { + ArrayList> lists = new ArrayList<>(); + lists.add( declaredProperties ); + for (Join join : joins) { + lists.add( join.getDeclaredProperties() ); + } + return new JoinedList<>( lists ); + } + + @Deprecated(since = "6.0") public Iterator getDeclaredPropertyIterator() { ArrayList> iterators = new ArrayList<>(); iterators.add( declaredProperties.iterator() ); - for ( int i = 0; i < joins.size(); i++ ) { - Join join = joins.get( i ); + for (Join join : joins) { iterators.add( join.getDeclaredPropertyIterator() ); } return new JoinedIterator<>( iterators ); diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/PrimaryKey.java b/hibernate-core/src/main/java/org/hibernate/mapping/PrimaryKey.java index 98d11fbb13..c8717eca8b 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/PrimaryKey.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/PrimaryKey.java @@ -28,9 +28,7 @@ public class PrimaryKey extends Constraint { @Override public void addColumn(Column column) { - final Iterator columnIterator = getTable().getColumnIterator(); - while ( columnIterator.hasNext() ) { - final Column next = columnIterator.next(); + for ( Column next : getTable().getColumns() ) { if ( next.getCanonicalName().equals( column.getCanonicalName() ) ) { next.setNullable( false ); if ( log.isDebugEnabled() ) { @@ -62,9 +60,9 @@ public class PrimaryKey extends Constraint { public String sqlConstraintString(Dialect dialect) { StringBuilder buf = new StringBuilder("primary key ("); - Iterator iter = getColumnIterator(); + Iterator iter = getColumnIterator(); while ( iter.hasNext() ) { - buf.append( ( (Column) iter.next() ).getQuotedName(dialect) ); + buf.append( iter.next().getQuotedName(dialect) ); if ( iter.hasNext() ) { buf.append(", "); } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java b/hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java index ed595ac884..8e84cc842c 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java @@ -146,11 +146,16 @@ public class RootClass extends PersistentClass implements TableOwner { return List.of( getTable() ); } - @Override + @Override @Deprecated public Iterator getKeyClosureIterator() { return new SingletonIterator<>( getKey() ); } + @Override + public List getKeyClosure() { + return List.of( getKey() ); + } + @Override public void addSubclass(Subclass subclass) throws MappingException { super.addSubclass( subclass ); @@ -351,9 +356,7 @@ public class RootClass extends PersistentClass implements TableOwner { public Set
getIdentityTables() { Set
tables = new HashSet<>(); - Iterator iter = getSubclassClosureIterator(); - while ( iter.hasNext() ) { - PersistentClass clazz = iter.next(); + for ( PersistentClass clazz : getSubclassClosure() ) { if ( clazz.isAbstract() == null || !clazz.isAbstract() ) { tables.add( clazz.getIdentityTable() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/SingleTableSubclass.java b/hibernate-core/src/main/java/org/hibernate/mapping/SingleTableSubclass.java index c487727686..3d851b97e5 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/SingleTableSubclass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/SingleTableSubclass.java @@ -36,6 +36,7 @@ public class SingleTableSubclass extends Subclass { return new JoinedList<>( getSuperclass().getUnjoinedProperties(), getUnjoinedProperties() ); } + @Deprecated protected Iterator getDiscriminatorColumnIterator() { return isDiscriminatorInsertable() && !getDiscriminator().hasFormula() ? getDiscriminator().getColumnIterator() diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Subclass.java b/hibernate-core/src/main/java/org/hibernate/mapping/Subclass.java index 70820bfb7c..f7de10a3f8 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Subclass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Subclass.java @@ -155,7 +155,7 @@ public class Subclass extends PersistentClass { ); } - @Override + @Override @Deprecated public Iterator getKeyClosureIterator() { return new JoinedIterator<>( getSuperclass().getKeyClosureIterator(), @@ -163,6 +163,14 @@ public class Subclass extends PersistentClass { ); } + @Override + public List getKeyClosure() { + return new JoinedList<>( + getSuperclass().getKeyClosure(), + List.of( getKey() ) + ); + } + @Override protected void addSubclassProperty(Property p) { super.addSubclassProperty(p); diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Table.java b/hibernate-core/src/main/java/org/hibernate/mapping/Table.java index 0411f08347..161218b859 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Table.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Table.java @@ -281,6 +281,7 @@ public class Table implements RelationalModel, Serializable, ContributableDataba return columns.size(); } + @Deprecated(since = "6.0") public Iterator getColumnIterator() { return columns.values().iterator(); } @@ -293,6 +294,7 @@ public class Table implements RelationalModel, Serializable, ContributableDataba return indexes.values().iterator(); } + @Deprecated(since = "6.0") public Iterator getForeignKeyIterator() { return foreignKeys.values().iterator(); } @@ -301,11 +303,12 @@ public class Table implements RelationalModel, Serializable, ContributableDataba return Collections.unmodifiableMap( foreignKeys ); } + @Deprecated(since = "6.0") public Iterator getUniqueKeyIterator() { return getUniqueKeys().values().iterator(); } - Map getUniqueKeys() { + public Map getUniqueKeys() { cleanseUniqueKeyMapIfNeeded(); return uniqueKeys; } @@ -425,12 +428,12 @@ public class Table implements RelationalModel, Serializable, ContributableDataba .append( ' ' ) .append( dialect.getAddColumnString() ); - Iterator iter = getColumnIterator(); List results = new ArrayList<>(); - while ( iter.hasNext() ) { - final Column column = iter.next(); - final ColumnInformation columnInfo = tableInfo.getColumn( Identifier.toIdentifier( column.getName(), column.isQuoted() ) ); + for ( Column column : getColumns() ) { + final ColumnInformation columnInfo = tableInfo.getColumn( + Identifier.toIdentifier( column.getName(), column.isQuoted() ) + ); if ( columnInfo == null ) { // the column doesnt exist at all. @@ -702,7 +705,7 @@ public class Table implements RelationalModel, Serializable, ContributableDataba fk.addColumn( keyColumn ); } if ( referencedColumns != null ) { - fk.addReferencedColumns( referencedColumns.iterator() ); + fk.addReferencedColumns( referencedColumns ); } // NOTE : if the name is null, we will generate an implicit name during second pass processing @@ -811,10 +814,15 @@ public class Table implements RelationalModel, Serializable, ContributableDataba this.comment = comment; } + @Deprecated(since = "6.0") public Iterator getCheckConstraintsIterator() { return checkConstraints.iterator(); } + public List getCheckConstraints() { + return checkConstraints; + } + @Override public String getExportIdentifier() { return Table.qualify( 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 ac312c02c5..0bcde484fd 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 @@ -32,9 +32,7 @@ public class EntityInstantiatorDynamicMap entityRoleNames.add( getRoleName() ); if ( bootDescriptor.hasSubclasses() ) { - final Iterator itr = bootDescriptor.getSubclassClosureIterator(); - while ( itr.hasNext() ) { - final PersistentClass subclassInfo = itr.next(); + for ( PersistentClass subclassInfo : bootDescriptor.getSubclassClosure() ) { entityRoleNames.add( subclassInfo.getEntityName() ); } } 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 34d4444360..14a7b398bc 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 @@ -208,9 +208,7 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent proxyInterfaces.add( mappedClass ); } - final Iterator subclasses = bootDescriptor.getSubclassIterator(); - while ( subclasses.hasNext() ) { - final Subclass subclass = subclasses.next(); + for ( Subclass subclass : bootDescriptor.getSubclasses() ) { final Class subclassProxy = subclass.getProxyInterface(); final Class subclassClass = subclass.getMappedClass(); if ( subclassProxy != null && !subclassClass.equals( subclassProxy ) ) { 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 17fa5e2966..ce66f135e8 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 @@ -11,7 +11,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -273,9 +272,7 @@ public class MetadataContext { applyIdMetadata( safeMapping, jpaMapping ); applyVersionAttribute( safeMapping, jpaMapping ); - Iterator properties = safeMapping.getDeclaredPropertyIterator(); - while ( properties.hasNext() ) { - final Property property = properties.next(); + for ( Property property : safeMapping.getDeclaredProperties() ) { if ( property.getValue() == safeMapping.getIdentifierMapper() ) { // property represents special handling for id-class mappings but we have already // accounted for the embedded property mappings in #applyIdMetadata && @@ -324,9 +321,7 @@ public class MetadataContext { applyVersionAttribute( safeMapping, jpaType ); // applyNaturalIdAttribute( safeMapping, jpaType ); - Iterator properties = safeMapping.getDeclaredPropertyIterator(); - while ( properties.hasNext() ) { - final Property property = properties.next(); + for ( Property property : safeMapping.getDeclaredProperties() ) { if ( safeMapping.isVersioned() && property == safeMapping.getVersion() ) { // skip the version property, it was already handled previously. continue; diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index 8bc62fcc3d..8877608983 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -1155,9 +1155,7 @@ public abstract class AbstractEntityPersister return true; } - final Iterator subclassIterator = persistentClass.getSubclassIterator(); - while ( subclassIterator.hasNext() ) { - final Subclass subclass = subclassIterator.next(); + for ( Subclass subclass : persistentClass.getSubclasses() ) { if ( subclass.isCached() ) { return true; } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java index 228c0ef62a..1de1aa011f 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java @@ -249,11 +249,11 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { ArrayList keyColumnReaders = new ArrayList<>(); ArrayList keyColumnReaderTemplates = new ArrayList<>(); ArrayList cascadeDeletes = new ArrayList<>(); - Iterator
tItr = persistentClass.getTableClosureIterator(); - Iterator kItr = persistentClass.getKeyClosureIterator(); - while ( tItr.hasNext() ) { - final Table table = tItr.next(); - final KeyValue key = kItr.next(); + List
tItr = persistentClass.getTableClosure(); + List kItr = persistentClass.getKeyClosure(); + for ( int i = 0; i < tItr.size() && i < kItr.size(); i++ ) { + final Table table = tItr.get(i); + final KeyValue key = kItr.get(i); final String tableName = determineTableName( table ); tableNames.add( tableName ); String[] keyCols = new String[idColumnSpan]; @@ -562,26 +562,25 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { notNullColumnNames = null; } - Iterator siter = persistentClass.getSubclassIterator(); int k = 0; - while ( siter.hasNext() ) { - Subclass sc = siter.next(); - subclassClosure[k] = sc.getEntityName(); - final Table table = sc.getTable(); - subclassNameByTableName.put( table.getName(), sc.getEntityName() ); + for ( Subclass subclass : persistentClass.getSubclasses() ) { + subclassClosure[k] = subclass.getEntityName(); + final Table table = subclass.getTable(); + subclassNameByTableName.put( table.getName(), subclass.getEntityName() ); try { if ( persistentClass.isPolymorphic() ) { final Object discriminatorValue; if ( explicitDiscriminatorColumnName != null ) { - if ( sc.isDiscriminatorValueNull() ) { + if ( subclass.isDiscriminatorValueNull() ) { discriminatorValue = NULL_DISCRIMINATOR; } - else if ( sc.isDiscriminatorValueNotNull() ) { + else if ( subclass.isDiscriminatorValueNotNull() ) { discriminatorValue = NOT_NULL_DISCRIMINATOR; } else { try { - discriminatorValue = discriminatorType.getJavaTypeDescriptor().fromString( sc.getDiscriminatorValue() ); + discriminatorValue = discriminatorType.getJavaTypeDescriptor() + .fromString( subclass.getDiscriminatorValue() ); } catch (ClassCastException cce) { throw new MappingException( "Illegal discriminator type: " + discriminatorType.getName() ); @@ -595,10 +594,10 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { // we now use subclass ids that are consistent across all // persisters for a class hierarchy, so that the use of // "foo.class = Bar" works in HQL - discriminatorValue = sc.getSubclassId(); + discriminatorValue = subclass.getSubclassId(); } initDiscriminatorProperties( factory, k, table, discriminatorValue ); - subclassesByDiscriminatorValue.put( discriminatorValue, sc.getEntityName() ); + subclassesByDiscriminatorValue.put( discriminatorValue, subclass.getEntityName() ); int id = getTableId( table.getQualifiedName( factory.getSqlStringGenerationContext() @@ -700,9 +699,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { // included when one of the collected class names is used in TREAT final Set classNames = new HashSet<>(); - final Iterator itr = persistentClass.getDirectSubclasses(); - while ( itr.hasNext() ) { - final Subclass subclass = itr.next(); + for ( Subclass subclass : persistentClass.getDirectSubclasses() ) { final Set subclassSubclassNames = processPersistentClassHierarchy( subclass, false, diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java index ec5f3b9b96..ca5bd858dc 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java @@ -9,7 +9,6 @@ package org.hibernate.persister.entity; import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -412,23 +411,21 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { // SUBCLASSES if ( persistentClass.isPolymorphic() ) { - Iterator subclasses = persistentClass.getSubclassIterator(); int k = 1; - while ( subclasses.hasNext() ) { - Subclass sc = subclasses.next(); - subclassClosure[k++] = sc.getEntityName(); - if ( sc.isDiscriminatorValueNull() ) { - addSubclassByDiscriminatorValue( subclassesByDiscriminatorValueLocal, NULL_DISCRIMINATOR, sc.getEntityName() ); + for ( Subclass subclass : persistentClass.getSubclasses() ) { + subclassClosure[k++] = subclass.getEntityName(); + if ( subclass.isDiscriminatorValueNull() ) { + addSubclassByDiscriminatorValue( subclassesByDiscriminatorValueLocal, NULL_DISCRIMINATOR, subclass.getEntityName() ); } - else if ( sc.isDiscriminatorValueNotNull() ) { - addSubclassByDiscriminatorValue( subclassesByDiscriminatorValueLocal, NOT_NULL_DISCRIMINATOR, sc.getEntityName() ); + else if ( subclass.isDiscriminatorValueNotNull() ) { + addSubclassByDiscriminatorValue( subclassesByDiscriminatorValueLocal, NOT_NULL_DISCRIMINATOR, subclass.getEntityName() ); } else { try { addSubclassByDiscriminatorValue( subclassesByDiscriminatorValueLocal, - discriminatorType.getJavaTypeDescriptor().fromString( sc.getDiscriminatorValue() ), - sc.getEntityName() + discriminatorType.getJavaTypeDescriptor().fromString( subclass.getDiscriminatorValue() ), + subclass.getEntityName() ); } catch (ClassCastException cce) { diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java index 988291283e..217dd0446a 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java @@ -34,8 +34,7 @@ import org.hibernate.id.IdentityGenerator; import org.hibernate.internal.FilterAliasGenerator; import org.hibernate.internal.StaticFilterAliasGenerator; import org.hibernate.internal.util.collections.ArrayHelper; -import org.hibernate.internal.util.collections.JoinedIterator; -import org.hibernate.internal.util.collections.SingletonIterator; +import org.hibernate.internal.util.collections.JoinedList; import org.hibernate.mapping.Column; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Subclass; @@ -162,9 +161,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { persistentClass.getEntityName() ); if ( persistentClass.isPolymorphic() ) { - Iterator subclassIter = persistentClass.getSubclassIterator(); - while ( subclassIter.hasNext() ) { - Subclass subclass = subclassIter.next(); + for ( Subclass subclass : persistentClass.getSubclasses() ) { subclassByDiscriminatorValue.put( subclass.getSubclassId(), subclass.getEntityName() ); } } @@ -196,9 +193,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { tableExpressions.add( generateSubquery( parentPersistentClass, creationContext.getMetadata() ) ); parentPersistentClass = parentPersistentClass.getSuperclass(); } - final Iterator subclassClosureIterator = persistentClass.getSubclassClosureIterator(); - while ( subclassClosureIterator.hasNext() ) { - final PersistentClass subPersistentClass = subclassClosureIterator.next(); + for ( PersistentClass subPersistentClass : persistentClass.getSubclassClosure() ) { if ( subPersistentClass.hasSubclasses() ) { tableExpressions.add( generateSubquery( subPersistentClass, creationContext.getMetadata() ) ); } @@ -475,13 +470,12 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { StringBuilder buf = new StringBuilder() .append( "( " ); - Iterator siter = new JoinedIterator<>( - new SingletonIterator<>( model ), - model.getSubclassIterator() + List classes = new JoinedList<>( + List.of( model ), + Collections.unmodifiableList( model.getSubclasses() ) ); - while ( siter.hasNext() ) { - PersistentClass clazz = siter.next(); + for ( PersistentClass clazz : classes ) { Table table = clazz.getTable(); if ( !table.isAbstractUnionTable() ) { //TODO: move to .sql package!! diff --git a/hibernate-core/src/main/java/org/hibernate/persister/internal/StandardPersisterClassResolver.java b/hibernate-core/src/main/java/org/hibernate/persister/internal/StandardPersisterClassResolver.java index 6ea880d0bf..1263455d43 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/internal/StandardPersisterClassResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/internal/StandardPersisterClassResolver.java @@ -28,29 +28,30 @@ import org.hibernate.persister.spi.UnknownPersisterException; public class StandardPersisterClassResolver implements PersisterClassResolver { @Override - public Class getEntityPersisterClass(PersistentClass metadata) { - // todo : make sure this is based on an attribute kept on the metamodel in the new code, not the concrete PersistentClass impl found! - if ( RootClass.class.isInstance( metadata ) ) { - if ( metadata.hasSubclasses() ) { + public Class getEntityPersisterClass(PersistentClass model) { + // todo : make sure this is based on an attribute kept on the metamodel in the new code, + // not the concrete PersistentClass impl found! + if ( model instanceof RootClass ) { + if ( model.hasSubclasses() ) { //If the class has children, we need to find of which kind - metadata = (PersistentClass) metadata.getDirectSubclasses().next(); + model = model.getDirectSubclasses().get(0); } else { return singleTableEntityPersister(); } } - if ( JoinedSubclass.class.isInstance( metadata ) ) { + if ( model instanceof JoinedSubclass ) { return joinedSubclassEntityPersister(); } - else if ( UnionSubclass.class.isInstance( metadata ) ) { + else if ( model instanceof UnionSubclass ) { return unionSubclassEntityPersister(); } - else if ( SingleTableSubclass.class.isInstance( metadata ) ) { + else if ( model instanceof SingleTableSubclass ) { return singleTableEntityPersister(); } else { throw new UnknownPersisterException( - "Could not determine persister implementation for entity [" + metadata.getEntityName() + "]" + "Could not determine persister implementation for entity [" + model.getEntityName() + "]" ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/proxy/pojo/ProxyFactoryHelper.java b/hibernate-core/src/main/java/org/hibernate/proxy/pojo/ProxyFactoryHelper.java index af2e6e8a40..cb7b2dce1c 100644 --- a/hibernate-core/src/main/java/org/hibernate/proxy/pojo/ProxyFactoryHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/proxy/pojo/ProxyFactoryHelper.java @@ -8,7 +8,6 @@ package org.hibernate.proxy.pojo; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.Iterator; import java.util.Set; import org.hibernate.HibernateException; @@ -50,9 +49,7 @@ public final class ProxyFactoryHelper { proxyInterfaces.add( mappedClass ); } - Iterator subclasses = persistentClass.getSubclassIterator(); - while ( subclasses.hasNext() ) { - final Subclass subclass = subclasses.next(); + for ( Subclass subclass : persistentClass.getSubclasses() ) { final Class subclassProxy = subclass.getProxyInterface(); final Class subclassClass = subclass.getMappedClass(); if ( subclassProxy != null && !subclassClass.equals( subclassProxy ) ) { diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaMigrator.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaMigrator.java index 2f9e03652a..1101d7cf06 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaMigrator.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaMigrator.java @@ -75,12 +75,9 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { HibernateSchemaManagementTool tool, SchemaFilter schemaFilter) { this.tool = tool; - if ( schemaFilter == null ) { - this.schemaFilter = DefaultSchemaFilter.INSTANCE; - } - else { - this.schemaFilter = schemaFilter; - } + this.schemaFilter = schemaFilter == null + ? DefaultSchemaFilter.INSTANCE + : schemaFilter; } private UniqueConstraintSchemaUpdateStrategy uniqueConstraintStrategy; @@ -325,9 +322,6 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { ExecutionOptions options, SqlStringGenerationContext sqlStringGenerationContext, GenerationTarget... targets) { - final Database database = metadata.getDatabase(); - - //noinspection unchecked applySqlStrings( false, table.sqlAlterStrings( @@ -394,9 +388,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { if ( uniqueConstraintStrategy != UniqueConstraintSchemaUpdateStrategy.SKIP ) { final Exporter exporter = dialect.getUniqueKeyExporter(); - final Iterator ukItr = table.getUniqueKeyIterator(); - while ( ukItr.hasNext() ) { - final UniqueKey uniqueKey = (UniqueKey) ukItr.next(); + for ( UniqueKey uniqueKey : table.getUniqueKeys().values() ) { // Skip if index already exists. Most of the time, this // won't work since most Dialects use Constraints. However, // keep it for the few that do use Indexes. @@ -449,10 +441,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { if ( dialect.hasAlterTable() ) { final Exporter exporter = dialect.getForeignKeyExporter(); - @SuppressWarnings("unchecked") - final Iterator fkItr = table.getForeignKeyIterator(); - while ( fkItr.hasNext() ) { - final ForeignKey foreignKey = fkItr.next(); + for ( ForeignKey foreignKey : table.getForeignKeys().values() ) { if ( foreignKey.isPhysicalConstraint() && foreignKey.isCreationEnabled() ) { boolean existingForeignKeyFound = false; if ( tableInformation != null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaValidator.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaValidator.java index 4ed754e66f..9f2898ccf6 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaValidator.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaValidator.java @@ -6,7 +6,6 @@ */ package org.hibernate.tool.schema.internal; -import java.util.Iterator; import java.util.Locale; import org.hibernate.boot.Metadata; @@ -137,9 +136,7 @@ public abstract class AbstractSchemaValidator implements SchemaValidator { ); } - final Iterator columnIter = table.getColumnIterator(); - while ( columnIter.hasNext() ) { - final Column column = columnIter.next(); + for ( Column column : table.getColumns() ) { final ColumnInformation existingColumn = tableInformation.getColumn( Identifier.toIdentifier( column.getQuotedName() ) ); if ( existingColumn == null ) { throw new SchemaManagementException( diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaCreatorImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaCreatorImpl.java index 3ceef871ac..360e9769f8 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaCreatorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaCreatorImpl.java @@ -397,9 +397,7 @@ public class SchemaCreatorImpl implements SchemaCreator { } // unique keys - final Iterator ukItr = table.getUniqueKeyIterator(); - while ( ukItr.hasNext() ) { - final UniqueKey uniqueKey = ukItr.next(); + for ( UniqueKey uniqueKey : table.getUniqueKeys().values() ) { checkExportIdentifier( uniqueKey, exportIdentifiers ); applySqlStrings( dialect.getUniqueKeyExporter().getSqlCreateStrings( uniqueKey, metadata, @@ -431,9 +429,7 @@ public class SchemaCreatorImpl implements SchemaCreator { } // foreign keys - final Iterator fkItr = table.getForeignKeyIterator(); - while ( fkItr.hasNext() ) { - final ForeignKey foreignKey = fkItr.next(); + for ( ForeignKey foreignKey : table.getForeignKeys().values() ) { applySqlStrings( dialect.getForeignKeyExporter().getSqlCreateStrings( foreignKey, metadata, sqlStringGenerationContext diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaDropperImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaDropperImpl.java index 576c73e190..dbb1cb782f 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaDropperImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaDropperImpl.java @@ -10,7 +10,6 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -370,9 +369,7 @@ public class SchemaDropperImpl implements SchemaDropper { continue; } - final Iterator fks = table.getForeignKeyIterator(); - while ( fks.hasNext() ) { - final ForeignKey foreignKey = fks.next(); + for ( ForeignKey foreignKey : table.getForeignKeys().values() ) { applySqlStrings( dialect.getForeignKeyExporter().getSqlDropStrings( foreignKey, metadata, sqlStringGenerationContext diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardTableExporter.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardTableExporter.java index cde4c10398..4dbb91e53a 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardTableExporter.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardTableExporter.java @@ -20,6 +20,7 @@ import org.hibernate.boot.model.relational.QualifiedNameParser; import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.dialect.Dialect; +import org.hibernate.internal.util.StringHelper; import org.hibernate.mapping.Column; import org.hibernate.mapping.Constraint; import org.hibernate.mapping.Table; @@ -70,10 +71,8 @@ public class StandardTableExporter implements Exporter
{ pkColName = pkColumn.getQuotedName( dialect ); } - final Iterator columnItr = table.getColumnIterator(); boolean isFirst = true; - while ( columnItr.hasNext() ) { - final Column col = (Column) columnItr.next(); + for ( Column col : table.getColumns() ) { if ( isFirst ) { isFirst = false; } @@ -162,7 +161,7 @@ public class StandardTableExporter implements Exporter
{ applyInitCommands( table, sqlStrings, context ); - return sqlStrings.toArray( new String[ sqlStrings.size() ] ); + return sqlStrings.toArray(StringHelper.EMPTY_STRINGS); } catch (Exception e) { throw new MappingException( "Error creating SQL create commands for table : " + tableName, e ); @@ -174,9 +173,7 @@ public class StandardTableExporter implements Exporter
{ if ( table.getComment() != null ) { sqlStrings.add( "comment on table " + tableName + " is '" + table.getComment() + "'" ); } - final Iterator iter = table.getColumnIterator(); - while ( iter.hasNext() ) { - Column column = (Column) iter.next(); + for ( Column column : table.getColumns() ) { String columnComment = column.getComment(); if ( columnComment != null ) { sqlStrings.add( "comment on column " + tableName + '.' + column.getQuotedName( dialect ) + " is '" + columnComment + "'" ); @@ -197,10 +194,9 @@ public class StandardTableExporter implements Exporter
{ protected void applyTableCheck(Table table, StringBuilder buf) { if ( dialect.supportsTableCheck() ) { - final Iterator checkConstraints = table.getCheckConstraintsIterator(); - while ( checkConstraints.hasNext() ) { + for (String constraint : table.getCheckConstraints() ) { buf.append( ", check (" ) - .append( checkConstraints.next() ) + .append( constraint ) .append( ')' ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/DynamicMapInstantiator.java b/hibernate-core/src/main/java/org/hibernate/tuple/DynamicMapInstantiator.java index 8b2403b7bb..5e17456051 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/DynamicMapInstantiator.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/DynamicMapInstantiator.java @@ -8,7 +8,6 @@ package org.hibernate.tuple; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -28,9 +27,7 @@ public class DynamicMapInstantiator implements Instantiator { this.roleName = mappingInfo.getEntityName(); isInstanceEntityNames.add( roleName ); if ( mappingInfo.hasSubclasses() ) { - Iterator itr = mappingInfo.getSubclassClosureIterator(); - while ( itr.hasNext() ) { - final PersistentClass subclassInfo = itr.next(); + for ( PersistentClass subclassInfo : mappingInfo.getSubclassClosure() ) { isInstanceEntityNames.add( subclassInfo.getEntityName() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java index 410a89d992..c85f826120 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java @@ -35,6 +35,7 @@ import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.mapping.Component; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; +import org.hibernate.mapping.Subclass; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.spi.PersisterCreationContext; import org.hibernate.tuple.GenerationTiming; @@ -404,10 +405,9 @@ public class EntityMetamodel implements Serializable { hasCollections = foundCollection; mutablePropertiesIndexes = mutableIndexes; - Iterator iter = persistentClass.getSubclassIterator(); final Set subclassEntityNamesLocal = new HashSet<>(); - while ( iter.hasNext() ) { - subclassEntityNamesLocal.add( ( (PersistentClass) iter.next() ).getEntityName() ); + for ( Subclass subclass : persistentClass.getSubclasses() ) { + subclassEntityNamesLocal.add( subclass.getEntityName() ); } subclassEntityNamesLocal.add( name ); subclassEntityNames = CollectionHelper.toSmallSet( subclassEntityNamesLocal ); @@ -415,10 +415,8 @@ public class EntityMetamodel implements Serializable { HashMap, String> entityNameByInheritanceClassMapLocal = new HashMap<>(); if ( persistentClass.hasPojoRepresentation() ) { entityNameByInheritanceClassMapLocal.put( persistentClass.getMappedClass(), persistentClass.getEntityName() ); - iter = persistentClass.getSubclassIterator(); - while ( iter.hasNext() ) { - final PersistentClass pc = ( PersistentClass ) iter.next(); - entityNameByInheritanceClassMapLocal.put( pc.getMappedClass(), pc.getEntityName() ); + for ( Subclass subclass : persistentClass.getSubclasses() ) { + entityNameByInheritanceClassMapLocal.put( subclass.getMappedClass(), subclass.getEntityName() ); } } entityNameByInheritenceClassMap = CollectionHelper.toSmallMap( entityNameByInheritanceClassMapLocal ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/CollectionMappedByResolver.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/CollectionMappedByResolver.java index bb8eecf1fe..881b9ed405 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/CollectionMappedByResolver.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/CollectionMappedByResolver.java @@ -22,7 +22,6 @@ import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; import org.hibernate.mapping.Selectable; import org.hibernate.mapping.Table; -import org.hibernate.mapping.Value; import org.jboss.logging.Logger; @@ -149,12 +148,10 @@ public class CollectionMappedByResolver { } private static String searchMappedByKey(PersistentClass referencedClass, Collection collectionValue) { - final Iterator assocIdClassProps = referencedClass.getKeyClosureIterator(); - while ( assocIdClassProps.hasNext() ) { - final Value value = assocIdClassProps.next(); + for ( KeyValue keyValue : referencedClass.getKeyClosure() ) { // make sure it's a 'Component' because IdClass is registered as this type. - if ( value instanceof Component ) { - final Component component = (Component) value; + if ( keyValue instanceof Component ) { + final Component component = (Component) keyValue; final Iterator componentPropertyIterator = component.getPropertyIterator(); while ( componentPropertyIterator.hasNext() ) { final Property property = componentPropertyIterator.next();