get rid of the last iterators in the mapping package

This commit is contained in:
Gavin King 2022-01-26 21:42:16 +01:00
parent 12a515a95a
commit 09299e1f41
56 changed files with 337 additions and 381 deletions

View File

@ -1872,16 +1872,14 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
final MetadataBuildingContext buildingContext) throws MappingException { final MetadataBuildingContext buildingContext) throws MappingException {
table.createForeignKeys(); table.createForeignKeys();
Iterator itr = table.getForeignKeyIterator(); for ( ForeignKey foreignKey : table.getForeignKeys().values() ) {
while ( itr.hasNext() ) { if ( !done.contains( foreignKey ) ) {
final ForeignKey fk = (ForeignKey) itr.next(); done.add( foreignKey );
if ( !done.contains( fk ) ) { final String referencedEntityName = foreignKey.getReferencedEntityName();
done.add( fk );
final String referencedEntityName = fk.getReferencedEntityName();
if ( referencedEntityName == null ) { if ( referencedEntityName == null ) {
throw new MappingException( throw new MappingException(
"An association from the table " + "An association from the table " +
fk.getTable().getName() + foreignKey.getTable().getName() +
" does not specify the referenced entity" " does not specify the referenced entity"
); );
} }
@ -1891,7 +1889,7 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
if ( referencedClass == null ) { if ( referencedClass == null ) {
throw new MappingException( throw new MappingException(
"An association from the table " + "An association from the table " +
fk.getTable().getName() + foreignKey.getTable().getName() +
" refers to an unmapped class: " + " refers to an unmapped class: " +
referencedEntityName referencedEntityName
); );
@ -1900,12 +1898,12 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
secondPassCompileForeignKeys( referencedClass.getSuperclass().getTable(), done, buildingContext ); secondPassCompileForeignKeys( referencedClass.getSuperclass().getTable(), done, buildingContext );
} }
fk.setReferencedTable( referencedClass.getTable() ); foreignKey.setReferencedTable( referencedClass.getTable() );
Identifier nameIdentifier; Identifier nameIdentifier;
ImplicitForeignKeyNameSource foreignKeyNameSource = new ImplicitForeignKeyNameSource() { ImplicitForeignKeyNameSource foreignKeyNameSource = new ImplicitForeignKeyNameSource() {
final List<Identifier> columnNames = extractColumnNames( fk.getColumns() ); final List<Identifier> columnNames = extractColumnNames( foreignKey.getColumns() );
List<Identifier> referencedColumnNames = null; List<Identifier> referencedColumnNames = null;
@Override @Override
@ -1920,20 +1918,20 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
@Override @Override
public Identifier getReferencedTableName() { public Identifier getReferencedTableName() {
return fk.getReferencedTable().getNameIdentifier(); return foreignKey.getReferencedTable().getNameIdentifier();
} }
@Override @Override
public List<Identifier> getReferencedColumnNames() { public List<Identifier> getReferencedColumnNames() {
if ( referencedColumnNames == null ) { if ( referencedColumnNames == null ) {
referencedColumnNames = extractColumnNames( fk.getReferencedColumns() ); referencedColumnNames = extractColumnNames( foreignKey.getReferencedColumns() );
} }
return referencedColumnNames; return referencedColumnNames;
} }
@Override @Override
public Identifier getUserProvidedIdentifier() { public Identifier getUserProvidedIdentifier() {
return fk.getName() != null ? Identifier.toIdentifier( fk.getName() ) : null; return foreignKey.getName() != null ? Identifier.toIdentifier( foreignKey.getName() ) : null;
} }
@Override @Override
@ -1944,9 +1942,9 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
nameIdentifier = getMetadataBuildingOptions().getImplicitNamingStrategy().determineForeignKeyName(foreignKeyNameSource); nameIdentifier = getMetadataBuildingOptions().getImplicitNamingStrategy().determineForeignKeyName(foreignKeyNameSource);
fk.setName( nameIdentifier.render( getDatabase().getJdbcEnvironment().getDialect() ) ); foreignKey.setName( nameIdentifier.render( getDatabase().getJdbcEnvironment().getDialect() ) );
fk.alignColumns(); foreignKey.alignColumns();
} }
} }
} }

View File

@ -1814,19 +1814,19 @@ public class ModelBinder {
secondaryTableJoin.createForeignKey(); secondaryTableJoin.createForeignKey();
} }
} }
//
private List<ColumnSource> sortColumns(List<ColumnSource> primaryKeyColumnSources, KeyValue identifier) { // private List<ColumnSource> sortColumns(List<ColumnSource> primaryKeyColumnSources, KeyValue identifier) {
if ( primaryKeyColumnSources.size() == 1 || !identifier.getType().isComponentType() ) { // if ( primaryKeyColumnSources.size() == 1 || !identifier.getType().isComponentType() ) {
return primaryKeyColumnSources; // return primaryKeyColumnSources;
} // }
final ComponentType componentType = (ComponentType) identifier.getType(); // final ComponentType componentType = (ComponentType) identifier.getType();
final List<ColumnSource> sortedColumnSource = new ArrayList<>( primaryKeyColumnSources.size() ); // final List<ColumnSource> sortedColumnSource = new ArrayList<>( primaryKeyColumnSources.size() );
final int[] originalPropertyOrder = componentType.getOriginalPropertyOrder(); // final int[] originalPropertyOrder = componentType.getOriginalPropertyOrder();
for ( int originalIndex : originalPropertyOrder ) { // for ( int originalIndex : originalPropertyOrder ) {
sortedColumnSource.add( primaryKeyColumnSources.get( originalIndex ) ); // sortedColumnSource.add( primaryKeyColumnSources.get( originalIndex ) );
} // }
return sortedColumnSource; // return sortedColumnSource;
} // }
private Property createEmbeddedAttribute( private Property createEmbeddedAttribute(
MappingDocument sourceDocument, MappingDocument sourceDocument,
@ -3168,7 +3168,7 @@ public class ModelBinder {
} }
@Override @Override
public void doSecondPass(Map persistentClasses) throws org.hibernate.MappingException { public void doSecondPass(Map<String, PersistentClass> persistentClasses) throws org.hibernate.MappingException {
bindCollectionTable(); bindCollectionTable();
bindCollectionKey(); bindCollectionKey();
@ -4108,7 +4108,7 @@ public class ModelBinder {
} }
@Override @Override
public void doSecondPass(Map persistentClasses) throws org.hibernate.MappingException { public void doSecondPass(Map<String, PersistentClass> persistentClasses) throws org.hibernate.MappingException {
if ( allColumnsNamed ) { if ( allColumnsNamed ) {
relationalObjectBinder.bindColumnsAndFormulas( relationalObjectBinder.bindColumnsAndFormulas(
mappingDocument, mappingDocument,
@ -4202,7 +4202,7 @@ public class ModelBinder {
} }
@Override @Override
public void doSecondPass(Map persistentClasses) throws org.hibernate.MappingException { public void doSecondPass(Map<String, PersistentClass> persistentClasses) throws org.hibernate.MappingException {
if ( referencedEntityAttributeName == null ) { if ( referencedEntityAttributeName == null ) {
manyToOneBinding.createForeignKey(); manyToOneBinding.createForeignKey();
} }

View File

@ -6,8 +6,6 @@
*/ */
package org.hibernate.cache.cfg.internal; package org.hibernate.cache.cfg.internal;
import java.util.Iterator;
import org.hibernate.cache.cfg.spi.NaturalIdDataCachingConfig; import org.hibernate.cache.cfg.spi.NaturalIdDataCachingConfig;
import org.hibernate.cache.spi.access.AccessType; import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
@ -36,10 +34,8 @@ public class NaturalIdDataCachingConfigImpl
} }
private boolean hasAnyMutableNaturalIdProps() { private boolean hasAnyMutableNaturalIdProps() {
final Iterator itr = rootEntityDescriptor.getDeclaredPropertyIterator(); for ( Property property : rootEntityDescriptor.getDeclaredProperties() ) {
while ( itr.hasNext() ) { if ( property.isNaturalIdentifier() && property.isUpdateable() ) {
final Property prop = (Property) itr.next();
if ( prop.isNaturalIdentifier() && prop.isUpdateable() ) {
return true; return true;
} }
} }

View File

@ -1617,17 +1617,12 @@ public final class AnnotationBinder {
reflectionManager, entityClass, callbackType ) ); reflectionManager, entityClass, callbackType ) );
} }
context.getMetadataCollector().addSecondPass( new SecondPass() { context.getMetadataCollector().addSecondPass( persistentClasses -> {
@Override for ( Property property : persistentClass.getDeclaredProperties() ) {
public void doSecondPass(Map persistentClasses) throws MappingException { if ( property.isComposite() ) {
for ( @SuppressWarnings("unchecked") Iterator<Property> propertyIterator = persistentClass.getDeclaredPropertyIterator(); for ( CallbackType callbackType : CallbackType.values() ) {
propertyIterator.hasNext(); ) { property.addCallbackDefinitions( CallbackDefinitionResolverLegacyImpl.resolveEmbeddableCallbacks(
Property property = propertyIterator.next(); reflectionManager, persistentClass.getMappedClass(), property, callbackType ) );
if ( property.isComposite() ) {
for ( CallbackType callbackType : CallbackType.values() ) {
property.addCallbackDefinitions( CallbackDefinitionResolverLegacyImpl.resolveEmbeddableCallbacks(
reflectionManager, persistentClass.getMappedClass(), property, callbackType ) );
}
} }
} }
} }

View File

@ -16,6 +16,7 @@ import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.mapping.Collection; import org.hibernate.mapping.Collection;
import org.hibernate.mapping.IndexedCollection; import org.hibernate.mapping.IndexedCollection;
import org.hibernate.mapping.OneToMany; import org.hibernate.mapping.OneToMany;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Selectable; import org.hibernate.mapping.Selectable;
import org.hibernate.mapping.Value; import org.hibernate.mapping.Value;
@ -44,7 +45,7 @@ public abstract class CollectionSecondPass implements SecondPass {
this( buildingContext, collection, Collections.EMPTY_MAP ); this( buildingContext, collection, Collections.EMPTY_MAP );
} }
public void doSecondPass(Map persistentClasses) public void doSecondPass(Map<String, PersistentClass> persistentClasses)
throws MappingException { throws MappingException {
if ( LOG.isDebugEnabled() ) { if ( LOG.isDebugEnabled() ) {
LOG.debugf( "Second pass for collection: %s", collection.getRole() ); LOG.debugf( "Second pass for collection: %s", collection.getRole() );

View File

@ -63,8 +63,8 @@ public class CopyIdentifierComponentSecondPass extends FkSecondPass {
} }
@Override @Override
public void doSecondPass(Map persistentClasses) throws MappingException { public void doSecondPass(Map<String, PersistentClass> persistentClasses) throws MappingException {
PersistentClass referencedPersistentClass = (PersistentClass) persistentClasses.get( referencedEntityName ); PersistentClass referencedPersistentClass = persistentClasses.get( referencedEntityName );
// TODO better error names // TODO better error names
if ( referencedPersistentClass == null ) { if ( referencedPersistentClass == null ) {
throw new AnnotationException( "Unknown entity name: " + referencedEntityName ); throw new AnnotationException( "Unknown entity name: " + referencedEntityName );

View File

@ -9,6 +9,7 @@ import java.util.Map;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.mapping.JoinedSubclass; import org.hibernate.mapping.JoinedSubclass;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.RootClass; import org.hibernate.mapping.RootClass;
/** /**
@ -26,7 +27,7 @@ public class CreateKeySecondPass implements SecondPass {
this.joinedSubClass = joinedSubClass; this.joinedSubClass = joinedSubClass;
} }
public void doSecondPass(Map persistentClasses) throws MappingException { public void doSecondPass(Map<String, PersistentClass> persistentClasses) throws MappingException {
if ( rootClass != null ) { if ( rootClass != null ) {
rootClass.createPrimaryKey(); rootClass.createPrimaryKey();
} }

View File

@ -12,6 +12,7 @@ import org.hibernate.MappingException;
import org.hibernate.annotations.common.reflection.XProperty; import org.hibernate.annotations.common.reflection.XProperty;
import org.hibernate.boot.model.IdentifierGeneratorDefinition; import org.hibernate.boot.model.IdentifierGeneratorDefinition;
import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.SimpleValue;
/** /**
@ -50,7 +51,7 @@ public class IdGeneratorResolverSecondPass implements SecondPass {
} }
@Override @Override
public void doSecondPass(Map idGeneratorDefinitionMap) throws MappingException { public void doSecondPass(Map<String, PersistentClass> idGeneratorDefinitionMap) throws MappingException {
BinderHelper.makeIdGenerator( id, idXProperty, generatorType, generatorName, buildingContext, localIdentifierGeneratorDefinition ); BinderHelper.makeIdGenerator( id, idXProperty, generatorType, generatorName, buildingContext, localIdentifierGeneratorDefinition );
} }
} }

View File

@ -11,6 +11,7 @@ import org.hibernate.MappingException;
import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.cfg.annotations.TableBinder; import org.hibernate.cfg.annotations.TableBinder;
import org.hibernate.mapping.JoinedSubclass; import org.hibernate.mapping.JoinedSubclass;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.SimpleValue;
/** /**
@ -39,7 +40,7 @@ public class JoinedSubclassFkSecondPass extends FkSecondPass {
return true; return true;
} }
public void doSecondPass(Map persistentClasses) throws MappingException { public void doSecondPass(Map<String, PersistentClass> persistentClasses) throws MappingException {
TableBinder.bindFk( entity.getSuperclass(), entity, columns, value, false, buildingContext ); TableBinder.bindFk( entity.getSuperclass(), entity, columns, value, false, buildingContext );
} }
} }

View File

@ -76,7 +76,7 @@ public class OneToOneSecondPass implements SecondPass {
} }
//TODO refactor this code, there is a lot of duplication in this method //TODO refactor this code, there is a lot of duplication in this method
public void doSecondPass(Map persistentClasses) throws MappingException { public void doSecondPass(Map<String, PersistentClass> persistentClasses) throws MappingException {
OneToOne value = new OneToOne( OneToOne value = new OneToOne(
buildingContext, buildingContext,
propertyHolder.getTable(), propertyHolder.getTable(),
@ -141,14 +141,13 @@ public class OneToOneSecondPass implements SecondPass {
//no column associated since its a one to one //no column associated since its a one to one
propertyHolder.addProperty( prop, inferredData.getDeclaringClass() ); propertyHolder.addProperty( prop, inferredData.getDeclaringClass() );
} }
else { // else {
//this is a many to one with Formula //this is a many to one with Formula
// }
}
} }
else { else {
value.setMappedByProperty( mappedBy ); value.setMappedByProperty( mappedBy );
PersistentClass otherSide = (PersistentClass) persistentClasses.get( value.getReferencedEntityName() ); PersistentClass otherSide = persistentClasses.get( value.getReferencedEntityName() );
Property otherSideProperty; Property otherSideProperty;
try { try {
if ( otherSide == null ) { if ( otherSide == null ) {

View File

@ -41,8 +41,8 @@ public class PkDrivenByDefaultMapsIdSecondPass extends FkSecondPass {
} }
@Override @Override
public void doSecondPass(Map persistentClasses) throws MappingException { public void doSecondPass(Map<String, PersistentClass> persistentClasses) throws MappingException {
PersistentClass referencedEntity = (PersistentClass) persistentClasses.get( referencedEntityName ); PersistentClass referencedEntity = persistentClasses.get( referencedEntityName );
if ( referencedEntity == null ) { if ( referencedEntity == null ) {
throw new AnnotationException( throw new AnnotationException(
"Unknown entity name: " + referencedEntityName "Unknown entity name: " + referencedEntityName

View File

@ -5,6 +5,7 @@
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.cfg; package org.hibernate.cfg;
import java.util.Map; import java.util.Map;
import org.hibernate.annotations.common.reflection.XClass; import org.hibernate.annotations.common.reflection.XClass;
@ -45,7 +46,7 @@ public final class PropertyHolderBuilder {
* *
* @param component component to wrap * @param component component to wrap
* @param path component path * @param path component path
* @param context *
* @return PropertyHolder * @return PropertyHolder
*/ */
public static PropertyHolder buildPropertyHolder( public static PropertyHolder buildPropertyHolder(

View File

@ -5,6 +5,7 @@
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.cfg; package org.hibernate.cfg;
import jakarta.persistence.Access; import jakarta.persistence.Access;
import org.hibernate.MappingException; import org.hibernate.MappingException;

View File

@ -5,19 +5,21 @@
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.cfg; package org.hibernate.cfg;
import java.util.Map; import java.util.Map;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.annotations.common.reflection.XAnnotatedElement; import org.hibernate.annotations.common.reflection.XAnnotatedElement;
import org.hibernate.cfg.annotations.EntityBinder; import org.hibernate.cfg.annotations.EntityBinder;
import org.hibernate.mapping.PersistentClass;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class SecondaryTableSecondPass implements SecondPass { public class SecondaryTableSecondPass implements SecondPass {
private EntityBinder entityBinder; private final EntityBinder entityBinder;
private PropertyHolder propertyHolder; private final PropertyHolder propertyHolder;
private XAnnotatedElement annotatedClass; private final XAnnotatedElement annotatedClass;
public SecondaryTableSecondPass(EntityBinder entityBinder, PropertyHolder propertyHolder, XAnnotatedElement annotatedClass) { public SecondaryTableSecondPass(EntityBinder entityBinder, PropertyHolder propertyHolder, XAnnotatedElement annotatedClass) {
this.entityBinder = entityBinder; this.entityBinder = entityBinder;
@ -25,7 +27,7 @@ public class SecondaryTableSecondPass implements SecondPass {
this.annotatedClass = annotatedClass; this.annotatedClass = annotatedClass;
} }
public void doSecondPass(Map persistentClasses) throws MappingException { public void doSecondPass(Map<String, PersistentClass> persistentClasses) throws MappingException {
entityBinder.finalSecondaryTableBinding( propertyHolder ); entityBinder.finalSecondaryTableBinding( propertyHolder );
} }

View File

@ -10,18 +10,19 @@ import java.util.Map;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.cfg.annotations.BasicValueBinder; import org.hibernate.cfg.annotations.BasicValueBinder;
import org.hibernate.mapping.PersistentClass;
/** /**
* @author Sharath Reddy * @author Sharath Reddy
*/ */
public class SetBasicValueTypeSecondPass implements SecondPass { public class SetBasicValueTypeSecondPass implements SecondPass {
private final BasicValueBinder binder; private final BasicValueBinder<?> binder;
public SetBasicValueTypeSecondPass(BasicValueBinder val) { public SetBasicValueTypeSecondPass(BasicValueBinder<?> val) {
binder = val; binder = val;
} }
public void doSecondPass(Map persistentClasses) throws MappingException { public void doSecondPass(Map<String, PersistentClass> persistentClasses) throws MappingException {
binder.fillSimpleValue(); binder.fillSimpleValue();
} }
} }

View File

@ -7,6 +7,7 @@
package org.hibernate.cfg; package org.hibernate.cfg;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.ToOne; import org.hibernate.mapping.ToOne;
/** /**
@ -30,7 +31,7 @@ public class SimpleToOneFkSecondPass extends FkSecondPass {
return false; return false;
} }
public void doSecondPass(java.util.Map persistentClasses) throws MappingException { public void doSecondPass(java.util.Map<String, PersistentClass> persistentClasses) throws MappingException {
value.createForeignKey(); value.createForeignKey();
} }
} }

View File

@ -6,8 +6,6 @@
*/ */
package org.hibernate.cfg; package org.hibernate.cfg;
import java.util.Iterator;
import org.hibernate.AnnotationException; import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.MappingException; import org.hibernate.MappingException;
@ -88,10 +86,10 @@ public class ToOneFkSecondPass extends FkSecondPass {
return false; return false;
} }
public void doSecondPass(java.util.Map persistentClasses) throws MappingException { public void doSecondPass(java.util.Map<String, PersistentClass> persistentClasses) throws MappingException {
if ( value instanceof ManyToOne ) { if ( value instanceof ManyToOne ) {
ManyToOne manyToOne = (ManyToOne) value; ManyToOne manyToOne = (ManyToOne) value;
PersistentClass ref = (PersistentClass) persistentClasses.get( manyToOne.getReferencedEntityName() ); PersistentClass ref = persistentClasses.get( manyToOne.getReferencedEntityName() );
if ( ref == null ) { if ( ref == null ) {
throw new AnnotationException( throw new AnnotationException(
"@OneToOne or @ManyToOne on " "@OneToOne or @ManyToOne on "

View File

@ -18,9 +18,9 @@ import org.hibernate.mapping.PersistentClass;
* @author Hardy Ferentschik * @author Hardy Ferentschik
*/ */
public class VerifyFetchProfileReferenceSecondPass implements SecondPass { public class VerifyFetchProfileReferenceSecondPass implements SecondPass {
private String fetchProfileName; private final String fetchProfileName;
private FetchProfile.FetchOverride fetch; private final FetchProfile.FetchOverride fetch;
private MetadataBuildingContext buildingContext; private final MetadataBuildingContext buildingContext;
public VerifyFetchProfileReferenceSecondPass( public VerifyFetchProfileReferenceSecondPass(
String fetchProfileName, String fetchProfileName,
@ -31,7 +31,7 @@ public class VerifyFetchProfileReferenceSecondPass implements SecondPass {
this.buildingContext = buildingContext; this.buildingContext = buildingContext;
} }
public void doSecondPass(Map persistentClasses) throws MappingException { public void doSecondPass(Map<String, PersistentClass> persistentClasses) throws MappingException {
org.hibernate.mapping.FetchProfile profile = buildingContext.getMetadataCollector().getFetchProfile( org.hibernate.mapping.FetchProfile profile = buildingContext.getMetadataCollector().getFetchProfile(
fetchProfileName fetchProfileName
); );

View File

@ -7,7 +7,7 @@
package org.hibernate.cfg.annotations; package org.hibernate.cfg.annotations;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier; 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; // 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 // @MapKeyColumn only maps a column to the primary table for the one-to-many, so we only
// need to check "un-joined" properties. // 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 // The index column is not mapped to an associated entity property so we can
// safely make the index column nullable. // safely make the index column nullable.
column.setNullable( true ); column.setNullable( true );
@ -138,9 +138,8 @@ public class MapBinder extends CollectionBinder {
} }
} }
private boolean propertyIteratorContainsColumn(Iterator<Property> propertyIterator, Column column) { private boolean propertiesContainColumn(List<Property> properties, Column column) {
for (; propertyIterator.hasNext(); ) { for ( Property property : properties ) {
final Property property = propertyIterator.next();
for ( Selectable selectable: property.getSelectables() ) { for ( Selectable selectable: property.getSelectables() ) {
if ( column.equals( selectable ) ) { if ( column.equals( selectable ) ) {
final Column iteratedColumn = (Column) selectable; final Column iteratedColumn = (Column) selectable;

View File

@ -6,29 +6,20 @@
*/ */
package org.hibernate.cfg.annotations; package org.hibernate.cfg.annotations;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import jakarta.persistence.SqlResultSetMapping; import jakarta.persistence.SqlResultSetMapping;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.cfg.QuerySecondPass; 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.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.ToOne;
import org.hibernate.mapping.Value;
import org.hibernate.boot.query.SqlResultSetMappingDescriptor; import org.hibernate.boot.query.SqlResultSetMappingDescriptor;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class ResultsetMappingSecondPass implements QuerySecondPass { 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 SqlResultSetMapping ann;
private final MetadataBuildingContext context; private final MetadataBuildingContext context;
@ -41,7 +32,7 @@ public class ResultsetMappingSecondPass implements QuerySecondPass {
} }
@Override @Override
public void doSecondPass(Map persistentClasses) throws MappingException { public void doSecondPass(Map<String, PersistentClass> persistentClasses) throws MappingException {
if ( ann == null ) { if ( ann == null ) {
return; return;
} }
@ -196,26 +187,26 @@ public class ResultsetMappingSecondPass implements QuerySecondPass {
// context.getMetadataCollector().addResultSetMapping( definition ); // context.getMetadataCollector().addResultSetMapping( definition );
// } // }
} }
//
private String normalizeColumnQuoting(String name) { // private String normalizeColumnQuoting(String name) {
return context.getMetadataCollector().getDatabase().toIdentifier( name ).render(); // return context.getMetadataCollector().getDatabase().toIdentifier( name ).render();
} // }
//
private List<String> getFollowers(Iterator parentPropIter, String reducedName, String name) { // private List<String> getFollowers(Iterator<Property> parentPropIter, String reducedName, String name) {
boolean hasFollowers = false; // boolean hasFollowers = false;
List<String> followers = new ArrayList<>(); // List<String> followers = new ArrayList<>();
while ( parentPropIter.hasNext() ) { // while ( parentPropIter.hasNext() ) {
String currentPropertyName = ( (Property) parentPropIter.next() ).getName(); // String currentPropertyName = parentPropIter.next().getName();
String currentName = reducedName + '.' + currentPropertyName; // String currentName = reducedName + '.' + currentPropertyName;
if ( hasFollowers ) { // if ( hasFollowers ) {
followers.add( currentName ); // followers.add( currentName );
} // }
if ( name.equals( currentName ) ) { // if ( name.equals( currentName ) ) {
hasFollowers = true; // hasFollowers = true;
} // }
} // }
return followers; // return followers;
} // }
// //
// private Iterator getSubPropertyIterator(PersistentClass pc, String reducedName) { // private Iterator getSubPropertyIterator(PersistentClass pc, String reducedName) {
// Value value = pc.getRecursiveProperty( reducedName ).getValue(); // Value value = pc.getRecursiveProperty( reducedName ).getValue();

View File

@ -24,9 +24,8 @@ public class NullableDiscriminatorColumnSecondPass implements SecondPass {
} }
@Override @Override
@SuppressWarnings("rawtypes") public void doSecondPass(Map<String, PersistentClass> persistentClasses) throws MappingException {
public void doSecondPass(Map persistentClasses) throws MappingException { PersistentClass rootPersistenceClass = persistentClasses.get( rootEntityName );
PersistentClass rootPersistenceClass = (PersistentClass) persistentClasses.get( rootEntityName );
if ( hasNullDiscriminatorValue( rootPersistenceClass ) ) { if ( hasNullDiscriminatorValue( rootPersistenceClass ) ) {
for ( Selectable selectable: rootPersistenceClass.getDiscriminator().getSelectables() ) { for ( Selectable selectable: rootPersistenceClass.getDiscriminator().getSelectables() ) {
if ( selectable instanceof Column ) { if ( selectable instanceof Column ) {
@ -40,9 +39,8 @@ public class NullableDiscriminatorColumnSecondPass implements SecondPass {
if ( rootPersistenceClass.isDiscriminatorValueNull() ) { if ( rootPersistenceClass.isDiscriminatorValueNull() ) {
return true; return true;
} }
Iterator<Subclass> subclassIterator = rootPersistenceClass.getSubclassIterator(); for ( Subclass subclass : rootPersistenceClass.getSubclasses() ) {
while ( subclassIterator.hasNext() ) { if ( subclass.isDiscriminatorValueNull() ) {
if ( subclassIterator.next().isDiscriminatorValueNull() ) {
return true; return true;
} }
} }

View File

@ -56,10 +56,7 @@ class SpannerDialectTableExporter implements Exporter<Table> {
} }
else if ( table.getForeignKeys().size() > 0 ) { else if ( table.getForeignKeys().size() > 0 ) {
// a table with no PK's but has FK's; often corresponds to element collection properties // a table with no PK's but has FK's; often corresponds to element collection properties
keyColumns = new ArrayList<>(); keyColumns = table.getColumns();
for (Iterator<Column> column = table.getColumnIterator(); column.hasNext();) {
keyColumns.add( column.next() );
}
} }
else { else {
// the case corresponding to a sequence-table that will only have 1 row. // the case corresponding to a sequence-table that will only have 1 row.
@ -77,12 +74,11 @@ class SpannerDialectTableExporter implements Exporter<Table> {
StringJoiner colsAndTypes = new StringJoiner( "," ); StringJoiner colsAndTypes = new StringJoiner( "," );
for (Iterator<Column> column = table.getColumnIterator(); column.hasNext();) { for ( Column column : table.getColumns() ) {
Column col = column.next();
String columnDeclaration = String columnDeclaration =
col.getName() column.getName()
+ " " + col.getSqlType() + " " + column.getSqlType()
+ ( col.isNullable() ? this.spannerDialect.getNullColumnString( col.getSqlType() ) : " not null" ); + ( column.isNullable() ? this.spannerDialect.getNullColumnString( column.getSqlType() ) : " not null" );
colsAndTypes.add( columnDeclaration ); colsAndTypes.add( columnDeclaration );
} }

View File

@ -48,10 +48,10 @@ public interface UniqueDelegate {
String getColumnDefinitionUniquenessFragment(Column column, SqlStringGenerationContext context); String getColumnDefinitionUniquenessFragment(Column column, SqlStringGenerationContext context);
/** /**
* Get the fragment that can be used to apply unique constraints as part of table creation. The implementation * Get the fragment that can be used to apply unique constraints as part of table creation. The
* should iterate over the {@link UniqueKey} instances for the given table (see * 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 * {@link org.hibernate.mapping.Table#getUniqueKeyIterator()} and generate the whole fragment for
* unique keys * all unique keys
* <p/> * <p/>
* Intended for Dialects which support unique constraint definitions, but just not in separate ALTER statements. * Intended for Dialects which support unique constraint definitions, but just not in separate ALTER statements.
* *

View File

@ -23,7 +23,7 @@ import java.util.function.Consumer;
public final class IdentityMap<K,V> implements Map<K,V> { public final class IdentityMap<K,V> implements Map<K,V> {
private final LinkedHashMap<IdentityKey<K>,V> map; private final LinkedHashMap<IdentityKey<K>,V> map;
@SuppressWarnings( {"unchecked"})
private transient Entry<IdentityKey<K>,V>[] entryArray = null; private transient Entry<IdentityKey<K>,V>[] entryArray = null;
/** /**

View File

@ -13,11 +13,9 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.jpa.event.spi.Callback; import org.hibernate.jpa.event.spi.Callback;
import org.hibernate.jpa.event.spi.CallbackDefinition; import org.hibernate.jpa.event.spi.CallbackDefinition;
import org.hibernate.jpa.event.spi.CallbackType;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.resource.beans.spi.ManagedBeanRegistry; import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
@ -68,9 +66,7 @@ public final class CallbacksFactory {
registry.registerCallbacks( persistentClass.getMappedClass(), registry.registerCallbacks( persistentClass.getMappedClass(),
buildCallbacks( persistentClass.getCallbackDefinitions(), beanRegistry ) ); buildCallbacks( persistentClass.getCallbackDefinitions(), beanRegistry ) );
for ( @SuppressWarnings("unchecked") Iterator<Property> propertyIterator = persistentClass.getDeclaredPropertyIterator(); for ( Property property : persistentClass.getDeclaredProperties() ) {
propertyIterator.hasNext(); ) {
final Property property = propertyIterator.next();
registry.registerCallbacks( persistentClass.getMappedClass(), registry.registerCallbacks( persistentClass.getMappedClass(),
buildCallbacks( property.getCallbackDefinitions(), beanRegistry ) ); buildCallbacks( property.getCallbackDefinitions(), beanRegistry ) );
} }

View File

@ -67,7 +67,6 @@ import static org.hibernate.mapping.MappingHelper.injectParameters;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@SuppressWarnings({"unchecked", "rawtypes"})
public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resolvable { public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resolvable {
private static final CoreMessageLogger log = CoreLogging.messageLogger( BasicValue.class ); private static final CoreMessageLogger log = CoreLogging.messageLogger( BasicValue.class );
@ -77,7 +76,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
// incoming "configuration" values // incoming "configuration" values
private String explicitTypeName; private String explicitTypeName;
private Map explicitLocalTypeParams; private Map<Object,Object> explicitLocalTypeParams;
private Function<TypeConfiguration, BasicJavaType> explicitJavaTypeAccess; private Function<TypeConfiguration, BasicJavaType> explicitJavaTypeAccess;
private Function<TypeConfiguration, JdbcType> explicitJdbcTypeAccess; private Function<TypeConfiguration, JdbcType> explicitJdbcTypeAccess;
@ -179,7 +178,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
@Override @Override
public long getColumnLength() { public long getColumnLength() {
final Selectable column = getColumn(); final Selectable column = getColumn();
if ( column != null && column instanceof Column ) { if ( column instanceof Column ) {
final Long length = ( (Column) column ).getLength(); final Long length = ( (Column) column ).getLength();
return length == null ? NO_COLUMN_LENGTH : length; return length == null ? NO_COLUMN_LENGTH : length;
} }
@ -191,7 +190,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
@Override @Override
public int getColumnPrecision() { public int getColumnPrecision() {
final Selectable column = getColumn(); final Selectable column = getColumn();
if ( column != null && column instanceof Column ) { if ( column instanceof Column ) {
final Integer length = ( (Column) column ).getPrecision(); final Integer length = ( (Column) column ).getPrecision();
return length == null ? NO_COLUMN_PRECISION : length; return length == null ? NO_COLUMN_PRECISION : length;
} }
@ -203,7 +202,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
@Override @Override
public int getColumnScale() { public int getColumnScale() {
final Selectable column = getColumn(); final Selectable column = getColumn();
if ( column != null && column instanceof Column ) { if ( column instanceof Column ) {
final Integer length = ( (Column) column ).getScale(); final Integer length = ( (Column) column ).getScale();
return length == null ? NO_COLUMN_SCALE : length; return length == null ? NO_COLUMN_SCALE : length;
} }
@ -240,13 +239,11 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
return; return;
} }
if ( column != null ) { throw new IllegalStateException(
throw new IllegalStateException( "BasicValue [" + ownerName + "." + propertyName +
"BasicValue [" + ownerName + "." + propertyName + "] already had column associated: `" + column.getText() +
"] already had column associated: `" + column.getText() + "` -> `" + incomingColumn.getText() + "`"
"` -> `" + incomingColumn.getText() + "`" );
);
}
} }
@Override @Override
@ -386,12 +383,12 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
); );
} }
JavaType jtd = null; JavaType<?> jtd = null;
// determine JavaType if we can // determine JavaType if we can
if ( explicitJavaTypeAccess != null ) { if ( explicitJavaTypeAccess != null ) {
final BasicJavaType explicitJtd = explicitJavaTypeAccess.apply( typeConfiguration ); final BasicJavaType<?> explicitJtd = explicitJavaTypeAccess.apply( typeConfiguration );
if ( explicitJtd != null ) { if ( explicitJtd != null ) {
jtd = explicitJtd; jtd = explicitJtd;
} }
@ -407,7 +404,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
} }
if ( jtd == null ) { if ( jtd == null ) {
final JavaType reflectedJtd = determineReflectedJavaType(); final JavaType<?> reflectedJtd = determineReflectedJavaType();
if ( reflectedJtd != null ) { if ( reflectedJtd != null ) {
jtd = reflectedJtd; 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; final java.lang.reflect.Type impliedJavaType;
if ( resolvedJavaType != null ) { 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, String name,
EnumType enumerationStyle, EnumType enumerationStyle,
Function<TypeConfiguration, java.lang.reflect.Type> implicitJavaTypeAccess, Function<TypeConfiguration, java.lang.reflect.Type> implicitJavaTypeAccess,
@ -495,7 +491,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
Function<TypeConfiguration, JdbcType> explicitStdAccess, Function<TypeConfiguration, JdbcType> explicitStdAccess,
Function<TypeConfiguration, MutabilityPlan> explicitMutabilityPlanAccess, Function<TypeConfiguration, MutabilityPlan> explicitMutabilityPlanAccess,
ConverterDescriptor converterDescriptor, ConverterDescriptor converterDescriptor,
Map localTypeParams, Map<Object,Object> localTypeParams,
Consumer<Properties> combinedParameterConsumer, Consumer<Properties> combinedParameterConsumer,
JdbcTypeIndicators stdIndicators, JdbcTypeIndicators stdIndicators,
TypeConfiguration typeConfiguration, TypeConfiguration typeConfiguration,
@ -539,7 +535,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
if ( name.startsWith( BasicTypeImpl.EXTERNALIZED_PREFIX ) ) { if ( name.startsWith( BasicTypeImpl.EXTERNALIZED_PREFIX ) ) {
final BasicTypeImpl<Object> basicType = context.getBootstrapContext().resolveAdHocBasicType( name ); final BasicTypeImpl<Object> basicType = context.getBootstrapContext().resolveAdHocBasicType( name );
return new NamedBasicTypeResolution( return new NamedBasicTypeResolution<>(
basicType.getJavaTypeDescriptor(), basicType.getJavaTypeDescriptor(),
basicType, basicType,
null, null,
@ -549,24 +545,24 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
} }
// see if it is a named basic type // 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 ) { if ( basicTypeByName != null ) {
final BasicValueConverter valueConverter; final BasicValueConverter<?,?> valueConverter;
final JavaType<?> domainJtd; final JavaType<?> domainJtd;
if ( converterDescriptor != null ) { if ( converterDescriptor != null ) {
valueConverter = converterDescriptor.createJpaAttributeConverter( converterCreationContext ); valueConverter = converterDescriptor.createJpaAttributeConverter( converterCreationContext );
domainJtd = valueConverter.getDomainJavaType(); domainJtd = valueConverter.getDomainJavaType();
} }
else if ( basicTypeByName instanceof ConvertedBasicType ) { else if ( basicTypeByName instanceof ConvertedBasicType ) {
final ConvertedBasicType convertedType = (ConvertedBasicType) basicTypeByName; final ConvertedBasicType<?> convertedType = (ConvertedBasicType<?>) basicTypeByName;
return new ConvertedBasicTypeResolution( convertedType, stdIndicators ); return new ConvertedBasicTypeResolution<>( convertedType, stdIndicators );
} }
else { else {
valueConverter = null; valueConverter = null;
domainJtd = basicTypeByName.getJavaTypeDescriptor(); domainJtd = basicTypeByName.getJavaTypeDescriptor();
} }
return new NamedBasicTypeResolution( return new NamedBasicTypeResolution<>(
domainJtd, domainJtd,
basicTypeByName, basicTypeByName,
valueConverter, 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 // see if the name is a UserType or BasicType implementor class name
final ClassLoaderService cls = typeConfiguration.getServiceRegistry().getService( ClassLoaderService.class ); final ClassLoaderService cls = typeConfiguration.getServiceRegistry().getService( ClassLoaderService.class );
try { 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 . // 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... // 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; return typeConfiguration;
} }
public void setExplicitTypeParams(Map explicitLocalTypeParams) { public void setExplicitTypeParams(Map<Object,Object> explicitLocalTypeParams) {
this.explicitLocalTypeParams = explicitLocalTypeParams; this.explicitLocalTypeParams = explicitLocalTypeParams;
} }

View File

@ -84,7 +84,8 @@ public abstract class Constraint implements RelationalModel, Exportable, Seriali
if ( o instanceof Column ) { if ( o instanceof Column ) {
defensive.add( (Column) o ); 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] ) ); 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 ); return columns.get( i );
} }
@Deprecated(since = "6.0")
public Iterator<Column> getColumnIterator() { public Iterator<Column> getColumnIterator() {
return columns.iterator(); return columns.iterator();
} }

View File

@ -60,19 +60,17 @@ public class DenormalizedTable extends Table {
@Override @Override
public void createForeignKeys() { public void createForeignKeys() {
includedTable.createForeignKeys(); includedTable.createForeignKeys();
Iterator<ForeignKey> iter = includedTable.getForeignKeyIterator(); for ( ForeignKey foreignKey : includedTable.getForeignKeys().values() ) {
while ( iter.hasNext() ) {
ForeignKey fk = iter.next();
createForeignKey( createForeignKey(
Constraint.generateName( Constraint.generateName(
fk.generatedConstraintNamePrefix(), foreignKey.generatedConstraintNamePrefix(),
this, this,
fk.getColumns() foreignKey.getColumns()
), ),
fk.getColumns(), foreignKey.getColumns(),
fk.getReferencedEntityName(), foreignKey.getReferencedEntityName(),
fk.getKeyDefinition(), foreignKey.getKeyDefinition(),
fk.getReferencedColumns() foreignKey.getReferencedColumns()
); );
} }
} }
@ -117,10 +115,8 @@ public class DenormalizedTable extends Table {
@Override @Override
public Iterator<UniqueKey> getUniqueKeyIterator() { public Iterator<UniqueKey> getUniqueKeyIterator() {
if ( !includedTable.isPhysicalTable() ) { if ( !includedTable.isPhysicalTable() ) {
Iterator<UniqueKey> iter = includedTable.getUniqueKeyIterator(); for ( UniqueKey uniqueKey : includedTable.getUniqueKeys().values() ) {
while ( iter.hasNext() ) { createUniqueKey( uniqueKey.getColumns() );
UniqueKey uk = iter.next();
createUniqueKey( uk.getColumns() );
} }
} }
return getUniqueKeys().values().iterator(); return getUniqueKeys().values().iterator();

View File

@ -65,20 +65,14 @@ public class ForeignKey extends Constraint {
String[] columnNames = new String[getColumnSpan()]; String[] columnNames = new String[getColumnSpan()];
String[] referencedColumnNames = new String[getColumnSpan()]; String[] referencedColumnNames = new String[getColumnSpan()];
final Iterator<Column> referencedColumnItr; final List<Column> referencedColumns = isReferenceToPrimaryKey()
if ( isReferenceToPrimaryKey() ) { ? referencedTable.getPrimaryKey().getColumns()
referencedColumnItr = referencedTable.getPrimaryKey().getColumnIterator(); : this.referencedColumns;
}
else {
referencedColumnItr = referencedColumns.iterator();
}
Iterator<Column> columnItr = getColumnIterator(); List<Column> columns = getColumns();
int i = 0; for ( int i=0; i<referencedColumns.size() && i<columns.size(); i++ ) {
while ( columnItr.hasNext() ) { columnNames[i] = columns.get(i).getQuotedName( dialect );
columnNames[i] = columnItr.next().getQuotedName( dialect ); referencedColumnNames[i] = referencedColumns.get(i).getQuotedName( dialect );
referencedColumnNames[i] = referencedColumnItr.next().getQuotedName( dialect );
i++;
} }
final String result = keyDefinition != null ? final String result = keyDefinition != null ?
@ -218,12 +212,11 @@ public class ForeignKey extends Constraint {
return referencedColumns.isEmpty(); return referencedColumns.isEmpty();
} }
public void addReferencedColumns(Iterator<Column> referencedColumnsIterator) { public void addReferencedColumns(List<Column> referencedColumns) {
while ( referencedColumnsIterator.hasNext() ) { for (Column referencedColumn : referencedColumns) {
Selectable col = referencedColumnsIterator.next(); // if ( !referencedColumn.isFormula() ) {
if ( !col.isFormula() ) { addReferencedColumn( referencedColumn );
addReferencedColumn( (Column) col ); // }
}
} }
} }

View File

@ -6,7 +6,6 @@
*/ */
package org.hibernate.mapping; package org.hibernate.mapping;
import java.util.Iterator;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.hibernate.MappingException; import org.hibernate.MappingException;
@ -76,7 +75,7 @@ public abstract class IndexedCollection extends Collection {
} }
getCollectionTable().setPrimaryKey(pk); getCollectionTable().setPrimaryKey(pk);
} }
else { // else {
// don't create a unique key, 'cos some // don't create a unique key, 'cos some
// databases don't like a UK on nullable // databases don't like a UK on nullable
// columns // columns
@ -84,7 +83,7 @@ public abstract class IndexedCollection extends Collection {
list.addAll( getKey().getConstraintColumns() ); list.addAll( getKey().getConstraintColumns() );
list.addAll( getIndex().getConstraintColumns() ); list.addAll( getIndex().getConstraintColumns() );
getCollectionTable().createUniqueKey(list);*/ getCollectionTable().createUniqueKey(list);*/
} // }
} }
public void validate(Mapping mapping) throws MappingException { public void validate(Mapping mapping) throws MappingException {

View File

@ -7,12 +7,10 @@
package org.hibernate.mapping; package org.hibernate.mapping;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.type.EntityType; import org.hibernate.type.EntityType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
@ -64,11 +62,11 @@ public class ManyToOne extends ToOne {
} }
} }
public void createPropertyRefConstraints(Map persistentClasses) { public void createPropertyRefConstraints(Map<String, PersistentClass> persistentClasses) {
if (referencedPropertyName!=null) { if (referencedPropertyName!=null) {
// Ensure properties are sorted before we create a foreign key // Ensure properties are sorted before we create a foreign key
sortProperties(); sortProperties();
PersistentClass pc = (PersistentClass) persistentClasses.get(getReferencedEntityName() ); PersistentClass pc = persistentClasses.get(getReferencedEntityName() );
Property property = pc.getReferencedProperty( getReferencedPropertyName() ); Property property = pc.getReferencedProperty( getReferencedPropertyName() );

View File

@ -30,8 +30,8 @@ import java.util.List;
public class MappedSuperclass { public class MappedSuperclass {
private final MappedSuperclass superMappedSuperclass; private final MappedSuperclass superMappedSuperclass;
private final PersistentClass superPersistentClass; private final PersistentClass superPersistentClass;
private final List declaredProperties; private final List<Property> declaredProperties;
private Class mappedClass; private Class<?> mappedClass;
private Property identifierProperty; private Property identifierProperty;
private Property version; private Property version;
private Component identifierMapper; private Component identifierMapper;
@ -39,7 +39,7 @@ public class MappedSuperclass {
public MappedSuperclass(MappedSuperclass superMappedSuperclass, PersistentClass superPersistentClass) { public MappedSuperclass(MappedSuperclass superMappedSuperclass, PersistentClass superPersistentClass) {
this.superMappedSuperclass = superMappedSuperclass; this.superMappedSuperclass = superMappedSuperclass;
this.superPersistentClass = superPersistentClass; this.superPersistentClass = superPersistentClass;
this.declaredProperties = new ArrayList(); this.declaredProperties = new ArrayList<>();
} }
/** /**
@ -71,28 +71,32 @@ public class MappedSuperclass {
return superPersistentClass; return superPersistentClass;
} }
public Iterator getDeclaredPropertyIterator() { @Deprecated(since = "6.0")
public Iterator<Property> getDeclaredPropertyIterator() {
return declaredProperties.iterator(); return declaredProperties.iterator();
} }
public List<Property> getDeclaredProperties() {
return declaredProperties;
}
public void addDeclaredProperty(Property p) { public void addDeclaredProperty(Property p) {
//Do not add duplicate properties //Do not add duplicate properties
//TODO is it efficient enough? //TODO is it efficient enough?
String name = p.getName(); String name = p.getName();
Iterator it = declaredProperties.iterator(); for (Property declaredProperty : declaredProperties) {
while (it.hasNext()) { if ( name.equals( declaredProperty.getName() ) ) {
if ( name.equals( ((Property)it.next()).getName() ) ) {
return; return;
} }
} }
declaredProperties.add(p); declaredProperties.add(p);
} }
public Class getMappedClass() { public Class<?> getMappedClass() {
return mappedClass; return mappedClass;
} }
public void setMappedClass(Class mappedClass) { public void setMappedClass(Class<?> mappedClass) {
this.mappedClass = 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 * @return {@code true} if a property with that name exists; {@code false} if not
*/ */
public boolean hasProperty(String name) { public boolean hasProperty(String name) {
final Iterator itr = getDeclaredPropertyIterator(); for ( Property property : getDeclaredProperties() ) {
while ( itr.hasNext() ) {
final Property property = (Property) itr.next();
if ( property.getName().equals( name ) ) { if ( property.getName().equals( name ) ) {
return true; return true;
} }
@ -210,8 +212,7 @@ public class MappedSuperclass {
return false; return false;
} }
@SuppressWarnings( "unchecked" )
public void prepareForMappingModel() { public void prepareForMappingModel() {
( (List<Property>) declaredProperties ).sort( Comparator.comparing( Property::getName ) ); declaredProperties.sort( Comparator.comparing( Property::getName ) );
} }
} }

View File

@ -67,12 +67,7 @@ public final class MappingHelper {
public static void injectParameters(Object type, Properties parameters) { public static void injectParameters(Object type, Properties parameters) {
if ( type instanceof ParameterizedType ) { if ( type instanceof ParameterizedType ) {
if ( parameters == null ) { ( (ParameterizedType) type ).setParameterValues( parameters == null ? EMPTY_PROPERTIES : parameters );
( (ParameterizedType) type ).setParameterValues( EMPTY_PROPERTIES );
}
else {
( (ParameterizedType) type ).setParameterValues( parameters );
}
} }
else if ( parameters != null && !parameters.isEmpty() ) { else if ( parameters != null && !parameters.isEmpty() ) {
MappingModelCreationLogger.LOGGER.debugf( MappingModelCreationLogger.LOGGER.debugf(

View File

@ -214,9 +214,25 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
} }
/** /**
* Iterate over subclasses in a special 'order', most derived subclasses * Get the subclasses in a special 'order', most derived subclasses first.
* first.
*/ */
public List<Subclass> getSubclasses() {
@SuppressWarnings("unchecked")
List<Subclass>[] 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<Subclass> getSubclassIterator() { public Iterator<Subclass> getSubclassIterator() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Iterator<Subclass>[] iters = new Iterator[subclasses.size() + 1]; Iterator<Subclass>[] iters = new Iterator[subclasses.size() + 1];
@ -229,13 +245,21 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
return new JoinedIterator<>( iters ); return new JoinedIterator<>( iters );
} }
public List<PersistentClass> getSubclassClosure() {
ArrayList<List<PersistentClass>> 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<PersistentClass> getSubclassClosureIterator() { public Iterator<PersistentClass> getSubclassClosureIterator() {
ArrayList<Iterator<PersistentClass>> iters = new ArrayList<>(); ArrayList<Iterator<PersistentClass>> iters = new ArrayList<>();
iters.add( new SingletonIterator<>( this ) ); iters.add( new SingletonIterator<>( this ) );
Iterator<Subclass> iter = getSubclassIterator(); for ( Subclass subclass : getSubclasses() ) {
while ( iter.hasNext() ) { iters.add( subclass.getSubclassClosureIterator() );
PersistentClass clazz = iter.next();
iters.add( clazz.getSubclassClosureIterator() );
} }
return new JoinedIterator<>( iters ); return new JoinedIterator<>( iters );
} }
@ -244,8 +268,8 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
return getRootTable(); return getRootTable();
} }
public Iterator<Subclass> getDirectSubclasses() { public List<Subclass> getDirectSubclasses() {
return subclasses.iterator(); return subclasses;
} }
@Override @Override
@ -328,6 +352,9 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
@Deprecated(since = "6.0") @Deprecated(since = "6.0")
public abstract Iterator<Table> getTableClosureIterator(); public abstract Iterator<Table> getTableClosureIterator();
public abstract List<KeyValue> getKeyClosure();
@Deprecated(since = "6.0")
public abstract Iterator<KeyValue> getKeyClosureIterator(); public abstract Iterator<KeyValue> getKeyClosureIterator();
protected void addSubclassProperty(Property prop) { 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. * defined in superclasses of the mapping inheritance are not included.
* *
* @return An iterator over the "normal" properties. * @return An iterator over the "normal" properties.
*
* @deprecated use {@link #getProperties()}
*/ */
@Deprecated(since = "6.0")
public Iterator<Property> getPropertyIterator() { public Iterator<Property> getPropertyIterator() {
ArrayList<Iterator<Property>> iterators = new ArrayList<>(); ArrayList<Iterator<Property>> iterators = new ArrayList<>();
iterators.add( properties.iterator() ); iterators.add( properties.iterator() );
@ -1006,6 +1036,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
return getUnjoinedProperties(); return getUnjoinedProperties();
} }
@Deprecated(since = "6.0")
protected Iterator<Selectable> getDiscriminatorColumnIterator() { protected Iterator<Selectable> getDiscriminatorColumnIterator() {
return Collections.emptyIterator(); 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 // The following methods are added to support @MappedSuperclass in the metamodel
public List<Property> getDeclaredProperties() {
ArrayList<List<Property>> lists = new ArrayList<>();
lists.add( declaredProperties );
for (Join join : joins) {
lists.add( join.getDeclaredProperties() );
}
return new JoinedList<>( lists );
}
@Deprecated(since = "6.0")
public Iterator<Property> getDeclaredPropertyIterator() { public Iterator<Property> getDeclaredPropertyIterator() {
ArrayList<Iterator<Property>> iterators = new ArrayList<>(); ArrayList<Iterator<Property>> iterators = new ArrayList<>();
iterators.add( declaredProperties.iterator() ); iterators.add( declaredProperties.iterator() );
for ( int i = 0; i < joins.size(); i++ ) { for (Join join : joins) {
Join join = joins.get( i );
iterators.add( join.getDeclaredPropertyIterator() ); iterators.add( join.getDeclaredPropertyIterator() );
} }
return new JoinedIterator<>( iterators ); return new JoinedIterator<>( iterators );

View File

@ -28,9 +28,7 @@ public class PrimaryKey extends Constraint {
@Override @Override
public void addColumn(Column column) { public void addColumn(Column column) {
final Iterator<Column> columnIterator = getTable().getColumnIterator(); for ( Column next : getTable().getColumns() ) {
while ( columnIterator.hasNext() ) {
final Column next = columnIterator.next();
if ( next.getCanonicalName().equals( column.getCanonicalName() ) ) { if ( next.getCanonicalName().equals( column.getCanonicalName() ) ) {
next.setNullable( false ); next.setNullable( false );
if ( log.isDebugEnabled() ) { if ( log.isDebugEnabled() ) {
@ -62,9 +60,9 @@ public class PrimaryKey extends Constraint {
public String sqlConstraintString(Dialect dialect) { public String sqlConstraintString(Dialect dialect) {
StringBuilder buf = new StringBuilder("primary key ("); StringBuilder buf = new StringBuilder("primary key (");
Iterator iter = getColumnIterator(); Iterator<Column> iter = getColumnIterator();
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
buf.append( ( (Column) iter.next() ).getQuotedName(dialect) ); buf.append( iter.next().getQuotedName(dialect) );
if ( iter.hasNext() ) { if ( iter.hasNext() ) {
buf.append(", "); buf.append(", ");
} }

View File

@ -146,11 +146,16 @@ public class RootClass extends PersistentClass implements TableOwner {
return List.of( getTable() ); return List.of( getTable() );
} }
@Override @Override @Deprecated
public Iterator<KeyValue> getKeyClosureIterator() { public Iterator<KeyValue> getKeyClosureIterator() {
return new SingletonIterator<>( getKey() ); return new SingletonIterator<>( getKey() );
} }
@Override
public List<KeyValue> getKeyClosure() {
return List.of( getKey() );
}
@Override @Override
public void addSubclass(Subclass subclass) throws MappingException { public void addSubclass(Subclass subclass) throws MappingException {
super.addSubclass( subclass ); super.addSubclass( subclass );
@ -351,9 +356,7 @@ public class RootClass extends PersistentClass implements TableOwner {
public Set<Table> getIdentityTables() { public Set<Table> getIdentityTables() {
Set<Table> tables = new HashSet<>(); Set<Table> tables = new HashSet<>();
Iterator<PersistentClass> iter = getSubclassClosureIterator(); for ( PersistentClass clazz : getSubclassClosure() ) {
while ( iter.hasNext() ) {
PersistentClass clazz = iter.next();
if ( clazz.isAbstract() == null || !clazz.isAbstract() ) { if ( clazz.isAbstract() == null || !clazz.isAbstract() ) {
tables.add( clazz.getIdentityTable() ); tables.add( clazz.getIdentityTable() );
} }

View File

@ -36,6 +36,7 @@ public class SingleTableSubclass extends Subclass {
return new JoinedList<>( getSuperclass().getUnjoinedProperties(), getUnjoinedProperties() ); return new JoinedList<>( getSuperclass().getUnjoinedProperties(), getUnjoinedProperties() );
} }
@Deprecated
protected Iterator<Selectable> getDiscriminatorColumnIterator() { protected Iterator<Selectable> getDiscriminatorColumnIterator() {
return isDiscriminatorInsertable() && !getDiscriminator().hasFormula() return isDiscriminatorInsertable() && !getDiscriminator().hasFormula()
? getDiscriminator().getColumnIterator() ? getDiscriminator().getColumnIterator()

View File

@ -155,7 +155,7 @@ public class Subclass extends PersistentClass {
); );
} }
@Override @Override @Deprecated
public Iterator<KeyValue> getKeyClosureIterator() { public Iterator<KeyValue> getKeyClosureIterator() {
return new JoinedIterator<>( return new JoinedIterator<>(
getSuperclass().getKeyClosureIterator(), getSuperclass().getKeyClosureIterator(),
@ -163,6 +163,14 @@ public class Subclass extends PersistentClass {
); );
} }
@Override
public List<KeyValue> getKeyClosure() {
return new JoinedList<>(
getSuperclass().getKeyClosure(),
List.of( getKey() )
);
}
@Override @Override
protected void addSubclassProperty(Property p) { protected void addSubclassProperty(Property p) {
super.addSubclassProperty(p); super.addSubclassProperty(p);

View File

@ -281,6 +281,7 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
return columns.size(); return columns.size();
} }
@Deprecated(since = "6.0")
public Iterator<Column> getColumnIterator() { public Iterator<Column> getColumnIterator() {
return columns.values().iterator(); return columns.values().iterator();
} }
@ -293,6 +294,7 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
return indexes.values().iterator(); return indexes.values().iterator();
} }
@Deprecated(since = "6.0")
public Iterator<ForeignKey> getForeignKeyIterator() { public Iterator<ForeignKey> getForeignKeyIterator() {
return foreignKeys.values().iterator(); return foreignKeys.values().iterator();
} }
@ -301,11 +303,12 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
return Collections.unmodifiableMap( foreignKeys ); return Collections.unmodifiableMap( foreignKeys );
} }
@Deprecated(since = "6.0")
public Iterator<UniqueKey> getUniqueKeyIterator() { public Iterator<UniqueKey> getUniqueKeyIterator() {
return getUniqueKeys().values().iterator(); return getUniqueKeys().values().iterator();
} }
Map<String, UniqueKey> getUniqueKeys() { public Map<String, UniqueKey> getUniqueKeys() {
cleanseUniqueKeyMapIfNeeded(); cleanseUniqueKeyMapIfNeeded();
return uniqueKeys; return uniqueKeys;
} }
@ -425,12 +428,12 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
.append( ' ' ) .append( ' ' )
.append( dialect.getAddColumnString() ); .append( dialect.getAddColumnString() );
Iterator<Column> iter = getColumnIterator();
List<String> results = new ArrayList<>(); List<String> results = new ArrayList<>();
while ( iter.hasNext() ) { for ( Column column : getColumns() ) {
final Column column = iter.next(); final ColumnInformation columnInfo = tableInfo.getColumn(
final ColumnInformation columnInfo = tableInfo.getColumn( Identifier.toIdentifier( column.getName(), column.isQuoted() ) ); Identifier.toIdentifier( column.getName(), column.isQuoted() )
);
if ( columnInfo == null ) { if ( columnInfo == null ) {
// the column doesnt exist at all. // the column doesnt exist at all.
@ -702,7 +705,7 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
fk.addColumn( keyColumn ); fk.addColumn( keyColumn );
} }
if ( referencedColumns != null ) { 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 // 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; this.comment = comment;
} }
@Deprecated(since = "6.0")
public Iterator<String> getCheckConstraintsIterator() { public Iterator<String> getCheckConstraintsIterator() {
return checkConstraints.iterator(); return checkConstraints.iterator();
} }
public List<String> getCheckConstraints() {
return checkConstraints;
}
@Override @Override
public String getExportIdentifier() { public String getExportIdentifier() {
return Table.qualify( return Table.qualify(

View File

@ -32,9 +32,7 @@ public class EntityInstantiatorDynamicMap
entityRoleNames.add( getRoleName() ); entityRoleNames.add( getRoleName() );
if ( bootDescriptor.hasSubclasses() ) { if ( bootDescriptor.hasSubclasses() ) {
final Iterator<PersistentClass> itr = bootDescriptor.getSubclassClosureIterator(); for ( PersistentClass subclassInfo : bootDescriptor.getSubclassClosure() ) {
while ( itr.hasNext() ) {
final PersistentClass subclassInfo = itr.next();
entityRoleNames.add( subclassInfo.getEntityName() ); entityRoleNames.add( subclassInfo.getEntityName() );
} }
} }

View File

@ -208,9 +208,7 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent
proxyInterfaces.add( mappedClass ); proxyInterfaces.add( mappedClass );
} }
final Iterator<Subclass> subclasses = bootDescriptor.getSubclassIterator(); for ( Subclass subclass : bootDescriptor.getSubclasses() ) {
while ( subclasses.hasNext() ) {
final Subclass subclass = subclasses.next();
final Class<?> subclassProxy = subclass.getProxyInterface(); final Class<?> subclassProxy = subclass.getProxyInterface();
final Class<?> subclassClass = subclass.getMappedClass(); final Class<?> subclassClass = subclass.getMappedClass();
if ( subclassProxy != null && !subclassClass.equals( subclassProxy ) ) { if ( subclassProxy != null && !subclassClass.equals( subclassProxy ) ) {

View File

@ -11,7 +11,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -273,9 +272,7 @@ public class MetadataContext {
applyIdMetadata( safeMapping, jpaMapping ); applyIdMetadata( safeMapping, jpaMapping );
applyVersionAttribute( safeMapping, jpaMapping ); applyVersionAttribute( safeMapping, jpaMapping );
Iterator<Property> properties = safeMapping.getDeclaredPropertyIterator(); for ( Property property : safeMapping.getDeclaredProperties() ) {
while ( properties.hasNext() ) {
final Property property = properties.next();
if ( property.getValue() == safeMapping.getIdentifierMapper() ) { if ( property.getValue() == safeMapping.getIdentifierMapper() ) {
// property represents special handling for id-class mappings but we have already // property represents special handling for id-class mappings but we have already
// accounted for the embedded property mappings in #applyIdMetadata && // accounted for the embedded property mappings in #applyIdMetadata &&
@ -324,9 +321,7 @@ public class MetadataContext {
applyVersionAttribute( safeMapping, jpaType ); applyVersionAttribute( safeMapping, jpaType );
// applyNaturalIdAttribute( safeMapping, jpaType ); // applyNaturalIdAttribute( safeMapping, jpaType );
Iterator<Property> properties = safeMapping.getDeclaredPropertyIterator(); for ( Property property : safeMapping.getDeclaredProperties() ) {
while ( properties.hasNext() ) {
final Property property = properties.next();
if ( safeMapping.isVersioned() && property == safeMapping.getVersion() ) { if ( safeMapping.isVersioned() && property == safeMapping.getVersion() ) {
// skip the version property, it was already handled previously. // skip the version property, it was already handled previously.
continue; continue;

View File

@ -1155,9 +1155,7 @@ public abstract class AbstractEntityPersister
return true; return true;
} }
final Iterator<Subclass> subclassIterator = persistentClass.getSubclassIterator(); for ( Subclass subclass : persistentClass.getSubclasses() ) {
while ( subclassIterator.hasNext() ) {
final Subclass subclass = subclassIterator.next();
if ( subclass.isCached() ) { if ( subclass.isCached() ) {
return true; return true;
} }

View File

@ -249,11 +249,11 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
ArrayList<String[]> keyColumnReaders = new ArrayList<>(); ArrayList<String[]> keyColumnReaders = new ArrayList<>();
ArrayList<String[]> keyColumnReaderTemplates = new ArrayList<>(); ArrayList<String[]> keyColumnReaderTemplates = new ArrayList<>();
ArrayList<Boolean> cascadeDeletes = new ArrayList<>(); ArrayList<Boolean> cascadeDeletes = new ArrayList<>();
Iterator<Table> tItr = persistentClass.getTableClosureIterator(); List<Table> tItr = persistentClass.getTableClosure();
Iterator<KeyValue> kItr = persistentClass.getKeyClosureIterator(); List<KeyValue> kItr = persistentClass.getKeyClosure();
while ( tItr.hasNext() ) { for ( int i = 0; i < tItr.size() && i < kItr.size(); i++ ) {
final Table table = tItr.next(); final Table table = tItr.get(i);
final KeyValue key = kItr.next(); final KeyValue key = kItr.get(i);
final String tableName = determineTableName( table ); final String tableName = determineTableName( table );
tableNames.add( tableName ); tableNames.add( tableName );
String[] keyCols = new String[idColumnSpan]; String[] keyCols = new String[idColumnSpan];
@ -562,26 +562,25 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
notNullColumnNames = null; notNullColumnNames = null;
} }
Iterator<Subclass> siter = persistentClass.getSubclassIterator();
int k = 0; int k = 0;
while ( siter.hasNext() ) { for ( Subclass subclass : persistentClass.getSubclasses() ) {
Subclass sc = siter.next(); subclassClosure[k] = subclass.getEntityName();
subclassClosure[k] = sc.getEntityName(); final Table table = subclass.getTable();
final Table table = sc.getTable(); subclassNameByTableName.put( table.getName(), subclass.getEntityName() );
subclassNameByTableName.put( table.getName(), sc.getEntityName() );
try { try {
if ( persistentClass.isPolymorphic() ) { if ( persistentClass.isPolymorphic() ) {
final Object discriminatorValue; final Object discriminatorValue;
if ( explicitDiscriminatorColumnName != null ) { if ( explicitDiscriminatorColumnName != null ) {
if ( sc.isDiscriminatorValueNull() ) { if ( subclass.isDiscriminatorValueNull() ) {
discriminatorValue = NULL_DISCRIMINATOR; discriminatorValue = NULL_DISCRIMINATOR;
} }
else if ( sc.isDiscriminatorValueNotNull() ) { else if ( subclass.isDiscriminatorValueNotNull() ) {
discriminatorValue = NOT_NULL_DISCRIMINATOR; discriminatorValue = NOT_NULL_DISCRIMINATOR;
} }
else { else {
try { try {
discriminatorValue = discriminatorType.getJavaTypeDescriptor().fromString( sc.getDiscriminatorValue() ); discriminatorValue = discriminatorType.getJavaTypeDescriptor()
.fromString( subclass.getDiscriminatorValue() );
} }
catch (ClassCastException cce) { catch (ClassCastException cce) {
throw new MappingException( "Illegal discriminator type: " + discriminatorType.getName() ); 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 // we now use subclass ids that are consistent across all
// persisters for a class hierarchy, so that the use of // persisters for a class hierarchy, so that the use of
// "foo.class = Bar" works in HQL // "foo.class = Bar" works in HQL
discriminatorValue = sc.getSubclassId(); discriminatorValue = subclass.getSubclassId();
} }
initDiscriminatorProperties( factory, k, table, discriminatorValue ); initDiscriminatorProperties( factory, k, table, discriminatorValue );
subclassesByDiscriminatorValue.put( discriminatorValue, sc.getEntityName() ); subclassesByDiscriminatorValue.put( discriminatorValue, subclass.getEntityName() );
int id = getTableId( int id = getTableId(
table.getQualifiedName( table.getQualifiedName(
factory.getSqlStringGenerationContext() factory.getSqlStringGenerationContext()
@ -700,9 +699,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
// included when one of the collected class names is used in TREAT // included when one of the collected class names is used in TREAT
final Set<String> classNames = new HashSet<>(); final Set<String> classNames = new HashSet<>();
final Iterator<Subclass> itr = persistentClass.getDirectSubclasses(); for ( Subclass subclass : persistentClass.getDirectSubclasses() ) {
while ( itr.hasNext() ) {
final Subclass subclass = itr.next();
final Set<String> subclassSubclassNames = processPersistentClassHierarchy( final Set<String> subclassSubclassNames = processPersistentClassHierarchy(
subclass, subclass,
false, false,

View File

@ -9,7 +9,6 @@ package org.hibernate.persister.entity;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -412,23 +411,21 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
// SUBCLASSES // SUBCLASSES
if ( persistentClass.isPolymorphic() ) { if ( persistentClass.isPolymorphic() ) {
Iterator<Subclass> subclasses = persistentClass.getSubclassIterator();
int k = 1; int k = 1;
while ( subclasses.hasNext() ) { for ( Subclass subclass : persistentClass.getSubclasses() ) {
Subclass sc = subclasses.next(); subclassClosure[k++] = subclass.getEntityName();
subclassClosure[k++] = sc.getEntityName(); if ( subclass.isDiscriminatorValueNull() ) {
if ( sc.isDiscriminatorValueNull() ) { addSubclassByDiscriminatorValue( subclassesByDiscriminatorValueLocal, NULL_DISCRIMINATOR, subclass.getEntityName() );
addSubclassByDiscriminatorValue( subclassesByDiscriminatorValueLocal, NULL_DISCRIMINATOR, sc.getEntityName() );
} }
else if ( sc.isDiscriminatorValueNotNull() ) { else if ( subclass.isDiscriminatorValueNotNull() ) {
addSubclassByDiscriminatorValue( subclassesByDiscriminatorValueLocal, NOT_NULL_DISCRIMINATOR, sc.getEntityName() ); addSubclassByDiscriminatorValue( subclassesByDiscriminatorValueLocal, NOT_NULL_DISCRIMINATOR, subclass.getEntityName() );
} }
else { else {
try { try {
addSubclassByDiscriminatorValue( addSubclassByDiscriminatorValue(
subclassesByDiscriminatorValueLocal, subclassesByDiscriminatorValueLocal,
discriminatorType.getJavaTypeDescriptor().fromString( sc.getDiscriminatorValue() ), discriminatorType.getJavaTypeDescriptor().fromString( subclass.getDiscriminatorValue() ),
sc.getEntityName() subclass.getEntityName()
); );
} }
catch (ClassCastException cce) { catch (ClassCastException cce) {

View File

@ -34,8 +34,7 @@ import org.hibernate.id.IdentityGenerator;
import org.hibernate.internal.FilterAliasGenerator; import org.hibernate.internal.FilterAliasGenerator;
import org.hibernate.internal.StaticFilterAliasGenerator; import org.hibernate.internal.StaticFilterAliasGenerator;
import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.internal.util.collections.JoinedIterator; import org.hibernate.internal.util.collections.JoinedList;
import org.hibernate.internal.util.collections.SingletonIterator;
import org.hibernate.mapping.Column; import org.hibernate.mapping.Column;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Subclass; import org.hibernate.mapping.Subclass;
@ -162,9 +161,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
persistentClass.getEntityName() persistentClass.getEntityName()
); );
if ( persistentClass.isPolymorphic() ) { if ( persistentClass.isPolymorphic() ) {
Iterator<Subclass> subclassIter = persistentClass.getSubclassIterator(); for ( Subclass subclass : persistentClass.getSubclasses() ) {
while ( subclassIter.hasNext() ) {
Subclass subclass = subclassIter.next();
subclassByDiscriminatorValue.put( subclass.getSubclassId(), subclass.getEntityName() ); subclassByDiscriminatorValue.put( subclass.getSubclassId(), subclass.getEntityName() );
} }
} }
@ -196,9 +193,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
tableExpressions.add( generateSubquery( parentPersistentClass, creationContext.getMetadata() ) ); tableExpressions.add( generateSubquery( parentPersistentClass, creationContext.getMetadata() ) );
parentPersistentClass = parentPersistentClass.getSuperclass(); parentPersistentClass = parentPersistentClass.getSuperclass();
} }
final Iterator<PersistentClass> subclassClosureIterator = persistentClass.getSubclassClosureIterator(); for ( PersistentClass subPersistentClass : persistentClass.getSubclassClosure() ) {
while ( subclassClosureIterator.hasNext() ) {
final PersistentClass subPersistentClass = subclassClosureIterator.next();
if ( subPersistentClass.hasSubclasses() ) { if ( subPersistentClass.hasSubclasses() ) {
tableExpressions.add( generateSubquery( subPersistentClass, creationContext.getMetadata() ) ); tableExpressions.add( generateSubquery( subPersistentClass, creationContext.getMetadata() ) );
} }
@ -475,13 +470,12 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
StringBuilder buf = new StringBuilder() StringBuilder buf = new StringBuilder()
.append( "( " ); .append( "( " );
Iterator<PersistentClass> siter = new JoinedIterator<>( List<PersistentClass> classes = new JoinedList<>(
new SingletonIterator<>( model ), List.of( model ),
model.getSubclassIterator() Collections.unmodifiableList( model.getSubclasses() )
); );
while ( siter.hasNext() ) { for ( PersistentClass clazz : classes ) {
PersistentClass clazz = siter.next();
Table table = clazz.getTable(); Table table = clazz.getTable();
if ( !table.isAbstractUnionTable() ) { if ( !table.isAbstractUnionTable() ) {
//TODO: move to .sql package!! //TODO: move to .sql package!!

View File

@ -28,29 +28,30 @@ import org.hibernate.persister.spi.UnknownPersisterException;
public class StandardPersisterClassResolver implements PersisterClassResolver { public class StandardPersisterClassResolver implements PersisterClassResolver {
@Override @Override
public Class<? extends EntityPersister> getEntityPersisterClass(PersistentClass metadata) { public Class<? extends EntityPersister> 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! // todo : make sure this is based on an attribute kept on the metamodel in the new code,
if ( RootClass.class.isInstance( metadata ) ) { // not the concrete PersistentClass impl found!
if ( metadata.hasSubclasses() ) { if ( model instanceof RootClass ) {
if ( model.hasSubclasses() ) {
//If the class has children, we need to find of which kind //If the class has children, we need to find of which kind
metadata = (PersistentClass) metadata.getDirectSubclasses().next(); model = model.getDirectSubclasses().get(0);
} }
else { else {
return singleTableEntityPersister(); return singleTableEntityPersister();
} }
} }
if ( JoinedSubclass.class.isInstance( metadata ) ) { if ( model instanceof JoinedSubclass ) {
return joinedSubclassEntityPersister(); return joinedSubclassEntityPersister();
} }
else if ( UnionSubclass.class.isInstance( metadata ) ) { else if ( model instanceof UnionSubclass ) {
return unionSubclassEntityPersister(); return unionSubclassEntityPersister();
} }
else if ( SingleTableSubclass.class.isInstance( metadata ) ) { else if ( model instanceof SingleTableSubclass ) {
return singleTableEntityPersister(); return singleTableEntityPersister();
} }
else { else {
throw new UnknownPersisterException( throw new UnknownPersisterException(
"Could not determine persister implementation for entity [" + metadata.getEntityName() + "]" "Could not determine persister implementation for entity [" + model.getEntityName() + "]"
); );
} }
} }

View File

@ -8,7 +8,6 @@ package org.hibernate.proxy.pojo;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.Iterator;
import java.util.Set; import java.util.Set;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
@ -50,9 +49,7 @@ public final class ProxyFactoryHelper {
proxyInterfaces.add( mappedClass ); proxyInterfaces.add( mappedClass );
} }
Iterator<Subclass> subclasses = persistentClass.getSubclassIterator(); for ( Subclass subclass : persistentClass.getSubclasses() ) {
while ( subclasses.hasNext() ) {
final Subclass subclass = subclasses.next();
final Class<?> subclassProxy = subclass.getProxyInterface(); final Class<?> subclassProxy = subclass.getProxyInterface();
final Class<?> subclassClass = subclass.getMappedClass(); final Class<?> subclassClass = subclass.getMappedClass();
if ( subclassProxy != null && !subclassClass.equals( subclassProxy ) ) { if ( subclassProxy != null && !subclassClass.equals( subclassProxy ) ) {

View File

@ -75,12 +75,9 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
HibernateSchemaManagementTool tool, HibernateSchemaManagementTool tool,
SchemaFilter schemaFilter) { SchemaFilter schemaFilter) {
this.tool = tool; this.tool = tool;
if ( schemaFilter == null ) { this.schemaFilter = schemaFilter == null
this.schemaFilter = DefaultSchemaFilter.INSTANCE; ? DefaultSchemaFilter.INSTANCE
} : schemaFilter;
else {
this.schemaFilter = schemaFilter;
}
} }
private UniqueConstraintSchemaUpdateStrategy uniqueConstraintStrategy; private UniqueConstraintSchemaUpdateStrategy uniqueConstraintStrategy;
@ -325,9 +322,6 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
ExecutionOptions options, ExecutionOptions options,
SqlStringGenerationContext sqlStringGenerationContext, SqlStringGenerationContext sqlStringGenerationContext,
GenerationTarget... targets) { GenerationTarget... targets) {
final Database database = metadata.getDatabase();
//noinspection unchecked
applySqlStrings( applySqlStrings(
false, false,
table.sqlAlterStrings( table.sqlAlterStrings(
@ -394,9 +388,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
if ( uniqueConstraintStrategy != UniqueConstraintSchemaUpdateStrategy.SKIP ) { if ( uniqueConstraintStrategy != UniqueConstraintSchemaUpdateStrategy.SKIP ) {
final Exporter<Constraint> exporter = dialect.getUniqueKeyExporter(); final Exporter<Constraint> exporter = dialect.getUniqueKeyExporter();
final Iterator ukItr = table.getUniqueKeyIterator(); for ( UniqueKey uniqueKey : table.getUniqueKeys().values() ) {
while ( ukItr.hasNext() ) {
final UniqueKey uniqueKey = (UniqueKey) ukItr.next();
// Skip if index already exists. Most of the time, this // Skip if index already exists. Most of the time, this
// won't work since most Dialects use Constraints. However, // won't work since most Dialects use Constraints. However,
// keep it for the few that do use Indexes. // keep it for the few that do use Indexes.
@ -449,10 +441,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
if ( dialect.hasAlterTable() ) { if ( dialect.hasAlterTable() ) {
final Exporter<ForeignKey> exporter = dialect.getForeignKeyExporter(); final Exporter<ForeignKey> exporter = dialect.getForeignKeyExporter();
@SuppressWarnings("unchecked") for ( ForeignKey foreignKey : table.getForeignKeys().values() ) {
final Iterator<ForeignKey> fkItr = table.getForeignKeyIterator();
while ( fkItr.hasNext() ) {
final ForeignKey foreignKey = fkItr.next();
if ( foreignKey.isPhysicalConstraint() && foreignKey.isCreationEnabled() ) { if ( foreignKey.isPhysicalConstraint() && foreignKey.isCreationEnabled() ) {
boolean existingForeignKeyFound = false; boolean existingForeignKeyFound = false;
if ( tableInformation != null ) { if ( tableInformation != null ) {

View File

@ -6,7 +6,6 @@
*/ */
package org.hibernate.tool.schema.internal; package org.hibernate.tool.schema.internal;
import java.util.Iterator;
import java.util.Locale; import java.util.Locale;
import org.hibernate.boot.Metadata; import org.hibernate.boot.Metadata;
@ -137,9 +136,7 @@ public abstract class AbstractSchemaValidator implements SchemaValidator {
); );
} }
final Iterator<Column> columnIter = table.getColumnIterator(); for ( Column column : table.getColumns() ) {
while ( columnIter.hasNext() ) {
final Column column = columnIter.next();
final ColumnInformation existingColumn = tableInformation.getColumn( Identifier.toIdentifier( column.getQuotedName() ) ); final ColumnInformation existingColumn = tableInformation.getColumn( Identifier.toIdentifier( column.getQuotedName() ) );
if ( existingColumn == null ) { if ( existingColumn == null ) {
throw new SchemaManagementException( throw new SchemaManagementException(

View File

@ -397,9 +397,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
} }
// unique keys // unique keys
final Iterator<UniqueKey> ukItr = table.getUniqueKeyIterator(); for ( UniqueKey uniqueKey : table.getUniqueKeys().values() ) {
while ( ukItr.hasNext() ) {
final UniqueKey uniqueKey = ukItr.next();
checkExportIdentifier( uniqueKey, exportIdentifiers ); checkExportIdentifier( uniqueKey, exportIdentifiers );
applySqlStrings( applySqlStrings(
dialect.getUniqueKeyExporter().getSqlCreateStrings( uniqueKey, metadata, dialect.getUniqueKeyExporter().getSqlCreateStrings( uniqueKey, metadata,
@ -431,9 +429,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
} }
// foreign keys // foreign keys
final Iterator<ForeignKey> fkItr = table.getForeignKeyIterator(); for ( ForeignKey foreignKey : table.getForeignKeys().values() ) {
while ( fkItr.hasNext() ) {
final ForeignKey foreignKey = fkItr.next();
applySqlStrings( applySqlStrings(
dialect.getForeignKeyExporter().getSqlCreateStrings( foreignKey, metadata, dialect.getForeignKeyExporter().getSqlCreateStrings( foreignKey, metadata,
sqlStringGenerationContext sqlStringGenerationContext

View File

@ -10,7 +10,6 @@ import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -370,9 +369,7 @@ public class SchemaDropperImpl implements SchemaDropper {
continue; continue;
} }
final Iterator<ForeignKey> fks = table.getForeignKeyIterator(); for ( ForeignKey foreignKey : table.getForeignKeys().values() ) {
while ( fks.hasNext() ) {
final ForeignKey foreignKey = fks.next();
applySqlStrings( applySqlStrings(
dialect.getForeignKeyExporter().getSqlDropStrings( foreignKey, metadata, dialect.getForeignKeyExporter().getSqlDropStrings( foreignKey, metadata,
sqlStringGenerationContext sqlStringGenerationContext

View File

@ -20,6 +20,7 @@ import org.hibernate.boot.model.relational.QualifiedNameParser;
import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.mapping.Column; import org.hibernate.mapping.Column;
import org.hibernate.mapping.Constraint; import org.hibernate.mapping.Constraint;
import org.hibernate.mapping.Table; import org.hibernate.mapping.Table;
@ -70,10 +71,8 @@ public class StandardTableExporter implements Exporter<Table> {
pkColName = pkColumn.getQuotedName( dialect ); pkColName = pkColumn.getQuotedName( dialect );
} }
final Iterator columnItr = table.getColumnIterator();
boolean isFirst = true; boolean isFirst = true;
while ( columnItr.hasNext() ) { for ( Column col : table.getColumns() ) {
final Column col = (Column) columnItr.next();
if ( isFirst ) { if ( isFirst ) {
isFirst = false; isFirst = false;
} }
@ -162,7 +161,7 @@ public class StandardTableExporter implements Exporter<Table> {
applyInitCommands( table, sqlStrings, context ); applyInitCommands( table, sqlStrings, context );
return sqlStrings.toArray( new String[ sqlStrings.size() ] ); return sqlStrings.toArray(StringHelper.EMPTY_STRINGS);
} }
catch (Exception e) { catch (Exception e) {
throw new MappingException( "Error creating SQL create commands for table : " + tableName, e ); throw new MappingException( "Error creating SQL create commands for table : " + tableName, e );
@ -174,9 +173,7 @@ public class StandardTableExporter implements Exporter<Table> {
if ( table.getComment() != null ) { if ( table.getComment() != null ) {
sqlStrings.add( "comment on table " + tableName + " is '" + table.getComment() + "'" ); sqlStrings.add( "comment on table " + tableName + " is '" + table.getComment() + "'" );
} }
final Iterator iter = table.getColumnIterator(); for ( Column column : table.getColumns() ) {
while ( iter.hasNext() ) {
Column column = (Column) iter.next();
String columnComment = column.getComment(); String columnComment = column.getComment();
if ( columnComment != null ) { if ( columnComment != null ) {
sqlStrings.add( "comment on column " + tableName + '.' + column.getQuotedName( dialect ) + " is '" + columnComment + "'" ); sqlStrings.add( "comment on column " + tableName + '.' + column.getQuotedName( dialect ) + " is '" + columnComment + "'" );
@ -197,10 +194,9 @@ public class StandardTableExporter implements Exporter<Table> {
protected void applyTableCheck(Table table, StringBuilder buf) { protected void applyTableCheck(Table table, StringBuilder buf) {
if ( dialect.supportsTableCheck() ) { if ( dialect.supportsTableCheck() ) {
final Iterator<String> checkConstraints = table.getCheckConstraintsIterator(); for (String constraint : table.getCheckConstraints() ) {
while ( checkConstraints.hasNext() ) {
buf.append( ", check (" ) buf.append( ", check (" )
.append( checkConstraints.next() ) .append( constraint )
.append( ')' ); .append( ')' );
} }
} }

View File

@ -8,7 +8,6 @@ package org.hibernate.tuple;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -28,9 +27,7 @@ public class DynamicMapInstantiator implements Instantiator {
this.roleName = mappingInfo.getEntityName(); this.roleName = mappingInfo.getEntityName();
isInstanceEntityNames.add( roleName ); isInstanceEntityNames.add( roleName );
if ( mappingInfo.hasSubclasses() ) { if ( mappingInfo.hasSubclasses() ) {
Iterator<PersistentClass> itr = mappingInfo.getSubclassClosureIterator(); for ( PersistentClass subclassInfo : mappingInfo.getSubclassClosure() ) {
while ( itr.hasNext() ) {
final PersistentClass subclassInfo = itr.next();
isInstanceEntityNames.add( subclassInfo.getEntityName() ); isInstanceEntityNames.add( subclassInfo.getEntityName() );
} }
} }

View File

@ -35,6 +35,7 @@ import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.mapping.Component; import org.hibernate.mapping.Component;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.mapping.Subclass;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.spi.PersisterCreationContext; import org.hibernate.persister.spi.PersisterCreationContext;
import org.hibernate.tuple.GenerationTiming; import org.hibernate.tuple.GenerationTiming;
@ -404,10 +405,9 @@ public class EntityMetamodel implements Serializable {
hasCollections = foundCollection; hasCollections = foundCollection;
mutablePropertiesIndexes = mutableIndexes; mutablePropertiesIndexes = mutableIndexes;
Iterator<?> iter = persistentClass.getSubclassIterator();
final Set<String> subclassEntityNamesLocal = new HashSet<>(); final Set<String> subclassEntityNamesLocal = new HashSet<>();
while ( iter.hasNext() ) { for ( Subclass subclass : persistentClass.getSubclasses() ) {
subclassEntityNamesLocal.add( ( (PersistentClass) iter.next() ).getEntityName() ); subclassEntityNamesLocal.add( subclass.getEntityName() );
} }
subclassEntityNamesLocal.add( name ); subclassEntityNamesLocal.add( name );
subclassEntityNames = CollectionHelper.toSmallSet( subclassEntityNamesLocal ); subclassEntityNames = CollectionHelper.toSmallSet( subclassEntityNamesLocal );
@ -415,10 +415,8 @@ public class EntityMetamodel implements Serializable {
HashMap<Class<?>, String> entityNameByInheritanceClassMapLocal = new HashMap<>(); HashMap<Class<?>, String> entityNameByInheritanceClassMapLocal = new HashMap<>();
if ( persistentClass.hasPojoRepresentation() ) { if ( persistentClass.hasPojoRepresentation() ) {
entityNameByInheritanceClassMapLocal.put( persistentClass.getMappedClass(), persistentClass.getEntityName() ); entityNameByInheritanceClassMapLocal.put( persistentClass.getMappedClass(), persistentClass.getEntityName() );
iter = persistentClass.getSubclassIterator(); for ( Subclass subclass : persistentClass.getSubclasses() ) {
while ( iter.hasNext() ) { entityNameByInheritanceClassMapLocal.put( subclass.getMappedClass(), subclass.getEntityName() );
final PersistentClass pc = ( PersistentClass ) iter.next();
entityNameByInheritanceClassMapLocal.put( pc.getMappedClass(), pc.getEntityName() );
} }
} }
entityNameByInheritenceClassMap = CollectionHelper.toSmallMap( entityNameByInheritanceClassMapLocal ); entityNameByInheritenceClassMap = CollectionHelper.toSmallMap( entityNameByInheritanceClassMapLocal );

View File

@ -22,7 +22,6 @@ import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.mapping.Selectable; import org.hibernate.mapping.Selectable;
import org.hibernate.mapping.Table; import org.hibernate.mapping.Table;
import org.hibernate.mapping.Value;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -149,12 +148,10 @@ public class CollectionMappedByResolver {
} }
private static String searchMappedByKey(PersistentClass referencedClass, Collection collectionValue) { private static String searchMappedByKey(PersistentClass referencedClass, Collection collectionValue) {
final Iterator<KeyValue> assocIdClassProps = referencedClass.getKeyClosureIterator(); for ( KeyValue keyValue : referencedClass.getKeyClosure() ) {
while ( assocIdClassProps.hasNext() ) {
final Value value = assocIdClassProps.next();
// make sure it's a 'Component' because IdClass is registered as this type. // make sure it's a 'Component' because IdClass is registered as this type.
if ( value instanceof Component ) { if ( keyValue instanceof Component ) {
final Component component = (Component) value; final Component component = (Component) keyValue;
final Iterator<Property> componentPropertyIterator = component.getPropertyIterator(); final Iterator<Property> componentPropertyIterator = component.getPropertyIterator();
while ( componentPropertyIterator.hasNext() ) { while ( componentPropertyIterator.hasNext() ) {
final Property property = componentPropertyIterator.next(); final Property property = componentPropertyIterator.next();