fix more warnings

This commit is contained in:
Gavin King 2024-09-10 15:34:05 +02:00
parent 0c3b8fd819
commit 1f16a0698e
9 changed files with 165 additions and 284 deletions

View File

@ -449,8 +449,7 @@ public class BinderHelper {
// Now, for each column find the properties of the target entity
// which are mapped to that column. (There might be multiple such
// properties for each column.)
if ( columnOwner instanceof PersistentClass ) {
final PersistentClass persistentClass = (PersistentClass) columnOwner;
if ( columnOwner instanceof PersistentClass persistentClass ) {
// Process ToOne associations after Components, Basic and Id properties
final List<Property> toOneProperties = new ArrayList<>();
for ( Property property : persistentClass.getReferenceableProperties() ) {
@ -969,22 +968,14 @@ public class BinderHelper {
}
private static CascadeType convertCascadeType(jakarta.persistence.CascadeType cascade) {
switch ( cascade ) {
case ALL:
return CascadeType.ALL;
case PERSIST:
return CascadeType.PERSIST;
case MERGE:
return CascadeType.MERGE;
case REMOVE:
return CascadeType.REMOVE;
case REFRESH:
return CascadeType.REFRESH;
case DETACH:
return CascadeType.DETACH;
default:
throw new AssertionFailure("unknown cascade type: " + cascade);
}
return switch (cascade) {
case ALL -> CascadeType.ALL;
case PERSIST -> CascadeType.PERSIST;
case MERGE -> CascadeType.MERGE;
case REMOVE -> CascadeType.REMOVE;
case REFRESH -> CascadeType.REFRESH;
case DETACH -> CascadeType.DETACH;
};
}
private static String renderCascadeTypeList(EnumSet<CascadeType> cascadeTypes) {

View File

@ -178,6 +178,7 @@ import static org.hibernate.internal.util.StringHelper.isEmpty;
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
import static org.hibernate.internal.util.StringHelper.nullIfEmpty;
import static org.hibernate.internal.util.StringHelper.qualify;
import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty;
import static org.hibernate.mapping.MappingHelper.createLocalUserCollectionTypeBean;
/**
@ -392,7 +393,7 @@ public abstract class CollectionBinder {
MemberDetails property) {
// Comment comment) {
return buildJoinColumnsWithDefaultColumnSuffix(
mapKeyJoinColumnAnnotations( propertyHolder, inferredData, property, context ),
mapKeyJoinColumnAnnotations( property, context ),
// comment,
null,
entityBinder.getSecondaryTables(),
@ -560,13 +561,8 @@ public abstract class CollectionBinder {
}
private static boolean isToManyAssociationWithinEmbeddableCollection(PropertyHolder propertyHolder) {
if ( propertyHolder instanceof ComponentPropertyHolder ) {
ComponentPropertyHolder componentPropertyHolder = (ComponentPropertyHolder) propertyHolder;
return componentPropertyHolder.isWithinElementCollection();
}
else {
return false;
}
return propertyHolder instanceof ComponentPropertyHolder componentPropertyHolder
&& componentPropertyHolder.isWithinElementCollection();
}
private static AnnotatedColumns elementColumns(
@ -626,8 +622,6 @@ public abstract class CollectionBinder {
}
private static JoinColumn[] mapKeyJoinColumnAnnotations(
PropertyHolder propertyHolder,
PropertyData inferredData,
MemberDetails property,
MetadataBuildingContext context) {
final MapKeyJoinColumn[] mapKeyJoinColumns = property.getRepeatedAnnotationUsages(
@ -635,7 +629,7 @@ public abstract class CollectionBinder {
context.getMetadataCollector().getSourceModelBuildingContext()
);
if ( CollectionHelper.isEmpty( mapKeyJoinColumns ) ) {
if ( isEmpty( mapKeyJoinColumns ) ) {
return null;
}
@ -945,7 +939,7 @@ public abstract class CollectionBinder {
MemberDetails property,
CollectionType typeAnnotation,
MetadataBuildingContext buildingContext) {
determineSemanticJavaType( property, buildingContext );
determineSemanticJavaType( property );
final ManagedBean<? extends UserCollectionType> customTypeBean = resolveCustomType(
property,
typeAnnotation,
@ -1014,7 +1008,7 @@ public abstract class CollectionBinder {
final SourceModelBuildingContext sourceModelContext = buildingContext.getMetadataCollector().getSourceModelBuildingContext();
if ( !property.hasAnnotationUsage( Bag.class, sourceModelContext ) ) {
return determineCollectionClassification( determineSemanticJavaType( property, buildingContext ), property, buildingContext );
return determineCollectionClassification( determineSemanticJavaType( property ), property, buildingContext );
}
if ( property.hasAnnotationUsage( OrderColumn.class, sourceModelContext ) ) {
@ -1126,7 +1120,7 @@ public abstract class CollectionBinder {
return null;
}
private static Class<?> determineSemanticJavaType(MemberDetails property, MetadataBuildingContext buildingContext) {
private static Class<?> determineSemanticJavaType(MemberDetails property) {
if ( property.isPlural() ) {
final ClassDetails collectionClassDetails = property.getType().determineRawClass();
final Class<?> collectionClass = collectionClassDetails.toJavaClass();
@ -1536,25 +1530,23 @@ public abstract class CollectionBinder {
private void setHibernateFetchMode(org.hibernate.annotations.FetchMode fetchMode) {
switch ( fetchMode ) {
case JOIN -> {
case JOIN :
collection.setFetchMode( FetchMode.JOIN );
collection.setLazy( false );
}
case SELECT -> {
break;
case SELECT:
collection.setFetchMode( FetchMode.SELECT );
}
case SUBSELECT -> {
break;
case SUBSELECT:
collection.setFetchMode( FetchMode.SELECT );
collection.setSubselectLoadable( true );
collection.getOwner().setSubselectLoadableCollections( true );
}
default -> {
break;
default:
throw new AssertionFailure( "unknown fetch type" );
}
}
}
@SuppressWarnings("deprecation")
private void handleLazy() {
final FetchType jpaFetchType = getJpaFetchType();
collection.setLazy( jpaFetchType == LAZY );
@ -1877,7 +1869,6 @@ public abstract class CollectionBinder {
}
private String getWhereOnClassClause() {
final TypeDetails elementType = property.getElementType();
final SQLRestriction restrictionOnClass = getOverridableAnnotation(
property.getAssociatedType().determineRawClass(),
SQLRestriction.class,
@ -2010,7 +2001,7 @@ public abstract class CollectionBinder {
public static String adjustUserSuppliedValueCollectionOrderingFragment(String orderByFragment) {
if ( orderByFragment != null ) {
orderByFragment = orderByFragment.trim();
if ( orderByFragment.length() == 0 || orderByFragment.equalsIgnoreCase( "asc" ) ) {
if ( orderByFragment.isEmpty() || orderByFragment.equalsIgnoreCase( "asc" ) ) {
// This indicates something like either:
// `@OrderBy()`
// `@OrderBy("asc")
@ -2071,7 +2062,6 @@ public abstract class CollectionBinder {
if ( key.getForeignKeyName() == null
&& key.getForeignKeyDefinition() == null
&& collectionTableAnn.joinColumns().length == 1 ) {
//noinspection unchecked
final JoinColumn joinColumn = collectionTableAnn.joinColumns()[0];
final ForeignKey nestedForeignKey = joinColumn.foreignKey();
key.setForeignKeyName( nullIfEmpty( nestedForeignKey.name() ) );
@ -2237,12 +2227,13 @@ public abstract class CollectionBinder {
buildingContext
);
final Class<? extends CompositeUserType<?>> compositeUserType = resolveCompositeUserType( property, elementClass, buildingContext );
boolean isComposite = classType == EMBEDDABLE || compositeUserType != null;
final Class<? extends CompositeUserType<?>> compositeUserType =
resolveCompositeUserType( property, elementClass, buildingContext );
final boolean isComposite = classType == EMBEDDABLE || compositeUserType != null;
holder.prepare( property, isComposite );
if ( isComposite ) {
handleCompositeCollectionElement( hqlOrderBy, elementType, elementClass, holder, compositeUserType );
handleCompositeCollectionElement( hqlOrderBy, elementType, holder, compositeUserType );
}
else {
handleCollectionElement( elementType, hqlOrderBy, elementClass, holder );
@ -2283,7 +2274,6 @@ public abstract class CollectionBinder {
private void handleCompositeCollectionElement(
String hqlOrderBy,
TypeDetails elementType,
ClassDetails elementClass,
CollectionPropertyHolder holder,
Class<? extends CompositeUserType<?>> compositeUserType) {
//TODO be smart with isNullable
@ -2555,7 +2545,7 @@ public abstract class CollectionBinder {
private void processSoftDeletes() {
assert collection.getCollectionTable() != null;
final SoftDelete softDelete = extractSoftDelete( property, propertyHolder, buildingContext );
final SoftDelete softDelete = extractSoftDelete( property, buildingContext );
if ( softDelete == null ) {
return;
}
@ -2568,20 +2558,18 @@ public abstract class CollectionBinder {
);
}
private static SoftDelete extractSoftDelete(
MemberDetails property,
PropertyHolder propertyHolder,
MetadataBuildingContext context) {
private static SoftDelete extractSoftDelete(MemberDetails property, MetadataBuildingContext context) {
final SoftDelete fromProperty = property.getDirectAnnotationUsage( SoftDelete.class );
if ( fromProperty != null ) {
return fromProperty;
}
return extractFromPackage(
SoftDelete.class,
property.getDeclaringType(),
context
);
else {
return extractFromPackage(
SoftDelete.class,
property.getDeclaringType(),
context
);
}
}
private void handleUnownedManyToMany(

View File

@ -65,9 +65,9 @@ public abstract class CollectionSecondPass implements SecondPass {
abstract public void secondPass(Map<String, PersistentClass> persistentClasses) throws MappingException;
private static String columns(Value val) {
StringBuilder columns = new StringBuilder();
final StringBuilder columns = new StringBuilder();
for ( Selectable selectable : val.getSelectables() ) {
if ( columns.length() > 0 ) {
if ( !columns.isEmpty() ) {
columns.append( ", " );
}
columns.append( selectable.getText() );

View File

@ -175,7 +175,7 @@ public class EntityBinder {
private static final CoreMessageLogger LOG = Logger.getMessageLogger( MethodHandles.lookup(), CoreMessageLogger.class, EntityBinder.class.getName() );
private static final String NATURAL_ID_CACHE_SUFFIX = "##NaturalId";
private MetadataBuildingContext context;
private final MetadataBuildingContext context;
private String name;
private ClassDetails annotatedClass;
@ -245,13 +245,13 @@ public class EntityBinder {
entityBinder.handleIdentifier( holder, inheritanceStates, generators, inheritanceState );
final InFlightMetadataCollector collector = context.getMetadataCollector();
if ( persistentClass instanceof RootClass ) {
collector.addSecondPass( new CreateKeySecondPass( (RootClass) persistentClass ) );
bindSoftDelete( clazzToProcess, (RootClass) persistentClass, inheritanceState, context );
if ( persistentClass instanceof RootClass rootClass ) {
collector.addSecondPass( new CreateKeySecondPass( rootClass ) );
bindSoftDelete( clazzToProcess, rootClass, context );
}
if ( persistentClass instanceof Subclass) {
if ( persistentClass instanceof Subclass subclass ) {
assert superEntity != null;
superEntity.addSubclass( (Subclass) persistentClass );
superEntity.addSubclass( subclass );
}
collector.addEntityBinding( persistentClass );
// process secondary tables and complementary definitions (ie o.h.a.Table)
@ -306,12 +306,11 @@ public class EntityBinder {
private static void bindSoftDelete(
ClassDetails classDetails,
RootClass rootClass,
InheritanceState inheritanceState,
MetadataBuildingContext context) {
// todo (soft-delete) : do we assume all package-level registrations are already available?
// or should this be a "second pass"?
final SoftDelete softDelete = extractSoftDelete( classDetails, inheritanceState, context );
final SoftDelete softDelete = extractSoftDelete( classDetails, context );
if ( softDelete != null ) {
SoftDeleteHelper.bindSoftDeleteIndicator(
softDelete,
@ -322,10 +321,7 @@ public class EntityBinder {
}
}
private static SoftDelete extractSoftDelete(
ClassDetails classDetails,
InheritanceState inheritanceState,
MetadataBuildingContext context) {
private static SoftDelete extractSoftDelete(ClassDetails classDetails, MetadataBuildingContext context) {
final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext();
final SoftDelete fromClass = classDetails.getAnnotationUsage( SoftDelete.class, sourceModelContext );
if ( fromClass != null ) {
@ -381,9 +377,10 @@ public class EntityBinder {
}
private void applyTypeBinder(Annotation containingAnnotation, PersistentClass persistentClass) {
final Class<? extends TypeBinder<?>> binderClass = containingAnnotation.annotationType()
.getAnnotation( TypeBinderType.class )
.binder();
final Class<? extends TypeBinder<?>> binderClass =
containingAnnotation.annotationType()
.getAnnotation( TypeBinderType.class )
.binder();
try {
//noinspection rawtypes
@ -1096,7 +1093,7 @@ public class EntityBinder {
private static String getMissingPropertiesString(Set<String> propertyNames) {
final StringBuilder sb = new StringBuilder();
for ( String property : propertyNames ) {
if ( sb.length() > 0 ) {
if ( !sb.isEmpty() ) {
sb.append( ", " );
}
sb.append( "'" ).append( property ).append( "'" );
@ -1113,16 +1110,11 @@ public class EntityBinder {
return new RootClass( metadataBuildingContext );
}
else {
switch ( inheritanceState.getType() ) {
case SINGLE_TABLE:
return new SingleTableSubclass( superEntity, metadataBuildingContext );
case JOINED:
return new JoinedSubclass( superEntity, metadataBuildingContext );
case TABLE_PER_CLASS:
return new UnionSubclass( superEntity, metadataBuildingContext );
default:
throw new AssertionFailure( "Unknown inheritance type: " + inheritanceState.getType() );
}
return switch ( inheritanceState.getType() ) {
case SINGLE_TABLE -> new SingleTableSubclass( superEntity, metadataBuildingContext );
case JOINED -> new JoinedSubclass( superEntity, metadataBuildingContext );
case TABLE_PER_CLASS -> new UnionSubclass( superEntity, metadataBuildingContext );
};
}
}
@ -1684,7 +1676,7 @@ public class EntityBinder {
effectiveCache = buildCacheMock( annotatedClass, context );
isCached = isCacheable( sharedCacheMode, cacheable );
}
cacheConcurrentStrategy = resolveCacheConcurrencyStrategy( effectiveCache.usage() );
cacheConcurrentStrategy = getCacheConcurrencyStrategy( effectiveCache.usage() );
cacheRegion = effectiveCache.region();
cacheLazyProperty = isCacheLazy( effectiveCache, annotatedClass );
@ -1723,11 +1715,6 @@ public class EntityBinder {
};
}
private static String resolveCacheConcurrencyStrategy(CacheConcurrencyStrategy strategy) {
final org.hibernate.cache.spi.access.AccessType accessType = strategy.toAccessType();
return accessType == null ? null : accessType.getExternalName();
}
private static Cache buildCacheMock(ClassDetails classDetails, MetadataBuildingContext context) {
final CacheAnnotation cacheUsage = HibernateAnnotations.CACHE.createUsage( context.getMetadataCollector().getSourceModelBuildingContext() );
cacheUsage.region( classDetails.getName() );

View File

@ -57,6 +57,4 @@ public abstract class FkSecondPass implements SecondPass {
public abstract String getReferencedEntityName();
public abstract boolean isInPrimaryKey();
}

View File

@ -204,10 +204,9 @@ public class OneToOneSecondPass implements SecondPass {
// HHH-6813
// Foo: @Id long id, @OneToOne(mappedBy="foo") Bar bar
// Bar: @Id @OneToOne Foo foo
final KeyValue targetEntityIdentifier = targetEntity.getIdentifier();
boolean referenceToPrimaryKey = mappedBy == null
|| targetEntityIdentifier instanceof Component
&& ( (Component) targetEntityIdentifier ).matchesAllProperties( mappedBy );
|| targetEntity.getIdentifier() instanceof Component compositeId
&& compositeId.matchesAllProperties( mappedBy );
oneToOne.setReferenceToPrimaryKey( referenceToPrimaryKey );
final String propertyRef = oneToOne.getReferencedPropertyName();
@ -293,11 +292,9 @@ public class OneToOneSecondPass implements SecondPass {
copy.setValue( key );
key.addColumn( copy );
}
if ( otherSideProperty.getValue() instanceof SortableValue ) {
final SortableValue value = (SortableValue) otherSideProperty.getValue();
if ( !value.isSorted() ) {
key.sortProperties();
}
if ( otherSideProperty.getValue() instanceof SortableValue value
&& !value.isSorted() ) {
key.sortProperties();
}
persistentClass.addJoin( join );
return join;

View File

@ -350,18 +350,18 @@ public class ToOneBinder {
MemberDetails property,
PropertyData inferredData,
PropertyHolder propertyHolder) {
handleLazy( toOne, property, inferredData, propertyHolder );
handleLazy( toOne, property );
handleFetch( toOne, property );
handleFetchProfileOverrides( toOne, property, propertyHolder, inferredData );
}
private static void handleLazy(ToOne toOne, MemberDetails property, PropertyData inferredData, PropertyHolder propertyHolder) {
private static void handleLazy(ToOne toOne, MemberDetails property) {
if ( property.hasDirectAnnotationUsage( NotFound.class ) ) {
toOne.setLazy( false );
toOne.setUnwrapProxy( true );
}
else {
boolean eager = isEager( property, inferredData, propertyHolder );
boolean eager = isEager( property );
toOne.setLazy( !eager );
toOne.setUnwrapProxy( eager );
toOne.setUnwrapProxyImplicit( true );
@ -376,9 +376,8 @@ public class ToOneBinder {
final MetadataBuildingContext context = toOne.getBuildingContext();
final InFlightMetadataCollector collector = context.getMetadataCollector();
final SourceModelBuildingContext sourceModelContext = collector.getSourceModelBuildingContext();
property.forEachAnnotationUsage( FetchProfileOverride.class, sourceModelContext, (usage) -> {
collector.addSecondPass( new FetchSecondPass( usage, propertyHolder, inferredData.getPropertyName(), context ) );
} );
property.forEachAnnotationUsage( FetchProfileOverride.class, sourceModelContext,
usage -> collector.addSecondPass( new FetchSecondPass( usage, propertyHolder, inferredData.getPropertyName(), context ) ));
}
private static void handleFetch(ToOne toOne, MemberDetails property) {
@ -410,9 +409,8 @@ public class ToOneBinder {
}
}
private static boolean isEager(MemberDetails property, PropertyData inferredData, PropertyHolder propertyHolder) {
final FetchType fetchType = getJpaFetchType( property );
return fetchType == EAGER;
private static boolean isEager(MemberDetails property) {
return getJpaFetchType( property ) == EAGER;
}
private static FetchType getJpaFetchType(MemberDetails property) {

View File

@ -6,20 +6,17 @@
*/
package org.hibernate.boot.model.internal;
import java.util.Map;
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.hibernate.MappingException;
import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.KeyValue;
import org.hibernate.mapping.ManyToOne;
import org.hibernate.mapping.OneToOne;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.ToOne;
import org.hibernate.mapping.Value;
import static org.hibernate.boot.model.internal.BinderHelper.createSyntheticPropertyReference;
import static org.hibernate.internal.util.StringHelper.qualify;
@ -66,8 +63,8 @@ public class ToOneFkSecondPass extends FkSecondPass {
if ( entityClassName == null ) {
return false;
}
final PersistentClass persistentClass = buildingContext.getMetadataCollector()
.getEntityBinding( entityClassName );
final PersistentClass persistentClass =
buildingContext.getMetadataCollector().getEntityBinding( entityClassName );
final Property property = persistentClass.getIdentifierProperty();
if ( path == null ) {
return false;
@ -78,8 +75,7 @@ public class ToOneFkSecondPass extends FkSecondPass {
}
//try the embedded property
else {
final KeyValue valueIdentifier = persistentClass.getIdentifier();
if ( valueIdentifier instanceof Component ) {
if ( persistentClass.getIdentifier() instanceof Component component ) {
// Embedded property starts their path with 'id.'
// See PropertyPreloadedData( ) use when idClass != null in AnnotationSourceProcessor
String localPath = path;
@ -87,7 +83,6 @@ public class ToOneFkSecondPass extends FkSecondPass {
localPath = path.substring( 3 );
}
final Component component = (Component) valueIdentifier;
for ( Property idProperty : component.getProperties() ) {
if ( localPath.equals( idProperty.getName() ) || localPath.startsWith( idProperty.getName() + "." ) ) {
return true;
@ -116,13 +111,10 @@ public class ToOneFkSecondPass extends FkSecondPass {
final String propertyRef = columns.getReferencedProperty();
if ( propertyRef != null ) {
handlePropertyRef(
columns,
targetEntity,
persistentClass,
manyToOne,
path,
propertyRef,
persistentClasses,
buildingContext
);
}
@ -151,25 +143,17 @@ public class ToOneFkSecondPass extends FkSecondPass {
}
private void handlePropertyRef(
AnnotatedJoinColumns columns,
PersistentClass targetEntity,
PersistentClass persistentClass,
ManyToOne manyToOne,
String path,
String referencedPropertyName,
Map<String, PersistentClass> persistentClasses,
MetadataBuildingContext buildingContext) {
manyToOne.setReferencedPropertyName( referencedPropertyName );
manyToOne.setReferenceToPrimaryKey( false );
buildingContext.getMetadataCollector().addUniquePropertyReference(
targetEntity.getEntityName(),
referencedPropertyName
);
buildingContext.getMetadataCollector().addPropertyReferencedAssociation(
targetEntity.getEntityName(),
path,
referencedPropertyName
);
final String entityName = targetEntity.getEntityName();
final InFlightMetadataCollector metadataCollector = buildingContext.getMetadataCollector();
metadataCollector.addUniquePropertyReference( entityName, referencedPropertyName );
metadataCollector.addPropertyReferencedAssociation( entityName, path, referencedPropertyName );
}
}

View File

@ -75,7 +75,6 @@ import org.hibernate.boot.model.source.spi.PluralAttributeMapKeySourceBasic;
import org.hibernate.boot.model.source.spi.PluralAttributeMapKeySourceEmbedded;
import org.hibernate.boot.model.source.spi.PluralAttributeSequentialIndexSource;
import org.hibernate.boot.model.source.spi.PluralAttributeSource;
import org.hibernate.boot.model.source.spi.PluralAttributeSourceArray;
import org.hibernate.boot.model.source.spi.RelationalValueSource;
import org.hibernate.boot.model.source.spi.RelationalValueSourceContainer;
import org.hibernate.boot.model.source.spi.SecondaryTableSource;
@ -303,25 +302,22 @@ public class ModelBinder {
}
private static boolean isCacheEnabled(MappingDocument mappingDocument, Caching caching) {
switch ( mappingDocument.getBuildingOptions().getSharedCacheMode() ) {
case UNSPECIFIED:
case ENABLE_SELECTIVE:
return switch ( mappingDocument.getBuildingOptions().getSharedCacheMode() ) {
case UNSPECIFIED, ENABLE_SELECTIVE ->
// this is default behavior for hbm.xml
return caching != null && caching.getRequested().toBoolean(false);
case NONE:
caching != null && caching.getRequested().toBoolean(false);
case NONE ->
// this option is actually really useful
return false;
case ALL:
false;
case ALL ->
// goes completely against the whole ideology we have for
// caching, and so it hurts me to support it here
return true;
case DISABLE_SELECTIVE:
true;
case DISABLE_SELECTIVE ->
// makes no sense for hbm.xml, and also goes against our
// ideology, and so it hurts me to support it here
return caching == null || caching.getRequested().toBoolean(true);
default:
throw new AssertionFailure( "unknown SharedCacheMode" );
}
caching == null || caching.getRequested().toBoolean(true);
};
}
private void bindEntityIdentifier(
@ -1021,9 +1017,9 @@ public class ModelBinder {
}
else {
// singular attribute
if ( attributeSource instanceof SingularAttributeSourceBasic ) {
final SingularAttributeSourceBasic basicAttributeSource = (SingularAttributeSourceBasic) attributeSource;
final Identifier tableName = determineTable( mappingDocument, basicAttributeSource.getName(), basicAttributeSource );
if ( attributeSource instanceof SingularAttributeSourceBasic basicAttributeSource ) {
final Identifier tableName =
determineTable( mappingDocument, basicAttributeSource.getName(), basicAttributeSource );
final AttributeContainer attributeContainer;
final Table table;
final Join secondaryTableJoin = entityTableXref.locateJoin( tableName );
@ -1054,8 +1050,7 @@ public class ModelBinder {
basicAttributeSource.getNaturalIdMutability()
);
}
else if ( attributeSource instanceof SingularAttributeSourceEmbedded ) {
final SingularAttributeSourceEmbedded embeddedAttributeSource = (SingularAttributeSourceEmbedded) attributeSource;
else if ( attributeSource instanceof SingularAttributeSourceEmbedded embeddedAttributeSource ) {
final Identifier tableName = determineTable( mappingDocument, embeddedAttributeSource );
final AttributeContainer attributeContainer;
final Table table;
@ -1071,7 +1066,7 @@ public class ModelBinder {
final Property attribute = createEmbeddedAttribute(
mappingDocument,
(SingularAttributeSourceEmbedded) attributeSource,
embeddedAttributeSource,
new Component( mappingDocument, table, entityDescriptor ),
entityDescriptor.getClassName()
);
@ -1087,9 +1082,9 @@ public class ModelBinder {
embeddedAttributeSource.getNaturalIdMutability()
);
}
else if ( attributeSource instanceof SingularAttributeSourceManyToOne ) {
final SingularAttributeSourceManyToOne manyToOneAttributeSource = (SingularAttributeSourceManyToOne) attributeSource;
final Identifier tableName = determineTable( mappingDocument, manyToOneAttributeSource.getName(), manyToOneAttributeSource );
else if ( attributeSource instanceof SingularAttributeSourceManyToOne manyToOneAttributeSource ) {
final Identifier tableName =
determineTable( mappingDocument, manyToOneAttributeSource.getName(), manyToOneAttributeSource );
final AttributeContainer attributeContainer;
final Table table;
final Join secondaryTableJoin = entityTableXref.locateJoin( tableName );
@ -1120,8 +1115,7 @@ public class ModelBinder {
manyToOneAttributeSource.getNaturalIdMutability()
);
}
else if ( attributeSource instanceof SingularAttributeSourceOneToOne ) {
final SingularAttributeSourceOneToOne oneToOneAttributeSource = (SingularAttributeSourceOneToOne) attributeSource;
else if ( attributeSource instanceof SingularAttributeSourceOneToOne oneToOneAttributeSource ) {
final Table table = entityDescriptor.getTable();
final Property attribute = createOneToOneAttribute(
mappingDocument,
@ -1141,8 +1135,7 @@ public class ModelBinder {
oneToOneAttributeSource.getNaturalIdMutability()
);
}
else if ( attributeSource instanceof SingularAttributeSourceAny ) {
final SingularAttributeSourceAny anyAttributeSource = (SingularAttributeSourceAny) attributeSource;
else if ( attributeSource instanceof SingularAttributeSourceAny anyAttributeSource ) {
final Identifier tableName = determineTable(
mappingDocument,
anyAttributeSource.getName(),
@ -1223,16 +1216,13 @@ public class ModelBinder {
PersistentClass entityDescriptor) {
final Collection collectionBinding;
if ( attributeSource instanceof PluralAttributeSourceListImpl ) {
collectionBinding = new org.hibernate.mapping.List( sourceDocument, entityDescriptor );
if ( attributeSource instanceof PluralAttributeSourceListImpl pluralAttributeSourceList ) {
org.hibernate.mapping.List list = new org.hibernate.mapping.List(sourceDocument, entityDescriptor);
collectionBinding = list;
bindCollectionMetadata( sourceDocument, attributeSource, collectionBinding );
registerSecondPass(
new PluralAttributeListSecondPass(
sourceDocument,
(IndexedPluralAttributeSource) attributeSource,
(org.hibernate.mapping.List) collectionBinding
),
new PluralAttributeListSecondPass( sourceDocument, pluralAttributeSourceList, list ),
sourceDocument
);
}
@ -1245,16 +1235,13 @@ public class ModelBinder {
sourceDocument
);
}
else if ( attributeSource instanceof PluralAttributeSourceMapImpl ) {
collectionBinding = new org.hibernate.mapping.Map( sourceDocument, entityDescriptor );
else if ( attributeSource instanceof PluralAttributeSourceMapImpl pluralAttributeSourceMap ) {
org.hibernate.mapping.Map map = new org.hibernate.mapping.Map(sourceDocument, entityDescriptor);
collectionBinding = map;
bindCollectionMetadata( sourceDocument, attributeSource, collectionBinding );
registerSecondPass(
new PluralAttributeMapSecondPass(
sourceDocument,
(IndexedPluralAttributeSource) attributeSource,
(org.hibernate.mapping.Map) collectionBinding
),
new PluralAttributeMapSecondPass( sourceDocument, pluralAttributeSourceMap, map ),
sourceDocument
);
}
@ -1276,33 +1263,28 @@ public class ModelBinder {
sourceDocument
);
}
else if ( attributeSource instanceof PluralAttributeSourceArrayImpl ) {
final PluralAttributeSourceArray arraySource = (PluralAttributeSourceArray) attributeSource;
collectionBinding = new Array( sourceDocument, entityDescriptor );
else if ( attributeSource instanceof PluralAttributeSourceArrayImpl arraySource ) {
final Array array = new Array(sourceDocument, entityDescriptor);
collectionBinding = array;
bindCollectionMetadata( sourceDocument, attributeSource, collectionBinding );
( (Array) collectionBinding ).setElementClassName(
sourceDocument.qualifyClassName( arraySource.getElementClass() )
);
array.setElementClassName( sourceDocument.qualifyClassName( arraySource.getElementClass() ) );
registerSecondPass(
new PluralAttributeArraySecondPass(
sourceDocument,
arraySource,
(Array) collectionBinding
),
new PluralAttributeArraySecondPass( sourceDocument, arraySource, array ),
sourceDocument
);
}
else if ( attributeSource instanceof PluralAttributeSourcePrimitiveArrayImpl ) {
collectionBinding = new PrimitiveArray( sourceDocument, entityDescriptor );
else if ( attributeSource instanceof PluralAttributeSourcePrimitiveArrayImpl pluralAttributeSourcePrimitiveArray ) {
final PrimitiveArray primitiveArray = new PrimitiveArray( sourceDocument, entityDescriptor );
collectionBinding = primitiveArray;
bindCollectionMetadata( sourceDocument, attributeSource, collectionBinding );
registerSecondPass(
new PluralAttributePrimitiveArraySecondPass(
sourceDocument,
(IndexedPluralAttributeSource) attributeSource,
(PrimitiveArray) collectionBinding
pluralAttributeSourcePrimitiveArray,
primitiveArray
),
sourceDocument
);
@ -1435,8 +1417,7 @@ public class ModelBinder {
);
}
if ( source instanceof Sortable ) {
final Sortable sortable = (Sortable) source;
if ( source instanceof Sortable sortable ) {
if ( sortable.isSorted() ) {
binding.setSorted( true );
if ( ! sortable.getComparatorName().equals( "natural" ) ) {
@ -1448,9 +1429,9 @@ public class ModelBinder {
}
}
if ( source instanceof Orderable ) {
if ( ( (Orderable) source ).isOrdered() ) {
binding.setOrderBy( ( (Orderable) source ).getOrder() );
if ( source instanceof Orderable orderable ) {
if ( orderable.isOrdered() ) {
binding.setOrderBy( orderable.getOrder() );
}
}
@ -1588,14 +1569,13 @@ public class ModelBinder {
Table secondaryTable;
final Identifier logicalTableName;
if ( secondaryTableSource.getTableSource() instanceof TableSource ) {
final TableSource tableSource = (TableSource) secondaryTableSource.getTableSource();
if ( secondaryTableSource.getTableSource() instanceof TableSource tableSource ) {
logicalTableName = database.toIdentifier( tableSource.getExplicitTableName() );
secondaryTable = namespace.locateTable( logicalTableName );
if ( secondaryTable == null ) {
secondaryTable = namespace.createTable(
logicalTableName,
(identifier) -> new Table( mappingDocument.getCurrentContributorName(), namespace, identifier, false )
identifier -> new Table( mappingDocument.getCurrentContributorName(), namespace, identifier, false )
);
}
else {
@ -1819,22 +1799,16 @@ public class ModelBinder {
private static boolean isLob(Integer sqlType, String sqlTypeName) {
if ( sqlType != null ) {
switch ( sqlType ) {
case Types.BLOB:
case Types.CLOB:
case Types.NCLOB:
return true;
}
return false;
return switch (sqlType) {
case Types.BLOB, Types.CLOB, Types.NCLOB -> true;
default -> false;
};
}
else if ( sqlTypeName != null ) {
switch ( sqlTypeName.toLowerCase( Locale.ROOT ) ) {
case "blob":
case "clob":
case "nclob":
return true;
}
return false;
return switch ( sqlTypeName.toLowerCase(Locale.ROOT) ) {
case "blob", "clob", "nclob" -> true;
default -> false;
};
}
return false;
}
@ -2395,9 +2369,7 @@ public class ModelBinder {
: mappingDocument.getEffectiveDefaults().getDefaultAccessStrategyName()
);
if ( propertySource instanceof CascadeStyleSource ) {
final CascadeStyleSource cascadeStyleSource = (CascadeStyleSource) propertySource;
if ( propertySource instanceof CascadeStyleSource cascadeStyleSource ) {
property.setCascade(
isNotEmpty( cascadeStyleSource.getCascadeStyleName() )
? cascadeStyleSource.getCascadeStyleName()
@ -3091,14 +3063,11 @@ public class ModelBinder {
// 1) one-to-many
// 2) everything else
if ( pluralAttributeSource.getElementSource() instanceof PluralAttributeElementSourceOneToMany ) {
if ( pluralAttributeSource.getElementSource() instanceof PluralAttributeElementSourceOneToMany elementSource ) {
// For one-to-many mappings, the "collection table" is the same as the table
// of the associated entity (the entity making up the collection elements).
// So lookup the associated entity and use its table here
final PluralAttributeElementSourceOneToMany elementSource =
(PluralAttributeElementSourceOneToMany) pluralAttributeSource.getElementSource();
final PersistentClass persistentClass = getReferencedEntityBinding( elementSource.getReferencedEntityName() );
// even though <key/> defines a property-ref I do not see where legacy
@ -3115,8 +3084,7 @@ public class ModelBinder {
final Table collectionTable;
if ( tableSpecSource instanceof TableSource ) {
final TableSource tableSource = (TableSource) tableSpecSource;
if ( tableSpecSource instanceof TableSource tableSource ) {
Identifier logicalName;
if ( isNotEmpty( tableSource.getExplicitTableName() ) ) {
@ -3485,13 +3453,8 @@ public class ModelBinder {
);
}
}
else if ( getPluralAttributeSource().getElementSource() instanceof PluralAttributeElementSourceManyToAny ) {
final PluralAttributeElementSourceManyToAny elementSource =
(PluralAttributeElementSourceManyToAny) getPluralAttributeSource().getElementSource();
final Any elementBinding = new Any(
getMappingDocument(),
getCollectionBinding().getCollectionTable()
);
else if ( getPluralAttributeSource().getElementSource() instanceof PluralAttributeElementSourceManyToAny elementSource ) {
final Any elementBinding = new Any( getMappingDocument(), getCollectionBinding().getCollectionTable() );
bindAny(
mappingDocument,
elementSource,
@ -3507,9 +3470,8 @@ public class ModelBinder {
}
private PersistentClass getReferencedEntityBinding(String referencedEntityName) {
PersistentClass entityBinding = mappingDocument.getMetadataCollector().getEntityBinding(
referencedEntityName
);
final PersistentClass entityBinding =
mappingDocument.getMetadataCollector().getEntityBinding( referencedEntityName );
if ( entityBinding == null ) {
throw new MappingException(
String.format(
@ -3755,10 +3717,7 @@ public class ModelBinder {
final PluralAttributeSequentialIndexSource indexSource =
(PluralAttributeSequentialIndexSource) attributeSource.getIndexSource();
final BasicValue indexBinding = new BasicValue(
mappingDocument,
collectionBinding.getCollectionTable()
);
final BasicValue indexBinding = new BasicValue( mappingDocument, collectionBinding.getCollectionTable() );
bindSimpleValueType(
mappingDocument,
@ -3794,13 +3753,8 @@ public class ModelBinder {
final MappingDocument mappingDocument,
final IndexedPluralAttributeSource pluralAttributeSource,
final org.hibernate.mapping.Map collectionBinding) {
if ( pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeySourceBasic ) {
final PluralAttributeMapKeySourceBasic mapKeySource =
(PluralAttributeMapKeySourceBasic) pluralAttributeSource.getIndexSource();
final BasicValue value = new BasicValue(
mappingDocument,
collectionBinding.getCollectionTable()
);
if ( pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeySourceBasic mapKeySource ) {
final BasicValue value = new BasicValue( mappingDocument, collectionBinding.getCollectionTable() );
bindSimpleValueType(
mappingDocument,
mapKeySource.getTypeInformation(),
@ -3824,13 +3778,8 @@ public class ModelBinder {
collectionBinding.setIndex( value );
}
else if ( pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeySourceEmbedded ) {
final PluralAttributeMapKeySourceEmbedded mapKeySource =
(PluralAttributeMapKeySourceEmbedded) pluralAttributeSource.getIndexSource();
final Component componentBinding = new Component(
mappingDocument,
collectionBinding
);
else if ( pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeySourceEmbedded mapKeySource ) {
final Component componentBinding = new Component( mappingDocument, collectionBinding );
bindComponent(
mappingDocument,
mapKeySource.getEmbeddableSource(),
@ -3841,13 +3790,8 @@ public class ModelBinder {
);
collectionBinding.setIndex( componentBinding );
}
else if ( pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeyManyToManySource ) {
final PluralAttributeMapKeyManyToManySource mapKeySource =
(PluralAttributeMapKeyManyToManySource) pluralAttributeSource.getIndexSource();
final ManyToOne mapKeyBinding = new ManyToOne(
mappingDocument,
collectionBinding.getCollectionTable()
);
else if ( pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeyManyToManySource mapKeySource ) {
final ManyToOne mapKeyBinding = new ManyToOne( mappingDocument, collectionBinding.getCollectionTable() );
mapKeyBinding.setReferencedEntityName( mapKeySource.getReferencedEntityName() );
@ -3872,13 +3816,8 @@ public class ModelBinder {
);
collectionBinding.setIndex( mapKeyBinding );
}
else if ( pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeyManyToAnySource ) {
final PluralAttributeMapKeyManyToAnySource mapKeySource =
(PluralAttributeMapKeyManyToAnySource) pluralAttributeSource.getIndexSource();
final Any mapKeyBinding = new Any(
mappingDocument,
collectionBinding.getCollectionTable()
);
else if ( pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeyManyToAnySource mapKeySource) {
final Any mapKeyBinding = new Any( mappingDocument, collectionBinding.getCollectionTable() );
bindAny(
mappingDocument,
mapKeySource,
@ -3910,8 +3849,8 @@ public class ModelBinder {
boolean allNamed = true;
for ( RelationalValueSource relationalValueSource : manyToOneSource.getRelationalValueSources() ) {
if ( relationalValueSource instanceof ColumnSource ) {
if ( ( (ColumnSource) relationalValueSource ).getName() == null ) {
if ( relationalValueSource instanceof ColumnSource columnSource ) {
if ( columnSource.getName() == null ) {
allNamed = false;
break;
}
@ -3925,8 +3864,8 @@ public class ModelBinder {
return true;
}
final PersistentClass referencedEntityBinding = mappingDocument.getMetadataCollector()
.getEntityBinding( referencedEntityName );
final PersistentClass referencedEntityBinding =
mappingDocument.getMetadataCollector().getEntityBinding( referencedEntityName );
if ( referencedEntityBinding == null ) {
return false;
}
@ -3940,7 +3879,7 @@ public class ModelBinder {
}
@Override
public void doSecondPass(Map<String, PersistentClass> persistentClasses) throws org.hibernate.MappingException {
public void doSecondPass(Map<String, PersistentClass> persistentClasses) {
if ( allColumnsNamed ) {
relationalObjectBinder.bindColumnsAndFormulas(
mappingDocument,
@ -3957,8 +3896,8 @@ public class ModelBinder {
// implicit naming. If we get here, we assume that there is only a single
// column making up the FK
final PersistentClass referencedEntityBinding = mappingDocument.getMetadataCollector()
.getEntityBinding( referencedEntityName );
final PersistentClass referencedEntityBinding =
mappingDocument.getMetadataCollector().getEntityBinding( referencedEntityName );
if ( referencedEntityBinding == null ) {
throw new AssertionFailure(
@ -4049,8 +3988,8 @@ public class ModelBinder {
//
// There is an assumption here that the columns making up the FK have been bound.
// We assume the caller checks that
final PersistentClass referencedEntityBinding = mappingDocument.getMetadataCollector()
.getEntityBinding( referencedEntityName );
final PersistentClass referencedEntityBinding =
mappingDocument.getMetadataCollector().getEntityBinding( referencedEntityName );
return referencedEntityBinding != null && referencedEntityAttributeName != null;
}
@ -4077,19 +4016,18 @@ public class ModelBinder {
final List<Identifier> columnNames = new ArrayList<>();
final UniqueKey uk = new UniqueKey(entityBinding.getTable() );
final UniqueKey uniqueKey = new UniqueKey( entityBinding.getTable() );
for ( Property attributeBinding : attributeBindings ) {
for ( Selectable selectable : attributeBinding.getSelectables() ) {
if ( selectable instanceof Column ) {
final Column column = (Column) selectable;
uk.addColumn( column );
if ( selectable instanceof Column column ) {
uniqueKey.addColumn( column );
columnNames.add( column.getNameIdentifier( mappingDocument ) );
}
}
uk.addColumns( attributeBinding.getValue() );
uniqueKey.addColumns( attributeBinding.getValue() );
}
final Identifier ukName = mappingDocument.getBuildingOptions().getImplicitNamingStrategy()
final Identifier uniqueKeyName = mappingDocument.getBuildingOptions().getImplicitNamingStrategy()
.determineUniqueKeyName(
new ImplicitUniqueKeyNameSource() {
@Override
@ -4109,21 +4047,21 @@ public class ModelBinder {
@Override
public Identifier getUserProvidedIdentifier() {
final String name = uk.getName();
final String name = uniqueKey.getName();
return name == null ? null : toIdentifier( name );
}
}
);
uk.setName( ukName.render( mappingDocument.getMetadataCollector().getDatabase().getDialect() ) );
uniqueKey.setName( uniqueKeyName.render( mappingDocument.getMetadataCollector().getDatabase().getDialect() ) );
entityBinding.getTable().addUniqueKey( uk );
entityBinding.getTable().addUniqueKey( uniqueKey );
}
}
private String columns(Value value) {
final StringBuilder builder = new StringBuilder();
for ( Selectable selectable : value.getSelectables() ) {
if ( builder.length()>0) {
if ( !builder.isEmpty() ) {
builder.append( ", " );
}
builder.append( selectable.getText() );