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 // Now, for each column find the properties of the target entity
// which are mapped to that column. (There might be multiple such // which are mapped to that column. (There might be multiple such
// properties for each column.) // properties for each column.)
if ( columnOwner instanceof PersistentClass ) { if ( columnOwner instanceof PersistentClass persistentClass ) {
final PersistentClass persistentClass = (PersistentClass) columnOwner;
// Process ToOne associations after Components, Basic and Id properties // Process ToOne associations after Components, Basic and Id properties
final List<Property> toOneProperties = new ArrayList<>(); final List<Property> toOneProperties = new ArrayList<>();
for ( Property property : persistentClass.getReferenceableProperties() ) { for ( Property property : persistentClass.getReferenceableProperties() ) {
@ -969,22 +968,14 @@ public class BinderHelper {
} }
private static CascadeType convertCascadeType(jakarta.persistence.CascadeType cascade) { private static CascadeType convertCascadeType(jakarta.persistence.CascadeType cascade) {
switch ( cascade ) { return switch (cascade) {
case ALL: case ALL -> CascadeType.ALL;
return CascadeType.ALL; case PERSIST -> CascadeType.PERSIST;
case PERSIST: case MERGE -> CascadeType.MERGE;
return CascadeType.PERSIST; case REMOVE -> CascadeType.REMOVE;
case MERGE: case REFRESH -> CascadeType.REFRESH;
return CascadeType.MERGE; case DETACH -> CascadeType.DETACH;
case REMOVE: };
return CascadeType.REMOVE;
case REFRESH:
return CascadeType.REFRESH;
case DETACH:
return CascadeType.DETACH;
default:
throw new AssertionFailure("unknown cascade type: " + cascade);
}
} }
private static String renderCascadeTypeList(EnumSet<CascadeType> cascadeTypes) { 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.isNotEmpty;
import static org.hibernate.internal.util.StringHelper.nullIfEmpty; import static org.hibernate.internal.util.StringHelper.nullIfEmpty;
import static org.hibernate.internal.util.StringHelper.qualify; import static org.hibernate.internal.util.StringHelper.qualify;
import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty;
import static org.hibernate.mapping.MappingHelper.createLocalUserCollectionTypeBean; import static org.hibernate.mapping.MappingHelper.createLocalUserCollectionTypeBean;
/** /**
@ -392,7 +393,7 @@ public abstract class CollectionBinder {
MemberDetails property) { MemberDetails property) {
// Comment comment) { // Comment comment) {
return buildJoinColumnsWithDefaultColumnSuffix( return buildJoinColumnsWithDefaultColumnSuffix(
mapKeyJoinColumnAnnotations( propertyHolder, inferredData, property, context ), mapKeyJoinColumnAnnotations( property, context ),
// comment, // comment,
null, null,
entityBinder.getSecondaryTables(), entityBinder.getSecondaryTables(),
@ -560,13 +561,8 @@ public abstract class CollectionBinder {
} }
private static boolean isToManyAssociationWithinEmbeddableCollection(PropertyHolder propertyHolder) { private static boolean isToManyAssociationWithinEmbeddableCollection(PropertyHolder propertyHolder) {
if ( propertyHolder instanceof ComponentPropertyHolder ) { return propertyHolder instanceof ComponentPropertyHolder componentPropertyHolder
ComponentPropertyHolder componentPropertyHolder = (ComponentPropertyHolder) propertyHolder; && componentPropertyHolder.isWithinElementCollection();
return componentPropertyHolder.isWithinElementCollection();
}
else {
return false;
}
} }
private static AnnotatedColumns elementColumns( private static AnnotatedColumns elementColumns(
@ -626,8 +622,6 @@ public abstract class CollectionBinder {
} }
private static JoinColumn[] mapKeyJoinColumnAnnotations( private static JoinColumn[] mapKeyJoinColumnAnnotations(
PropertyHolder propertyHolder,
PropertyData inferredData,
MemberDetails property, MemberDetails property,
MetadataBuildingContext context) { MetadataBuildingContext context) {
final MapKeyJoinColumn[] mapKeyJoinColumns = property.getRepeatedAnnotationUsages( final MapKeyJoinColumn[] mapKeyJoinColumns = property.getRepeatedAnnotationUsages(
@ -635,7 +629,7 @@ public abstract class CollectionBinder {
context.getMetadataCollector().getSourceModelBuildingContext() context.getMetadataCollector().getSourceModelBuildingContext()
); );
if ( CollectionHelper.isEmpty( mapKeyJoinColumns ) ) { if ( isEmpty( mapKeyJoinColumns ) ) {
return null; return null;
} }
@ -945,7 +939,7 @@ public abstract class CollectionBinder {
MemberDetails property, MemberDetails property,
CollectionType typeAnnotation, CollectionType typeAnnotation,
MetadataBuildingContext buildingContext) { MetadataBuildingContext buildingContext) {
determineSemanticJavaType( property, buildingContext ); determineSemanticJavaType( property );
final ManagedBean<? extends UserCollectionType> customTypeBean = resolveCustomType( final ManagedBean<? extends UserCollectionType> customTypeBean = resolveCustomType(
property, property,
typeAnnotation, typeAnnotation,
@ -1014,7 +1008,7 @@ public abstract class CollectionBinder {
final SourceModelBuildingContext sourceModelContext = buildingContext.getMetadataCollector().getSourceModelBuildingContext(); final SourceModelBuildingContext sourceModelContext = buildingContext.getMetadataCollector().getSourceModelBuildingContext();
if ( !property.hasAnnotationUsage( Bag.class, sourceModelContext ) ) { 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 ) ) { if ( property.hasAnnotationUsage( OrderColumn.class, sourceModelContext ) ) {
@ -1126,7 +1120,7 @@ public abstract class CollectionBinder {
return null; return null;
} }
private static Class<?> determineSemanticJavaType(MemberDetails property, MetadataBuildingContext buildingContext) { private static Class<?> determineSemanticJavaType(MemberDetails property) {
if ( property.isPlural() ) { if ( property.isPlural() ) {
final ClassDetails collectionClassDetails = property.getType().determineRawClass(); final ClassDetails collectionClassDetails = property.getType().determineRawClass();
final Class<?> collectionClass = collectionClassDetails.toJavaClass(); final Class<?> collectionClass = collectionClassDetails.toJavaClass();
@ -1536,25 +1530,23 @@ public abstract class CollectionBinder {
private void setHibernateFetchMode(org.hibernate.annotations.FetchMode fetchMode) { private void setHibernateFetchMode(org.hibernate.annotations.FetchMode fetchMode) {
switch ( fetchMode ) { switch ( fetchMode ) {
case JOIN -> { case JOIN :
collection.setFetchMode( FetchMode.JOIN ); collection.setFetchMode( FetchMode.JOIN );
collection.setLazy( false ); collection.setLazy( false );
} break;
case SELECT -> { case SELECT:
collection.setFetchMode( FetchMode.SELECT ); collection.setFetchMode( FetchMode.SELECT );
} break;
case SUBSELECT -> { case SUBSELECT:
collection.setFetchMode( FetchMode.SELECT ); collection.setFetchMode( FetchMode.SELECT );
collection.setSubselectLoadable( true ); collection.setSubselectLoadable( true );
collection.getOwner().setSubselectLoadableCollections( true ); collection.getOwner().setSubselectLoadableCollections( true );
} break;
default -> { default:
throw new AssertionFailure( "unknown fetch type" ); throw new AssertionFailure( "unknown fetch type" );
}
} }
} }
@SuppressWarnings("deprecation")
private void handleLazy() { private void handleLazy() {
final FetchType jpaFetchType = getJpaFetchType(); final FetchType jpaFetchType = getJpaFetchType();
collection.setLazy( jpaFetchType == LAZY ); collection.setLazy( jpaFetchType == LAZY );
@ -1877,7 +1869,6 @@ public abstract class CollectionBinder {
} }
private String getWhereOnClassClause() { private String getWhereOnClassClause() {
final TypeDetails elementType = property.getElementType();
final SQLRestriction restrictionOnClass = getOverridableAnnotation( final SQLRestriction restrictionOnClass = getOverridableAnnotation(
property.getAssociatedType().determineRawClass(), property.getAssociatedType().determineRawClass(),
SQLRestriction.class, SQLRestriction.class,
@ -2010,7 +2001,7 @@ public abstract class CollectionBinder {
public static String adjustUserSuppliedValueCollectionOrderingFragment(String orderByFragment) { public static String adjustUserSuppliedValueCollectionOrderingFragment(String orderByFragment) {
if ( orderByFragment != null ) { if ( orderByFragment != null ) {
orderByFragment = orderByFragment.trim(); orderByFragment = orderByFragment.trim();
if ( orderByFragment.length() == 0 || orderByFragment.equalsIgnoreCase( "asc" ) ) { if ( orderByFragment.isEmpty() || orderByFragment.equalsIgnoreCase( "asc" ) ) {
// This indicates something like either: // This indicates something like either:
// `@OrderBy()` // `@OrderBy()`
// `@OrderBy("asc") // `@OrderBy("asc")
@ -2071,7 +2062,6 @@ public abstract class CollectionBinder {
if ( key.getForeignKeyName() == null if ( key.getForeignKeyName() == null
&& key.getForeignKeyDefinition() == null && key.getForeignKeyDefinition() == null
&& collectionTableAnn.joinColumns().length == 1 ) { && collectionTableAnn.joinColumns().length == 1 ) {
//noinspection unchecked
final JoinColumn joinColumn = collectionTableAnn.joinColumns()[0]; final JoinColumn joinColumn = collectionTableAnn.joinColumns()[0];
final ForeignKey nestedForeignKey = joinColumn.foreignKey(); final ForeignKey nestedForeignKey = joinColumn.foreignKey();
key.setForeignKeyName( nullIfEmpty( nestedForeignKey.name() ) ); key.setForeignKeyName( nullIfEmpty( nestedForeignKey.name() ) );
@ -2237,12 +2227,13 @@ public abstract class CollectionBinder {
buildingContext buildingContext
); );
final Class<? extends CompositeUserType<?>> compositeUserType = resolveCompositeUserType( property, elementClass, buildingContext ); final Class<? extends CompositeUserType<?>> compositeUserType =
boolean isComposite = classType == EMBEDDABLE || compositeUserType != null; resolveCompositeUserType( property, elementClass, buildingContext );
final boolean isComposite = classType == EMBEDDABLE || compositeUserType != null;
holder.prepare( property, isComposite ); holder.prepare( property, isComposite );
if ( isComposite ) { if ( isComposite ) {
handleCompositeCollectionElement( hqlOrderBy, elementType, elementClass, holder, compositeUserType ); handleCompositeCollectionElement( hqlOrderBy, elementType, holder, compositeUserType );
} }
else { else {
handleCollectionElement( elementType, hqlOrderBy, elementClass, holder ); handleCollectionElement( elementType, hqlOrderBy, elementClass, holder );
@ -2283,7 +2274,6 @@ public abstract class CollectionBinder {
private void handleCompositeCollectionElement( private void handleCompositeCollectionElement(
String hqlOrderBy, String hqlOrderBy,
TypeDetails elementType, TypeDetails elementType,
ClassDetails elementClass,
CollectionPropertyHolder holder, CollectionPropertyHolder holder,
Class<? extends CompositeUserType<?>> compositeUserType) { Class<? extends CompositeUserType<?>> compositeUserType) {
//TODO be smart with isNullable //TODO be smart with isNullable
@ -2555,7 +2545,7 @@ public abstract class CollectionBinder {
private void processSoftDeletes() { private void processSoftDeletes() {
assert collection.getCollectionTable() != null; assert collection.getCollectionTable() != null;
final SoftDelete softDelete = extractSoftDelete( property, propertyHolder, buildingContext ); final SoftDelete softDelete = extractSoftDelete( property, buildingContext );
if ( softDelete == null ) { if ( softDelete == null ) {
return; return;
} }
@ -2568,20 +2558,18 @@ public abstract class CollectionBinder {
); );
} }
private static SoftDelete extractSoftDelete( private static SoftDelete extractSoftDelete(MemberDetails property, MetadataBuildingContext context) {
MemberDetails property,
PropertyHolder propertyHolder,
MetadataBuildingContext context) {
final SoftDelete fromProperty = property.getDirectAnnotationUsage( SoftDelete.class ); final SoftDelete fromProperty = property.getDirectAnnotationUsage( SoftDelete.class );
if ( fromProperty != null ) { if ( fromProperty != null ) {
return fromProperty; return fromProperty;
} }
else {
return extractFromPackage( return extractFromPackage(
SoftDelete.class, SoftDelete.class,
property.getDeclaringType(), property.getDeclaringType(),
context context
); );
}
} }
private void handleUnownedManyToMany( 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; abstract public void secondPass(Map<String, PersistentClass> persistentClasses) throws MappingException;
private static String columns(Value val) { private static String columns(Value val) {
StringBuilder columns = new StringBuilder(); final StringBuilder columns = new StringBuilder();
for ( Selectable selectable : val.getSelectables() ) { for ( Selectable selectable : val.getSelectables() ) {
if ( columns.length() > 0 ) { if ( !columns.isEmpty() ) {
columns.append( ", " ); columns.append( ", " );
} }
columns.append( selectable.getText() ); 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 CoreMessageLogger LOG = Logger.getMessageLogger( MethodHandles.lookup(), CoreMessageLogger.class, EntityBinder.class.getName() );
private static final String NATURAL_ID_CACHE_SUFFIX = "##NaturalId"; private static final String NATURAL_ID_CACHE_SUFFIX = "##NaturalId";
private MetadataBuildingContext context; private final MetadataBuildingContext context;
private String name; private String name;
private ClassDetails annotatedClass; private ClassDetails annotatedClass;
@ -245,13 +245,13 @@ public class EntityBinder {
entityBinder.handleIdentifier( holder, inheritanceStates, generators, inheritanceState ); entityBinder.handleIdentifier( holder, inheritanceStates, generators, inheritanceState );
final InFlightMetadataCollector collector = context.getMetadataCollector(); final InFlightMetadataCollector collector = context.getMetadataCollector();
if ( persistentClass instanceof RootClass ) { if ( persistentClass instanceof RootClass rootClass ) {
collector.addSecondPass( new CreateKeySecondPass( (RootClass) persistentClass ) ); collector.addSecondPass( new CreateKeySecondPass( rootClass ) );
bindSoftDelete( clazzToProcess, (RootClass) persistentClass, inheritanceState, context ); bindSoftDelete( clazzToProcess, rootClass, context );
} }
if ( persistentClass instanceof Subclass) { if ( persistentClass instanceof Subclass subclass ) {
assert superEntity != null; assert superEntity != null;
superEntity.addSubclass( (Subclass) persistentClass ); superEntity.addSubclass( subclass );
} }
collector.addEntityBinding( persistentClass ); collector.addEntityBinding( persistentClass );
// process secondary tables and complementary definitions (ie o.h.a.Table) // process secondary tables and complementary definitions (ie o.h.a.Table)
@ -306,12 +306,11 @@ public class EntityBinder {
private static void bindSoftDelete( private static void bindSoftDelete(
ClassDetails classDetails, ClassDetails classDetails,
RootClass rootClass, RootClass rootClass,
InheritanceState inheritanceState,
MetadataBuildingContext context) { MetadataBuildingContext context) {
// todo (soft-delete) : do we assume all package-level registrations are already available? // todo (soft-delete) : do we assume all package-level registrations are already available?
// or should this be a "second pass"? // or should this be a "second pass"?
final SoftDelete softDelete = extractSoftDelete( classDetails, inheritanceState, context ); final SoftDelete softDelete = extractSoftDelete( classDetails, context );
if ( softDelete != null ) { if ( softDelete != null ) {
SoftDeleteHelper.bindSoftDeleteIndicator( SoftDeleteHelper.bindSoftDeleteIndicator(
softDelete, softDelete,
@ -322,10 +321,7 @@ public class EntityBinder {
} }
} }
private static SoftDelete extractSoftDelete( private static SoftDelete extractSoftDelete(ClassDetails classDetails, MetadataBuildingContext context) {
ClassDetails classDetails,
InheritanceState inheritanceState,
MetadataBuildingContext context) {
final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext();
final SoftDelete fromClass = classDetails.getAnnotationUsage( SoftDelete.class, sourceModelContext ); final SoftDelete fromClass = classDetails.getAnnotationUsage( SoftDelete.class, sourceModelContext );
if ( fromClass != null ) { if ( fromClass != null ) {
@ -381,9 +377,10 @@ public class EntityBinder {
} }
private void applyTypeBinder(Annotation containingAnnotation, PersistentClass persistentClass) { private void applyTypeBinder(Annotation containingAnnotation, PersistentClass persistentClass) {
final Class<? extends TypeBinder<?>> binderClass = containingAnnotation.annotationType() final Class<? extends TypeBinder<?>> binderClass =
.getAnnotation( TypeBinderType.class ) containingAnnotation.annotationType()
.binder(); .getAnnotation( TypeBinderType.class )
.binder();
try { try {
//noinspection rawtypes //noinspection rawtypes
@ -1096,7 +1093,7 @@ public class EntityBinder {
private static String getMissingPropertiesString(Set<String> propertyNames) { private static String getMissingPropertiesString(Set<String> propertyNames) {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
for ( String property : propertyNames ) { for ( String property : propertyNames ) {
if ( sb.length() > 0 ) { if ( !sb.isEmpty() ) {
sb.append( ", " ); sb.append( ", " );
} }
sb.append( "'" ).append( property ).append( "'" ); sb.append( "'" ).append( property ).append( "'" );
@ -1113,16 +1110,11 @@ public class EntityBinder {
return new RootClass( metadataBuildingContext ); return new RootClass( metadataBuildingContext );
} }
else { else {
switch ( inheritanceState.getType() ) { return switch ( inheritanceState.getType() ) {
case SINGLE_TABLE: case SINGLE_TABLE -> new SingleTableSubclass( superEntity, metadataBuildingContext );
return new SingleTableSubclass( superEntity, metadataBuildingContext ); case JOINED -> new JoinedSubclass( superEntity, metadataBuildingContext );
case JOINED: case TABLE_PER_CLASS -> new UnionSubclass( superEntity, metadataBuildingContext );
return new JoinedSubclass( superEntity, metadataBuildingContext ); };
case TABLE_PER_CLASS:
return new UnionSubclass( superEntity, metadataBuildingContext );
default:
throw new AssertionFailure( "Unknown inheritance type: " + inheritanceState.getType() );
}
} }
} }
@ -1684,7 +1676,7 @@ public class EntityBinder {
effectiveCache = buildCacheMock( annotatedClass, context ); effectiveCache = buildCacheMock( annotatedClass, context );
isCached = isCacheable( sharedCacheMode, cacheable ); isCached = isCacheable( sharedCacheMode, cacheable );
} }
cacheConcurrentStrategy = resolveCacheConcurrencyStrategy( effectiveCache.usage() ); cacheConcurrentStrategy = getCacheConcurrencyStrategy( effectiveCache.usage() );
cacheRegion = effectiveCache.region(); cacheRegion = effectiveCache.region();
cacheLazyProperty = isCacheLazy( effectiveCache, annotatedClass ); 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) { private static Cache buildCacheMock(ClassDetails classDetails, MetadataBuildingContext context) {
final CacheAnnotation cacheUsage = HibernateAnnotations.CACHE.createUsage( context.getMetadataCollector().getSourceModelBuildingContext() ); final CacheAnnotation cacheUsage = HibernateAnnotations.CACHE.createUsage( context.getMetadataCollector().getSourceModelBuildingContext() );
cacheUsage.region( classDetails.getName() ); cacheUsage.region( classDetails.getName() );

View File

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

View File

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

View File

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

View File

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