From dcd7ebbb5648968228c21de6db7070e52da9ac69 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Mon, 31 Jan 2022 19:07:17 +0100 Subject: [PATCH] clean up some warnings use Metadata instead of deprecated Mapping (I'm not sure that's really an improvement) --- .../org/hibernate/metadata/ClassMetadata.java | 4 ++- .../AbstractCollectionPersister.java | 4 +-- .../CompositeElementPropertyMapping.java | 6 ++-- .../entity/AbstractEntityPersister.java | 31 +++++++++---------- .../entity/AbstractPropertyMapping.java | 11 ++++--- .../entity/JoinedSubclassEntityPersister.java | 12 +++---- .../hibernate/persister/entity/Queryable.java | 4 ++- .../entity/SingleTableEntityPersister.java | 7 +++-- .../entity/UnionSubclassEntityPersister.java | 12 +++---- .../internal/StandardTableExporter.java | 1 - 10 files changed, 48 insertions(+), 44 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metadata/ClassMetadata.java b/hibernate-core/src/main/java/org/hibernate/metadata/ClassMetadata.java index 0aa792d32d..bb70620c04 100644 --- a/hibernate-core/src/main/java/org/hibernate/metadata/ClassMetadata.java +++ b/hibernate-core/src/main/java/org/hibernate/metadata/ClassMetadata.java @@ -201,7 +201,9 @@ public interface ClassMetadata { * @deprecated Use {@link #getIdentifier(Object,SharedSessionContractImplementor)} instead */ @Deprecated - Object getIdentifier(Object object) throws HibernateException; + default Object getIdentifier(Object object) throws HibernateException { + return getIdentifier( object, null ); + } /** * Get the identifier of an instance (throw an exception if no identifier property) diff --git a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java index 1dda8b347e..36cb8df645 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java @@ -613,8 +613,8 @@ public abstract class AbstractCollectionPersister elementColumnReaderTemplates, elementFormulaTemplates, (CompositeType) elementType, - factory - ); + creationContext.getMetadata() + ); } else if ( !elementType.isEntityType() ) { elementPropertyMapping = new ElementPropertyMapping( diff --git a/hibernate-core/src/main/java/org/hibernate/persister/collection/CompositeElementPropertyMapping.java b/hibernate-core/src/main/java/org/hibernate/persister/collection/CompositeElementPropertyMapping.java index 8a40c77cc3..bde68b042e 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/collection/CompositeElementPropertyMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/collection/CompositeElementPropertyMapping.java @@ -6,7 +6,7 @@ */ package org.hibernate.persister.collection; import org.hibernate.MappingException; -import org.hibernate.engine.spi.Mapping; +import org.hibernate.boot.Metadata; import org.hibernate.persister.entity.AbstractPropertyMapping; import org.hibernate.type.CompositeType; import org.hibernate.type.Type; @@ -24,13 +24,13 @@ public class CompositeElementPropertyMapping extends AbstractPropertyMapping { String[] elementColumnReaderTemplates, String[] elementFormulaTemplates, CompositeType compositeType, - Mapping factory) + Metadata factory) throws MappingException { this.compositeType = compositeType; initComponentPropertyPaths(null, compositeType, elementColumns, elementColumnReaders, - elementColumnReaderTemplates, elementFormulaTemplates, factory); + elementColumnReaderTemplates, elementFormulaTemplates, factory ); } 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 4ed6ee3a92..38611db23c 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 @@ -45,6 +45,7 @@ import org.hibernate.QueryException; import org.hibernate.Session; import org.hibernate.StaleObjectStateException; import org.hibernate.StaleStateException; +import org.hibernate.boot.Metadata; import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer; import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor; @@ -85,7 +86,6 @@ import org.hibernate.engine.spi.EntityEntryFactory; import org.hibernate.engine.spi.EntityKey; import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; import org.hibernate.engine.spi.LoadQueryInfluencers; -import org.hibernate.engine.spi.Mapping; import org.hibernate.engine.spi.NaturalIdResolutions; import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.PersistentAttributeInterceptable; @@ -2694,7 +2694,7 @@ public abstract class AbstractEntityPersister return sqlWhereStringTemplate != null; } - private void initOrdinaryPropertyPaths(Mapping mapping) throws MappingException { + private void initOrdinaryPropertyPaths(Metadata mapping) throws MappingException { for ( int i = 0; i < getSubclassPropertyNameClosure().length; i++ ) { propertyMapping.initPropertyPaths( getSubclassPropertyNameClosure()[i], @@ -2708,7 +2708,7 @@ public abstract class AbstractEntityPersister } } - private void initIdentifierPropertyPaths(Mapping mapping) throws MappingException { + private void initIdentifierPropertyPaths(Metadata mapping) throws MappingException { String idProp = getIdentifierPropertyName(); if ( idProp != null ) { propertyMapping.initPropertyPaths( @@ -2730,7 +2730,7 @@ public abstract class AbstractEntityPersister } } - private void initDiscriminatorPropertyPath() { + private void initDiscriminatorPropertyPath(Metadata mapping) { propertyMapping.initPropertyPaths( ENTITY_CLASS, getDiscriminatorType(), @@ -2738,16 +2738,16 @@ public abstract class AbstractEntityPersister new String[] {getDiscriminatorColumnReaders()}, new String[] {getDiscriminatorColumnReaderTemplate()}, new String[] {getDiscriminatorFormulaTemplate()}, - getFactory() + mapping ); } - protected void initPropertyPaths(Mapping mapping) throws MappingException { + protected void initPropertyPaths(Metadata mapping) throws MappingException { initOrdinaryPropertyPaths( mapping ); initOrdinaryPropertyPaths( mapping ); //do two passes, for collection property-ref! initIdentifierPropertyPaths( mapping ); if ( entityMetamodel.isPolymorphic() ) { - initDiscriminatorPropertyPath(); + initDiscriminatorPropertyPath( mapping ); } } @@ -4054,7 +4054,7 @@ public abstract class AbstractEntityPersister * * @throws MappingException Indicates a problem accessing the Mapping */ - protected void postConstruct(Mapping mapping) throws MappingException { + protected void postConstruct(Metadata mapping) throws MappingException { initPropertyPaths( mapping ); //doLateInit(); @@ -5054,11 +5054,6 @@ public abstract class AbstractEntityPersister return getPropertyValue( baseValue, baseValueType, propertyName, nextDotIndex ); } - @Override @Deprecated - public Object getIdentifier(Object object) { - return getIdentifier( object, null ); - } - @Override public Object getIdentifier(Object entity, SharedSessionContractImplementor session) { return identifierMapping.getIdentifier( entity ); @@ -5160,8 +5155,12 @@ public abstract class AbstractEntityPersister } } - @Override @Deprecated + @Override @Deprecated(since = "6.0") public boolean isMultiTable() { + return hasMultipleTables(); + } + + protected boolean hasMultipleTables() { return false; } @@ -5585,7 +5584,7 @@ public abstract class AbstractEntityPersister } ); - boolean needsMultiTableInsert = isMultiTable(); + boolean needsMultiTableInsert = hasMultipleTables(); if ( needsMultiTableInsert ) { creationProcess.registerInitializationCallback( "Entity(" + getEntityName() + ") `sqmMultiTableMutationStrategy` interpretation", @@ -5741,7 +5740,7 @@ public abstract class AbstractEntityPersister protected static SqmMultiTableMutationStrategy interpretSqmMultiTableStrategy( AbstractEntityPersister entityMappingDescriptor, MappingModelCreationProcess creationProcess) { - assert entityMappingDescriptor.isMultiTable(); + assert entityMappingDescriptor.hasMultipleTables(); EntityMappingType superMappingType = entityMappingDescriptor.getSuperMappingType(); if ( superMappingType != null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractPropertyMapping.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractPropertyMapping.java index c29d40402e..422183ceca 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractPropertyMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractPropertyMapping.java @@ -13,6 +13,7 @@ import java.util.Set; import org.hibernate.MappingException; import org.hibernate.QueryException; +import org.hibernate.boot.Metadata; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.engine.spi.Mapping; import org.hibernate.internal.CoreLogging; @@ -134,7 +135,7 @@ public abstract class AbstractPropertyMapping implements PropertyMapping { String[] columnReaders, String[] columnReaderTemplates, String[] formulaTemplates, - Mapping factory) { + Metadata factory) { Type existingType = typesByPropertyPath.get( path ); if ( existingType != null || ( duplicateIncompatiblePaths != null && duplicateIncompatiblePaths.contains( path ) ) ) { // If types match or the new type is not an association type, there is nothing for us to do @@ -265,7 +266,7 @@ public abstract class AbstractPropertyMapping implements PropertyMapping { String[] columnReaders, String[] columnReaderTemplates, final String[] formulaTemplates, - final Mapping factory) throws MappingException { + final Metadata factory) throws MappingException { assert columns != null : "Incoming columns should not be null : " + path; assert type != null : "Incoming type should not be null : " + path; @@ -344,7 +345,7 @@ public abstract class AbstractPropertyMapping implements PropertyMapping { final String[] columns, final String[] columnReaders, final String[] columnReaderTemplates, - final Mapping factory) throws MappingException { + final Metadata factory) throws MappingException { initIdentifierPropertyPaths(path, etype, columns, columnReaders, columnReaderTemplates, null, factory); } @@ -355,7 +356,7 @@ public abstract class AbstractPropertyMapping implements PropertyMapping { final String[] columnReaders, final String[] columnReaderTemplates, final String[] formulaTemplates, - final Mapping factory) throws MappingException { + final Metadata factory) throws MappingException { Type idtype = etype.getIdentifierOrUniqueKeyType( factory ); String idPropName = etype.getIdentifierOrUniqueKeyPropertyName( factory ); @@ -398,7 +399,7 @@ public abstract class AbstractPropertyMapping implements PropertyMapping { final String[] columnReaders, final String[] columnReaderTemplates, final String[] formulaTemplates, - final Mapping factory) throws MappingException { + final Metadata factory) throws MappingException { Type[] types = type.getSubtypes(); String[] properties = type.getPropertyNames(); 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 4dd9d433b6..9c7489f67b 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 @@ -510,14 +510,14 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { propTableNumbers.add( tableNumber ); for ( Selectable selectable : property.getSelectables() ) { - if ( selectable.isFormula() ) { -// formulaTableNumbers.add( tableNumber ); - } - else { + if ( !selectable.isFormula() ) { columnTableNumbers.add( tableNumber ); Column column = (Column) selectable; columns.add( column.getQuotedName( dialect ) ); } +// else { +// formulaTableNumbers.add( tableNumber ); +// } } } @@ -1009,8 +1009,8 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { return tableSpan; } - @Override @Deprecated - public boolean isMultiTable() { + @Override + protected boolean hasMultipleTables() { return true; } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/Queryable.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/Queryable.java index 9aaba68159..4d5e91d67b 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/Queryable.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/Queryable.java @@ -50,7 +50,9 @@ public interface Queryable extends Loadable, PropertyMapping, Joinable { * @deprecated Use {@link EntityPersister#getSqmMultiTableMutationStrategy} instead */ @Deprecated(since = "6.0") - boolean isMultiTable(); + default boolean isMultiTable() { + return false; + } /** * Get the names of all tables used in the hierarchy (up and down) ordered such 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 1a90a881eb..aaa3116450 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 @@ -649,6 +649,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { private String[] decodeTreatAsRequests(Set treatAsDeclarations) { final List values = new ArrayList<>(); for ( String subclass : treatAsDeclarations ) { + //TODO: move getDiscriminatorSQLValue() to Loadable to get rid of Queryable final Queryable queryable = (Queryable) getFactory() .getRuntimeMetamodels() .getMappingMetamodel() @@ -707,7 +708,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { // first access; build it final List values = new ArrayList<>(); for ( String subclass : getSubclassClosure() ) { - final Queryable queryable = (Queryable) getFactory().getRuntimeMetamodels() + final Loadable queryable = (Loadable) getFactory().getRuntimeMetamodels() .getMappingMetamodel() .getEntityDescriptor( subclass ); if ( !queryable.isAbstract() ) { @@ -795,8 +796,8 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { return index == null ? null : qualifiedTableNames[propertyTableNumbers[index]]; } - @Override @Deprecated - public boolean isMultiTable() { + @Override + protected boolean hasMultipleTables() { return getTableSpan() > 1; } 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 09694164c9..52beaf4b8d 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 @@ -23,12 +23,12 @@ import java.util.function.Supplier; import org.hibernate.AssertionFailure; import org.hibernate.HibernateException; import org.hibernate.MappingException; +import org.hibernate.boot.Metadata; import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.cache.spi.access.EntityDataAccess; import org.hibernate.cache.spi.access.NaturalIdDataAccess; import org.hibernate.dialect.Dialect; import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; -import org.hibernate.engine.spi.Mapping; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.id.IdentityGenerator; import org.hibernate.internal.FilterAliasGenerator; @@ -212,7 +212,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { } subclassTableExpressions = ArrayHelper.toStringArray( tableExpressions ); - if ( isMultiTable() ) { + if ( hasMultipleTables() ) { int idColumnSpan = getIdentifierColumnSpan(); ArrayList tableNames = new ArrayList<>(); ArrayList keyColumns = new ArrayList<>(); @@ -374,8 +374,8 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { return 0; } - @Override @Deprecated - public boolean isMultiTable() { + @Override + protected boolean hasMultipleTables() { // This could also just be true all the time... return isAbstract() || hasSubclasses(); } @@ -429,7 +429,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { return new int[getPropertySpan()]; } - protected String generateSubquery(PersistentClass model, Mapping mapping) { + protected String generateSubquery(PersistentClass model, Metadata mapping) { Dialect dialect = getFactory().getJdbcServices().getDialect(); SqlStringGenerationContext sqlStringGenerationContext = getFactory().getSqlStringGenerationContext(); @@ -460,7 +460,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { buf.append( "select " ); for ( Column col : columns ) { if ( !table.containsColumn(col) ) { - int sqlType = col.getSqlTypeCode(mapping); + int sqlType = col.getSqlTypeCode( mapping ); buf.append( dialect.getSelectClauseNullString(sqlType) ) .append(" as "); } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardTableExporter.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardTableExporter.java index 4dbb91e53a..799b3fe4ef 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardTableExporter.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardTableExporter.java @@ -8,7 +8,6 @@ package org.hibernate.tool.schema.internal; import java.util.ArrayList; import java.util.Collections; -import java.util.Iterator; import java.util.List; import org.hibernate.MappingException;