squash warnings + remove usages of some deprecated methods

This commit is contained in:
Gavin King 2022-10-29 20:18:02 +02:00
parent ce860e31ff
commit 6e8d609485
39 changed files with 325 additions and 479 deletions

View File

@ -25,7 +25,7 @@ import org.hibernate.type.spi.TypeConfiguration;
* *
* @since 5.0 * @since 5.0
*/ */
public interface MetadataImplementor extends Metadata, Mapping { public interface MetadataImplementor extends Metadata {
/** /**
* Access to the options used to build this Metadata * Access to the options used to build this Metadata
* *

View File

@ -225,7 +225,7 @@ public class ClassPropertyHolder extends AbstractPropertyHolder {
); );
} }
if ( inheritanceState.isEmbeddableSuperclass() ) { if ( inheritanceState.isEmbeddableSuperclass() ) {
persistentClass.addMappedsuperclassProperty(prop); persistentClass.addMappedSuperclassProperty( prop );
addPropertyToMappedSuperclass( prop, declaringClass ); addPropertyToMappedSuperclass( prop, declaringClass );
} }
else { else {

View File

@ -18,7 +18,6 @@ import java.util.function.Consumer;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.LockOptions; import org.hibernate.LockOptions;
import org.hibernate.internal.build.AllowSysOut;
import org.hibernate.type.Type; import org.hibernate.type.Type;
public final class ArrayHelper { public final class ArrayHelper {
@ -268,36 +267,36 @@ public final class ArrayHelper {
public static final Type[] EMPTY_TYPE_ARRAY = {}; public static final Type[] EMPTY_TYPE_ARRAY = {};
public static final byte[] EMPTY_BYTE_ARRAY = {}; public static final byte[] EMPTY_BYTE_ARRAY = {};
public static int[] getBatchSizes(int maxBatchSize) { // public static int[] getBatchSizes(int maxBatchSize) {
int batchSize = maxBatchSize; // int batchSize = maxBatchSize;
int n = 1; // int n = 1;
while ( batchSize > 1 ) { // while ( batchSize > 1 ) {
batchSize = getNextBatchSize( batchSize ); // batchSize = getNextBatchSize( batchSize );
n++; // n++;
} // }
int[] result = new int[n]; // int[] result = new int[n];
batchSize = maxBatchSize; // batchSize = maxBatchSize;
for ( int i = 0; i < n; i++ ) { // for ( int i = 0; i < n; i++ ) {
result[i] = batchSize; // result[i] = batchSize;
batchSize = getNextBatchSize( batchSize ); // batchSize = getNextBatchSize( batchSize );
} // }
return result; // return result;
} // }
//
// private static int getNextBatchSize(int batchSize) {
// if ( batchSize <= 10 ) {
// return batchSize - 1; //allow 9,8,7,6,5,4,3,2,1
// }
// else if ( batchSize / 2 < 10 ) {
// return 10;
// }
// else {
// return batchSize / 2;
// }
// }
private static int getNextBatchSize(int batchSize) { private static final int SEED = 23;
if ( batchSize <= 10 ) { private static final int PRIME_NUMBER = 37;
return batchSize - 1; //allow 9,8,7,6,5,4,3,2,1
}
else if ( batchSize / 2 < 10 ) {
return 10;
}
else {
return batchSize / 2;
}
}
private static int SEED = 23;
private static int PRIME_NUMBER = 37;
/** /**
* calculate the array hash (only the first level) * calculate the array hash (only the first level)
@ -406,21 +405,6 @@ public final class ArrayHelper {
return Arrays.asList( values ); return Arrays.asList( values );
} }
@AllowSysOut
public static void main(String... args) {
int[] batchSizes = ArrayHelper.getBatchSizes( 32 );
System.out.println( "Forward ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );
for ( int i = 0; i < batchSizes.length; i++ ) {
System.out.println( "[" + i + "] -> " + batchSizes[i] );
}
System.out.println( "Backward ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );
for ( int i = batchSizes.length - 1; i >= 0; i-- ) {
System.out.println( "[" + i + "] -> " + batchSizes[i] );
}
}
public static boolean isEmpty(Object[] array) { public static boolean isEmpty(Object[] array) {
return array == null || array.length == 0; return array == null || array.length == 0;
} }

View File

@ -22,7 +22,7 @@ import org.jboss.logging.Logger;
public enum BatchFetchStyle { public enum BatchFetchStyle {
/** /**
* The legacy algorithm where we keep a set of pre-built batch sizes based on * The legacy algorithm where we keep a set of pre-built batch sizes based on
* {@link org.hibernate.internal.util.collections.ArrayHelper#getBatchSizes}. Batches are performed * {@code org.hibernate.internal.util.collections.ArrayHelper#getBatchSizes}. Batches are performed
* using the next-smaller pre-built batch size from the number of existing batchable identifiers. * using the next-smaller pre-built batch size from the number of existing batchable identifiers.
* <p/> * <p/>
* For example, with a batch-size setting of 32 the pre-built batch sizes would be [32, 16, 10, 9, 8, 7, .., 1]. * For example, with a batch-size setting of 32 the pre-built batch sizes would be [32, 16, 10, 9, 8, 7, .., 1].

View File

@ -16,6 +16,7 @@ import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.Remove;
import org.hibernate.boot.model.relational.Database; import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.boot.model.source.internal.hbm.MappingDocument; import org.hibernate.boot.model.source.internal.hbm.MappingDocument;
@ -43,26 +44,30 @@ import org.hibernate.type.Type;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class Component extends SimpleValue implements MetaAttributable, SortableValue { public class Component extends SimpleValue implements MetaAttributable, SortableValue {
private final ArrayList<Property> properties = new ArrayList<>();
private int[] originalPropertyOrder = ArrayHelper.EMPTY_INT_ARRAY;
private String componentClassName; private String componentClassName;
private boolean embedded; private boolean embedded;
private String parentProperty; private String parentProperty;
private PersistentClass owner; private PersistentClass owner;
private boolean dynamic; private boolean dynamic;
private Map metaAttributes;
private boolean isKey; private boolean isKey;
private String roleName; private String roleName;
private final ArrayList<Property> properties = new ArrayList<>();
private int[] originalPropertyOrder = ArrayHelper.EMPTY_INT_ARRAY;
private Map<String,MetaAttribute> metaAttributes;
private Class<? extends EmbeddableInstantiator> customInstantiator; private Class<? extends EmbeddableInstantiator> customInstantiator;
// cache the status of the type // cache the status of the type
private volatile Type type; private volatile Type type;
// lazily computed based on 'properties' field: invalidate by setting to null when properties are modified // lazily computed based on 'properties' field: invalidate by setting to null when properties are modified
private List<Selectable> cachedSelectables; private transient List<Selectable> cachedSelectables;
// lazily computed based on 'properties' field: invalidate by setting to null when properties are modified // lazily computed based on 'properties' field: invalidate by setting to null when properties are modified
private List<Column> cachedColumns; private transient List<Column> cachedColumns;
private transient IdentifierGenerator builtIdentifierGenerator;
public Component(MetadataBuildingContext metadata, PersistentClass owner) throws MappingException { public Component(MetadataBuildingContext metadata, PersistentClass owner) throws MappingException {
this( metadata, owner.getTable(), owner ); this( metadata, owner.getTable(), owner );
@ -96,7 +101,7 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
this.parentProperty = original.parentProperty; this.parentProperty = original.parentProperty;
this.owner = original.owner; this.owner = original.owner;
this.dynamic = original.dynamic; this.dynamic = original.dynamic;
this.metaAttributes = original.metaAttributes == null ? null : new HashMap(original.metaAttributes); this.metaAttributes = original.metaAttributes == null ? null : new HashMap<>(original.metaAttributes);
this.isKey = original.isKey; this.isKey = original.isKey;
this.roleName = original.roleName; this.roleName = original.roleName;
this.customInstantiator = original.customInstantiator; this.customInstantiator = original.customInstantiator;
@ -112,6 +117,7 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
return properties.size(); return properties.size();
} }
@Deprecated @Remove
public Iterator<Property> getPropertyIterator() { public Iterator<Property> getPropertyIterator() {
return properties.iterator(); return properties.iterator();
} }
@ -137,14 +143,14 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
@Override @Override
public int getColumnSpan() { public int getColumnSpan() {
int n=0; int span = 0;
for ( Property property : getProperties() ) { for ( Property property : getProperties() ) {
n += property.getColumnSpan(); span += property.getColumnSpan();
} }
return n; return span;
} }
@Override @Deprecated @Override @Deprecated @SuppressWarnings("deprecation")
public Iterator<Selectable> getColumnIterator() { public Iterator<Selectable> getColumnIterator() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Iterator<Selectable>[] iters = new Iterator[ getPropertySpan() ]; Iterator<Selectable>[] iters = new Iterator[ getPropertySpan() ];
@ -157,15 +163,12 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
@Override @Override
public List<Selectable> getSelectables() { public List<Selectable> getSelectables() {
if ( cachedSelectables != null ) { if ( cachedSelectables == null ) {
return cachedSelectables;
}
else {
cachedSelectables = properties.stream() cachedSelectables = properties.stream()
.flatMap( p -> p.getSelectables().stream() ) .flatMap(p -> p.getSelectables().stream())
.collect( Collectors.toList() ); .collect(Collectors.toList());
return cachedSelectables;
} }
return cachedSelectables;
} }
@Override @Override
@ -268,17 +271,17 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
} }
@Override @Override
public Map getMetaAttributes() { public Map<String, MetaAttribute> getMetaAttributes() {
return metaAttributes; return metaAttributes;
} }
@Override @Override
public MetaAttribute getMetaAttribute(String attributeName) { public MetaAttribute getMetaAttribute(String attributeName) {
return metaAttributes==null?null:(MetaAttribute) metaAttributes.get(attributeName); return metaAttributes==null ? null : metaAttributes.get(attributeName);
} }
@Override @Override
public void setMetaAttributes(Map metas) { public void setMetaAttributes(Map<String, MetaAttribute> metas) {
this.metaAttributes = metas; this.metaAttributes = metas;
} }
@ -303,22 +306,21 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
@Override @Override
public boolean[] getColumnInsertability() { public boolean[] getColumnInsertability() {
boolean[] result = new boolean[ getColumnSpan() ]; final boolean[] result = new boolean[ getColumnSpan() ];
int i=0; int i = 0;
for ( Property prop : getProperties() ) { for ( Property prop : getProperties() ) {
boolean[] chunk = prop.getValue().getColumnInsertability(); final boolean[] chunk = prop.getValue().getColumnInsertability();
if ( prop.isInsertable() ) { if ( prop.isInsertable() ) {
System.arraycopy(chunk, 0, result, i, chunk.length); System.arraycopy( chunk, 0, result, i, chunk.length );
} }
i+=chunk.length; i += chunk.length;
} }
return result; return result;
} }
@Override @Override
public boolean hasAnyInsertableColumns() { public boolean hasAnyInsertableColumns() {
for ( int i = 0; i < properties.size(); i++ ) { for ( Property property : properties ) {
final Property property = properties.get( i );
if ( property.getValue().hasAnyInsertableColumns() ) { if ( property.getValue().hasAnyInsertableColumns() ) {
return true; return true;
} }
@ -343,13 +345,11 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
@Override @Override
public boolean hasAnyUpdatableColumns() { public boolean hasAnyUpdatableColumns() {
for ( int i = 0; i < properties.size(); i++ ) { for ( Property property : properties ) {
final Property property = properties.get( i );
if ( property.getValue().hasAnyUpdatableColumns() ) { if ( property.getValue().hasAnyUpdatableColumns() ) {
return true; return true;
} }
} }
return false; return false;
} }
@ -408,8 +408,6 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
return getClass().getSimpleName() + '(' + componentClassName + ')'; return getClass().getSimpleName() + '(' + componentClassName + ')';
} }
private IdentifierGenerator builtIdentifierGenerator;
@Override @Override
public IdentifierGenerator createIdentifierGenerator( public IdentifierGenerator createIdentifierGenerator(
IdentifierGeneratorFactory identifierGeneratorFactory, IdentifierGeneratorFactory identifierGeneratorFactory,
@ -577,8 +575,9 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
// to be able to sort the other side of the foreign key accordingly // to be able to sort the other side of the foreign key accordingly
// and also if the source is a XML mapping // and also if the source is a XML mapping
// because XML mappings might refer to this through the defined order // because XML mappings might refer to this through the defined order
if ( forceRetainOriginalOrder || isAlternateUniqueKey() || isEmbedded() || getBuildingContext() instanceof MappingDocument ) { if ( forceRetainOriginalOrder || isAlternateUniqueKey() || isEmbedded()
final Object[] originalProperties = properties.toArray(); || getBuildingContext() instanceof MappingDocument ) {
final Property[] originalProperties = properties.toArray( new Property[0] );
properties.sort( Comparator.comparing( Property::getName ) ); properties.sort( Comparator.comparing( Property::getName ) );
originalPropertyOrder = new int[originalProperties.length]; originalPropertyOrder = new int[originalProperties.length];
for ( int j = 0; j < originalPropertyOrder.length; j++ ) { for ( int j = 0; j < originalPropertyOrder.length; j++ ) {
@ -595,8 +594,8 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
// We have to re-order the primary key accordingly // We have to re-order the primary key accordingly
final List<Column> columns = primaryKey.getColumns(); final List<Column> columns = primaryKey.getColumns();
columns.clear(); columns.clear();
for ( int i = 0; i < properties.size(); i++ ) { for ( Property property : properties ) {
for ( Selectable selectable : properties.get(i).getSelectables() ) { for ( Selectable selectable : property.getSelectables() ) {
if ( selectable instanceof Column ) { if ( selectable instanceof Column ) {
columns.add( (Column) selectable ); columns.add( (Column) selectable );
} }

View File

@ -159,7 +159,7 @@ public abstract class Constraint implements RelationalModel, Exportable, Seriali
@Deprecated(since = "6.0") @Deprecated(since = "6.0")
public Iterator<Column> getColumnIterator() { public Iterator<Column> getColumnIterator() {
return columns.iterator(); return getColumns().iterator();
} }
public Table getTable() { public Table getTable() {

View File

@ -27,10 +27,10 @@ import org.hibernate.internal.util.StringHelper;
* @author Gavin King * @author Gavin King
*/ */
public class Index implements RelationalModel, Exportable, Serializable { public class Index implements RelationalModel, Exportable, Serializable {
private Table table;
private java.util.List<Column> columns = new ArrayList<>();
private java.util.Map<Column, String> columnOrderMap = new HashMap<>( );
private Identifier name; private Identifier name;
private Table table;
private final java.util.List<Column> columns = new ArrayList<>();
private final java.util.Map<Column, String> columnOrderMap = new HashMap<>( );
@Override @Override
public String sqlCreateString(Mapping mapping, SqlStringGenerationContext context, String defaultCatalog, public String sqlCreateString(Mapping mapping, SqlStringGenerationContext context, String defaultCatalog,

View File

@ -9,8 +9,8 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.engine.spi.Mapping;
/** /**
* A subclass in a table-per-subclass mapping * A subclass in a table-per-subclass mapping
@ -41,9 +41,9 @@ public class JoinedSubclass extends Subclass implements TableOwner {
this.key = key; this.key = key;
} }
public void validate(Mapping mapping) throws MappingException { public void validate(Metadata mapping) throws MappingException {
super.validate(mapping); super.validate(mapping);
if ( key!=null && !key.isValid(mapping) ) { if ( key != null && !key.isValid( mapping ) ) {
throw new MappingException( throw new MappingException(
"subclass key mapping has wrong number of columns: " + "subclass key mapping has wrong number of columns: " +
getEntityName() + getEntityName() +
@ -53,7 +53,7 @@ public class JoinedSubclass extends Subclass implements TableOwner {
} }
} }
@Deprecated @Deprecated @SuppressWarnings("deprecation")
public Iterator<Property> getReferenceablePropertyIterator() { public Iterator<Property> getReferenceablePropertyIterator() {
return getPropertyIterator(); return getPropertyIterator();
} }

View File

@ -7,6 +7,8 @@
package org.hibernate.mapping; package org.hibernate.mapping;
import java.util.Map;
/** /**
* Common interface for things that can handle meta attributes. * Common interface for things that can handle meta attributes.
* *
@ -14,9 +16,9 @@ package org.hibernate.mapping;
*/ */
public interface MetaAttributable { public interface MetaAttributable {
java.util.Map getMetaAttributes(); Map<String, MetaAttribute> getMetaAttributes();
void setMetaAttributes(java.util.Map metas); void setMetaAttributes(Map<String, MetaAttribute> metas);
MetaAttribute getMetaAttribute(String name); MetaAttribute getMetaAttribute(String name);

View File

@ -16,8 +16,8 @@ import java.util.Collections;
* @author Gavin King * @author Gavin King
*/ */
public class MetaAttribute implements Serializable { public class MetaAttribute implements Serializable {
private String name; private final String name;
private java.util.List values = new ArrayList(); private final java.util.List<String> values = new ArrayList<>();
public MetaAttribute(String name) { public MetaAttribute(String name) {
this.name = name; this.name = name;
@ -27,7 +27,7 @@ public class MetaAttribute implements Serializable {
return name; return name;
} }
public java.util.List getValues() { public java.util.List<String> getValues() {
return Collections.unmodifiableList(values); return Collections.unmodifiableList(values);
} }
@ -39,7 +39,7 @@ public class MetaAttribute implements Serializable {
if ( values.size()!=1 ) { if ( values.size()!=1 ) {
throw new IllegalStateException("no unique value"); throw new IllegalStateException("no unique value");
} }
return (String) values.get(0); return values.get(0);
} }
public boolean isMultiValued() { public boolean isMultiValued() {

View File

@ -13,22 +13,24 @@ import java.util.Comparator;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.Remove;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.model.CustomSql; import org.hibernate.boot.model.CustomSql;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.boot.spi.ClassLoaderAccess;
import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.engine.OptimisticLockStyle; import org.hibernate.engine.OptimisticLockStyle;
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.internal.FilterConfiguration; import org.hibernate.internal.FilterConfiguration;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.JoinedIterator; import org.hibernate.internal.util.collections.JoinedIterator;
import org.hibernate.internal.util.collections.JoinedList; import org.hibernate.internal.util.collections.JoinedList;
import org.hibernate.internal.util.collections.SingletonIterator; import org.hibernate.internal.util.collections.SingletonIterator;
import org.hibernate.metamodel.RepresentationMode;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.jpa.event.spi.CallbackDefinition; import org.hibernate.jpa.event.spi.CallbackDefinition;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;
@ -41,6 +43,7 @@ import org.hibernate.type.Type;
* @author Gavin King * @author Gavin King
*/ */
public abstract class PersistentClass implements AttributeContainer, Serializable, Filterable, MetaAttributable, Contributable { public abstract class PersistentClass implements AttributeContainer, Serializable, Filterable, MetaAttributable, Contributable {
private static final Alias PK_ALIAS = new Alias( 15, "PK" ); private static final Alias PK_ALIAS = new Alias( 15, "PK" );
public static final String NULL_DISCRIMINATOR_MAPPING = "null"; public static final String NULL_DISCRIMINATOR_MAPPING = "null";
@ -61,25 +64,25 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
private String discriminatorValue; private String discriminatorValue;
private boolean lazy; private boolean lazy;
private final java.util.List<Property> properties = new ArrayList<>(); private final List<Property> properties = new ArrayList<>();
private final java.util.List<Property> declaredProperties = new ArrayList<>(); private final List<Property> declaredProperties = new ArrayList<>();
private final java.util.List<Subclass> subclasses = new ArrayList<>(); private final List<Subclass> subclasses = new ArrayList<>();
private final java.util.List<Property> subclassProperties = new ArrayList<>(); private final List<Property> subclassProperties = new ArrayList<>();
private final java.util.List<Table> subclassTables = new ArrayList<>(); private final List<Table> subclassTables = new ArrayList<>();
private boolean dynamicInsert; private boolean dynamicInsert;
private boolean dynamicUpdate; private boolean dynamicUpdate;
private int batchSize = -1; private int batchSize = -1;
private boolean selectBeforeUpdate; private boolean selectBeforeUpdate;
private java.util.Map metaAttributes; private java.util.Map<String, MetaAttribute> metaAttributes;
private final java.util.List<Join> joins = new ArrayList<>(); private final List<Join> joins = new ArrayList<>();
private final java.util.List<Join> subclassJoins = new ArrayList<>(); private final List<Join> subclassJoins = new ArrayList<>();
private final java.util.List<FilterConfiguration> filters = new ArrayList<>(); private final List<FilterConfiguration> filters = new ArrayList<>();
protected final Set<String> synchronizedTables = new HashSet<>(); protected final Set<String> synchronizedTables = new HashSet<>();
private String loaderName; private String loaderName;
private Boolean isAbstract; private Boolean isAbstract;
private boolean hasSubselectLoadableCollections; private boolean hasSubselectLoadableCollections;
private Component identifierMapper; private Component identifierMapper;
private java.util.List<CallbackDefinition> callbackDefinitions; private List<CallbackDefinition> callbackDefinitions;
// Custom SQL // Custom SQL
private String customSQLInsert; private String customSQLInsert;
@ -98,9 +101,9 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
private boolean isCached; private boolean isCached;
public PersistentClass(MetadataBuildingContext metadataBuildingContext) { public PersistentClass(MetadataBuildingContext buildingContext) {
this.metadataBuildingContext = metadataBuildingContext; this.metadataBuildingContext = buildingContext;
this.contributor = metadataBuildingContext.getCurrentContributorName(); this.contributor = buildingContext.getCurrentContributorName();
} }
public String getContributor() { public String getContributor() {
@ -129,6 +132,10 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
this.proxyInterface = null; this.proxyInterface = null;
} }
private ClassLoaderAccess getClassLoaderAccess() {
return metadataBuildingContext.getBootstrapContext().getClassLoaderAccess();
}
public Class<?> getMappedClass() throws MappingException { public Class<?> getMappedClass() throws MappingException {
if ( className == null ) { if ( className == null ) {
return null; return null;
@ -136,7 +143,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
try { try {
if ( mappedClass == null ) { if ( mappedClass == null ) {
mappedClass = metadataBuildingContext.getBootstrapContext().getClassLoaderAccess().classForName( className ); mappedClass = getClassLoaderAccess().classForName( className );
} }
return mappedClass; return mappedClass;
} }
@ -151,7 +158,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
} }
try { try {
if ( proxyInterface == null ) { if ( proxyInterface == null ) {
proxyInterface = metadataBuildingContext.getBootstrapContext().getClassLoaderAccess().classForName( proxyInterfaceName ); proxyInterface = getClassLoaderAccess().classForName( proxyInterfaceName );
} }
return proxyInterface; return proxyInterface;
} }
@ -207,11 +214,11 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
} }
public int getSubclassSpan() { public int getSubclassSpan() {
int n = subclasses.size(); int span = subclasses.size();
for ( Subclass subclass : subclasses ) { for ( Subclass subclass : subclasses ) {
n += subclass.getSubclassSpan(); span += subclass.getSubclassSpan();
} }
return n; return span;
} }
/** /**
@ -219,13 +226,14 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
*/ */
public List<Subclass> getSubclasses() { public List<Subclass> getSubclasses() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<Subclass>[] iters = new List[subclasses.size() + 1]; List<Subclass>[] subclassLists = new List[subclasses.size() + 1];
int i = 0; int j;
for ( Subclass subclass : subclasses ) { for (j = 0; j < subclasses.size(); j++) {
iters[i++] = subclass.getSubclasses(); Subclass subclass = subclasses.get(j);
subclassLists[j] = subclass.getSubclasses();
} }
iters[i] = subclasses; subclassLists[j] = subclasses;
return new JoinedList<>( iters ); return new JoinedList<>( subclassLists );
} }
/** /**
@ -233,11 +241,11 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
* *
* @deprecated use {@link #getSubclasses()} * @deprecated use {@link #getSubclasses()}
*/ */
@Deprecated(since = "6.0") @Deprecated(since = "6.0") @Remove
public Iterator<Subclass> getSubclassIterator() { public Iterator<Subclass> getSubclassIterator() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Iterator<Subclass>[] iters = new Iterator[subclasses.size() + 1]; final Iterator<Subclass>[] iters = new Iterator[subclasses.size() + 1];
Iterator<Subclass> iter = subclasses.iterator(); final Iterator<Subclass> iter = subclasses.iterator();
int i = 0; int i = 0;
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
iters[i++] = iter.next().getSubclassIterator(); iters[i++] = iter.next().getSubclassIterator();
@ -247,7 +255,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
} }
public List<PersistentClass> getSubclassClosure() { public List<PersistentClass> getSubclassClosure() {
ArrayList<List<PersistentClass>> lists = new ArrayList<>(); final ArrayList<List<PersistentClass>> lists = new ArrayList<>();
lists.add( List.of( this ) ); lists.add( List.of( this ) );
for ( Subclass subclass : getSubclasses() ) { for ( Subclass subclass : getSubclasses() ) {
lists.add( subclass.getSubclassClosure() ); lists.add( subclass.getSubclassClosure() );
@ -255,9 +263,9 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
return new JoinedList<>( lists ); return new JoinedList<>( lists );
} }
@Deprecated(since = "6.0") @Deprecated(since = "6.0") @Remove
public Iterator<PersistentClass> getSubclassClosureIterator() { public Iterator<PersistentClass> getSubclassClosureIterator() {
ArrayList<Iterator<PersistentClass>> iters = new ArrayList<>(); final ArrayList<Iterator<PersistentClass>> iters = new ArrayList<>();
iters.add( new SingletonIterator<>( this ) ); iters.add( new SingletonIterator<>( this ) );
for ( Subclass subclass : getSubclasses() ) { for ( Subclass subclass : getSubclasses() ) {
iters.add( subclass.getSubclassClosureIterator() ); iters.add( subclass.getSubclassClosureIterator() );
@ -345,17 +353,17 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
public abstract List<Property> getPropertyClosure(); public abstract List<Property> getPropertyClosure();
@Deprecated(since = "6.0") @Deprecated(since = "6.0") @Remove
public abstract Iterator<Property> getPropertyClosureIterator(); public abstract Iterator<Property> getPropertyClosureIterator();
public abstract List<Table> getTableClosure(); public abstract List<Table> getTableClosure();
@Deprecated(since = "6.0") @Deprecated(since = "6.0") @Remove
public abstract Iterator<Table> getTableClosureIterator(); public abstract Iterator<Table> getTableClosureIterator();
public abstract List<KeyValue> getKeyClosure(); public abstract List<KeyValue> getKeyClosure();
@Deprecated(since = "6.0") @Deprecated(since = "6.0") @Remove
public abstract Iterator<KeyValue> getKeyClosureIterator(); public abstract Iterator<KeyValue> getKeyClosureIterator();
protected void addSubclassProperty(Property prop) { protected void addSubclassProperty(Property prop) {
@ -370,9 +378,9 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
subclassTables.add( subclassTable ); subclassTables.add( subclassTable );
} }
@Deprecated(since = "6.0") @Deprecated(since = "6.0") @Remove
public Iterator<Property> getSubclassPropertyClosureIterator() { public Iterator<Property> getSubclassPropertyClosureIterator() {
ArrayList<Iterator<Property>> iters = new ArrayList<>(); final ArrayList<Iterator<Property>> iters = new ArrayList<>();
iters.add( getPropertyClosureIterator() ); iters.add( getPropertyClosureIterator() );
iters.add( subclassProperties.iterator() ); iters.add( subclassProperties.iterator() );
for (Join join : subclassJoins) { for (Join join : subclassJoins) {
@ -382,7 +390,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
} }
public List<Property> getSubclassPropertyClosure() { public List<Property> getSubclassPropertyClosure() {
ArrayList<List<Property>> lists = new ArrayList<>(); final ArrayList<List<Property>> lists = new ArrayList<>();
lists.add( getPropertyClosure() ); lists.add( getPropertyClosure() );
lists.add( subclassProperties ); lists.add( subclassProperties );
for (Join join : subclassJoins) { for (Join join : subclassJoins) {
@ -391,7 +399,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
return new JoinedList<>( lists ); return new JoinedList<>( lists );
} }
@Deprecated(since = "6.0") @Deprecated(since = "6.0") @Remove
public Iterator<Join> getSubclassJoinClosureIterator() { public Iterator<Join> getSubclassJoinClosureIterator() {
return new JoinedIterator<>( getJoinClosureIterator(), subclassJoins.iterator() ); return new JoinedIterator<>( getJoinClosureIterator(), subclassJoins.iterator() );
} }
@ -404,7 +412,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
return new JoinedList<>( getTableClosure(), subclassTables ); return new JoinedList<>( getTableClosure(), subclassTables );
} }
@Deprecated(since = "6.0") @Deprecated(since = "6.0") @Remove
public Iterator<Table> getSubclassTableClosureIterator() { public Iterator<Table> getSubclassTableClosureIterator() {
return new JoinedIterator<>( getTableClosureIterator(), subclassTables.iterator() ); return new JoinedIterator<>( getTableClosureIterator(), subclassTables.iterator() );
} }
@ -448,7 +456,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
public void createPrimaryKey() { public void createPrimaryKey() {
//Primary key constraint //Primary key constraint
final Table table = getTable(); final Table table = getTable();
PrimaryKey pk = new PrimaryKey( table ); final PrimaryKey pk = new PrimaryKey( table );
pk.setName( PK_ALIAS.toAliasString( table.getName() ) ); pk.setName( PK_ALIAS.toAliasString( table.getName() ) );
table.setPrimaryKey( pk ); table.setPrimaryKey( pk );
@ -485,7 +493,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
* *
* @deprecated use {@link #getReferenceableProperties()} * @deprecated use {@link #getReferenceableProperties()}
*/ */
@Deprecated(since = "6.0") @Deprecated(since = "6.0") @Remove
public Iterator<Property> getReferenceablePropertyIterator() { public Iterator<Property> getReferenceablePropertyIterator() {
return getPropertyClosureIterator(); return getPropertyClosureIterator();
} }
@ -638,10 +646,8 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
return true; return true;
} }
final Iterator<Property> itr = getPropertyClosureIterator(); for ( Property property : getPropertyClosure() ) {
while ( itr.hasNext() ) { if (property.getName().equals(name)) {
final Property property = itr.next();
if ( property.getName().equals( name ) ) {
return true; return true;
} }
} }
@ -702,7 +708,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
this.optimisticLockStyle = optimisticLockStyle; this.optimisticLockStyle = optimisticLockStyle;
} }
public void validate(Mapping mapping) throws MappingException { public void validate(Metadata mapping) throws MappingException {
for ( Property prop : getProperties() ) { for ( Property prop : getProperties() ) {
if ( !prop.isValid( mapping ) ) { if ( !prop.isValid( mapping ) ) {
Type type = prop.getType(); Type type = prop.getType();
@ -721,7 +727,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
} }
private void checkPropertyDuplication() throws MappingException { private void checkPropertyDuplication() throws MappingException {
HashSet<String> names = new HashSet<>(); final HashSet<String> names = new HashSet<>();
for ( Property prop : getProperties() ) { for ( Property prop : getProperties() ) {
if ( !names.add( prop.getName() ) ) { if ( !names.add( prop.getName() ) ) {
throw new MappingException( "Duplicate property mapping of " + prop.getName() + " found in " + getEntityName() ); throw new MappingException( "Duplicate property mapping of " + prop.getName() + " found in " + getEntityName() );
@ -737,18 +743,16 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
return NULL_DISCRIMINATOR_MAPPING.equals( getDiscriminatorValue() ); return NULL_DISCRIMINATOR_MAPPING.equals( getDiscriminatorValue() );
} }
public java.util.Map getMetaAttributes() { public Map<String, MetaAttribute> getMetaAttributes() {
return metaAttributes; return metaAttributes;
} }
public void setMetaAttributes(java.util.Map metas) { public void setMetaAttributes(java.util.Map<String,MetaAttribute> metas) {
this.metaAttributes = metas; this.metaAttributes = metas;
} }
public MetaAttribute getMetaAttribute(String name) { public MetaAttribute getMetaAttribute(String name) {
return metaAttributes == null return metaAttributes == null ? null : metaAttributes.get( name );
? null
: (MetaAttribute) metaAttributes.get( name );
} }
@Override @Override
@ -819,7 +823,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
*/ */
@Deprecated(since = "6.0") @Deprecated(since = "6.0")
public Iterator<Property> getPropertyIterator() { public Iterator<Property> getPropertyIterator() {
ArrayList<Iterator<Property>> iterators = new ArrayList<>(); final ArrayList<Iterator<Property>> iterators = new ArrayList<>();
iterators.add( properties.iterator() ); iterators.add( properties.iterator() );
for (Join join : joins) { for (Join join : joins) {
iterators.add( join.getPropertyIterator() ); iterators.add( join.getPropertyIterator() );
@ -827,8 +831,21 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
return new JoinedIterator<>( iterators ); return new JoinedIterator<>( iterators );
} }
/**
* Build a list of the properties defined on this class. The returned
* iterator only accounts for "normal" properties (i.e. non-identifier
* properties).
* <p/>
* Differs from {@link #getUnjoinedProperties} in that the returned iterator
* will include properties defined as part of a join.
* <p/>
* Differs from {@link #getReferenceableProperties} in that the properties
* defined in superclasses of the mapping inheritance are not included.
*
* @return An iterator over the "normal" properties.
*/
public List<Property> getProperties() { public List<Property> getProperties() {
ArrayList<List<Property>> list = new ArrayList<>(); final ArrayList<List<Property>> list = new ArrayList<>();
list.add( properties ); list.add( properties );
for (Join join : joins) { for (Join join : joins) {
list.add( join.getProperties() ); list.add( join.getProperties() );
@ -997,12 +1014,10 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
protected void checkColumnDuplication(Set<String> distinctColumns, Value value) protected void checkColumnDuplication(Set<String> distinctColumns, Value value)
throws MappingException { throws MappingException {
if (value == null) { if ( value != null ) {
return;
}
for ( Selectable columnOrFormula : value.getSelectables() ) { for ( Selectable columnOrFormula : value.getSelectables() ) {
if ( !columnOrFormula.isFormula() ) { if ( !columnOrFormula.isFormula() ) {
Column col = (Column) columnOrFormula; final Column col = (Column) columnOrFormula;
if ( !distinctColumns.add( col.getName() ) ) { if ( !distinctColumns.add( col.getName() ) ) {
throw new MappingException( throw new MappingException(
"Column '" + col.getName() "Column '" + col.getName()
@ -1013,6 +1028,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
} }
} }
} }
}
protected void checkPropertyColumnDuplication(Set<String> distinctColumns, List<Property> properties) protected void checkPropertyColumnDuplication(Set<String> distinctColumns, List<Property> properties)
throws MappingException { throws MappingException {
@ -1045,7 +1061,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
} }
protected void checkColumnDuplication() { protected void checkColumnDuplication() {
HashSet<String> cols = new HashSet<>(); final HashSet<String> cols = new HashSet<>();
if ( getIdentifierMapper() == null ) { if ( getIdentifierMapper() == null ) {
//an identifier mapper => getKey will be included in the getNonDuplicatedPropertyIterator() //an identifier mapper => getKey will be included in the getNonDuplicatedPropertyIterator()
//and checked later, so it needs to be excluded //and checked later, so it needs to be excluded
@ -1119,14 +1135,6 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
this.identifierMapper = handle; this.identifierMapper = handle;
} }
public String getTuplizerImplClassName(RepresentationMode mode) {
return null;
}
public java.util.Map getTuplizerMap() {
return null;
}
private Boolean hasNaturalId; private Boolean hasNaturalId;
public boolean hasNaturalId() { public boolean hasNaturalId() {
@ -1166,7 +1174,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
return new JoinedIterator<>( iterators ); return new JoinedIterator<>( iterators );
} }
public void addMappedsuperclassProperty(Property p) { public void addMappedSuperclassProperty(Property p) {
properties.add( p ); properties.add( p );
p.setPersistentClass( this ); p.setPersistentClass( this );
} }

View File

@ -6,26 +6,13 @@
*/ */
package org.hibernate.mapping; package org.hibernate.mapping;
/** /**
* @author max * @author max
*
*/ */
public interface PersistentClassVisitor { public interface PersistentClassVisitor {
Object accept(RootClass class1); Object accept(RootClass class1);
Object accept(UnionSubclass subclass); Object accept(UnionSubclass subclass);
Object accept(SingleTableSubclass subclass); Object accept(SingleTableSubclass subclass);
Object accept(JoinedSubclass subclass); Object accept(JoinedSubclass subclass);
Object accept(Subclass subclass); Object accept(Subclass subclass);
} }

View File

@ -10,6 +10,7 @@ import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
@ -258,7 +259,7 @@ public class Property implements Serializable, MetaAttributable {
return propertyAccessorName==null || "property".equals( propertyAccessorName ); return propertyAccessorName==null || "property".equals( propertyAccessorName );
} }
public java.util.Map getMetaAttributes() { public Map<String, MetaAttribute> getMetaAttributes() {
return metaAttributes; return metaAttributes;
} }
@ -266,7 +267,7 @@ public class Property implements Serializable, MetaAttributable {
return metaAttributes==null?null:(MetaAttribute) metaAttributes.get(attributeName); return metaAttributes==null?null:(MetaAttribute) metaAttributes.get(attributeName);
} }
public void setMetaAttributes(java.util.Map metas) { public void setMetaAttributes(Map<String, MetaAttribute> metas) {
this.metaAttributes = metas; this.metaAttributes = metas;
} }

View File

@ -12,8 +12,8 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.ReflectHelper;
@ -55,8 +55,8 @@ public class RootClass extends PersistentClass implements TableOwner {
private Property declaredIdentifierProperty; private Property declaredIdentifierProperty;
private Property declaredVersion; private Property declaredVersion;
public RootClass(MetadataBuildingContext metadataBuildingContext) { public RootClass(MetadataBuildingContext buildingContext) {
super( metadataBuildingContext ); super( buildingContext );
} }
@Override @Override
@ -279,7 +279,7 @@ public class RootClass extends PersistentClass implements TableOwner {
} }
@Override @Override
public void validate(Mapping mapping) throws MappingException { public void validate(Metadata mapping) throws MappingException {
super.validate( mapping ); super.validate( mapping );
if ( !getIdentifier().isValid( mapping ) ) { if ( !getIdentifier().isValid( mapping ) ) {
throw new MappingException( throw new MappingException(

View File

@ -10,8 +10,8 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.internal.util.collections.JoinedIterator; import org.hibernate.internal.util.collections.JoinedIterator;
import org.hibernate.internal.util.collections.JoinedList; import org.hibernate.internal.util.collections.JoinedList;
@ -20,11 +20,11 @@ import org.hibernate.internal.util.collections.JoinedList;
*/ */
public class SingleTableSubclass extends Subclass { public class SingleTableSubclass extends Subclass {
public SingleTableSubclass(PersistentClass superclass, MetadataBuildingContext metadataBuildingContext) { public SingleTableSubclass(PersistentClass superclass, MetadataBuildingContext buildingContext) {
super( superclass, metadataBuildingContext ); super( superclass, buildingContext );
} }
@Deprecated @Deprecated @SuppressWarnings("deprecation")
protected Iterator<Property> getNonDuplicatedPropertyIterator() { protected Iterator<Property> getNonDuplicatedPropertyIterator() {
return new JoinedIterator<>( return new JoinedIterator<>(
getSuperclass().getUnjoinedPropertyIterator(), getSuperclass().getUnjoinedPropertyIterator(),
@ -36,7 +36,7 @@ public class SingleTableSubclass extends Subclass {
return new JoinedList<>( getSuperclass().getUnjoinedProperties(), getUnjoinedProperties() ); return new JoinedList<>( getSuperclass().getUnjoinedProperties(), getUnjoinedProperties() );
} }
@Deprecated @Deprecated @SuppressWarnings("deprecation")
protected Iterator<Selectable> getDiscriminatorColumnIterator() { protected Iterator<Selectable> getDiscriminatorColumnIterator() {
return isDiscriminatorInsertable() && !getDiscriminator().hasFormula() return isDiscriminatorInsertable() && !getDiscriminator().hasFormula()
? getDiscriminator().getColumnIterator() ? getDiscriminator().getColumnIterator()
@ -47,7 +47,7 @@ public class SingleTableSubclass extends Subclass {
return mv.accept( this ); return mv.accept( this );
} }
public void validate(Mapping mapping) throws MappingException { public void validate(Metadata mapping) throws MappingException {
if ( getDiscriminator() == null ) { if ( getDiscriminator() == null ) {
throw new MappingException( throw new MappingException(
"No discriminator found for " + getEntityName() "No discriminator found for " + getEntityName()

View File

@ -7,11 +7,9 @@
package org.hibernate.mapping; package org.hibernate.mapping;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.MetadataBuildingContext;
@ -20,7 +18,6 @@ import org.hibernate.internal.FilterConfiguration;
import org.hibernate.internal.util.collections.JoinedIterator; import org.hibernate.internal.util.collections.JoinedIterator;
import org.hibernate.internal.util.collections.JoinedList; import org.hibernate.internal.util.collections.JoinedList;
import org.hibernate.internal.util.collections.SingletonIterator; import org.hibernate.internal.util.collections.SingletonIterator;
import org.hibernate.metamodel.RepresentationMode;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
/** /**
@ -28,12 +25,13 @@ import org.hibernate.persister.entity.EntityPersister;
* @author Gavin King * @author Gavin King
*/ */
public class Subclass extends PersistentClass { public class Subclass extends PersistentClass {
private PersistentClass superclass; private PersistentClass superclass;
private Class<? extends EntityPersister> classPersisterClass; private Class<? extends EntityPersister> classPersisterClass;
private final int subclassId; private final int subclassId;
public Subclass(PersistentClass superclass, MetadataBuildingContext metadataBuildingContext) { public Subclass(PersistentClass superclass, MetadataBuildingContext buildingContext) {
super( metadataBuildingContext ); super( buildingContext );
this.superclass = superclass; this.superclass = superclass;
this.subclassId = superclass.nextSubclassId(); this.subclassId = superclass.nextSubclassId();
} }
@ -115,8 +113,8 @@ public class Subclass extends PersistentClass {
} }
@Override @Override
public void addMappedsuperclassProperty(Property p) { public void addMappedSuperclassProperty(Property p) {
super.addMappedsuperclassProperty( p ); super.addMappedSuperclassProperty( p );
getSuperclass().addSubclassProperty(p); getSuperclass().addSubclassProperty(p);
} }
@ -273,7 +271,7 @@ public class Subclass extends PersistentClass {
return new JoinedList<>( getSuperclass().getJoinClosure(), super.getJoinClosure() ); return new JoinedList<>( getSuperclass().getJoinClosure(), super.getJoinClosure() );
} }
@Deprecated(since = "6.0") @Deprecated(since = "6.0") @SuppressWarnings("deprecation")
public Iterator<Join> getJoinClosureIterator() { public Iterator<Join> getJoinClosureIterator() {
return new JoinedIterator<>( return new JoinedIterator<>(
getSuperclass().getJoinClosureIterator(), getSuperclass().getJoinClosureIterator(),
@ -333,34 +331,6 @@ public class Subclass extends PersistentClass {
getSuperclass().hasSubselectLoadableCollections(); getSuperclass().hasSubselectLoadableCollections();
} }
@Override
public String getTuplizerImplClassName(RepresentationMode mode) {
String impl = super.getTuplizerImplClassName( mode );
if ( impl == null ) {
impl = getSuperclass().getTuplizerImplClassName( mode );
}
return impl;
}
@Override
public Map getTuplizerMap() {
Map specificTuplizerDefs = super.getTuplizerMap();
Map superclassTuplizerDefs = getSuperclass().getTuplizerMap();
if ( specificTuplizerDefs == null && superclassTuplizerDefs == null ) {
return null;
}
else {
Map combined = new HashMap();
if ( superclassTuplizerDefs != null ) {
combined.putAll( superclassTuplizerDefs );
}
if ( specificTuplizerDefs != null ) {
combined.putAll( specificTuplizerDefs );
}
return java.util.Collections.unmodifiableMap( combined );
}
}
@Override @Override
public Component getIdentifierMapper() { public Component getIdentifierMapper() {
return superclass.getIdentifierMapper(); return superclass.getIdentifierMapper();

View File

@ -34,6 +34,9 @@ import org.hibernate.tool.schema.extract.spi.TableInformation;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import static java.util.Collections.unmodifiableList;
import static java.util.Collections.unmodifiableMap;
/** /**
* A relational database table. * A relational database table.
* *
@ -228,24 +231,19 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
if ( column == null ) { if ( column == null ) {
return null; return null;
} }
final Column myColumn = columns.get( column.getCanonicalName() );
Column myColumn = columns.get( column.getCanonicalName() ); return column.equals( myColumn ) ? myColumn : null;
return column.equals( myColumn ) ?
myColumn :
null;
} }
public Column getColumn(Identifier name) { public Column getColumn(Identifier name) {
if ( name == null ) { if ( name == null ) {
return null; return null;
} }
return columns.get( name.getCanonicalName() ); return columns.get( name.getCanonicalName() );
} }
public Column getColumn(int n) { public Column getColumn(int n) {
Iterator<Column> iter = columns.values().iterator(); final Iterator<Column> iter = columns.values().iterator();
for ( int i = 0; i < n - 1; i++ ) { for ( int i = 0; i < n - 1; i++ ) {
iter.next(); iter.next();
} }
@ -253,7 +251,7 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
} }
public void addColumn(Column column) { public void addColumn(Column column) {
Column old = getColumn( column ); final Column old = getColumn( column );
if ( old == null ) { if ( old == null ) {
if ( primaryKey != null ) { if ( primaryKey != null ) {
for ( Column c : primaryKey.getColumns() ) { for ( Column c : primaryKey.getColumns() ) {
@ -269,8 +267,8 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
} }
} }
} }
this.columns.put( column.getCanonicalName(), column ); columns.put( column.getCanonicalName(), column );
column.uniqueInteger = this.columns.size(); column.uniqueInteger = columns.size();
} }
else { else {
column.uniqueInteger = old.uniqueInteger; column.uniqueInteger = old.uniqueInteger;
@ -283,24 +281,29 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
@Deprecated(since = "6.0") @Deprecated(since = "6.0")
public Iterator<Column> getColumnIterator() { public Iterator<Column> getColumnIterator() {
return columns.values().iterator(); return getColumns().iterator();
} }
public Collection<Column> getColumns() { public Collection<Column> getColumns() {
return columns.values(); return columns.values();
} }
@Deprecated(since = "6.2")
public Iterator<Index> getIndexIterator() { public Iterator<Index> getIndexIterator() {
return indexes.values().iterator(); return getIndexes().values().iterator();
}
public Map<String, Index> getIndexes() {
return unmodifiableMap( indexes );
} }
@Deprecated(since = "6.0") @Deprecated(since = "6.0")
public Iterator<ForeignKey> getForeignKeyIterator() { public Iterator<ForeignKey> getForeignKeyIterator() {
return foreignKeys.values().iterator(); return getForeignKeys().values().iterator();
} }
public Map<ForeignKeyKey, ForeignKey> getForeignKeys() { public Map<ForeignKeyKey, ForeignKey> getForeignKeys() {
return Collections.unmodifiableMap( foreignKeys ); return unmodifiableMap( foreignKeys );
} }
@Deprecated(since = "6.0") @Deprecated(since = "6.0")
@ -310,7 +313,7 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
public Map<String, UniqueKey> getUniqueKeys() { public Map<String, UniqueKey> getUniqueKeys() {
cleanseUniqueKeyMapIfNeeded(); cleanseUniqueKeyMapIfNeeded();
return uniqueKeys; return unmodifiableMap( uniqueKeys );
} }
private int sizeOfUniqueKeyMapOnLastCleanse; private int sizeOfUniqueKeyMapOnLastCleanse;
@ -381,7 +384,7 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
} }
private boolean isSameAsPrimaryKeyColumns(UniqueKey uniqueKey) { private boolean isSameAsPrimaryKeyColumns(UniqueKey uniqueKey) {
if ( primaryKey == null || ! primaryKey.getColumnIterator().hasNext() ) { if ( primaryKey == null || primaryKey.getColumns().isEmpty() ) {
// happens for many-to-many tables // happens for many-to-many tables
return false; return false;
} }
@ -393,9 +396,9 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((catalog == null) ? 0 : catalog.hashCode()); result = prime * result + (catalog == null ? 0 : catalog.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + (name == null ? 0 : name.hashCode());
result = prime * result + ((schema == null) ? 0 : schema.hashCode()); result = prime * result + (schema == null ? 0 : schema.hashCode());
return result; return result;
} }
@ -820,11 +823,11 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
@Deprecated(since = "6.0") @Deprecated(since = "6.0")
public Iterator<String> getCheckConstraintsIterator() { public Iterator<String> getCheckConstraintsIterator() {
return checkConstraints.iterator(); return getCheckConstraints().iterator();
} }
public List<String> getCheckConstraints() { public List<String> getCheckConstraints() {
return checkConstraints; return unmodifiableList( checkConstraints );
} }
@Override @Override
@ -900,7 +903,7 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
for ( Function<SqlStringGenerationContext, InitCommand> producer : initCommandProducers ) { for ( Function<SqlStringGenerationContext, InitCommand> producer : initCommandProducers ) {
initCommands.add( producer.apply( context ) ); initCommands.add( producer.apply( context ) );
} }
return Collections.unmodifiableList( initCommands ); return unmodifiableList( initCommands );
} }
} }
} }

View File

@ -8,9 +8,7 @@ package org.hibernate.mapping;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.hibernate.MappingException;
import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.engine.spi.Mapping;
/** /**
* A subclass in a table-per-concrete-class mapping * A subclass in a table-per-concrete-class mapping
@ -18,10 +16,9 @@ import org.hibernate.engine.spi.Mapping;
*/ */
public class UnionSubclass extends Subclass implements TableOwner { public class UnionSubclass extends Subclass implements TableOwner {
private Table table; private Table table;
private KeyValue key;
public UnionSubclass(PersistentClass superclass, MetadataBuildingContext metadataBuildingContext) { public UnionSubclass(PersistentClass superclass, MetadataBuildingContext buildingContext) {
super( superclass, metadataBuildingContext ); super( superclass, buildingContext );
} }
public Table getTable() { public Table getTable() {
@ -37,7 +34,7 @@ public class UnionSubclass extends Subclass implements TableOwner {
return synchronizedTables; return synchronizedTables;
} }
@Deprecated @Deprecated @SuppressWarnings("deprecation")
protected Iterator<Property> getNonDuplicatedPropertyIterator() { protected Iterator<Property> getNonDuplicatedPropertyIterator() {
return getPropertyClosureIterator(); return getPropertyClosureIterator();
} }
@ -47,18 +44,6 @@ public class UnionSubclass extends Subclass implements TableOwner {
return getPropertyClosure(); return getPropertyClosure();
} }
public void validate(Mapping mapping) throws MappingException {
super.validate(mapping);
if ( key!=null && !key.isValid(mapping) ) {
throw new MappingException(
"subclass key mapping has wrong number of columns: " +
getEntityName() +
" type: " +
key.getType().getName()
);
}
}
public Table getIdentityTable() { public Table getIdentityTable() {
return getTable(); return getTable();
} }

View File

@ -19,7 +19,7 @@ import org.hibernate.internal.util.StringHelper;
* @author Brett Meyer * @author Brett Meyer
*/ */
public class UniqueKey extends Constraint { public class UniqueKey extends Constraint {
private Map<Column, String> columnOrderMap = new HashMap<>(); private final Map<Column, String> columnOrderMap = new HashMap<>();
@Override @Override
public String sqlConstraintString( public String sqlConstraintString(

View File

@ -51,20 +51,12 @@ public class EntityRepresentationStrategyMap implements EntityRepresentationStra
this.proxyFactory = createProxyFactory( bootType ); this.proxyFactory = createProxyFactory( bootType );
this.instantiator = new EntityInstantiatorDynamicMap( bootType ); this.instantiator = new EntityInstantiatorDynamicMap( bootType );
//noinspection unchecked for ( Property property : bootType.getPropertyClosure() ) {
final Iterator<Property> itr = bootType.getPropertyClosureIterator();
int i = 0;
while ( itr.hasNext() ) {
//TODO: redesign how PropertyAccessors are acquired... //TODO: redesign how PropertyAccessors are acquired...
final Property property = itr.next(); final PropertyAccess propertyAccess = PropertyAccessStrategyMapImpl.INSTANCE
final PropertyAccess propertyAccess = PropertyAccessStrategyMapImpl.INSTANCE.buildPropertyAccess( .buildPropertyAccess( null, property.getName(), true );
null,
property.getName(),
true );
propertyAccessMap.put( property.getName(), propertyAccess ); propertyAccessMap.put(property.getName(), propertyAccess);
i++;
} }
createProxyFactory( bootType ); createProxyFactory( bootType );

View File

@ -308,22 +308,20 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent
boolean foundCustomAccessor = false; boolean foundCustomAccessor = false;
final Iterator<Property> itr = bootType.getPropertyClosureIterator(); for ( Property property : bootType.getPropertyClosure() ) {
while ( itr.hasNext() ) {
//TODO: redesign how PropertyAccessors are acquired... //TODO: redesign how PropertyAccessors are acquired...
final Property property = itr.next(); final PropertyAccess propertyAccess = makePropertyAccess(property);
final PropertyAccess propertyAccess = makePropertyAccess( property );
propertyAccessMap.put( property.getName(), propertyAccess ); propertyAccessMap.put(property.getName(), propertyAccess);
if ( ! (propertyAccess instanceof PropertyAccessBasicImpl) ) { if (!(propertyAccess instanceof PropertyAccessBasicImpl)) {
foundCustomAccessor = true; foundCustomAccessor = true;
} }
getterNames.add( propertyAccess.getGetter().getMethodName() ); getterNames.add(propertyAccess.getGetter().getMethodName());
getterTypes.add( propertyAccess.getGetter().getReturnTypeClass() ); getterTypes.add(propertyAccess.getGetter().getReturnTypeClass());
setterNames.add( propertyAccess.getSetter().getMethodName() ); setterNames.add(propertyAccess.getSetter().getMethodName());
} }
if ( foundCustomAccessor || ! Environment.useReflectionOptimizer() ) { if ( foundCustomAccessor || ! Environment.useReflectionOptimizer() ) {

View File

@ -237,14 +237,11 @@ public class ToOneAttributeMapping
} }
// Simple one-to-one mapped by cases // Simple one-to-one mapped by cases
if ( bidirectionalAttributeName == null ) { if ( bidirectionalAttributeName == null ) {
//noinspection deprecation for ( Property property : entityBinding.getPropertyClosure() ) {
final Iterator<Property> propertyClosureIterator = entityBinding.getPropertyClosureIterator(); if (property.getValue() instanceof OneToOne
while ( propertyClosureIterator.hasNext() ) { && name.equals(((OneToOne) property.getValue()).getMappedByProperty())
final Property property = propertyClosureIterator.next(); && ((OneToOne) property.getValue()).getReferencedEntityName().equals(
if ( property.getValue() instanceof OneToOne declaringType.getJavaType().getJavaType().getTypeName())) {
&& name.equals( ( (OneToOne) property.getValue() ).getMappedByProperty() )
&& ( (OneToOne) property.getValue() ).getReferencedEntityName().equals(
declaringType.getJavaType().getJavaType().getTypeName() ) ) {
bidirectionalAttributeName = property.getName(); bidirectionalAttributeName = property.getName();
break; break;
} }
@ -252,15 +249,12 @@ public class ToOneAttributeMapping
} }
} }
else { else {
//noinspection deprecation for ( Property property : entityBinding.getPropertyClosure() ) {
final Iterator<Property> propertyClosureIterator = entityBinding.getPropertyClosureIterator();
while ( propertyClosureIterator.hasNext() ) {
final Property property = propertyClosureIterator.next();
final Value value = property.getValue(); final Value value = property.getValue();
if ( value instanceof Collection if (value instanceof Collection
&& name.equals( ( (Collection) value ).getMappedByProperty() ) && name.equals(((Collection) value).getMappedByProperty())
&& ( (Collection) value ).getElement().getType().getName() && ((Collection) value).getElement().getType().getName()
.equals( declaringType.getJavaType().getJavaType().getTypeName() ) ) { .equals(declaringType.getJavaType().getJavaType().getTypeName())) {
bidirectionalAttributeName = property.getName(); bidirectionalAttributeName = property.getName();
break; break;
} }

View File

@ -86,7 +86,6 @@ import org.hibernate.engine.spi.EntityEntryFactory;
import org.hibernate.engine.spi.EntityKey; import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.engine.spi.LoadQueryInfluencers; import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.Managed;
import org.hibernate.engine.spi.NaturalIdResolutions; import org.hibernate.engine.spi.NaturalIdResolutions;
import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.PersistentAttributeInterceptable; import org.hibernate.engine.spi.PersistentAttributeInterceptable;

View File

@ -47,10 +47,12 @@ import org.hibernate.type.ComponentType;
import org.hibernate.type.EntityType; import org.hibernate.type.EntityType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import static org.hibernate.internal.util.collections.ArrayHelper.EMPTY_STRING_ARRAY;
/** /**
* Responsible for processing the {@link ResultSetMapping} * Responsible for processing the {@link ResultSetMapping} defined by a
* defined by a {@link org.hibernate.query.sql.spi.NativeSelectQueryDefinition} and * {@link org.hibernate.query.sql.spi.NativeSelectQueryDefinition} and
* pre-process it for consumption in {@link SQLQueryParser}. * preprocessing it for consumption by {@link SQLQueryParser}.
* *
* @author Gavin King * @author Gavin King
* @author Max Andersen * @author Max Andersen
@ -102,11 +104,6 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext {
} }
} }
private boolean hasPropertyResultMap(String alias) {
Map<String, String[]> propertyMaps = internalGetPropertyResultsMap( alias );
return propertyMaps != null && ! propertyMaps.isEmpty();
}
public SQLQueryParser.ParserContext process() { public SQLQueryParser.ParserContext process() {
// first, break down the returns into maps keyed by alias // first, break down the returns into maps keyed by alias
// so that role returns can be more easily resolved to their owners // so that role returns can be more easily resolved to their owners
@ -617,9 +614,9 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext {
} }
public String[] collectQuerySpaces() { public String[] collectQuerySpaces() {
final HashSet<String> spaces = new HashSet<String>(); final HashSet<String> spaces = new HashSet<>();
collectQuerySpaces( spaces ); collectQuerySpaces( spaces );
return spaces.toArray( new String[ spaces.size() ] ); return spaces.toArray( EMPTY_STRING_ARRAY );
} }
public void collectQuerySpaces(Collection<String> spaces) { public void collectQuerySpaces(Collection<String> spaces) {

View File

@ -84,9 +84,8 @@ public class NonRootTablePolymorphicTests {
assertThat( rootRootTable, sameInstance( rootTable ) ); assertThat( rootRootTable, sameInstance( rootTable ) );
assertThat( rootRootTable.getName(), is( "root" ) ); assertThat( rootRootTable.getName(), is( "root" ) );
final Iterator<Subclass> subclassIterator = root.getSubclassIterator(); for ( Subclass value : root.getSubclasses() ) {
while ( subclassIterator.hasNext() ) { final JoinedSubclass subclass = (JoinedSubclass) value;
final JoinedSubclass subclass = (JoinedSubclass) subclassIterator.next();
final org.hibernate.mapping.Table subclassTable = subclass.getTable(); final org.hibernate.mapping.Table subclassTable = subclass.getTable();
if ( subclass.getJpaEntityName().equals( "Sub" ) ) { if ( subclass.getJpaEntityName().equals( "Sub" ) ) {

View File

@ -59,24 +59,22 @@ public class AttributeOrderingTests {
} }
public void verifyBootModel(DomainModelScope modelScope) { public void verifyBootModel(DomainModelScope modelScope) {
final Consumer<Iterator<Property>> alphabeticOrderChecker = (properties) -> { final Consumer<Iterator<Property>> alphabeticOrderChecker = properties -> {
String last = null; String last = null;
while ( properties.hasNext() ) { while ( properties.hasNext() ) {
final String current = properties.next().getName(); final String current = properties.next().getName();
if ( last != null ) { assert last == null || last.compareTo( current ) < 0 : "not alphabetical : " + last + " -> " + current;
assert last.compareTo( current ) < 0 : "not alphabetical : " + last + " -> " + current;
}
last = current; last = current;
} }
}; };
modelScope.getDomainModel().getEntityBindings().forEach( modelScope.getDomainModel().getEntityBindings().forEach(
(binding) -> alphabeticOrderChecker.accept( binding.getPropertyClosureIterator() ) binding -> alphabeticOrderChecker.accept( binding.getPropertyClosure().iterator() )
); );
modelScope.getDomainModel().visitRegisteredComponents( modelScope.getDomainModel().visitRegisteredComponents(
(binding) -> alphabeticOrderChecker.accept( binding.getPropertyIterator() ) binding -> alphabeticOrderChecker.accept( binding.getProperties().iterator() )
); );
} }

View File

@ -15,7 +15,6 @@ import java.time.OffsetDateTime;
import java.time.OffsetTime; import java.time.OffsetTime;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.Iterator;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
@ -46,9 +45,7 @@ public class Java8DateTimeTests extends BaseNonConfigCoreFunctionalTestCase {
@Test @Test
public void basicTests() { public void basicTests() {
final PersistentClass entityBinding = metadata().getEntityBinding( TheEntity.class.getName() ); final PersistentClass entityBinding = metadata().getEntityBinding( TheEntity.class.getName() );
final Iterator propertyBindingIterator = entityBinding.getPropertyClosureIterator(); for ( Property propertyBinding : entityBinding.getPropertyClosure() ) {
while ( propertyBindingIterator.hasNext() ) {
final Property propertyBinding = (Property) propertyBindingIterator.next();
assertFalse( assertFalse(
"Found property bound as Serializable : " + propertyBinding.getName(), "Found property bound as Serializable : " + propertyBinding.getName(),
propertyBinding.getType() instanceof SerializableType propertyBinding.getType() instanceof SerializableType
@ -65,7 +62,7 @@ public class Java8DateTimeTests extends BaseNonConfigCoreFunctionalTestCase {
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
theEntity = (TheEntity) s.get( TheEntity.class, 1 ); theEntity = s.get( TheEntity.class, 1 );
dump( entityBinding, theEntity ); dump( entityBinding, theEntity );
assertNotNull( theEntity ); assertNotNull( theEntity );
s.delete( theEntity ); s.delete( theEntity );
@ -74,17 +71,14 @@ public class Java8DateTimeTests extends BaseNonConfigCoreFunctionalTestCase {
} }
private void dump(PersistentClass entityBinding, TheEntity theEntity) { private void dump(PersistentClass entityBinding, TheEntity theEntity) {
final Iterator propertyBindingIterator = entityBinding.getPropertyClosureIterator(); for ( Property propertyBinding : entityBinding.getPropertyClosure() ) {
while ( propertyBindingIterator.hasNext() ) {
final Property propertyBinding = (Property) propertyBindingIterator.next();
final JavaType javaType = ( (AbstractStandardBasicType) propertyBinding.getType() ).getJavaTypeDescriptor(); final JavaType javaType = ( (AbstractStandardBasicType) propertyBinding.getType() ).getJavaTypeDescriptor();
System.out.println( System.out.println(
String.format( String.format(
"%s (%s) -> %s", "%s (%s) -> %s",
propertyBinding.getName(), propertyBinding.getName(),
javaType.getJavaTypeClass().getSimpleName(), javaType.getJavaTypeClass().getSimpleName(),
javaType.toString( propertyBinding.getGetter( TheEntity.class ).get( theEntity ) ) javaType.toString(propertyBinding.getGetter(TheEntity.class).get(theEntity))
) )
); );
} }

View File

@ -7,7 +7,6 @@
package org.hibernate.envers.configuration.internal; package org.hibernate.envers.configuration.internal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.MetadataImplementor;
@ -38,11 +37,10 @@ public class PersistentClassGraphDefiner implements GraphDefiner<PersistentClass
return metadata.getEntityBinding( entityName ); return metadata.getEntityBinding( entityName );
} }
private void addNeighbours(List<PersistentClass> neighbours, Iterator<? extends PersistentClass> subclassIterator) { private void addNeighbours(List<PersistentClass> neighbours, List<? extends PersistentClass> subclasses) {
while ( subclassIterator.hasNext() ) { for ( PersistentClass subclass : subclasses ) {
final PersistentClass subclass = subclassIterator.next();
neighbours.add( subclass ); neighbours.add( subclass );
addNeighbours( neighbours, subclass.getSubclassIterator() ); addNeighbours( neighbours, subclass.getSubclasses() );
} }
} }
@ -50,7 +48,7 @@ public class PersistentClassGraphDefiner implements GraphDefiner<PersistentClass
public List<PersistentClass> getNeighbours(PersistentClass pc) { public List<PersistentClass> getNeighbours(PersistentClass pc) {
final List<PersistentClass> neighbours = new ArrayList<>(); final List<PersistentClass> neighbours = new ArrayList<>();
addNeighbours( neighbours, pc.getSubclassIterator() ); addNeighbours( neighbours, pc.getSubclasses() );
return neighbours; return neighbours;
} }

View File

@ -7,7 +7,9 @@
package org.hibernate.envers.configuration.internal.metadata; package org.hibernate.envers.configuration.internal.metadata;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Objects;
import org.hibernate.envers.boot.EnversMappingException; import org.hibernate.envers.boot.EnversMappingException;
import org.hibernate.envers.configuration.internal.metadata.reader.PropertyAuditingData; import org.hibernate.envers.configuration.internal.metadata.reader.PropertyAuditingData;
@ -107,9 +109,9 @@ public class CollectionMappedByResolver {
while ( assocClassProps.hasNext() ) { while ( assocClassProps.hasNext() ) {
final Property property = assocClassProps.next(); final Property property = assocClassProps.next();
final Iterator<Selectable> assocClassColumnIterator = property.getValue().getColumnIterator(); final List<Selectable> assocClassSelectables = property.getValue().getSelectables();
final Iterator<Selectable> collectionKeyColumnIterator = collectionValue.getKey().getColumnIterator(); final List<Selectable> collectionKeySelectables = collectionValue.getKey().getSelectables();
if ( Tools.iteratorsContentEqual( assocClassColumnIterator, collectionKeyColumnIterator ) ) { if ( Objects.equals( assocClassSelectables, collectionKeySelectables ) ) {
return property.getName(); return property.getName();
} }
} }
@ -119,12 +121,11 @@ public class CollectionMappedByResolver {
} }
private static String searchMappedBy(PersistentClass referencedClass, Table collectionTable) { private static String searchMappedBy(PersistentClass referencedClass, Table collectionTable) {
return searchMappedBy( referencedClass.getPropertyIterator(), collectionTable ); return searchMappedBy( referencedClass.getProperties(), collectionTable );
} }
private static String searchMappedBy(Iterator<Property> properties, Table collectionTable) { private static String searchMappedBy(List<Property> properties, Table collectionTable) {
while ( properties.hasNext() ) { for ( Property property : properties ) {
final Property property = properties.next();
if ( property.getValue() instanceof Collection ) { if ( property.getValue() instanceof Collection ) {
// The equality is intentional. We want to find a collection property with the same collection table. // The equality is intentional. We want to find a collection property with the same collection table.
//noinspection ObjectEquality //noinspection ObjectEquality
@ -138,7 +139,7 @@ public class CollectionMappedByResolver {
// happens to be an attribute inside the embeddable rather than directly on the entity. // happens to be an attribute inside the embeddable rather than directly on the entity.
final Component component = (Component) property.getValue(); final Component component = (Component) property.getValue();
final String mappedBy = searchMappedBy( component.getPropertyIterator(), collectionTable ); final String mappedBy = searchMappedBy( component.getProperties(), collectionTable );
if ( mappedBy != null ) { if ( mappedBy != null ) {
return property.getName() + "_" + mappedBy; return property.getName() + "_" + mappedBy;
} }
@ -152,12 +153,10 @@ public class CollectionMappedByResolver {
// 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 ( keyValue instanceof Component ) { if ( keyValue instanceof Component ) {
final Component component = (Component) keyValue; final Component component = (Component) keyValue;
final Iterator<Property> componentPropertyIterator = component.getPropertyIterator(); for ( Property property : component.getProperties() ) {
while ( componentPropertyIterator.hasNext() ) { final List<Selectable> propertySelectables = property.getValue().getSelectables();
final Property property = componentPropertyIterator.next(); final List<Selectable> collectionSelectables = collectionValue.getKey().getSelectables();
final Iterator<Selectable> propertySelectables = property.getValue().getColumnIterator(); if ( Objects.equals( propertySelectables, collectionSelectables ) ) {
final Iterator<Selectable> collectionSelectables = collectionValue.getKey().getColumnIterator();
if ( Tools.iteratorsContentEqual( propertySelectables, collectionSelectables ) ) {
return property.getName(); return property.getName();
} }
} }

View File

@ -6,7 +6,6 @@
*/ */
package org.hibernate.envers.configuration.internal.metadata; package org.hibernate.envers.configuration.internal.metadata;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import org.hibernate.envers.boot.model.AttributeContainer; import org.hibernate.envers.boot.model.AttributeContainer;
@ -50,13 +49,6 @@ public final class ComponentMetadataGenerator extends AbstractMetadataGenerator
EntityMappingData mappingData, EntityMappingData mappingData,
boolean firstPass) { boolean firstPass) {
final Component propComponent = (Component) value; final Component propComponent = (Component) value;
final Class<? extends EmbeddableInstantiator> instantiatorClass;
if ( propComponent.getCustomInstantiator() != null ) {
instantiatorClass = propComponent.getCustomInstantiator();
}
else {
instantiatorClass = null;
}
final EmbeddableInstantiator instantiator; final EmbeddableInstantiator instantiator;
if ( propComponent.getCustomInstantiator() != null ) { if ( propComponent.getCustomInstantiator() != null ) {
instantiator = getMetadataBuildingContext().getBootstrapContext() instantiator = getMetadataBuildingContext().getBootstrapContext()
@ -94,10 +86,7 @@ public final class ComponentMetadataGenerator extends AbstractMetadataGenerator
// Adding all properties of the component // Adding all properties of the component
propComponent.sortProperties(); propComponent.sortProperties();
final Iterator<Property> properties = propComponent.getPropertyIterator(); for ( Property property : propComponent.getProperties() ) {
while ( properties.hasNext() ) {
final Property property = properties.next();
final PropertyAuditingData componentPropertyAuditingData = final PropertyAuditingData componentPropertyAuditingData =
componentAuditingData.getPropertyAuditingData( property.getName() ); componentAuditingData.getPropertyAuditingData( property.getName() );

View File

@ -6,7 +6,6 @@
*/ */
package org.hibernate.envers.configuration.internal.metadata; package org.hibernate.envers.configuration.internal.metadata;
import java.util.Iterator;
import java.util.Locale; import java.util.Locale;
import org.hibernate.envers.boot.EnversMappingException; import org.hibernate.envers.boot.EnversMappingException;
@ -120,18 +119,10 @@ public final class IdMetadataGenerator extends AbstractMetadataGenerator {
SimpleIdMapperBuilder mapper, SimpleIdMapperBuilder mapper,
boolean key, boolean key,
boolean audited) { boolean audited) {
final Iterator<Property> properties = component.getPropertyIterator(); for ( Property property : component.getProperties() ) {
while ( properties.hasNext() ) { final Property virtualProperty = virtualComponent != null
final Property property = properties.next(); ? virtualComponent.getProperty( property.getName() )
: null;
final Property virtualProperty;
if ( virtualComponent != null ) {
virtualProperty = virtualComponent.getProperty( property.getName() );
}
else {
virtualProperty = null;
}
if ( !addIdProperty( attributeContainer, key, mapper, property, virtualProperty, audited ) ) { if ( !addIdProperty( attributeContainer, key, mapper, property, virtualProperty, audited ) ) {
// If the entity is audited, and a non-supported id component is used, throw exception. // If the entity is audited, and a non-supported id component is used, throw exception.
if ( audited ) { if ( audited ) {
@ -162,12 +153,11 @@ public final class IdMetadataGenerator extends AbstractMetadataGenerator {
} }
private void generateSecondPass(String entityName, Component component) { private void generateSecondPass(String entityName, Component component) {
Iterator<Property> properties = component.getPropertyIterator(); for ( Property property : component.getProperties() ) {
while ( properties.hasNext() ) { final Value value = property.getValue();
final Property property = properties.next(); if ( value instanceof ToOne ) {
if ( property.getValue() instanceof ToOne ) {
final PropertyAuditingData propertyData = getIdPersistentPropertyAuditingData( property ); final PropertyAuditingData propertyData = getIdPersistentPropertyAuditingData( property );
final String referencedEntityName = ( (ToOne) property.getValue() ).getReferencedEntityName(); final String referencedEntityName = ( (ToOne) value).getReferencedEntityName();
final String prefix = getMetadataBuildingContext().getConfiguration() final String prefix = getMetadataBuildingContext().getConfiguration()
.getOriginalIdPropertyName() + "." + propertyData.getName(); .getOriginalIdPropertyName() + "." + propertyData.getName();

View File

@ -35,8 +35,7 @@ public enum InheritanceType {
} }
// We assume that every subclass is of the same type. // We assume that every subclass is of the same type.
final Subclass subclass = (Subclass) superclass.getSubclassIterator().next(); final Subclass subclass = superclass.getSubclasses().get(0);
if ( subclass instanceof SingleTableSubclass ) { if ( subclass instanceof SingleTableSubclass ) {
return InheritanceType.SINGLE; return InheritanceType.SINGLE;
} }

View File

@ -9,7 +9,6 @@ package org.hibernate.envers.configuration.internal.metadata.reader;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -306,12 +305,9 @@ public class AuditedPropertiesReader {
} }
} }
@SuppressWarnings("unchecked")
private void createPropertiesGroupMapping(Property property) { private void createPropertiesGroupMapping(Property property) {
final Component component = (Component) property.getValue(); final Component component = (Component) property.getValue();
final Iterator<Property> componentProperties = component.getPropertyIterator(); for ( Property componentProperty : component.getProperties() ) {
while ( componentProperties.hasNext() ) {
final Property componentProperty = componentProperties.next();
propertiesGroupMapping.put( componentProperty.getName(), property.getName() ); propertiesGroupMapping.put( componentProperty.getName(), property.getName() );
} }
} }

View File

@ -45,7 +45,7 @@ public interface PersistentPropertiesSource {
return new PersistentPropertiesSource() { return new PersistentPropertiesSource() {
@Override @Override
public Iterator<Property> getPropertyIterator() { public Iterator<Property> getPropertyIterator() {
return persistentClass.getPropertyIterator(); return persistentClass.getProperties().iterator();
} }
@Override @Override
@ -105,7 +105,7 @@ public interface PersistentPropertiesSource {
return new PersistentPropertiesSource() { return new PersistentPropertiesSource() {
@Override @Override
public Iterator<Property> getPropertyIterator() { public Iterator<Property> getPropertyIterator() {
return component.getPropertyIterator(); return component.getProperties().iterator();
} }
@Override @Override

View File

@ -51,27 +51,10 @@ public abstract class Tools {
return (List<X>) collection; return (List<X>) collection;
} }
else { else {
List<X> list = new ArrayList<>(); return new ArrayList<>( collection );
list.addAll( collection );
return list;
} }
} }
public static boolean iteratorsContentEqual(Iterator iter1, Iterator iter2) {
while ( iter1.hasNext() && iter2.hasNext() ) {
if ( !iter1.next().equals( iter2.next() ) ) {
return false;
}
}
//noinspection RedundantIfStatement
if ( iter1.hasNext() || iter2.hasNext() ) {
return false;
}
return true;
}
/** /**
* Transforms a list of arbitrary elements to a list of index-element pairs. * Transforms a list of arbitrary elements to a list of index-element pairs.
* *

View File

@ -9,7 +9,6 @@ package org.hibernate.testing.junit4;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@ -342,9 +341,7 @@ public class BaseNonConfigCoreFunctionalTestCase extends BaseUnitTestCase {
boolean hasLob = false; boolean hasLob = false;
final Iterator props = entityBinding.getPropertyClosureIterator(); for ( Property prop : entityBinding.getPropertyClosure() ) {
while ( props.hasNext() ) {
final Property prop = (Property) props.next();
if ( prop.getValue().isSimpleValue() ) { if ( prop.getValue().isSimpleValue() ) {
if ( isLob( (SimpleValue) prop.getValue() ) ) { if ( isLob( (SimpleValue) prop.getValue() ) ) {
hasLob = true; hasLob = true;

View File

@ -8,7 +8,6 @@ package org.hibernate.testing.orm.junit;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Iterator;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -137,9 +136,7 @@ public abstract class BaseSessionFactoryFunctionalTest
boolean hasLob = false; boolean hasLob = false;
final Iterator props = entityBinding.getPropertyClosureIterator(); for ( Property prop : entityBinding.getPropertyClosure() ) {
while ( props.hasNext() ) {
final Property prop = (Property) props.next();
if ( prop.getValue().isSimpleValue() ) { if ( prop.getValue().isSimpleValue() ) {
if ( isLob( (SimpleValue) prop.getValue() ) ) { if ( isLob( (SimpleValue) prop.getValue() ) ) {
hasLob = true; hasLob = true;

View File

@ -7,7 +7,6 @@
package org.hibernate.testing.orm.junit; package org.hibernate.testing.orm.junit;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.Locale; import java.util.Locale;
import java.util.Optional; import java.util.Optional;
@ -255,15 +254,9 @@ public class DomainModelExtension
} }
for ( PersistentClass entityBinding : metadata.getEntityBindings() ) { for ( PersistentClass entityBinding : metadata.getEntityBindings() ) {
if ( entityBinding.isInherited() ) { if ( !entityBinding.isInherited() ) {
continue;
}
boolean hasLob = false; boolean hasLob = false;
for ( Property prop : entityBinding.getPropertyClosure() ) {
final Iterator<Property> props = entityBinding.getPropertyClosureIterator();
while ( props.hasNext() ) {
final Property prop = props.next();
if ( prop.getValue().isSimpleValue() ) { if ( prop.getValue().isSimpleValue() ) {
if ( isLob( (SimpleValue) prop.getValue() ) ) { if ( isLob( (SimpleValue) prop.getValue() ) ) {
hasLob = true; hasLob = true;
@ -277,10 +270,10 @@ public class DomainModelExtension
entityBinding.setCached( true ); entityBinding.setCached( true );
} }
} }
}
for ( Collection collectionBinding : metadata.getCollectionBindings() ) { for ( Collection collectionBinding : metadata.getCollectionBindings() ) {
boolean isLob = false; boolean isLob = false;
if ( collectionBinding.getElement().isSimpleValue() ) { if ( collectionBinding.getElement().isSimpleValue() ) {
isLob = isLob( (SimpleValue) collectionBinding.getElement() ); isLob = isLob( (SimpleValue) collectionBinding.getElement() );
} }
@ -361,7 +354,4 @@ public class DomainModelExtension
} }
} }
protected void afterMetadataBuilt(Metadata metadata) {
}
} }

View File

@ -7,16 +7,15 @@
package org.hibernate.orm.tooling.gradle.metamodel.model; package org.hibernate.orm.tooling.gradle.metamodel.model;
import java.io.File; import java.io.File;
import java.util.Collections; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.List;
import java.util.Set; import java.util.Set;
import org.gradle.api.file.Directory; import org.gradle.api.file.Directory;
import org.gradle.api.file.RegularFile; import org.gradle.api.file.RegularFile;
import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.jpa.boot.spi.Bootstrap;
import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder; import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
import org.hibernate.mapping.Component; import org.hibernate.mapping.Component;
import org.hibernate.mapping.MappedSuperclass; import org.hibernate.mapping.MappedSuperclass;
@ -25,12 +24,13 @@ import org.hibernate.mapping.Property;
import jakarta.persistence.spi.PersistenceUnitInfo; import jakarta.persistence.spi.PersistenceUnitInfo;
import static java.util.Collections.emptyMap;
import static org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder;
public class JpaStaticMetamodelGenerator { public class JpaStaticMetamodelGenerator {
public static void processMetamodel( public static void processMetamodel(PersistenceUnitInfo persistenceUnitInfo, GenerationOptions options) {
PersistenceUnitInfo persistenceUnitInfo, final EntityManagerFactoryBuilder target = getEntityManagerFactoryBuilder( persistenceUnitInfo, emptyMap() );
GenerationOptions options) {
EntityManagerFactoryBuilder target = Bootstrap.getEntityManagerFactoryBuilder( persistenceUnitInfo, Collections.emptyMap() );
try { try {
new JpaStaticMetamodelGenerator( options, target.metadata() ).process(); new JpaStaticMetamodelGenerator( options, target.metadata() ).process();
} }
@ -60,7 +60,7 @@ public class JpaStaticMetamodelGenerator {
mappedSuperclasses.forEach( this::handleMappedClass ); mappedSuperclasses.forEach( this::handleMappedClass );
} }
final java.util.Collection<PersistentClass> entityBindings = metadata.getEntityBindings(); final Collection<PersistentClass> entityBindings = metadata.getEntityBindings();
if ( entityBindings != null ) { if ( entityBindings != null ) {
entityBindings.forEach( this::handlePersistentClass ); entityBindings.forEach( this::handlePersistentClass );
} }
@ -68,25 +68,22 @@ public class JpaStaticMetamodelGenerator {
private void handleMappedClass(MappedSuperclass mappingDescriptor) { private void handleMappedClass(MappedSuperclass mappingDescriptor) {
final MetamodelClass metamodelClass = objectFactory.metamodelClass( mappingDescriptor ); final MetamodelClass metamodelClass = objectFactory.metamodelClass( mappingDescriptor );
handleManagedClass( metamodelClass, mappingDescriptor.getDeclaredPropertyIterator() ); handleManagedClass( metamodelClass, mappingDescriptor.getDeclaredProperties() );
} }
private void handlePersistentClass(PersistentClass persistentClass) { private void handlePersistentClass(PersistentClass persistentClass) {
final MetamodelClass metamodelClass = objectFactory.metamodelClass( persistentClass ); final MetamodelClass metamodelClass = objectFactory.metamodelClass( persistentClass );
handleManagedClass( metamodelClass, persistentClass.getDeclaredPropertyIterator() ); handleManagedClass( metamodelClass, persistentClass.getDeclaredProperties() );
} }
private void handleManagedClass(MetamodelClass metamodelClass, Iterator<Property> propertyIterator) { private void handleManagedClass(MetamodelClass metamodelClass, List<Property> properties) {
if ( ! processedDomainTypeNames.add( metamodelClass.getDomainClassName() ) ) { if ( processedDomainTypeNames.add( metamodelClass.getDomainClassName() ) ) {
// already processed // not yet processed
return; for ( Property property : properties ) {
} metamodelClass.addAttribute(
propertyIterator.forEachRemaining(
property -> metamodelClass.addAttribute(
objectFactory.attribute( property, property.getValue(), metamodelClass, this::handleEmbeddable ) objectFactory.attribute( property, property.getValue(), metamodelClass, this::handleEmbeddable )
)
); );
}
final String replaced = metamodelClass.getMetamodelClassName().replace( '.', '/' ); final String replaced = metamodelClass.getMetamodelClassName().replace( '.', '/' );
final String metamodelClassJavaFileName = replaced + ".java"; final String metamodelClassJavaFileName = replaced + ".java";
@ -95,9 +92,10 @@ public class JpaStaticMetamodelGenerator {
final File metamodelClassJavaFileAsFile = metamodelClassJavaFile.getAsFile(); final File metamodelClassJavaFileAsFile = metamodelClassJavaFile.getAsFile();
metamodelClass.writeToFile( metamodelClassJavaFileAsFile, options ); metamodelClass.writeToFile( metamodelClassJavaFileAsFile, options );
} }
}
private void handleEmbeddable(Component embeddedValueMapping) { private void handleEmbeddable(Component embeddedValueMapping) {
final MetamodelClass metamodelClass = objectFactory.metamodelClass( embeddedValueMapping ); final MetamodelClass metamodelClass = objectFactory.metamodelClass( embeddedValueMapping );
handleManagedClass( metamodelClass, embeddedValueMapping.getPropertyIterator() ); handleManagedClass( metamodelClass, embeddedValueMapping.getProperties() );
} }
} }