diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java index 9ee2a74be6..05593096be 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java @@ -88,7 +88,7 @@ import org.hibernate.mapping.Table; import org.hibernate.mapping.TableOwner; import org.hibernate.mapping.Value; -import org.hibernate.tuple.Tuplizer; +import org.hibernate.persister.entity.EntityPersister; import org.jboss.logging.Logger; import static org.hibernate.cfg.BinderHelper.toAliasEntityMap; @@ -305,7 +305,7 @@ public class EntityBinder { //set persister if needed Persister persisterAnn = annotatedClass.getAnnotation( Persister.class ); if ( persisterAnn != null ) { - Class persister = persisterAnn.impl(); + Class persister = (Class) persisterAnn.impl(); persistentClass.setEntityPersisterClass( persister ); } diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultFlushEntityEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultFlushEntityEventListener.java index 12f4751a39..7a6396854b 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultFlushEntityEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultFlushEntityEventListener.java @@ -6,7 +6,6 @@ */ package org.hibernate.event.internal; -import java.io.Serializable; import java.util.Arrays; import org.hibernate.AssertionFailure; diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/ArrayHelper.java b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/ArrayHelper.java index 58a447b84b..5d95852b5e 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/ArrayHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/ArrayHelper.java @@ -75,33 +75,33 @@ public final class ArrayHelper { return array; } - public static String[] toStringArray(Collection coll) { - return (String[]) coll.toArray( new String[coll.size()] ); + public static String[] toStringArray(Collection coll) { + return coll.toArray( EMPTY_STRING_ARRAY ); } - public static String[][] to2DStringArray(Collection coll) { - return (String[][]) coll.toArray( new String[coll.size()][] ); + public static String[][] to2DStringArray(Collection coll) { + return coll.toArray( new String[0][] ); } - public static int[][] to2DIntArray(Collection coll) { - return (int[][]) coll.toArray( new int[coll.size()][] ); + public static int[][] to2DIntArray(Collection coll) { + return coll.toArray( new int[0][] ); } - public static Type[] toTypeArray(Collection coll) { - return (Type[]) coll.toArray( new Type[coll.size()] ); + public static Type[] toTypeArray(Collection coll) { + return coll.toArray( EMPTY_TYPE_ARRAY ); } - public static int[] toIntArray(Collection coll) { - Iterator iter = coll.iterator(); + public static int[] toIntArray(Collection coll) { + Iterator iter = coll.iterator(); int[] arr = new int[coll.size()]; int i = 0; while ( iter.hasNext() ) { - arr[i++] = (Integer) iter.next(); + arr[i++] = iter.next(); } return arr; } - public static boolean[] toBooleanArray(Collection coll) { + public static boolean[] toBooleanArray(Collection coll) { Iterator iter = coll.iterator(); boolean[] arr = new boolean[coll.size()]; int i = 0; diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/JoinedIterator.java b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/JoinedIterator.java index 5ece18e469..dc9e6fdabf 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/JoinedIterator.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/JoinedIterator.java @@ -19,18 +19,18 @@ import java.util.List; * @author Steve Ebersole */ public class JoinedIterator implements Iterator { - private Iterator[] wrappedIterators; + private final Iterator[] wrappedIterators; private int currentIteratorIndex; - private Iterator currentIterator; - private Iterator lastUsedIterator; + private Iterator currentIterator; + private Iterator lastUsedIterator; @SuppressWarnings("unchecked") public JoinedIterator(List> wrappedIterators) { - this( wrappedIterators.toArray( new Iterator[ wrappedIterators.size() ]) ); + this( wrappedIterators.toArray(new Iterator[0]) ); } - public JoinedIterator(Iterator... iteratorsToWrap) { + public JoinedIterator(Iterator... iteratorsToWrap) { if( iteratorsToWrap == null ) { throw new NullPointerException( "Iterators to join were null" ); } @@ -58,7 +58,7 @@ public class JoinedIterator implements Iterator { protected void updateCurrentIterator() { if ( currentIterator == null ) { if( wrappedIterators.length == 0 ) { - currentIterator = Collections.emptyList().iterator(); + currentIterator = Collections.emptyIterator(); } else { currentIterator = wrappedIterators[0]; diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/DatabaseSnapshotExecutor.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/DatabaseSnapshotExecutor.java index c6a57590ab..3c6572becb 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/DatabaseSnapshotExecutor.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/DatabaseSnapshotExecutor.java @@ -29,7 +29,6 @@ import org.hibernate.sql.ast.Clause; import org.hibernate.sql.ast.SqlAstTranslatorFactory; import org.hibernate.sql.ast.spi.SqlAliasBaseManager; import org.hibernate.sql.ast.spi.SqlExpressionResolver; -import org.hibernate.sql.ast.spi.SqlSelection; import org.hibernate.sql.ast.tree.expression.ColumnReference; import org.hibernate.sql.ast.tree.expression.JdbcParameter; import org.hibernate.sql.ast.tree.expression.QueryLiteral; @@ -61,7 +60,6 @@ class DatabaseSnapshotExecutor { private static final Logger log = Logger.getLogger( DatabaseSnapshotExecutor.class ); private final EntityMappingType entityDescriptor; - private final SessionFactoryImplementor sessionFactory; private final JdbcSelect jdbcSelect; private final List jdbcParameters; @@ -70,7 +68,6 @@ class DatabaseSnapshotExecutor { EntityMappingType entityDescriptor, SessionFactoryImplementor sessionFactory) { this.entityDescriptor = entityDescriptor; - this.sessionFactory = sessionFactory; this.jdbcParameters = new ArrayList<>( entityDescriptor.getIdentifierMapping().getJdbcTypeCount() ); @@ -170,7 +167,7 @@ class DatabaseSnapshotExecutor { // TODO: Instead use a delayed collection result? Or will we remove this when redesigning this //noinspection unchecked domainResults.add( - new BasicResult( + new BasicResult( 0, null, contributorMapping.getJavaTypeDescriptor() diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Filterable.java b/hibernate-core/src/main/java/org/hibernate/mapping/Filterable.java index 187d8e5430..9d41d3b211 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Filterable.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Filterable.java @@ -7,6 +7,8 @@ package org.hibernate.mapping; +import org.hibernate.internal.FilterConfiguration; + /** * Defines mapping elements to which filters may be applied. * @@ -15,5 +17,5 @@ package org.hibernate.mapping; public interface Filterable { public void addFilter(String name, String condition, boolean autoAliasInjection, java.util.Map aliasTableMap, java.util.Map aliasEntityMap); - public java.util.List getFilters(); + public java.util.List getFilters(); } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Join.java b/hibernate-core/src/main/java/org/hibernate/mapping/Join.java index 387c5b5dcb..1335004719 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Join.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Join.java @@ -20,8 +20,8 @@ public class Join implements AttributeContainer, Serializable { private static final Alias PK_ALIAS = new Alias(15, "PK"); - private ArrayList properties = new ArrayList(); - private ArrayList declaredProperties = new ArrayList(); + private final ArrayList properties = new ArrayList<>(); + private final ArrayList declaredProperties = new ArrayList<>(); private Table table; private KeyValue key; private PersistentClass persistentClass; @@ -52,14 +52,14 @@ public class Join implements AttributeContainer, Serializable { prop.setPersistentClass( getPersistentClass() ); } - public Iterator getDeclaredPropertyIterator() { + public Iterator getDeclaredPropertyIterator() { return declaredProperties.iterator(); } public boolean containsProperty(Property prop) { return properties.contains(prop); } - public Iterator getPropertyIterator() { + public Iterator getPropertyIterator() { return properties.iterator(); } @@ -176,10 +176,9 @@ public class Join implements AttributeContainer, Serializable { } public boolean isLazy() { - Iterator iter = getPropertyIterator(); + Iterator iter = getPropertyIterator(); while ( iter.hasNext() ) { - Property prop = (Property) iter.next(); - if ( !prop.isLazy() ) { + if ( !iter.next().isLazy() ) { return false; } } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/JoinedSubclass.java b/hibernate-core/src/main/java/org/hibernate/mapping/JoinedSubclass.java index 5bac28be01..44c20a3ace 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/JoinedSubclass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/JoinedSubclass.java @@ -52,7 +52,7 @@ public class JoinedSubclass extends Subclass implements TableOwner { } } - public Iterator getReferenceablePropertyIterator() { + public Iterator getReferenceablePropertyIterator() { return getPropertyIterator(); } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java b/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java index 37befc293f..5606aa410a 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java @@ -27,6 +27,7 @@ import org.hibernate.internal.FilterConfiguration; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.JoinedIterator; import org.hibernate.internal.util.collections.SingletonIterator; +import org.hibernate.persister.entity.EntityPersister; import org.hibernate.service.ServiceRegistry; import org.hibernate.sql.Alias; @@ -47,10 +48,10 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl private String entityName; private String className; - private transient Class mappedClass; + private transient Class mappedClass; private String proxyInterfaceName; - private transient Class proxyInterface; + private transient Class proxyInterface; private String jpaEntityName; @@ -125,7 +126,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl this.proxyInterface = null; } - public Class getMappedClass() throws MappingException { + public Class getMappedClass() throws MappingException { if ( className == null ) { return null; } @@ -141,7 +142,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl } } - public Class getProxyInterface() { + public Class getProxyInterface() { if ( proxyInterfaceName == null ) { return null; } @@ -214,33 +215,33 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl * Iterate over subclasses in a special 'order', most derived subclasses * first. */ - public Iterator getSubclassIterator() { - Iterator[] iters = new Iterator[subclasses.size() + 1]; - Iterator iter = subclasses.iterator(); + public Iterator getSubclassIterator() { + Iterator[] iters = new Iterator[subclasses.size() + 1]; + Iterator iter = subclasses.iterator(); int i = 0; while ( iter.hasNext() ) { - iters[i++] = ( (Subclass) iter.next() ).getSubclassIterator(); + iters[i++] = iter.next().getSubclassIterator(); } iters[i] = subclasses.iterator(); - return new JoinedIterator( iters ); + return new JoinedIterator<>( iters ); } - public Iterator getSubclassClosureIterator() { - ArrayList iters = new ArrayList(); - iters.add( new SingletonIterator( this ) ); - Iterator iter = getSubclassIterator(); + public Iterator getSubclassClosureIterator() { + ArrayList> iters = new ArrayList<>(); + iters.add( new SingletonIterator<>( this ) ); + Iterator iter = getSubclassIterator(); while ( iter.hasNext() ) { - PersistentClass clazz = (PersistentClass) iter.next(); + PersistentClass clazz = iter.next(); iters.add( clazz.getSubclassClosureIterator() ); } - return new JoinedIterator( iters ); + return new JoinedIterator<>( iters ); } public Table getIdentityTable() { return getRootTable(); } - public Iterator getDirectSubclasses() { + public Iterator getDirectSubclasses() { return subclasses.iterator(); } @@ -314,11 +315,11 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl public abstract boolean isDiscriminatorInsertable(); - public abstract Iterator getPropertyClosureIterator(); + public abstract Iterator getPropertyClosureIterator(); - public abstract Iterator getTableClosureIterator(); + public abstract Iterator getTableClosureIterator(); - public abstract Iterator getKeyClosureIterator(); + public abstract Iterator getKeyClosureIterator(); protected void addSubclassProperty(Property prop) { subclassProperties.add( prop ); @@ -332,23 +333,23 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl subclassTables.add( subclassTable ); } - public Iterator getSubclassPropertyClosureIterator() { - ArrayList iters = new ArrayList(); + public Iterator getSubclassPropertyClosureIterator() { + ArrayList> iters = new ArrayList<>(); iters.add( getPropertyClosureIterator() ); iters.add( subclassProperties.iterator() ); for ( int i = 0; i < subclassJoins.size(); i++ ) { Join join = subclassJoins.get( i ); iters.add( join.getPropertyIterator() ); } - return new JoinedIterator( iters ); + return new JoinedIterator<>( iters ); } - public Iterator getSubclassJoinClosureIterator() { - return new JoinedIterator( getJoinClosureIterator(), subclassJoins.iterator() ); + public Iterator getSubclassJoinClosureIterator() { + return new JoinedIterator<>( getJoinClosureIterator(), subclassJoins.iterator() ); } - public Iterator getSubclassTableClosureIterator() { - return new JoinedIterator( getTableClosureIterator(), subclassTables.iterator() ); + public Iterator
getSubclassTableClosureIterator() { + return new JoinedIterator<>( getTableClosureIterator(), subclassTables.iterator() ); } public boolean isClassOrSuperclassJoin(Join join) { @@ -369,9 +370,9 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl public abstract boolean hasEmbeddedIdentifier(); - public abstract Class getEntityPersisterClass(); + public abstract Class getEntityPersisterClass(); - public abstract void setEntityPersisterClass(Class classPersisterClass); + public abstract void setEntityPersisterClass(Class classPersisterClass); public abstract Table getRootTable(); @@ -424,7 +425,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl * @see #getReferencedProperty for a discussion of "referenceable" * @return The referenceable property iterator. */ - public Iterator getReferenceablePropertyIterator() { + public Iterator getReferenceablePropertyIterator() { return getPropertyClosureIterator(); } @@ -462,7 +463,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl } } - private Property getRecursiveProperty(String propertyPath, Iterator iter) throws MappingException { + private Property getRecursiveProperty(String propertyPath, Iterator iter) throws MappingException { Property property = null; StringTokenizer st = new StringTokenizer( propertyPath, ".", false ); try { @@ -508,11 +509,11 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl return property; } - private Property getProperty(String propertyName, Iterator iterator) throws MappingException { + private Property getProperty(String propertyName, Iterator iterator) throws MappingException { if ( iterator.hasNext() ) { String root = StringHelper.root( propertyName ); while ( iterator.hasNext() ) { - Property prop = (Property) iterator.next(); + Property prop = iterator.next(); if ( prop.getName().equals( root ) || (prop instanceof Backref || prop instanceof IndexBackref) && prop.getName().equals( propertyName ) ) { @@ -524,7 +525,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl } public Property getProperty(String propertyName) throws MappingException { - Iterator iter = getPropertyClosureIterator(); + Iterator iter = getPropertyClosureIterator(); Property identifierProperty = getIdentifierProperty(); if ( identifierProperty != null && identifierProperty.getName().equals( StringHelper.root( propertyName ) ) ) { @@ -549,9 +550,9 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl return true; } - final Iterator itr = getPropertyClosureIterator(); + final Iterator itr = getPropertyClosureIterator(); while ( itr.hasNext() ) { - final Property property = (Property) itr.next(); + final Property property = itr.next(); if ( property.getName().equals( name ) ) { return true; } @@ -627,9 +628,9 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl } public void validate(Mapping mapping) throws MappingException { - Iterator iter = getPropertyIterator(); + Iterator iter = getPropertyIterator(); while ( iter.hasNext() ) { - Property prop = (Property) iter.next(); + Property prop = iter.next(); if ( !prop.isValid( mapping ) ) { throw new MappingException( "property mapping has wrong number of columns: " + @@ -645,9 +646,9 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl private void checkPropertyDuplication() throws MappingException { HashSet names = new HashSet<>(); - Iterator iter = getPropertyIterator(); + Iterator iter = getPropertyIterator(); while ( iter.hasNext() ) { - Property prop = (Property) iter.next(); + Property prop = iter.next(); if ( !names.add( prop.getName() ) ) { throw new MappingException( "Duplicate property mapping of " + prop.getName() + " found in " + getEntityName() ); } @@ -681,11 +682,11 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl return getClass().getName() + '(' + getEntityName() + ')'; } - public Iterator getJoinIterator() { + public Iterator getJoinIterator() { return joins.iterator(); } - public Iterator getJoinClosureIterator() { + public Iterator getJoinClosureIterator() { return joins.iterator(); } @@ -708,9 +709,9 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl public int getJoinNumber(Property prop) { int result = 1; - Iterator iter = getSubclassJoinClosureIterator(); + Iterator iter = getSubclassJoinClosureIterator(); while ( iter.hasNext() ) { - Join join = (Join) iter.next(); + Join join = iter.next(); if ( join.containsProperty( prop ) ) { return result; } @@ -732,14 +733,14 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl * * @return An iterator over the "normal" properties. */ - public Iterator getPropertyIterator() { - ArrayList iterators = new ArrayList(); + public Iterator getPropertyIterator() { + ArrayList> iterators = new ArrayList<>(); iterators.add( properties.iterator() ); for ( int i = 0; i < joins.size(); i++ ) { Join join = joins.get( i ); iterators.add( join.getPropertyIterator() ); } - return new JoinedIterator( iterators ); + return new JoinedIterator<>( iterators ); } /** @@ -749,7 +750,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl * * @return An iterator over the non-joined "normal" properties. */ - public Iterator getUnjoinedPropertyIterator() { + public Iterator getUnjoinedPropertyIterator() { return properties.iterator(); } @@ -825,7 +826,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl ); } - public java.util.List getFilters() { + public java.util.List getFilters() { return filters; } @@ -843,7 +844,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl this.loaderName = loaderName == null ? null : loaderName.intern(); } - public abstract java.util.Set getSynchronizedTables(); + public abstract java.util.Set getSynchronizedTables(); public void addSynchronizedTable(String table) { synchronizedTables.add( table ); @@ -857,10 +858,10 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl this.isAbstract = isAbstract; } - protected void checkColumnDuplication(Set distinctColumns, Iterator columns) + protected void checkColumnDuplication(Set distinctColumns, Iterator columns) throws MappingException { while ( columns.hasNext() ) { - Selectable columnOrFormula = (Selectable) columns.next(); + Selectable columnOrFormula = columns.next(); if ( !columnOrFormula.isFormula() ) { Column col = (Column) columnOrFormula; if ( !distinctColumns.add( col.getName() ) ) { @@ -892,16 +893,16 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl } } - protected Iterator getNonDuplicatedPropertyIterator() { + protected Iterator getNonDuplicatedPropertyIterator() { return getUnjoinedPropertyIterator(); } - protected Iterator getDiscriminatorColumnIterator() { + protected Iterator getDiscriminatorColumnIterator() { return Collections.emptyIterator(); } protected void checkColumnDuplication() { - HashSet cols = new HashSet(); + HashSet cols = new HashSet<>(); if ( getIdentifierMapper() == null ) { //an identifier mapper => getKey will be included in the getNonDuplicatedPropertyIterator() //and checked later, so it needs to be excluded @@ -909,10 +910,10 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl } checkColumnDuplication( cols, getDiscriminatorColumnIterator() ); checkPropertyColumnDuplication( cols, getNonDuplicatedPropertyIterator() ); - Iterator iter = getJoinIterator(); + Iterator iter = getJoinIterator(); while ( iter.hasNext() ) { cols.clear(); - Join join = (Join) iter.next(); + Join join = iter.next(); checkColumnDuplication( cols, join.getKey().getColumnIterator() ); checkPropertyColumnDuplication( cols, join.getPropertyIterator() ); } @@ -991,7 +992,6 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl } private boolean determineIfNaturalIdDefined() { - //noinspection unchecked final Iterator props = getRootClass().getPropertyIterator(); while ( props.hasNext() ) { if ( props.next().isNaturalIdentifier() ) { @@ -1002,14 +1002,14 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl } // The following methods are added to support @MappedSuperclass in the metamodel - public Iterator getDeclaredPropertyIterator() { - ArrayList iterators = new ArrayList(); + public Iterator getDeclaredPropertyIterator() { + ArrayList> iterators = new ArrayList<>(); iterators.add( declaredProperties.iterator() ); for ( int i = 0; i < joins.size(); i++ ) { Join join = joins.get( i ); iterators.add( join.getDeclaredPropertyIterator() ); } - return new JoinedIterator( iterators ); + return new JoinedIterator<>( iterators ); } public void addMappedsuperclassProperty(Property p) { diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java b/hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java index 00617ba1ef..420f4a3b2f 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java @@ -18,6 +18,7 @@ import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.SingletonIterator; +import org.hibernate.persister.entity.EntityPersister; /** * The root class of an inheritance hierarchy @@ -44,7 +45,7 @@ public class RootClass extends PersistentClass implements TableOwner { private boolean mutable = true; private boolean embeddedIdentifier; private boolean explicitPolymorphism; - private Class entityPersisterClass; + private Class entityPersisterClass; private boolean forceDiscriminator; private String where; private Table table; @@ -125,18 +126,18 @@ public class RootClass extends PersistentClass implements TableOwner { } @Override - public Iterator getPropertyClosureIterator() { + public Iterator getPropertyClosureIterator() { return getPropertyIterator(); } @Override - public Iterator getTableClosureIterator() { - return new SingletonIterator( getTable() ); + public Iterator
getTableClosureIterator() { + return new SingletonIterator<>( getTable() ); } @Override - public Iterator getKeyClosureIterator() { - return new SingletonIterator( getKey() ); + public Iterator getKeyClosureIterator() { + return new SingletonIterator<>( getKey() ); } @Override @@ -184,7 +185,7 @@ public class RootClass extends PersistentClass implements TableOwner { } @Override - public Class getEntityPersisterClass() { + public Class getEntityPersisterClass() { return entityPersisterClass; } @@ -194,7 +195,7 @@ public class RootClass extends PersistentClass implements TableOwner { } @Override - public void setEntityPersisterClass(Class persister) { + public void setEntityPersisterClass(Class persister) { this.entityPersisterClass = persister; } @@ -333,7 +334,7 @@ public class RootClass extends PersistentClass implements TableOwner { } @Override - public java.util.Set getSynchronizedTables() { + public java.util.Set getSynchronizedTables() { return synchronizedTables; } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/SingleTableSubclass.java b/hibernate-core/src/main/java/org/hibernate/mapping/SingleTableSubclass.java index 9b7703b8b2..e035071ece 100755 --- a/hibernate-core/src/main/java/org/hibernate/mapping/SingleTableSubclass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/SingleTableSubclass.java @@ -23,14 +23,14 @@ public class SingleTableSubclass extends Subclass { } @SuppressWarnings("unchecked") - protected Iterator getNonDuplicatedPropertyIterator() { - return new JoinedIterator( + protected Iterator getNonDuplicatedPropertyIterator() { + return new JoinedIterator<>( getSuperclass().getUnjoinedPropertyIterator(), getUnjoinedPropertyIterator() ); } - protected Iterator getDiscriminatorColumnIterator() { + protected Iterator getDiscriminatorColumnIterator() { if ( isDiscriminatorInsertable() && !getDiscriminator().hasFormula() ) { return getDiscriminator().getColumnIterator(); } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Subclass.java b/hibernate-core/src/main/java/org/hibernate/mapping/Subclass.java index 0affe8d9ae..68ee9c1577 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Subclass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Subclass.java @@ -15,8 +15,10 @@ import org.hibernate.AssertionFailure; import org.hibernate.EntityMode; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.engine.OptimisticLockStyle; +import org.hibernate.internal.FilterConfiguration; import org.hibernate.internal.util.collections.JoinedIterator; import org.hibernate.internal.util.collections.SingletonIterator; +import org.hibernate.persister.entity.EntityPersister; /** * A subclass in a table-per-class-hierarchy mapping @@ -24,7 +26,7 @@ import org.hibernate.internal.util.collections.SingletonIterator; */ public class Subclass extends PersistentClass { private PersistentClass superclass; - private Class classPersisterClass; + private Class classPersisterClass; private final int subclassId; public Subclass(PersistentClass superclass, MetadataBuildingContext metadataBuildingContext) { @@ -100,22 +102,22 @@ public class Subclass extends PersistentClass { getSuperclass().addSubclassJoin(j); } - public Iterator getPropertyClosureIterator() { - return new JoinedIterator( + public Iterator getPropertyClosureIterator() { + return new JoinedIterator<>( getSuperclass().getPropertyClosureIterator(), getPropertyIterator() ); } - public Iterator getTableClosureIterator() { - return new JoinedIterator( + public Iterator
getTableClosureIterator() { + return new JoinedIterator<>( getSuperclass().getTableClosureIterator(), - new SingletonIterator( getTable() ) + new SingletonIterator<>( getTable() ) ); } - public Iterator getKeyClosureIterator() { - return new JoinedIterator( + public Iterator getKeyClosureIterator() { + return new JoinedIterator<>( getSuperclass().getKeyClosureIterator(), - new SingletonIterator( getKey() ) + new SingletonIterator<>( getKey() ) ); } protected void addSubclassProperty(Property p) { @@ -146,7 +148,7 @@ public class Subclass extends PersistentClass { public boolean hasEmbeddedIdentifier() { return getSuperclass().hasEmbeddedIdentifier(); } - public Class getEntityPersisterClass() { + public Class getEntityPersisterClass() { if (classPersisterClass==null) { return getSuperclass().getEntityPersisterClass(); } @@ -186,7 +188,7 @@ public class Subclass extends PersistentClass { getKey().createForeignKeyOfEntity( getSuperclass().getEntityName() ); } - public void setEntityPersisterClass(Class classPersisterClass) { + public void setEntityPersisterClass(Class classPersisterClass) { this.classPersisterClass = classPersisterClass; } @@ -198,8 +200,8 @@ public class Subclass extends PersistentClass { return getSuperclass().getPropertyClosureSpan() + super.getPropertyClosureSpan(); } - public Iterator getJoinClosureIterator() { - return new JoinedIterator( + public Iterator getJoinClosureIterator() { + return new JoinedIterator<>( getSuperclass().getJoinClosureIterator(), super.getJoinClosureIterator() ); @@ -225,8 +227,8 @@ public class Subclass extends PersistentClass { return getSuperclass().isDiscriminatorInsertable(); } - public java.util.Set getSynchronizedTables() { - HashSet result = new HashSet(); + public java.util.Set getSynchronizedTables() { + HashSet result = new HashSet<>(); result.addAll(synchronizedTables); result.addAll( getSuperclass().getSynchronizedTables() ); return result; @@ -236,8 +238,8 @@ public class Subclass extends PersistentClass { return mv.accept(this); } - public java.util.List getFilters() { - java.util.List filters = new ArrayList(super.getFilters()); + public java.util.List getFilters() { + java.util.List filters = new ArrayList<>(super.getFilters()); filters.addAll(getSuperclass().getFilters()); return filters; } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/UnionSubclass.java b/hibernate-core/src/main/java/org/hibernate/mapping/UnionSubclass.java index 75b7a5a294..2963d7a3c5 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/UnionSubclass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/UnionSubclass.java @@ -32,11 +32,11 @@ public class UnionSubclass extends Subclass implements TableOwner { getSuperclass().addSubclassTable(table); } - public java.util.Set getSynchronizedTables() { + public java.util.Set getSynchronizedTables() { return synchronizedTables; } - protected Iterator getNonDuplicatedPropertyIterator() { + protected Iterator getNonDuplicatedPropertyIterator() { return getPropertyClosureIterator(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityDiscriminatorMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityDiscriminatorMapping.java index b1f6651cef..3998f781f1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityDiscriminatorMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityDiscriminatorMapping.java @@ -30,7 +30,7 @@ public interface EntityDiscriminatorMapping extends VirtualModelPart, BasicValue } @Override - default JavaTypeDescriptor getJavaTypeDescriptor() { + default JavaTypeDescriptor getJavaTypeDescriptor() { return null; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityMappingType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityMappingType.java index e4a421b17d..172d0ab6f6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityMappingType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityMappingType.java @@ -79,7 +79,7 @@ public interface EntityMappingType extends ManagedMappingType, EntityValuedModel } @Override - default JavaTypeDescriptor getJavaTypeDescriptor() { + default JavaTypeDescriptor getJavaTypeDescriptor() { return getMappedJavaTypeDescriptor(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ManagedMappingType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ManagedMappingType.java index fd6d34b9e3..59586f17d6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ManagedMappingType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ManagedMappingType.java @@ -22,7 +22,7 @@ import org.hibernate.type.descriptor.java.JavaTypeDescriptor; */ public interface ManagedMappingType extends MappingType, FetchableContainer { @Override - default JavaTypeDescriptor getJavaTypeDescriptor() { + default JavaTypeDescriptor getJavaTypeDescriptor() { return getMappedJavaTypeDescriptor(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/MappingType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/MappingType.java index 141d1679e2..6b376a0fe8 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/MappingType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/MappingType.java @@ -14,5 +14,5 @@ import org.hibernate.type.descriptor.java.JavaTypeDescriptor; * @author Steve Ebersole */ public interface MappingType { - JavaTypeDescriptor getMappedJavaTypeDescriptor(); + JavaTypeDescriptor getMappedJavaTypeDescriptor(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ModelPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ModelPart.java index 2eb64b7775..21296ce368 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ModelPart.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ModelPart.java @@ -32,7 +32,7 @@ import org.hibernate.type.descriptor.java.JavaTypeDescriptor; public interface ModelPart extends MappingModelExpressable { MappingType getPartMappingType(); - JavaTypeDescriptor getJavaTypeDescriptor(); + JavaTypeDescriptor getJavaTypeDescriptor(); String getPartName(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractAttributeMapping.java index 9685dd9693..1736c5842e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractAttributeMapping.java @@ -42,8 +42,7 @@ public abstract class AbstractAttributeMapping implements AttributeMapping { } @Override - @SuppressWarnings("rawtypes") - public JavaTypeDescriptor getJavaTypeDescriptor() { + public JavaTypeDescriptor getJavaTypeDescriptor() { return getMappedType().getMappedJavaTypeDescriptor(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEntityDiscriminatorMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEntityDiscriminatorMapping.java index b53911abb7..b10f4bb0e5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEntityDiscriminatorMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEntityDiscriminatorMapping.java @@ -36,14 +36,14 @@ public abstract class AbstractEntityDiscriminatorMapping implements EntityDiscri private final String mappedColumnExpression; private final boolean isFormula; - private final BasicType mappingType; + private final BasicType mappingType; public AbstractEntityDiscriminatorMapping( EntityPersister entityDescriptor, String tableExpression, String mappedColumnExpression, boolean isFormula, - BasicType mappingType) { + BasicType mappingType) { this.entityDescriptor = entityDescriptor; this.tableExpression = tableExpression; this.mappedColumnExpression = mappedColumnExpression; @@ -146,7 +146,7 @@ public abstract class AbstractEntityDiscriminatorMapping implements EntityDiscri } @Override - public JavaTypeDescriptor getJavaTypeDescriptor() { + public JavaTypeDescriptor getJavaTypeDescriptor() { return getMappedType().getMappedJavaTypeDescriptor(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java index d8b6b1963f..f91bc191f1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java @@ -17,7 +17,6 @@ import org.hibernate.mapping.IndexedConsumer; import org.hibernate.mapping.PersistentClass; import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping; import org.hibernate.metamodel.mapping.BasicValuedMapping; -import org.hibernate.metamodel.mapping.BasicValuedModelPart; import org.hibernate.metamodel.mapping.SelectionConsumer; import org.hibernate.metamodel.mapping.EntityIdentifierMapping; import org.hibernate.metamodel.mapping.EntityMappingType; @@ -59,7 +58,7 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa private final String rootTable; private final String pkColumnName; - private final BasicType idType; + private final BasicType idType; private final SessionFactoryImplementor sessionFactory; @@ -68,7 +67,7 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa String attributeName, String rootTable, String pkColumnName, - BasicType idType, + BasicType idType, MappingModelCreationProcess creationProcess) { assert attributeName != null; this.attributeName = attributeName; @@ -162,7 +161,7 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa } @Override - public JavaTypeDescriptor getJavaTypeDescriptor() { + public JavaTypeDescriptor getJavaTypeDescriptor() { return getMappedType().getMappedJavaTypeDescriptor(); } @@ -179,7 +178,6 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa DomainResultCreationState creationState) { final SqlSelection sqlSelection = resolveSqlSelection( navigablePath, tableGroup, creationState ); - //noinspection unchecked return new BasicResult( sqlSelection.getValuesArrayPosition(), resultVariable, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedCollectionPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedCollectionPart.java index b11dffd0a5..5c91dcdbbc 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedCollectionPart.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedCollectionPart.java @@ -110,7 +110,7 @@ public class BasicValuedCollectionPart } @Override - public JavaTypeDescriptor getJavaTypeDescriptor() { + public JavaTypeDescriptor getJavaTypeDescriptor() { return selectionMapping.getJdbcMapping().getJavaTypeDescriptor(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedSingularAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedSingularAttributeMapping.java index b1dfac9a62..18fa0d84a4 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedSingularAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedSingularAttributeMapping.java @@ -112,7 +112,7 @@ public class BasicValuedSingularAttributeMapping } @Override - public JavaTypeDescriptor getJavaTypeDescriptor() { + public JavaTypeDescriptor getJavaTypeDescriptor() { return domainTypeDescriptor; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/DiscriminatedAssociationMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/DiscriminatedAssociationMapping.java index 0c5f14edc4..89d1568409 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/DiscriminatedAssociationMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/DiscriminatedAssociationMapping.java @@ -458,7 +458,7 @@ public class DiscriminatedAssociationMapping implements MappingType, FetchOption @Override public JavaTypeDescriptor getAssembledJavaTypeDescriptor() { //noinspection unchecked - return fetchedPart.getJavaTypeDescriptor(); + return (JavaTypeDescriptor) fetchedPart.getJavaTypeDescriptor(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedForeignKeyDescriptor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedForeignKeyDescriptor.java index 429acad1aa..ebecae1076 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedForeignKeyDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedForeignKeyDescriptor.java @@ -341,7 +341,7 @@ public class EmbeddedForeignKeyDescriptor implements ForeignKeyDescriptor, Model } @Override - public JavaTypeDescriptor getJavaTypeDescriptor() { + public JavaTypeDescriptor getJavaTypeDescriptor() { return mappingType.getJavaTypeDescriptor(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityCollectionPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityCollectionPart.java index 0e988aca81..e8bf495824 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityCollectionPart.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityCollectionPart.java @@ -107,7 +107,7 @@ public class EntityCollectionPart } @Override - public JavaTypeDescriptor getJavaTypeDescriptor() { + public JavaTypeDescriptor getJavaTypeDescriptor() { return getEntityMappingType().getJavaTypeDescriptor(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityDiscriminatorMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityDiscriminatorMappingImpl.java index 9e6157a8f1..45d27ca0ca 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityDiscriminatorMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityDiscriminatorMappingImpl.java @@ -32,7 +32,7 @@ public class EntityDiscriminatorMappingImpl extends AbstractEntityDiscriminatorM String tableExpression, String mappedColumnExpression, boolean isFormula, - BasicType mappingType) { + BasicType mappingType) { super( entityDescriptor, tableExpression, mappedColumnExpression, isFormula, mappingType ); this.navigableRole = entityDescriptor.getNavigableRole().append( EntityDiscriminatorMapping.ROLE_NAME ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityRowIdMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityRowIdMappingImpl.java index 87da0389c2..eedc55fa0e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityRowIdMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityRowIdMappingImpl.java @@ -55,7 +55,7 @@ public class EntityRowIdMappingImpl implements EntityRowIdMapping, SelectionMapp } @Override - public JavaTypeDescriptor getJavaTypeDescriptor() { + public JavaTypeDescriptor getJavaTypeDescriptor() { return JavaObjectType.INSTANCE.getJavaTypeDescriptor(); } @@ -106,7 +106,7 @@ public class EntityRowIdMappingImpl implements EntityRowIdMapping, SelectionMapp sqlAstCreationState.getCreationContext().getDomainModel().getTypeConfiguration() ); - return new BasicResult( + return new BasicResult( sqlSelection.getValuesArrayPosition(), resultVariable, getJavaTypeDescriptor(), diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityVersionMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityVersionMappingImpl.java index 66a62491b1..8adc7ef6bc 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityVersionMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityVersionMappingImpl.java @@ -109,7 +109,7 @@ public class EntityVersionMappingImpl implements EntityVersionMapping, FetchOpti } @Override - public JavaTypeDescriptor getJavaTypeDescriptor() { + public JavaTypeDescriptor getJavaTypeDescriptor() { return versionBasicType.getJavaTypeDescriptor(); } @@ -190,8 +190,7 @@ public class EntityVersionMappingImpl implements EntityVersionMapping, FetchOpti DomainResultCreationState creationState) { final SqlSelection sqlSelection = resolveSqlSelection( tableGroup, creationState ); - //noinspection unchecked - return new BasicResult<>( + return new BasicResult( sqlSelection.getValuesArrayPosition(), resultVariable, getJavaTypeDescriptor(), diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/JoinedSubclassDiscriminatorMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/JoinedSubclassDiscriminatorMappingImpl.java index 2263e3b2b3..ef66bc8af4 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/JoinedSubclassDiscriminatorMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/JoinedSubclassDiscriminatorMappingImpl.java @@ -38,7 +38,7 @@ public class JoinedSubclassDiscriminatorMappingImpl extends AbstractEntityDiscri boolean isFormula, CaseSearchedExpression caseSearchedExpression, List columnReferences, - BasicType mappingType) { + BasicType mappingType) { super( entityDescriptor, tableExpression, mappedColumnExpression, isFormula, mappingType ); this.navigableRole = entityDescriptor.getNavigableRole().append( EntityDiscriminatorMapping.ROLE_NAME ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleNaturalIdMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleNaturalIdMapping.java index 62ea3ea130..8e6dbb64e0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleNaturalIdMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleNaturalIdMapping.java @@ -161,7 +161,7 @@ public class SimpleNaturalIdMapping extends AbstractNaturalIdMapping { } @Override - public JavaTypeDescriptor getJavaTypeDescriptor() { + public JavaTypeDescriptor getJavaTypeDescriptor() { return attribute.getJavaTypeDescriptor(); } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index 29d6e02a2e..85f5f16a9b 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -41,7 +41,6 @@ import org.hibernate.JDBCException; import org.hibernate.LockMode; import org.hibernate.LockOptions; import org.hibernate.MappingException; -import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.QueryException; import org.hibernate.Session; import org.hibernate.StaleObjectStateException; @@ -267,10 +266,10 @@ public abstract class AbstractEntityPersister private final String sqlAliasStem; private EntityMappingType rootEntityDescriptor; - private final SingleIdEntityLoader singleIdEntityLoader; - private final MultiIdEntityLoader multiIdEntityLoader; - private NaturalIdLoader naturalIdLoader; - private MultiNaturalIdLoader multiNaturalIdLoader; + private final SingleIdEntityLoader singleIdEntityLoader; + private final MultiIdEntityLoader multiIdEntityLoader; + private NaturalIdLoader naturalIdLoader; + private MultiNaturalIdLoader multiNaturalIdLoader; private SqmMultiTableMutationStrategy sqmMultiTableMutationStrategy; @@ -392,8 +391,8 @@ public abstract class AbstractEntityPersister private boolean[] tableHasColumns; - private final Map subclassPropertyAliases = new HashMap(); - private final Map subclassPropertyColumnNames = new HashMap(); + private final Map subclassPropertyAliases = new HashMap<>(); + private final Map subclassPropertyColumnNames = new HashMap<>(); /** * Warning: @@ -757,7 +756,7 @@ public abstract class AbstractEntityPersister if ( namedQueryMemento == null ) { throw new IllegalArgumentException( "Could not resolve named load-query [" + getEntityName() + "] : " + bootDescriptor.getLoaderName() ); } - singleIdEntityLoader = new SingleIdEntityLoaderProvidedQueryImpl( + singleIdEntityLoader = new SingleIdEntityLoaderProvidedQueryImpl<>( this, namedQueryMemento ); @@ -766,19 +765,19 @@ public abstract class AbstractEntityPersister singleIdEntityLoader = createBatchingIdEntityLoader( this, batchSize, factory ); } else { - singleIdEntityLoader = new SingleIdEntityLoaderStandardImpl( this, factory ); + singleIdEntityLoader = new SingleIdEntityLoaderStandardImpl<>( this, factory ); } // todo (6.0) : allow a "max entities" to be passed (or determine based on Dialect?) indicating how many entities // to load at once. i.e. it limits the number of the generated IN-list JDBC-parameters in a given // PreparedStatement, opting to split the load into multiple JDBC operations to work around database // limits on number of parameters, number of IN-list values, etc - multiIdEntityLoader = new MultiIdLoaderStandard( this, factory ); + multiIdEntityLoader = new MultiIdLoaderStandard<>( this, factory ); - Iterator iter = bootDescriptor.getIdentifier().getColumnIterator(); + Iterator idColumns = bootDescriptor.getIdentifier().getColumnIterator(); int i = 0; - while ( iter.hasNext() ) { - Column col = (Column) iter.next(); + while ( idColumns.hasNext() ) { + Column col = (Column) idColumns.next(); rootTableKeyColumnNames[i] = col.getQuotedName( dialect ); rootTableKeyColumnReaders[i] = col.getReadExpr( dialect ); rootTableKeyColumnReaderTemplates[i] = col.getTemplate( @@ -813,8 +812,6 @@ public abstract class AbstractEntityPersister // PROPERTIES - final boolean lazyAvailable = isInstrumented(); - int hydrateSpan = entityMetamodel.getPropertySpan(); propertyColumnSpans = new int[hydrateSpan]; propertySubclassNames = new String[hydrateSpan]; @@ -827,19 +824,19 @@ public abstract class AbstractEntityPersister propertySelectable = new boolean[hydrateSpan]; propertyColumnUpdateable = new boolean[hydrateSpan][]; propertyColumnInsertable = new boolean[hydrateSpan][]; - HashSet thisClassProperties = new HashSet(); + HashSet thisClassProperties = new HashSet<>(); - ArrayList lazyNames = new ArrayList(); - ArrayList lazyNumbers = new ArrayList(); - ArrayList lazyTypes = new ArrayList(); - ArrayList lazyColAliases = new ArrayList(); + ArrayList lazyNames = new ArrayList<>(); + ArrayList lazyNumbers = new ArrayList<>(); + ArrayList lazyTypes = new ArrayList<>(); + ArrayList lazyColAliases = new ArrayList<>(); final ArrayList lobPropertiesLocalCollector = new ArrayList<>(); - iter = bootDescriptor.getPropertyClosureIterator(); + Iterator properties = bootDescriptor.getPropertyClosureIterator(); i = 0; boolean foundFormula = false; - while ( iter.hasNext() ) { - Property prop = (Property) iter.next(); + while ( properties.hasNext() ) { + Property prop = properties.next(); thisClassProperties.add( prop ); int span = prop.getColumnSpan(); @@ -850,10 +847,10 @@ public abstract class AbstractEntityPersister String[] colReaderTemplates = new String[span]; String[] colWriters = new String[span]; String[] formulaTemplates = new String[span]; - Iterator colIter = prop.getColumnIterator(); + Iterator colIter = prop.getColumnIterator(); int k = 0; while ( colIter.hasNext() ) { - Selectable thing = (Selectable) colIter.next(); + Selectable thing = colIter.next(); colAliases[k] = thing.getAlias( dialect, prop.getValue().getTable() ); if ( thing.isFormula() ) { foundFormula = true; @@ -916,32 +913,32 @@ public abstract class AbstractEntityPersister // SUBCLASS PROPERTY CLOSURE - ArrayList columns = new ArrayList(); - ArrayList columnsLazy = new ArrayList(); - ArrayList columnReaderTemplates = new ArrayList(); - ArrayList aliases = new ArrayList(); - ArrayList formulas = new ArrayList(); - ArrayList formulaAliases = new ArrayList(); - ArrayList formulaTemplates = new ArrayList(); - ArrayList formulasLazy = new ArrayList(); - ArrayList types = new ArrayList(); - ArrayList names = new ArrayList(); - ArrayList classes = new ArrayList(); - ArrayList templates = new ArrayList(); - ArrayList propColumns = new ArrayList(); - ArrayList propColumnReaders = new ArrayList(); - ArrayList propColumnReaderTemplates = new ArrayList(); - ArrayList joinedFetchesList = new ArrayList(); - ArrayList cascades = new ArrayList(); - ArrayList definedBySubclass = new ArrayList(); - ArrayList propColumnNumbers = new ArrayList(); - ArrayList propFormulaNumbers = new ArrayList(); - ArrayList columnSelectables = new ArrayList(); - ArrayList propNullables = new ArrayList(); + ArrayList columns = new ArrayList<>(); + ArrayList columnsLazy = new ArrayList<>(); + ArrayList columnReaderTemplates = new ArrayList<>(); + ArrayList aliases = new ArrayList<>(); + ArrayList formulas = new ArrayList<>(); + ArrayList formulaAliases = new ArrayList<>(); + ArrayList formulaTemplates = new ArrayList<>(); + ArrayList formulasLazy = new ArrayList<>(); + ArrayList types = new ArrayList<>(); + ArrayList names = new ArrayList<>(); + ArrayList classes = new ArrayList<>(); + ArrayList templates = new ArrayList<>(); + ArrayList propColumns = new ArrayList<>(); + ArrayList propColumnReaders = new ArrayList<>(); + ArrayList propColumnReaderTemplates = new ArrayList<>(); + ArrayList joinedFetchesList = new ArrayList<>(); + ArrayList cascades = new ArrayList<>(); + ArrayList definedBySubclass = new ArrayList<>(); + ArrayList propColumnNumbers = new ArrayList<>(); + ArrayList propFormulaNumbers = new ArrayList<>(); + ArrayList columnSelectables = new ArrayList<>(); + ArrayList propNullables = new ArrayList<>(); - iter = bootDescriptor.getSubclassPropertyClosureIterator(); + Iterator iter = bootDescriptor.getSubclassPropertyClosureIterator(); while ( iter.hasNext() ) { - final Property prop = (Property) iter.next(); + final Property prop = iter.next(); names.add( prop.getName() ); classes.add( prop.getPersistentClass().getEntityName() ); types.add( prop.getType() ); @@ -950,7 +947,7 @@ public abstract class AbstractEntityPersister definedBySubclass.add( Boolean.valueOf( isDefinedBySubclass ) ); propNullables.add( Boolean.valueOf( prop.isOptional() || isDefinedBySubclass ) ); //TODO: is this completely correct? - final Iterator colIter = prop.getColumnIterator(); + final Iterator colIter = prop.getColumnIterator(); String[] cols = new String[ prop.getColumnSpan() ]; String[] readers = new String[ prop.getColumnSpan() ]; String[] readerTemplates = new String[ prop.getColumnSpan() ]; @@ -971,7 +968,7 @@ public abstract class AbstractEntityPersister sessionFactoryOptions.isCollectionsInDefaultFetchGroupEnabled() ); while ( colIter.hasNext() ) { - final Selectable thing = (Selectable) colIter.next(); + final Selectable thing = colIter.next(); if ( thing.isFormula() ) { String template = thing.getTemplate( dialect, factory.getQueryEngine().getSqmFunctionRegistry() ); formnos[l] = formulaTemplates.size(); @@ -1033,24 +1030,17 @@ public abstract class AbstractEntityPersister subclassPropertyFormulaNumberClosure = ArrayHelper.to2DIntArray( propFormulaNumbers ); subclassPropertyCascadeStyleClosure = new CascadeStyle[cascades.size()]; - iter = cascades.iterator(); int j = 0; - while ( iter.hasNext() ) { - subclassPropertyCascadeStyleClosure[j++] = (CascadeStyle) iter.next(); + for (CascadeStyle cascade: cascades) { + subclassPropertyCascadeStyleClosure[j++] = cascade; } subclassPropertyFetchModeClosure = new FetchMode[joinedFetchesList.size()]; - iter = joinedFetchesList.iterator(); j = 0; - while ( iter.hasNext() ) { - subclassPropertyFetchModeClosure[j++] = (FetchMode) iter.next(); + for (FetchMode fetchMode : joinedFetchesList) { + subclassPropertyFetchModeClosure[j++] = fetchMode; } - propertyDefinedOnSubclass = new boolean[definedBySubclass.size()]; - iter = definedBySubclass.iterator(); - j = 0; - while ( iter.hasNext() ) { - propertyDefinedOnSubclass[j++] = (Boolean) iter.next(); - } + propertyDefinedOnSubclass = ArrayHelper.toBooleanArray( definedBySubclass ); // Handle any filters applied to the class level filterHelper = new FilterHelper( bootDescriptor.getFilters(), factory ); @@ -1088,11 +1078,11 @@ public abstract class AbstractEntityPersister } - private static SingleIdEntityLoader createBatchingIdEntityLoader( + private static SingleIdEntityLoader createBatchingIdEntityLoader( EntityMappingType entityDescriptor, int batchSize, SessionFactoryImplementor factory) { - return new SingleIdEntityLoaderDynamicBatch( entityDescriptor, batchSize, factory ); + return new SingleIdEntityLoaderDynamicBatch<>( entityDescriptor, batchSize, factory ); } @SuppressWarnings("RedundantIfStatement") @@ -1140,7 +1130,6 @@ public abstract class AbstractEntityPersister return persistentClass.isCached(); } - @SuppressWarnings("unchecked") private boolean determineCanReadFromCache(PersistentClass persistentClass, EntityDataAccess cacheAccessStrategy) { if ( cacheAccessStrategy == null ) { return false; @@ -1184,7 +1173,7 @@ public abstract class AbstractEntityPersister protected static String getTemplateFromString(String string, SessionFactoryImplementor factory) { return string == null ? null : - Template.renderWhereStringTemplate( string, factory.getDialect(), factory.getQueryEngine().getSqmFunctionRegistry() ); + Template.renderWhereStringTemplate( string, factory.getJdbcServices().getDialect(), factory.getQueryEngine().getSqmFunctionRegistry() ); } protected Map generateLazySelectStringsByFetchGroup() { @@ -1198,9 +1187,9 @@ public abstract class AbstractEntityPersister final LazyAttributesMetadata lazyAttributesMetadata = enhancementMetadata.getLazyAttributesMetadata(); for ( String groupName : lazyAttributesMetadata.getFetchGroupNames() ) { - HashSet tableNumbers = new HashSet(); - ArrayList columnNumbers = new ArrayList(); - ArrayList formulaNumbers = new ArrayList(); + HashSet tableNumbers = new HashSet<>(); + ArrayList columnNumbers = new ArrayList<>(); + ArrayList formulaNumbers = new ArrayList<>(); for ( LazyAttributeDescriptor lazyAttributeDescriptor : lazyAttributesMetadata.getFetchGroupAttributeDescriptors( groupName ) ) { @@ -1557,7 +1546,7 @@ public abstract class AbstractEntityPersister // see if there is already a collection instance associated with the session // NOTE : can this ever happen? final Object key = getCollectionKey( persister, entity, entry, session ); - PersistentCollection collection = persistenceContext.getCollection( new CollectionKey( persister, key ) ); + PersistentCollection collection = persistenceContext.getCollection( new CollectionKey( persister, key ) ); if ( collection == null ) { collection = collectionType.instantiate( session, persister, key ); collection.setOwner( entity ); @@ -1993,7 +1982,7 @@ public abstract class AbstractEntityPersister * Generate the SQL that selects the version number by id */ public String generateSelectVersionString() { - SimpleSelect select = new SimpleSelect( getFactory().getDialect() ) + SimpleSelect select = new SimpleSelect( getFactory().getJdbcServices().getDialect() ) .setTableName( getVersionedTableName() ); if ( isVersioned() ) { select.addColumn( versionColumnName ); @@ -2020,7 +2009,7 @@ public abstract class AbstractEntityPersister } private String generateGeneratedValuesSelectString(final GenerationTiming generationTimingToMatch) { - Select select = new Select( getFactory().getDialect() ); + Select select = new Select( getFactory().getJdbcServices().getDialect() ); if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { select.setComment( "get generated state " + getEntityName() ); @@ -2096,7 +2085,7 @@ public abstract class AbstractEntityPersister //TODO: should we use SELECT .. FOR UPDATE? - Select select = new Select( getFactory().getDialect() ); + Select select = new Select( getFactory().getJdbcServices().getDialect() ); if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { select.setComment( "get current state " + getEntityName() ); @@ -2144,7 +2133,7 @@ public abstract class AbstractEntityPersister throw new HibernateException( "LockMode.FORCE is currently not supported for generated version properties" ); } - Object nextVersion = getVersionType().next( currentVersion, session ); + Object nextVersion = ((VersionType) getVersionType()).next( currentVersion, session ); if ( LOG.isTraceEnabled() ) { LOG.trace( "Forcing version increment [" + MessageHelper.infoString( this, id, getFactory() ) + "; " @@ -2243,7 +2232,7 @@ public abstract class AbstractEntityPersister } protected LockingStrategy generateLocker(LockMode lockMode) { - return factory.getDialect().getLockingStrategy( this, lockMode ); + return factory.getJdbcServices().getDialect().getLockingStrategy( this, lockMode ); } private LockingStrategy getLocker(LockMode lockMode) { @@ -2619,7 +2608,7 @@ public abstract class AbstractEntityPersister } public String[] getSubclassPropertyColumnAliases(String propertyName, String suffix) { - String[] rawAliases = (String[]) subclassPropertyAliases.get( propertyName ); + String[] rawAliases = subclassPropertyAliases.get( propertyName ); if ( rawAliases == null ) { return null; @@ -2634,7 +2623,7 @@ public abstract class AbstractEntityPersister public String[] getSubclassPropertyColumnNames(String propertyName) { //TODO: should we allow suffixes on these ? - return (String[]) subclassPropertyColumnNames.get( propertyName ); + return subclassPropertyColumnNames.get( propertyName ); } @@ -2705,25 +2694,26 @@ public abstract class AbstractEntityPersister } - private void internalInitSubclassPropertyAliasesMap(String path, Iterator propertyIterator) { + private void internalInitSubclassPropertyAliasesMap(String path, Iterator propertyIterator) { while ( propertyIterator.hasNext() ) { - Property prop = (Property) propertyIterator.next(); + Property prop = propertyIterator.next(); String propname = path == null ? prop.getName() : path + "." + prop.getName(); if ( prop.isComposite() ) { Component component = (Component) prop.getValue(); - Iterator compProps = component.getPropertyIterator(); + Iterator compProps = component.getPropertyIterator(); internalInitSubclassPropertyAliasesMap( propname, compProps ); } else { String[] aliases = new String[prop.getColumnSpan()]; String[] cols = new String[prop.getColumnSpan()]; - Iterator colIter = prop.getColumnIterator(); + Iterator colIter = prop.getColumnIterator(); int l = 0; while ( colIter.hasNext() ) { - Selectable thing = (Selectable) colIter.next(); - aliases[l] = thing.getAlias( getFactory().getDialect(), prop.getValue().getTable() ); - cols[l] = thing.getText( getFactory().getDialect() ); // TODO: skip formulas? + Selectable thing = colIter.next(); + Dialect dialect = getFactory().getJdbcServices().getDialect(); + aliases[l] = thing.getAlias( dialect, prop.getValue().getTable() ); + cols[l] = thing.getText(dialect); // TODO: skip formulas? l++; } @@ -2767,7 +2757,7 @@ public abstract class AbstractEntityPersister private Map> uniqueKeyLoadersNew; - protected SingleUniqueKeyEntityLoader getUniqueKeyLoader(String attributeName) { + protected SingleUniqueKeyEntityLoader getUniqueKeyLoader(String attributeName) { final SingularAttributeMapping attribute = (SingularAttributeMapping) findSubPart( attributeName ); final SingleUniqueKeyEntityLoader existing; if ( uniqueKeyLoadersNew == null ) { @@ -2782,7 +2772,7 @@ public abstract class AbstractEntityPersister return existing; } - final SingleUniqueKeyEntityLoader loader = new SingleUniqueKeyEntityLoaderStandard( this, attribute ); + final SingleUniqueKeyEntityLoader loader = new SingleUniqueKeyEntityLoaderStandard<>( this, attribute ); uniqueKeyLoadersNew.put( attribute, loader ); return loader; @@ -3087,7 +3077,7 @@ public abstract class AbstractEntityPersister // append the SQL to return the generated identifier if ( j == 0 && identityInsert && useInsertSelectIdentity() ) { //TODO: suck into Insert - result = getFactory().getDialect().getIdentityColumnSupport().appendIdentitySelectToInsert( result ); + result = getFactory().getJdbcServices().getDialect().getIdentityColumnSupport().appendIdentitySelectToInsert( result ); } return result; @@ -3364,7 +3354,7 @@ public abstract class AbstractEntityPersister } if ( sequentialResultSet != null ) { - session.getJdbcCoordinator().getResourceRegistry().release( sequentialResultSet, sequentialSelect ); + session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( sequentialResultSet, sequentialSelect ); } return values; @@ -3372,14 +3362,15 @@ public abstract class AbstractEntityPersister } finally { if ( sequentialSelect != null ) { - session.getJdbcCoordinator().getResourceRegistry().release( sequentialSelect ); + session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( sequentialSelect ); session.getJdbcCoordinator().afterStatementExecution(); } } } public boolean useInsertSelectIdentity() { - return !useGetGeneratedKeys() && getFactory().getDialect().getIdentityColumnSupport().supportsInsertSelectIdentity(); + return !useGetGeneratedKeys() + && getFactory().getJdbcServices().getDialect().getIdentityColumnSupport().supportsInsertSelectIdentity(); } public boolean useGetGeneratedKeys() { @@ -3425,7 +3416,7 @@ public abstract class AbstractEntityPersister public String getIdentitySelectString() { //TODO: cache this in an instvar - return getFactory().getDialect().getIdentityColumnSupport() + return getFactory().getJdbcServices().getDialect().getIdentityColumnSupport() .getIdentitySelectString( getTableName( 0 ), getKeyColumns( 0 )[0], @@ -3434,7 +3425,7 @@ public abstract class AbstractEntityPersister } public String getSelectByUniqueKeyString(String propertyName) { - return new SimpleSelect( getFactory().getDialect() ) + return new SimpleSelect( getFactory().getJdbcServices().getDialect() ) .setTableName( getTableName( 0 ) ) .addColumns( getKeyColumns( 0 ) ) .addCondition( getPropertyColumnNames( propertyName ), "=?" ) @@ -3534,13 +3525,13 @@ public abstract class AbstractEntityPersister } finally { if ( !useBatch ) { - session.getJdbcCoordinator().getResourceRegistry().release( insert ); + session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( insert ); session.getJdbcCoordinator().afterStatementExecution(); } } } catch (SQLException e) { - throw getFactory().getSQLExceptionHelper().convert( + throw getFactory().getJdbcServices().getSqlExceptionHelper().convert( e, "could not insert: " + MessageHelper.infoString( this ), sql @@ -3735,14 +3726,14 @@ public abstract class AbstractEntityPersister } finally { if ( !useBatch ) { - session.getJdbcCoordinator().getResourceRegistry().release( update ); + session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( update ); session.getJdbcCoordinator().afterStatementExecution(); } } } catch (SQLException e) { - throw getFactory().getSQLExceptionHelper().convert( + throw getFactory().getJdbcServices().getSqlExceptionHelper().convert( e, "could not update: " + MessageHelper.infoString( this, id, getFactory() ), sql @@ -3861,14 +3852,14 @@ public abstract class AbstractEntityPersister } finally { if ( !useBatch ) { - session.getJdbcCoordinator().getResourceRegistry().release( delete ); + session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( delete ); session.getJdbcCoordinator().afterStatementExecution(); } } } catch (SQLException sqle) { - throw getFactory().getSQLExceptionHelper().convert( + throw getFactory().getJdbcServices().getSqlExceptionHelper().convert( sqle, "could not delete: " + MessageHelper.infoString( this, id, getFactory() ), @@ -4287,7 +4278,7 @@ public abstract class AbstractEntityPersister Set referencedTables) { // IMPL NOTE : all joins join to the pk of the driving table final String[] idCols = StringHelper.qualify( name, getIdentifierColumnNames() ); - final JoinFragment join = getFactory().getDialect().createOuterJoinFragment(); + final JoinFragment join = getFactory().getJdbcServices().getDialect().createOuterJoinFragment(); final int tableSpan = getSubclassTableSpan(); // IMPL NOTE : notice that we skip the first table; it is the driving table! for ( int j = 1; j < tableSpan; j++ ) { @@ -4393,7 +4384,7 @@ public abstract class AbstractEntityPersister protected JoinFragment createJoin(int[] tableNumbers, String drivingAlias) { final String[] keyCols = StringHelper.qualify( drivingAlias, getSubclassTableKeyColumns( tableNumbers[0] ) ); - final JoinFragment jf = getFactory().getDialect().createOuterJoinFragment(); + final JoinFragment jf = getFactory().getJdbcServices().getDialect().createOuterJoinFragment(); // IMPL NOTE : notice that we skip the first table; it is the driving table! for ( int i = 1; i < tableNumbers.length; i++ ) { final int j = tableNumbers[i]; @@ -4478,7 +4469,7 @@ public abstract class AbstractEntityPersister SelectFragment selectFragment = createSelect( columnNumbers, formulaNumbers ); //now tie it all together - Select select = new Select( getFactory().getDialect() ); + Select select = new Select( getFactory().getJdbcServices().getDialect() ); select.setSelectClause( selectFragment.toFragmentString().substring( 2 ) ); select.setFromClause( from ); select.setWhereClause( where ); @@ -4556,7 +4547,11 @@ public abstract class AbstractEntityPersister } if ( isIdentifierAssignedByInsert() ) { identityDelegate = ( (PostInsertIdentifierGenerator) getIdentifierGenerator() ) - .getInsertGeneratedIdentifierDelegate( this, getFactory().getDialect(), useGetGeneratedKeys() ); + .getInsertGeneratedIdentifierDelegate( + this, + getFactory().getJdbcServices().getDialect(), + useGetGeneratedKeys() + ); sqlIdentityInsertString = customSQLInsert[0] == null ? generateIdentityInsertString( getPropertyInsertability() ) : substituteBrackets( customSQLInsert[0] ); @@ -4626,7 +4621,7 @@ public abstract class AbstractEntityPersister } } - public SingleIdEntityLoader getSingleIdEntityLoader() { + public SingleIdEntityLoader getSingleIdEntityLoader() { return singleIdEntityLoader; } @@ -4930,7 +4925,7 @@ public abstract class AbstractEntityPersister return naturalIdRegionAccessStrategy; } - public Comparator getVersionComparator() { + public Comparator getVersionComparator() { return isVersioned() ? getVersionType().getComparator() : null; } @@ -4959,14 +4954,10 @@ public abstract class AbstractEntityPersister return !entityMetamodel.getIdentifierProperty().isVirtual(); } - public VersionType getVersionType() { - return (VersionType) locateVersionType(); - } - - private Type locateVersionType() { - return entityMetamodel.getVersionProperty() == null ? - null : - entityMetamodel.getVersionProperty().getType(); + public VersionType getVersionType() { + return entityMetamodel.getVersionProperty() == null + ? null + : (VersionType) entityMetamodel.getVersionProperty().getType(); } public int getVersionProperty() { @@ -5144,14 +5135,6 @@ public abstract class AbstractEntityPersister return entityMetamodel.isExplicitPolymorphism(); } - protected boolean useDynamicUpdate() { - return entityMetamodel.isDynamicUpdate(); - } - - protected boolean useDynamicInsert() { - return entityMetamodel.isDynamicInsert(); - } - public boolean hasEmbeddedCompositeIdentifier() { return entityMetamodel.getIdentifierProperty().isEmbedded(); } @@ -5335,7 +5318,7 @@ public abstract class AbstractEntityPersister return entityMetamodel.getCascadeStyles(); } - public final Class getMappedClass() { + public final Class getMappedClass() { return getMappedJavaTypeDescriptor().getJavaTypeClass(); } @@ -5343,7 +5326,7 @@ public abstract class AbstractEntityPersister return Lifecycle.class.isAssignableFrom( getMappedClass() ); } - public Class getConcreteProxyClass() { + public Class getConcreteProxyClass() { final JavaTypeDescriptor proxyJavaTypeDescriptor = getRepresentationStrategy().getProxyJavaTypeDescriptor(); return proxyJavaTypeDescriptor != null ? proxyJavaTypeDescriptor.getJavaTypeClass() : javaTypeDescriptor.getJavaTypeClass(); } @@ -5495,9 +5478,7 @@ public abstract class AbstractEntityPersister Object currentVersion, SharedSessionContractImplementor session) { final IdentifierProperty identifierProperty = entityMetamodel.getIdentifierProperty(); - if ( identifierProperty.getIdentifierGenerator() instanceof Assigned ) { - } - else { + if ( !(identifierProperty.getIdentifierGenerator() instanceof Assigned) ) { //reset the id Object result = identifierProperty .getUnsavedValue() @@ -5659,17 +5640,17 @@ public abstract class AbstractEntityPersister } finally { if ( rs != null ) { - session.getJdbcCoordinator().getResourceRegistry().release( rs, ps ); + session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( rs, ps ); } } } finally { - session.getJdbcCoordinator().getResourceRegistry().release( ps ); + session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( ps ); session.getJdbcCoordinator().afterStatementExecution(); } } catch (SQLException e) { - throw getFactory().getSQLExceptionHelper().convert( + throw getFactory().getJdbcServices().getSqlExceptionHelper().convert( e, "unable to select generated column values", selectionSQL @@ -5735,8 +5716,7 @@ public abstract class AbstractEntityPersister ); } - final Object result = getNaturalIdLoader().resolveIdToNaturalId( id, session ); - return result; + return getNaturalIdLoader().resolveIdToNaturalId( id, session ); } @@ -5944,8 +5924,8 @@ public abstract class AbstractEntityPersister // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // org.hibernate.metamodel.mapping.EntityMappingType - private JavaTypeDescriptor javaTypeDescriptor; - private EntityRepresentationStrategy representationStrategy; + private final JavaTypeDescriptor javaTypeDescriptor; + private final EntityRepresentationStrategy representationStrategy; private EntityMappingType superMappingType; private SortedMap subclassMappingTypes; @@ -6226,7 +6206,7 @@ public abstract class AbstractEntityPersister getTableName(), discriminatorColumnExpression, getDiscriminatorFormulaTemplate() != null, - (BasicType) getDiscriminatorType() + (BasicType) getDiscriminatorType() ); } } @@ -6270,7 +6250,7 @@ public abstract class AbstractEntityPersister public void linkWithSubType(EntityMappingType sub, MappingModelCreationProcess creationProcess) { if ( subclassMappingTypes == null ) { //noinspection unchecked - subclassMappingTypes = new TreeMap(); + subclassMappingTypes = new TreeMap<>(); } subclassMappingTypes.put( sub.getEntityName(), sub ); } @@ -6357,7 +6337,7 @@ public abstract class AbstractEntityPersister bootEntityDescriptor.getIdentifierProperty().getName(), getTableName(), rootTableKeyColumnNames[0], - (BasicType) idType, + (BasicType) idType, creationProcess ); } @@ -6675,10 +6655,7 @@ public abstract class AbstractEntityPersister } if ( superMappingType != null ) { - final AttributeMapping fromSuperType = superMappingType.findAttributeMapping( name ); - if ( fromSuperType != null ) { - return fromSuperType; - } + return superMappingType.findAttributeMapping( name ); } return null; @@ -6755,10 +6732,7 @@ public abstract class AbstractEntityPersister } if ( hasIdentifierProperty() ) { - final String identifierPropertyName = getIdentifierPropertyName(); - if ( identifierPropertyName.equals( name ) ) { - return true; - } + return getIdentifierPropertyName().equals( name ); } return false; @@ -6803,13 +6777,10 @@ public abstract class AbstractEntityPersister return; } - //noinspection unchecked attributeMappings.forEach( fetchableConsumer ); if ( treatTargetType.isTypeOrSuperType( this ) ) { - visitSubTypeAttributeMappings( - attributeMapping -> fetchableConsumer.accept( attributeMapping ) - ); + visitSubTypeAttributeMappings( fetchableConsumer::accept ); } } @@ -6860,7 +6831,7 @@ public abstract class AbstractEntityPersister // EntityDefinition impl (walking model - deprecated) private EntityIdentifierDefinition entityIdentifierDefinition; - private SortedSet attributeDefinitions = new TreeSet<>( + private final SortedSet attributeDefinitions = new TreeSet<>( Comparator.comparing( AttributeDefinition::getName ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java index 1f0ca246ce..5d1cc2c588 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java @@ -364,7 +364,7 @@ public interface EntityPersister * * @return The type of the version property; or null, if not versioned. */ - VersionType getVersionType(); + VersionType getVersionType(); /** * If {@link #isVersioned()}, then what is the index of the property @@ -433,7 +433,7 @@ public interface EntityPersister */ boolean hasLazyProperties(); - default NaturalIdLoader getNaturalIdLoader() { + default NaturalIdLoader getNaturalIdLoader() { throw new UnsupportedOperationException( "EntityPersister implementation `" + getClass().getName() + "` does not support `NaturalIdLoader`" ); @@ -447,7 +447,6 @@ public interface EntityPersister /** * Load the id for the entity based on the natural id. - * @return */ Object loadEntityIdByNaturalId( Object[] naturalIdValues, @@ -763,7 +762,7 @@ public interface EntityPersister /** * The persistent class, or null */ - Class getMappedClass(); + Class getMappedClass(); /** * Does the class implement the {@link org.hibernate.classic.Lifecycle} interface. @@ -774,7 +773,7 @@ public interface EntityPersister * Get the proxy interface that instances of this concrete class will be * cast to (optional operation). */ - Class getConcreteProxyClass(); + Class getConcreteProxyClass(); /** * Set the given values to the mapped properties of the given object diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java index d14f34c641..b8c4e1e3b3 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java @@ -8,19 +8,15 @@ package org.hibernate.persister.entity; import java.io.Serializable; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.function.Consumer; -import java.util.function.Supplier; import org.hibernate.AssertionFailure; import org.hibernate.HibernateException; -import org.hibernate.LockMode; import org.hibernate.MappingException; import org.hibernate.QueryException; import org.hibernate.boot.model.relational.Database; @@ -61,18 +57,12 @@ import org.hibernate.sql.CaseFragment; import org.hibernate.sql.InFragment; import org.hibernate.sql.Insert; import org.hibernate.sql.SelectFragment; -import org.hibernate.sql.ast.spi.SqlAliasBase; -import org.hibernate.sql.ast.spi.SqlAliasBaseGenerator; -import org.hibernate.sql.ast.spi.SqlAstCreationContext; -import org.hibernate.sql.ast.spi.SqlExpressionResolver; import org.hibernate.sql.ast.tree.expression.CaseSearchedExpression; import org.hibernate.sql.ast.tree.expression.ColumnReference; import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.ast.tree.expression.QueryLiteral; -import org.hibernate.sql.ast.tree.from.StandardTableGroup; import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.sql.ast.tree.from.TableReference; -import org.hibernate.sql.ast.tree.from.TableReferenceJoin; import org.hibernate.sql.ast.tree.predicate.NullnessPredicate; import org.hibernate.sql.ast.tree.predicate.Predicate; import org.hibernate.sql.results.graph.DomainResult; @@ -86,6 +76,8 @@ import org.hibernate.type.Type; import org.jboss.logging.Logger; +import static java.util.Collections.emptyMap; + /** * An EntityPersister implementing the normalized "table-per-subclass" * mapping strategy @@ -98,8 +90,6 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { private static final String IMPLICIT_DISCRIMINATOR_ALIAS = "clazz_"; private static final Object NULL_DISCRIMINATOR = new MarkerObject(""); private static final Object NOT_NULL_DISCRIMINATOR = new MarkerObject(""); - private static final String NULL_STRING = "null"; - private static final String NOT_NULL_STRING = "not null"; // the class hierarchy structure private final int tableSpan; @@ -142,7 +132,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { // subclass discrimination works by assigning particular // values to certain combinations of null primary key // values in the outer join using an SQL CASE - private final Map subclassesByDiscriminatorValue = new HashMap(); + private final Map subclassesByDiscriminatorValue = new HashMap<>(); private final String[] discriminatorValues; private final String[] notNullColumnNames; private final int[] notNullColumnTableNumbers; @@ -152,7 +142,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { private final Object discriminatorValue; private final String discriminatorSQLString; - private final DiscriminatorType discriminatorType; + private final DiscriminatorType discriminatorType; private final String explicitDiscriminatorColumnName; private final String discriminatorAlias; @@ -188,7 +178,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { log.debug( "Encountered explicit discriminator mapping for joined inheritance" ); final Selectable selectable = discriminatorMapping.getColumnIterator().next(); - if ( Formula.class.isInstance( selectable ) ) { + if ( selectable instanceof Formula ) { throw new MappingException( "Discriminator formulas on joined inheritance hierarchies not supported at this time" ); } else { @@ -196,7 +186,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { explicitDiscriminatorColumnName = column.getQuotedName( factory.getDialect() ); discriminatorAlias = column.getAlias( factory.getDialect(), persistentClass.getRootTable() ); } - discriminatorType = (DiscriminatorType) persistentClass.getDiscriminator().getType(); + discriminatorType = (DiscriminatorType) persistentClass.getDiscriminator().getType(); if ( persistentClass.isDiscriminatorValueNull() ) { discriminatorValue = NULL_DISCRIMINATOR; discriminatorSQLString = InFragment.NULL; @@ -208,7 +198,10 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { else { try { discriminatorValue = discriminatorType.stringToObject( persistentClass.getDiscriminatorValue() ); - discriminatorSQLString = discriminatorType.objectToSQLString( discriminatorValue, factory.getDialect() ); + discriminatorSQLString = ((DiscriminatorType) discriminatorType).objectToSQLString( + discriminatorValue, + factory.getJdbcServices().getDialect() + ); } catch (ClassCastException cce) { throw new MappingException("Illegal discriminator type: " + discriminatorType.getName() ); @@ -252,27 +245,27 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { ArrayList keyColumnReaders = new ArrayList<>(); ArrayList keyColumnReaderTemplates = new ArrayList<>(); ArrayList cascadeDeletes = new ArrayList<>(); - Iterator tItr = persistentClass.getTableClosureIterator(); - Iterator kItr = persistentClass.getKeyClosureIterator(); + Iterator
tItr = persistentClass.getTableClosureIterator(); + Iterator kItr = persistentClass.getKeyClosureIterator(); while ( tItr.hasNext() ) { - final Table table = (Table) tItr.next(); - final KeyValue key = (KeyValue) kItr.next(); + final Table table = tItr.next(); + final KeyValue key = kItr.next(); final String tableName = determineTableName( table, jdbcEnvironment ); tableNames.add( tableName ); String[] keyCols = new String[idColumnSpan]; String[] keyColReaders = new String[idColumnSpan]; String[] keyColReaderTemplates = new String[idColumnSpan]; - Iterator cItr = key.getColumnIterator(); + Iterator cItr = key.getColumnIterator(); for ( int k = 0; k < idColumnSpan; k++ ) { Column column = (Column) cItr.next(); - keyCols[k] = column.getQuotedName( factory.getDialect() ); - keyColReaders[k] = column.getReadExpr( factory.getDialect() ); - keyColReaderTemplates[k] = column.getTemplate( factory.getDialect(), factory.getQueryEngine().getSqmFunctionRegistry() ); + keyCols[k] = column.getQuotedName( factory.getJdbcServices().getDialect() ); + keyColReaders[k] = column.getReadExpr( factory.getJdbcServices().getDialect() ); + keyColReaderTemplates[k] = column.getTemplate( factory.getJdbcServices().getDialect(), factory.getQueryEngine().getSqmFunctionRegistry() ); } keyColumns.add( keyCols ); keyColumnReaders.add( keyColReaders ); keyColumnReaderTemplates.add( keyColReaderTemplates ); - cascadeDeletes.add( key.isCascadeDeleteEnabled() && factory.getDialect().supportsCascadeDelete() ); + cascadeDeletes.add( key.isCascadeDeleteEnabled() && factory.getJdbcServices().getDialect().supportsCascadeDelete() ); } //Span of the tableNames directly mapped by this entity and super-classes, if any @@ -282,9 +275,9 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { isNullableTable = new boolean[tableSpan]; isInverseTable = new boolean[tableSpan]; - Iterator joinItr = persistentClass.getJoinClosureIterator(); + Iterator joinItr = persistentClass.getJoinClosureIterator(); for ( int tableIndex = 0; joinItr.hasNext(); tableIndex++ ) { - Join join = (Join) joinItr.next(); + Join join = joinItr.next(); isNullableTable[tableIndex] = join.isOptional(); isInverseTable[tableIndex] = join.isInverse(); @@ -300,18 +293,17 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { String[] keyColReaders = new String[joinIdColumnSpan]; String[] keyColReaderTemplates = new String[joinIdColumnSpan]; - Iterator cItr = key.getColumnIterator(); - + Iterator cItr = key.getColumnIterator(); for ( int k = 0; k < joinIdColumnSpan; k++ ) { Column column = (Column) cItr.next(); - keyCols[k] = column.getQuotedName( factory.getDialect() ); - keyColReaders[k] = column.getReadExpr( factory.getDialect() ); - keyColReaderTemplates[k] = column.getTemplate( factory.getDialect(), factory.getQueryEngine().getSqmFunctionRegistry() ); + keyCols[k] = column.getQuotedName( factory.getJdbcServices().getDialect() ); + keyColReaders[k] = column.getReadExpr( factory.getJdbcServices().getDialect() ); + keyColReaderTemplates[k] = column.getTemplate( factory.getJdbcServices().getDialect(), factory.getQueryEngine().getSqmFunctionRegistry() ); } keyColumns.add( keyCols ); keyColumnReaders.add( keyColReaders ); keyColumnReaderTemplates.add( keyColReaderTemplates ); - cascadeDeletes.add( key.isCascadeDeleteEnabled() && factory.getDialect().supportsCascadeDelete() ); + cascadeDeletes.add( key.isCascadeDeleteEnabled() && factory.getJdbcServices().getDialect().supportsCascadeDelete() ); } naturalOrderTableNames = ArrayHelper.toStringArray( tableNames ); @@ -330,7 +322,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { keyColumns = new ArrayList<>(); tItr = persistentClass.getSubclassTableClosureIterator(); while ( tItr.hasNext() ) { - Table tab = (Table) tItr.next(); + Table tab = tItr.next(); isConcretes.add( persistentClass.isClassOrSuperclassTable( tab ) ); isDeferreds.add( Boolean.FALSE ); isLazies.add( Boolean.FALSE ); @@ -339,9 +331,9 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { final String tableName = determineTableName( tab, jdbcEnvironment ); subclassTableNames.add( tableName ); String[] key = new String[idColumnSpan]; - Iterator cItr = tab.getPrimaryKey().getColumnIterator(); + Iterator cItr = tab.getPrimaryKey().getColumnIterator(); for ( int k = 0; k < idColumnSpan; k++ ) { - key[k] = ( (Column) cItr.next() ).getQuotedName( factory.getDialect() ); + key[k] = cItr.next().getQuotedName( factory.getJdbcServices().getDialect() ); } keyColumns.add( key ); } @@ -349,7 +341,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { //Add joins joinItr = persistentClass.getSubclassJoinClosureIterator(); while ( joinItr.hasNext() ) { - final Join join = (Join) joinItr.next(); + final Join join = joinItr.next(); final Table joinTable = join.getTable(); isConcretes.add( persistentClass.isClassOrSuperclassTable( joinTable ) ); @@ -361,9 +353,9 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { String joinTableName = determineTableName( joinTable, jdbcEnvironment ); subclassTableNames.add( joinTableName ); String[] key = new String[idColumnSpan]; - Iterator citer = joinTable.getPrimaryKey().getColumnIterator(); + Iterator citer = joinTable.getPrimaryKey().getColumnIterator(); for ( int k = 0; k < idColumnSpan; k++ ) { - key[k] = ( (Column) citer.next() ).getQuotedName( factory.getDialect() ); + key[k] = citer.next().getQuotedName( factory.getJdbcServices().getDialect() ); } keyColumns.add( key ); } @@ -384,7 +376,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { constraintOrderedKeyColumnNames[currentPosition] = naturalOrderSubclassTableKeyColumnClosure[i]; } - /** + /* * Suppose an entity Client extends Person, mapped to the tableNames CLIENT and PERSON respectively. * For the Client entity: * naturalOrderTableNames -> PERSON, CLIENT; this reflects the sequence in which the tableNames are @@ -450,7 +442,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { joinItr = persistentClass.getJoinClosureIterator(); int j = coreTableSpan; while ( joinItr.hasNext() ) { - Join join = (Join) joinItr.next(); + Join join = joinItr.next(); isInverseTable[j] = join.isInverse(); isNullableTable[j] = join.isOptional(); @@ -477,12 +469,12 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { int hydrateSpan = getPropertySpan(); naturalOrderPropertyTableNumbers = new int[hydrateSpan]; propertyTableNumbers = new int[hydrateSpan]; - Iterator iter = persistentClass.getPropertyClosureIterator(); + Iterator iter = persistentClass.getPropertyClosureIterator(); int i = 0; while ( iter.hasNext() ) { - Property prop = (Property) iter.next(); + Property prop = iter.next(); String tabname = prop.getValue().getTable().getQualifiedName( - factory.getDialect(), + factory.getJdbcServices().getDialect(), factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultSchemaName() ); @@ -495,25 +487,25 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { //TODO: code duplication with SingleTableEntityPersister - ArrayList columnTableNumbers = new ArrayList(); - ArrayList formulaTableNumbers = new ArrayList(); - ArrayList propTableNumbers = new ArrayList(); + ArrayList columnTableNumbers = new ArrayList<>(); + ArrayList formulaTableNumbers = new ArrayList<>(); + ArrayList propTableNumbers = new ArrayList<>(); iter = persistentClass.getSubclassPropertyClosureIterator(); while ( iter.hasNext() ) { - Property prop = (Property) iter.next(); + Property prop = iter.next(); Table tab = prop.getValue().getTable(); String tabname = tab.getQualifiedName( - factory.getDialect(), + factory.getJdbcServices().getDialect(), factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultSchemaName() ); Integer tabnum = getTableId( tabname, subclassTableNameClosure ); propTableNumbers.add( tabnum ); - Iterator citer = prop.getColumnIterator(); + Iterator citer = prop.getColumnIterator(); while ( citer.hasNext() ) { - Selectable thing = (Selectable) citer.next(); + Selectable thing = citer.next(); if ( thing.isFormula() ) { formulaTableNumbers.add( tabnum ); } @@ -552,7 +544,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { notNullColumnTableNumbers = new int[subclassSpan]; final int id = getTableId( table.getQualifiedName( - factory.getDialect(), + factory.getJdbcServices().getDialect(), factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultSchemaName() ), @@ -574,18 +566,18 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { } } else { - subclassNameByTableName = Collections.EMPTY_MAP; - discriminatorValuesByTableName = Collections.EMPTY_MAP; - discriminatorColumnNameByTableName = Collections.EMPTY_MAP; + subclassNameByTableName = emptyMap(); + discriminatorValuesByTableName = emptyMap(); + discriminatorColumnNameByTableName = emptyMap(); discriminatorValues = null; notNullColumnTableNumbers = null; notNullColumnNames = null; } - iter = persistentClass.getSubclassIterator(); + Iterator siter = persistentClass.getSubclassIterator(); int k = 0; - while ( iter.hasNext() ) { - Subclass sc = (Subclass) iter.next(); + while ( siter.hasNext() ) { + Subclass sc = siter.next(); subclassClosure[k] = sc.getEntityName(); final Table table = sc.getTable(); subclassNameByTableName.put( table.getName(), sc.getClassName() ); @@ -621,7 +613,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { subclassesByDiscriminatorValue.put( discriminatorValue, sc.getEntityName() ); int id = getTableId( table.getQualifiedName( - factory.getDialect(), + factory.getJdbcServices().getDialect(), factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultSchemaName() ), @@ -652,7 +644,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { Table table, Object discriminatorValue) { final String tableName = determineTableName( table, jdbcEnvironment ); - final String columnName = table.getPrimaryKey().getColumn( 0 ).getQuotedName( factory.getDialect() ); + final String columnName = table.getPrimaryKey().getColumn( 0 ).getQuotedName( factory.getJdbcServices().getDialect() ); discriminatorValuesByTableName.put( tableName, discriminatorValue ); discriminatorColumnNameByTableName.put( tableName, columnName ); discriminatorValues[k] = discriminatorValue.toString(); @@ -698,8 +690,6 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { * Essentially we are building a mapping that we can later use to determine whether a given "subclass table" * should be included in joins when JPA TREAT-AS is used. * - * @param persistentClass - * @param factory * @return subclassNamesBySubclassTable */ private String[][] buildSubclassNamesBySubclassTableMapping(PersistentClass persistentClass, SessionFactoryImplementor factory) { @@ -725,9 +715,9 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { // included when one of the collected class names is used in TREAT final Set classNames = new HashSet<>(); - final Iterator itr = persistentClass.getDirectSubclasses(); + final Iterator itr = persistentClass.getDirectSubclasses(); while ( itr.hasNext() ) { - final Subclass subclass = (Subclass) itr.next(); + final Subclass subclass = itr.next(); final Set subclassSubclassNames = processPersistentClassHierarchy( subclass, false, @@ -759,18 +749,18 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { SessionFactoryImplementor factory) { final String tableName = persistentClass.getTable().getQualifiedName( - factory.getDialect(), + factory.getJdbcServices().getDialect(), factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultSchemaName() ); associateSubclassNamesToSubclassTableIndex( tableName, classNames, mapping ); - Iterator itr = persistentClass.getJoinIterator(); + Iterator itr = persistentClass.getJoinIterator(); while ( itr.hasNext() ) { - final Join join = (Join) itr.next(); + final Join join = itr.next(); final String secondaryTableName = join.getTable().getQualifiedName( - factory.getDialect(), + factory.getJdbcServices().getDialect(), factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultSchemaName() ); @@ -798,7 +788,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { ) ); } - mapping[index] = classNames.toArray( new String[ classNames.size() ] ); + mapping[index] = ArrayHelper.toStringArray( classNames ); break; } } @@ -881,7 +871,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { } public String getSubclassForDiscriminatorValue(Object value) { - return (String) subclassesByDiscriminatorValue.get( value ); + return subclassesByDiscriminatorValue.get( value ); } @Override @@ -915,9 +905,6 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { /** * Reverse the first n elements of the incoming array * - * @param objects - * @param n - * * @return New array with the first n elements in reversed order */ private static String[] reverse(String[] objects, int n) { @@ -939,9 +926,6 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { /** * Reverse the first n elements of the incoming array * - * @param objects - * @param n - * * @return New array with the first n elements in reversed order */ private static String[][] reverse(String[][] objects, int n) { @@ -991,7 +975,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { } private CaseFragment discriminatorFragment(String alias) { - CaseFragment cases = getFactory().getDialect().createCaseFragment(); + CaseFragment cases = getFactory().getJdbcServices().getDialect().createCaseFragment(); for ( int i = 0; i < discriminatorValues.length; i++ ) { cases.addWhenColumnNotNull( @@ -1270,7 +1254,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { bootEntityDescriptor.getIdentifierProperty().getName(), getTableName(), tableKeyColumns[0][0], - (BasicType) idType, + (BasicType) idType, creationProcess ); } @@ -1336,7 +1320,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { getDiscriminatorFormulaTemplate() != null, info.caseSearchedExpression, info.columnReferences, - (BasicType) getDiscriminatorType() + (BasicType) getDiscriminatorType() ); } else { @@ -1354,9 +1338,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { consumer.consume( tableName, - () -> columnConsumer -> { - columnConsumer.accept(tableName, constraintOrderedKeyColumnNames[tablePosition]); - } + () -> columnConsumer -> columnConsumer.accept( tableName, constraintOrderedKeyColumnNames[tablePosition] ) ); } } @@ -1370,10 +1352,10 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { CaseSearchedExpressionInfo info = new CaseSearchedExpressionInfo(); final TableReference primaryTableReference = entityTableGroup.getPrimaryTableReference(); - final BasicType discriminatorType = (BasicType) getDiscriminatorType(); + final BasicType discriminatorType = (BasicType) getDiscriminatorType(); final CaseSearchedExpression caseSearchedExpression = new CaseSearchedExpression( discriminatorType ); - Boolean addPrimaryTableCaseAsLastCaseExpression = false; + boolean addPrimaryTableCaseAsLastCaseExpression = false; for ( String tableName : discriminatorValuesByTableName.keySet() ) { if ( !primaryTableReference.getTableExpression().equals( tableName ) ) { TableReference tableReference = entityTableGroup.getTableReference( tableName ); @@ -1414,7 +1396,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { CaseSearchedExpression caseSearchedExpression, TableReference table, ColumnReference identifierColumnReference, - BasicType resultType) { + BasicType resultType) { final Predicate predicate = new NullnessPredicate( identifierColumnReference, true ); final Expression expression = new QueryLiteral<>( discriminatorValuesByTableName.get( table.getTableExpression() ), diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java index 9cc6df0549..a1d610ef1b 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java @@ -8,7 +8,6 @@ package org.hibernate.persister.entity; import java.io.Serializable; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -61,6 +60,8 @@ import org.hibernate.type.BasicType; import org.hibernate.type.DiscriminatorType; import org.hibernate.type.Type; +import static java.util.Collections.emptyMap; + /** * The default implementation of the EntityPersister interface. * Implements the "table-per-class-hierarchy" or "roll-up" mapping strategy @@ -113,7 +114,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { private final String discriminatorFormula; private final String discriminatorFormulaTemplate; private final String discriminatorAlias; - private final Type discriminatorType; + private final DiscriminatorType discriminatorType; private final Object discriminatorValue; private final String discriminatorSQLValue; private final boolean discriminatorInsertable; @@ -129,8 +130,6 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { private static final Object NULL_DISCRIMINATOR = new MarkerObject( "" ); private static final Object NOT_NULL_DISCRIMINATOR = new MarkerObject( "" ); - private static final String NULL_STRING = "null"; - private static final String NOT_NULL_STRING = "not null"; //INITIALIZATION: @@ -191,15 +190,15 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { // JOINS - Iterator joinIter = persistentClass.getJoinClosureIterator(); + Iterator joinIter = persistentClass.getJoinClosureIterator(); int j = 1; while ( joinIter.hasNext() ) { - Join join = (Join) joinIter.next(); + Join join = joinIter.next(); qualifiedTableNames[j] = determineTableName( join.getTable(), jdbcEnvironment ); isInverseTable[j] = join.isInverse(); isNullableTable[j] = join.isOptional(); cascadeDeleteEnabled[j] = join.getKey().isCascadeDeleteEnabled() && - factory.getDialect().supportsCascadeDelete(); + factory.getJdbcServices().getDialect().supportsCascadeDelete(); customSQLInsert[j] = join.getCustomSQLInsert(); insertCallable[j] = customSQLInsert[j] != null && join.isCustomInsertCallable(); @@ -217,12 +216,12 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLDelete[j], deleteCallable[j] ) : join.getCustomSQLDeleteCheckStyle(); - Iterator iter = join.getKey().getColumnIterator(); + Iterator iter = join.getKey().getColumnIterator(); keyColumnNames[j] = new String[join.getKey().getColumnSpan()]; int i = 0; while ( iter.hasNext() ) { Column col = (Column) iter.next(); - keyColumnNames[j][i++] = col.getQuotedName( factory.getDialect() ); + keyColumnNames[j][i++] = col.getQuotedName( factory.getJdbcServices().getDialect() ); } j++; @@ -261,7 +260,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { isLazies.add( Boolean.FALSE ); joinIter = persistentClass.getSubclassJoinClosureIterator(); while ( joinIter.hasNext() ) { - Join join = (Join) joinIter.next(); + Join join = joinIter.next(); isConcretes.add( persistentClass.isClassOrSuperclassTable( join.getTable() ) ); isClassOrSuperclassJoins.add( persistentClass.isClassOrSuperclassJoin( join ) ); isInverses.add( join.isInverse() ); @@ -275,12 +274,12 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { String joinTableName = determineTableName( join.getTable(), jdbcEnvironment ); subclassTables.add( joinTableName ); - Iterator iter = join.getKey().getColumnIterator(); + Iterator iter = join.getKey().getColumnIterator(); String[] keyCols = new String[join.getKey().getColumnSpan()]; int i = 0; while ( iter.hasNext() ) { Column col = (Column) iter.next(); - keyCols[i++] = col.getQuotedName( factory.getDialect() ); + keyCols[i++] = col.getQuotedName( factory.getJdbcServices().getDialect() ); } joinKeyColumns.add( keyCols ); } @@ -295,7 +294,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { isNullableSubclassTable = ArrayHelper.toBooleanArray( isNullables ); hasSequentialSelects = hasDeferred; - this.sequentialSelectStringsByEntityName = hasSequentialSelects ? new HashMap<>() : Collections.EMPTY_MAP; + sequentialSelectStringsByEntityName = hasSequentialSelects ? new HashMap<>() : emptyMap(); // DISCRIMINATOR @@ -310,7 +309,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { Formula formula = (Formula) selectable; discriminatorFormula = formula.getFormula(); discriminatorFormulaTemplate = formula.getTemplate( - factory.getDialect(), + factory.getJdbcServices().getDialect(), factory.getQueryEngine().getSqmFunctionRegistry() ); discriminatorColumnName = null; @@ -320,17 +319,17 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { } else { Column column = (Column) selectable; - discriminatorColumnName = column.getQuotedName( factory.getDialect() ); - discriminatorColumnReaders = column.getReadExpr( factory.getDialect() ); + discriminatorColumnName = column.getQuotedName( factory.getJdbcServices().getDialect() ); + discriminatorColumnReaders = column.getReadExpr( factory.getJdbcServices().getDialect() ); discriminatorColumnReaderTemplate = column.getTemplate( - factory.getDialect(), + factory.getJdbcServices().getDialect(), factory.getQueryEngine().getSqmFunctionRegistry() ); - discriminatorAlias = column.getAlias( factory.getDialect(), persistentClass.getRootTable() ); + discriminatorAlias = column.getAlias( factory.getJdbcServices().getDialect(), persistentClass.getRootTable() ); discriminatorFormula = null; discriminatorFormulaTemplate = null; } - discriminatorType = persistentClass.getDiscriminator().getType(); + discriminatorType = (DiscriminatorType) persistentClass.getDiscriminator().getType(); if ( persistentClass.isDiscriminatorValueNull() ) { discriminatorValue = NULL_DISCRIMINATOR; discriminatorSQLValue = InFragment.NULL; @@ -344,9 +343,8 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { else { discriminatorInsertable = persistentClass.isDiscriminatorInsertable() && !discrimValue.hasFormula(); try { - DiscriminatorType dtype = (DiscriminatorType) discriminatorType; - discriminatorValue = dtype.stringToObject( persistentClass.getDiscriminatorValue() ); - discriminatorSQLValue = dtype.objectToSQLString( discriminatorValue, factory.getDialect() ); + discriminatorValue = discriminatorType.stringToObject( persistentClass.getDiscriminatorValue() ); + discriminatorSQLValue = ((DiscriminatorType) discriminatorType).objectToSQLString( discriminatorValue, factory.getJdbcServices().getDialect() ); } catch (ClassCastException cce) { throw new MappingException( "Illegal discriminator type: " + discriminatorType.getName() ); @@ -373,10 +371,10 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { // PROPERTIES propertyTableNumbers = new int[getPropertySpan()]; - Iterator iter = persistentClass.getPropertyClosureIterator(); + Iterator props = persistentClass.getPropertyClosureIterator(); int i = 0; - while ( iter.hasNext() ) { - Property prop = (Property) iter.next(); + while ( props.hasNext() ) { + Property prop = props.next(); propertyTableNumbers[i++] = persistentClass.getJoinNumber( prop ); } @@ -390,9 +388,9 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { final HashMap propertyTableNumbersByNameAndSubclassLocal = new HashMap<>(); final Map subclassesByDiscriminatorValueLocal = new HashMap<>(); - iter = persistentClass.getSubclassPropertyClosureIterator(); + Iterator iter = persistentClass.getSubclassPropertyClosureIterator(); while ( iter.hasNext() ) { - Property prop = (Property) iter.next(); + Property prop = iter.next(); Integer join = persistentClass.getJoinNumber( prop ); propertyJoinNumbers.add( join ); @@ -402,9 +400,9 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { join ); - Iterator citer = prop.getColumnIterator(); + Iterator citer = prop.getColumnIterator(); while ( citer.hasNext() ) { - Selectable thing = (Selectable) citer.next(); + Selectable thing = citer.next(); if ( thing.isFormula() ) { formulaJoinedNumbers.add( join ); } @@ -429,10 +427,10 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { // SUBCLASSES if ( persistentClass.isPolymorphic() ) { - iter = persistentClass.getSubclassIterator(); + Iterator subclasses = persistentClass.getSubclassIterator(); int k = 1; - while ( iter.hasNext() ) { - Subclass sc = (Subclass) iter.next(); + while ( subclasses.hasNext() ) { + Subclass sc = subclasses.next(); subclassClosure[k++] = sc.getEntityName(); if ( sc.isDiscriminatorValueNull() ) { addSubclassByDiscriminatorValue( subclassesByDiscriminatorValueLocal, NULL_DISCRIMINATOR, sc.getEntityName() ); @@ -442,10 +440,9 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { } else { try { - DiscriminatorType dtype = (DiscriminatorType) discriminatorType; addSubclassByDiscriminatorValue( subclassesByDiscriminatorValueLocal, - dtype.stringToObject( sc.getDiscriminatorValue() ), + discriminatorType.stringToObject( sc.getDiscriminatorValue() ), sc.getEntityName() ); } @@ -652,7 +649,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { private String[] decodeTreatAsRequests(Set treatAsDeclarations) { final List values = new ArrayList<>(); for ( String subclass : treatAsDeclarations ) { - final Queryable queryable = (Queryable) getFactory().getEntityPersister( subclass ); + final Queryable queryable = (Queryable) getFactory().getMetamodel().entityPersister( subclass ); if ( !queryable.isAbstract() ) { values.add( queryable.getDiscriminatorSQLValue() ); } @@ -665,14 +662,14 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { continue; } - Queryable actualQueryable = (Queryable) getFactory().getEntityPersister( actualSubClass ); + Queryable actualQueryable = (Queryable) getFactory().getMetamodel().entityPersister( actualSubClass ); if ( !actualQueryable.hasSubclasses() ) { values.add( actualQueryable.getDiscriminatorSQLValue() ); } } } } - return values.toArray( new String[values.size()] ); + return ArrayHelper.toStringArray( values ); } private String[] fullDiscriminatorValues; @@ -682,12 +679,12 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { // first access; build it final List values = new ArrayList<>(); for ( String subclass : getSubclassClosure() ) { - final Queryable queryable = (Queryable) getFactory().getEntityPersister( subclass ); + final Queryable queryable = (Queryable) getFactory().getMetamodel().entityPersister( subclass ); if ( !queryable.isAbstract() ) { values.add( queryable.getDiscriminatorSQLValue() ); } } - fullDiscriminatorValues = values.toArray( new String[values.size()] ); + fullDiscriminatorValues = ArrayHelper.toStringArray( values ); } return fullDiscriminatorValues; @@ -870,7 +867,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { if ( hasSequentialSelects ) { String[] entityNames = getSubclassClosure(); for ( int i = 1; i < entityNames.length; i++ ) { - Loadable loadable = (Loadable) getFactory().getEntityPersister( entityNames[i] ); + Loadable loadable = (Loadable) getFactory().getMetamodel().entityPersister( entityNames[i] ); if ( !loadable.isAbstract() ) { //perhaps not really necessary... String sequentialSelect = generateSequentialSelect( loadable ); sequentialSelectStringsByEntityName.put( entityNames[i], sequentialSelect ); @@ -980,9 +977,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { consumer.consume( tableName, - () -> columnConsumer -> { - columnConsumer.accept(tableName, constraintOrderedKeyColumnNames[tablePosition]); - } + () -> columnConsumer -> columnConsumer.accept( tableName, constraintOrderedKeyColumnNames[tablePosition] ) ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java index 5854783bbc..014a2b00f4 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java @@ -72,7 +72,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { private final String[] subclassSpaces; private final Object discriminatorValue; private final String discriminatorSQLValue; - private final Map subclassByDiscriminatorValue = new HashMap(); + private final Map subclassByDiscriminatorValue = new HashMap<>(); private final String[] constraintOrderedTableNames; private final String[][] constraintOrderedKeyColumnNames; @@ -145,8 +145,6 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { // PROPERTIES - int subclassSpan = persistentClass.getSubclassSpan() + 1; - // SUBCLASSES subclassByDiscriminatorValue.put( persistentClass.getSubclassId(), @@ -172,7 +170,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { spaces[i] = iter.next(); } - HashSet subclassTables = new HashSet(); + HashSet subclassTables = new HashSet<>(); Iterator
subclassTableIter = persistentClass.getSubclassTableClosureIterator(); while ( subclassTableIter.hasNext() ) { subclassTables.add( determineTableName( subclassTableIter.next(), jdbcEnvironment ) ); @@ -194,7 +192,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { String[] key = new String[idColumnSpan]; Iterator citer = tab.getPrimaryKey().getColumnIterator(); for ( int k = 0; k < idColumnSpan; k++ ) { - key[k] = citer.next().getQuotedName( factory.getDialect() ); + key[k] = citer.next().getQuotedName( factory.getJdbcServices().getDialect() ); } keyColumns.add( key ); } @@ -285,7 +283,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { @Override public String getSubclassForDiscriminatorValue(Object value) { - return (String) subclassByDiscriminatorValue.get( value ); + return subclassByDiscriminatorValue.get( value ); } @Override @@ -383,9 +381,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { consumer.consume( tableName, - () -> columnConsumer -> { - columnConsumer.accept(tableName, constraintOrderedKeyColumnNames[tablePosition]); - } + () -> columnConsumer -> columnConsumer.accept( tableName, constraintOrderedKeyColumnNames[tablePosition] ) ); } } @@ -424,7 +420,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { protected String generateSubquery(PersistentClass model, Mapping mapping) { - Dialect dialect = getFactory().getDialect(); + Dialect dialect = getFactory().getJdbcServices().getDialect(); Settings settings = getFactory().getSettings(); if ( !model.hasSubclasses() ) { @@ -435,12 +431,12 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { ); } - HashSet columns = new LinkedHashSet(); - Iterator titer = model.getSubclassTableClosureIterator(); + HashSet columns = new LinkedHashSet<>(); + Iterator
titer = model.getSubclassTableClosureIterator(); while ( titer.hasNext() ) { - Table table = (Table) titer.next(); + Table table = titer.next(); if ( !table.isAbstractUnionTable() ) { - Iterator citer = table.getColumnIterator(); + Iterator citer = table.getColumnIterator(); while ( citer.hasNext() ) { columns.add( citer.next() ); } @@ -450,27 +446,25 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { StringBuilder buf = new StringBuilder() .append( "( " ); - Iterator siter = new JoinedIterator( - new SingletonIterator( model ), + Iterator siter = new JoinedIterator<>( + new SingletonIterator<>( model ), model.getSubclassIterator() ); while ( siter.hasNext() ) { - PersistentClass clazz = (PersistentClass) siter.next(); + PersistentClass clazz = siter.next(); Table table = clazz.getTable(); if ( !table.isAbstractUnionTable() ) { //TODO: move to .sql package!! buf.append( "select " ); - Iterator citer = columns.iterator(); - while ( citer.hasNext() ) { - Column col = (Column) citer.next(); - if ( !table.containsColumn( col ) ) { - int sqlType = col.getSqlTypeCode( mapping ); - buf.append( dialect.getSelectClauseNullString( sqlType ) ) - .append( " as " ); + for ( Column col : columns ) { + if ( !table.containsColumn(col) ) { + int sqlType = col.getSqlTypeCode(mapping); + buf.append( dialect.getSelectClauseNullString(sqlType) ) + .append(" as "); } - buf.append( col.getQuotedName( dialect ) ); - buf.append( ", " ); + buf.append(col.getQuotedName(dialect)); + buf.append(", "); } buf.append( clazz.getSubclassId() ) .append( " as clazz_" ); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/AbstractLiteral.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/AbstractLiteral.java index 15289c8eff..9c26d24e7d 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/AbstractLiteral.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/AbstractLiteral.java @@ -69,8 +69,7 @@ public abstract class AbstractLiteral .getTypeConfiguration() ); - //noinspection unchecked - return new BasicResult<>( + return new BasicResult( sqlSelection.getValuesArrayPosition(), resultVariable, type.getMappedType().getMappedJavaTypeDescriptor() diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/QueryLiteral.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/QueryLiteral.java index b870b247c6..2af9af69c5 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/QueryLiteral.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/QueryLiteral.java @@ -73,8 +73,7 @@ public class QueryLiteral implements Literal, DomainResultProducer { .getTypeConfiguration() ); - //noinspection unchecked - return new BasicResult<>( + return new BasicResult( sqlSelection.getValuesArrayPosition(), resultVariable, type.getMappedType().getMappedJavaTypeDescriptor() diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/domain/CircularBiDirectionalFetchImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/domain/CircularBiDirectionalFetchImpl.java index fb09b2ad53..a6bc779d10 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/domain/CircularBiDirectionalFetchImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/domain/CircularBiDirectionalFetchImpl.java @@ -135,7 +135,7 @@ public class CircularBiDirectionalFetchImpl implements BiDirectionalFetch, Assoc } @Override - public JavaTypeDescriptor getJavaTypeDescriptor() { + public JavaTypeDescriptor getJavaTypeDescriptor() { return fetchable.getJavaTypeDescriptor(); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/domain/CircularFetchImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/domain/CircularFetchImpl.java index e6127fd797..6dca813a4d 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/domain/CircularFetchImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/domain/CircularFetchImpl.java @@ -172,7 +172,7 @@ public class CircularFetchImpl implements BiDirectionalFetch, Association { } @Override - public JavaTypeDescriptor getJavaTypeDescriptor() { + public JavaTypeDescriptor getJavaTypeDescriptor() { return fetchable.getJavaTypeDescriptor(); } diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java index e92446a197..e486467025 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java @@ -123,7 +123,7 @@ public class EntityMetamodel implements Serializable { private final boolean explicitPolymorphism; private final boolean inherited; private final boolean hasSubclasses; - private final Set subclassEntityNames; + private final Set subclassEntityNames; private final Map entityNameByInheritenceClassMap; private final BytecodeEnhancementMetadata bytecodeEnhancementMetadata; @@ -154,7 +154,6 @@ public class EntityMetamodel implements Serializable { if ( identifierMapperComponent != null ) { nonAggregatedCidMapper = (CompositeType) identifierMapperComponent.getType(); idAttributeNames = new HashSet<>( ); - //noinspection unchecked final Iterator propertyItr = identifierMapperComponent.getPropertyIterator(); while ( propertyItr.hasNext() ) { idAttributeNames.add( propertyItr.next().getName() ); @@ -205,7 +204,7 @@ public class EntityMetamodel implements Serializable { boolean foundPostUpdateGeneratedValues = false; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Iterator iter = persistentClass.getPropertyClosureIterator(); + Iterator props = persistentClass.getPropertyClosureIterator(); int i = 0; int tempVersionProperty = NO_VERSION_INDX; boolean foundCascade = false; @@ -214,8 +213,8 @@ public class EntityMetamodel implements Serializable { boolean foundNonIdentifierPropertyNamedId = false; boolean foundUpdateableNaturalIdProperty = false; - while ( iter.hasNext() ) { - Property prop = ( Property ) iter.next(); + while ( props.hasNext() ) { + Property prop = props.next(); if ( prop == persistentClass.getVersion() ) { tempVersionProperty = i; @@ -404,7 +403,7 @@ public class EntityMetamodel implements Serializable { hasCollections = foundCollection; mutablePropertiesIndexes = mutableIndexes; - iter = persistentClass.getSubclassIterator(); + Iterator iter = persistentClass.getSubclassIterator(); final Set subclassEntityNamesLocal = new HashSet<>(); while ( iter.hasNext() ) { subclassEntityNamesLocal.add( ( (PersistentClass) iter.next() ).getEntityName() ); @@ -803,7 +802,7 @@ public class EntityMetamodel implements Serializable { return hasImmutableNaturalId; } - public Set getSubclassEntityNames() { + public Set getSubclassEntityNames() { return subclassEntityNames; } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/PersistentClassGraphDefiner.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/PersistentClassGraphDefiner.java index 7e0f65cc54..de8823c562 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/PersistentClassGraphDefiner.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/PersistentClassGraphDefiner.java @@ -38,27 +38,24 @@ public class PersistentClassGraphDefiner implements GraphDefiner neighbours, Iterator subclassIterator) { + private void addNeighbours(List neighbours, Iterator subclassIterator) { while ( subclassIterator.hasNext() ) { final PersistentClass subclass = subclassIterator.next(); neighbours.add( subclass ); - addNeighbours( neighbours, (Iterator) subclass.getSubclassIterator() ); + addNeighbours( neighbours, subclass.getSubclassIterator() ); } } @Override - @SuppressWarnings({"unchecked"}) public List getNeighbours(PersistentClass pc) { final List neighbours = new ArrayList<>(); - addNeighbours( neighbours, (Iterator) pc.getSubclassIterator() ); + addNeighbours( neighbours, pc.getSubclassIterator() ); return neighbours; } @Override - @SuppressWarnings({"unchecked"}) public List getValues() { return Tools.collectionToList( metadata.getEntityBindings() ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/CollectionMetadataGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/CollectionMetadataGenerator.java index a58334bca0..0d502b3956 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/CollectionMetadataGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/CollectionMetadataGenerator.java @@ -70,6 +70,7 @@ import org.hibernate.envers.internal.tools.Tools; import org.hibernate.mapping.Collection; import org.hibernate.mapping.Component; import org.hibernate.mapping.IndexedCollection; +import org.hibernate.mapping.KeyValue; import org.hibernate.mapping.ManyToOne; import org.hibernate.mapping.OneToMany; import org.hibernate.mapping.PersistentClass; @@ -1012,9 +1013,8 @@ public final class CollectionMetadataGenerator { return null; } - @SuppressWarnings({"unchecked"}) private String searchMappedByKey(PersistentClass referencedClass, Collection collectionValue) { - final Iterator assocIdClassProps = referencedClass.getKeyClosureIterator(); + final Iterator assocIdClassProps = referencedClass.getKeyClosureIterator(); while ( assocIdClassProps.hasNext() ) { final Value value = assocIdClassProps.next(); // make sure its a 'Component' because IdClass is registered as this type.