Skip to content

Commit 9a84f8d

Browse files
committed
further cleanups in boot.model.internal
1 parent 648d30d commit 9a84f8d

File tree

9 files changed

+106
-126
lines changed

9 files changed

+106
-126
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/internal/AggregateComponentBinder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import org.hibernate.type.SqlTypes;
2020
import org.hibernate.type.descriptor.java.spi.EmbeddableAggregateJavaType;
2121

22+
import static org.hibernate.boot.model.internal.BasicValueBinder.Kind.ATTRIBUTE;
23+
2224
/**
2325
* Processes aggregate component annotations from Java classes and produces the Hibernate configuration-time metamodel,
2426
* that is, the objects defined in the package {@link org.hibernate.mapping}.
@@ -51,7 +53,7 @@ public static void processAggregate(
5153
component.setStructColumnNames( determineStructAttributeNames( inferredData, componentClassDetails ) );
5254

5355
// Determine the aggregate column
54-
final var basicValueBinder = new BasicValueBinder( BasicValueBinder.Kind.ATTRIBUTE, component, context );
56+
final var basicValueBinder = new BasicValueBinder( ATTRIBUTE, component, context );
5557
basicValueBinder.setReturnedClassName( inferredData.getClassOrElementType().getName() );
5658
basicValueBinder.setColumns( columns );
5759
basicValueBinder.setPersistentClassName( propertyHolder.getClassName() );

hibernate-core/src/main/java/org/hibernate/boot/model/internal/BasicValueBinder.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,14 @@ private static JdbcType getDescriptor(TypeConfiguration typeConfiguration, int c
293293
return typeConfiguration.getJdbcTypeRegistry().getDescriptor( code );
294294
}
295295

296+
public void setType(MemberDetails value, TypeDetails typeDetails) {
297+
setType( value, typeDetails, null, null );
298+
}
296299
public void setType(
297300
MemberDetails value,
298301
TypeDetails typeDetails,
299-
String declaringClassName,
300-
@Nullable ConverterDescriptor converterDescriptor) {
302+
@Nullable String declaringClassName,
303+
@Nullable ConverterDescriptor<?,?> converterDescriptor) {
301304
this.memberDetails = value;
302305
final boolean isArray = value.isArray();
303306
if ( typeDetails == null && !isArray ) {

hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55
package org.hibernate.boot.model.internal;
66

7-
import jakarta.persistence.ConstraintMode;
87
import jakarta.persistence.FetchType;
98
import jakarta.persistence.ForeignKey;
109
import jakarta.persistence.ManyToOne;
@@ -37,7 +36,6 @@
3736
import org.hibernate.mapping.Property;
3837
import org.hibernate.mapping.Selectable;
3938
import org.hibernate.mapping.SyntheticProperty;
40-
import org.hibernate.mapping.Table;
4139
import org.hibernate.mapping.ToOne;
4240
import org.hibernate.mapping.Value;
4341
import org.hibernate.models.spi.AnnotationTarget;
@@ -62,10 +60,11 @@
6260
import static java.util.Collections.addAll;
6361
import static org.hibernate.boot.model.internal.AnnotatedColumn.buildColumnOrFormulaFromAnnotation;
6462
import static org.hibernate.boot.model.internal.AnyBinder.resolveImplicitDiscriminatorStrategy;
63+
import static org.hibernate.boot.model.internal.BasicValueBinder.Kind.ANY_DISCRIMINATOR;
64+
import static org.hibernate.boot.model.internal.BasicValueBinder.Kind.ANY_KEY;
6565
import static org.hibernate.boot.model.internal.ForeignKeyType.NON_PRIMARY_KEY_REFERENCE;
6666
import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER;
6767
import static org.hibernate.internal.util.StringHelper.isEmpty;
68-
import static org.hibernate.internal.util.StringHelper.isNotBlank;
6968
import static org.hibernate.internal.util.StringHelper.qualifier;
7069
import static org.hibernate.internal.util.StringHelper.qualify;
7170
import static org.hibernate.internal.util.collections.ArrayHelper.isEmpty;
@@ -146,16 +145,15 @@ public static void createSyntheticPropertyReference(
146145
// figure out which table has the columns by looking
147146
// for a PersistentClass or Join in the hierarchy of
148147
// the target entity which has the first column
149-
final AttributeContainer columnOwner =
150-
findReferencedColumnOwner( targetEntity, joinColumns.getJoinColumns().get(0), context );
148+
final var firstJoinColumn = joinColumns.getJoinColumns().get( 0 );
149+
final var columnOwner = findReferencedColumnOwner( targetEntity, firstJoinColumn, context );
151150
checkColumnInSameTable( joinColumns, targetEntity, associatedEntity, context, columnOwner );
152151
// find all properties mapped to each column
153-
final List<Property> properties =
154-
findPropertiesByColumns( columnOwner, joinColumns, associatedEntity, context );
152+
final var properties = findPropertiesByColumns( columnOwner, joinColumns, associatedEntity, context );
155153
// create a Property along with the new synthetic
156154
// Component if necessary (or reuse the existing
157155
// Property that matches exactly)
158-
final Property property = referencedProperty(
156+
final var property = referencedProperty(
159157
targetEntity,
160158
associatedEntity,
161159
propertyName,
@@ -192,8 +190,8 @@ private static void checkColumnInSameTable(
192190
// we should only get called for owning side of association
193191
throw new AssertionFailure("no need to create synthetic properties for unowned collections");
194192
}
195-
for ( AnnotatedJoinColumn column: joinColumns.getJoinColumns() ) {
196-
final AttributeContainer owner = findReferencedColumnOwner( targetEntity, column, context );
193+
for ( var column: joinColumns.getJoinColumns() ) {
194+
final var owner = findReferencedColumnOwner( targetEntity, column, context );
197195
if ( owner == null ) {
198196
throw new AnnotationException( "A '@JoinColumn' for association "
199197
+ associationMessage( associatedEntity, joinColumns )
@@ -202,7 +200,7 @@ private static void checkColumnInSameTable(
202200
+ targetEntity.getEntityName() + "'" );
203201
}
204202
if ( owner != columnOwner) {
205-
final AnnotatedJoinColumn firstColumn = joinColumns.getJoinColumns().get(0);
203+
final var firstColumn = joinColumns.getJoinColumns().get(0);
206204
throw new AnnotationException( "The '@JoinColumn's for association "
207205
+ associationMessage( associatedEntity, joinColumns )
208206
+ " reference columns of different tables mapped by the target entity '"
@@ -241,7 +239,7 @@ private static Property referencedProperty(
241239
&& ownerEntity == columnOwner
242240
&& !( properties.get(0).getValue() instanceof ToOne ) ) {
243241
// no need to make a synthetic property
244-
final Property property = properties.get( 0 );
242+
final var property = properties.get( 0 );
245243
// mark it unique
246244
property.getValue().createUniqueKey( context );
247245
return property;
@@ -320,9 +318,9 @@ private static Property makeSyntheticComponentProperty(
320318
MetadataBuildingContext context,
321319
String syntheticPropertyName,
322320
List<Property> properties) {
323-
final Component embeddedComponent =
321+
final var embeddedComponent =
324322
embeddedComponent( ownerEntity, persistentClassOrJoin, context, properties );
325-
final Property result = new SyntheticProperty();
323+
final var result = new SyntheticProperty();
326324
result.setName( syntheticPropertyName );
327325
result.setPersistentClass( ownerEntity );
328326
result.setUpdatable( false );
@@ -379,7 +377,7 @@ private static Property cloneProperty(PersistentClass ownerEntity, MetadataBuild
379377
copy.addProperty( cloneProperty( ownerEntity, context, subproperty ) );
380378
}
381379
copy.sortProperties();
382-
final Property result = new SyntheticProperty();
380+
final var result = new SyntheticProperty();
383381
result.setName( property.getName() );
384382
result.setPersistentClass( ownerEntity );
385383
result.setUpdatable( false );
@@ -389,7 +387,7 @@ private static Property cloneProperty(PersistentClass ownerEntity, MetadataBuild
389387
return result;
390388
}
391389
else {
392-
final Property clone = shallowCopy( property );
390+
final var clone = shallowCopy( property );
393391
clone.setInsertable( false );
394392
clone.setUpdatable( false );
395393
clone.setNaturalIdentifier( false );
@@ -403,7 +401,7 @@ private static Property cloneProperty(PersistentClass ownerEntity, MetadataBuild
403401
* and other attributes.
404402
*/
405403
public static Property shallowCopy(Property property) {
406-
final Property clone = new SyntheticProperty();
404+
final var clone = new SyntheticProperty();
407405
clone.setCascade( property.getCascade() );
408406
clone.setInsertable( property.isInsertable() );
409407
clone.setLazy( property.isLazy() );
@@ -425,21 +423,20 @@ private static List<Property> findPropertiesByColumns(
425423
PersistentClass associatedEntity,
426424
MetadataBuildingContext context) {
427425

428-
final Table referencedTable = columnOwner.getTable();
429-
430426
// Build the list of column names in the exact order they were
431427
// specified by the @JoinColumn annotations.
432428
final List<Column> orderedColumns = new ArrayList<>( columns.getJoinColumns().size() );
433429
final Map<Column, Set<Property>> columnsToProperty = new HashMap<>();
434430
final var collector = context.getMetadataCollector();
431+
final var referencedTable = columnOwner.getTable();
435432
for ( var joinColumn : columns.getJoinColumns() ) {
436433
if ( joinColumn.isReferenceImplicit() ) {
437434
throw new AnnotationException( "Association " + associationMessage( associatedEntity, columns )
438435
+ " has a '@JoinColumn' which does not specify the 'referencedColumnName'"
439436
+ " (when an association has multiple '@JoinColumn's, they must each specify their 'referencedColumnName')");
440437
}
441438
final String name = collector.getPhysicalColumnName( referencedTable, joinColumn.getReferencedColumn() );
442-
final Column column = new Column( name );
439+
final var column = new Column( name );
443440
orderedColumns.add( column );
444441
columnsToProperty.put( column, new LinkedHashSet<>() ); //need to use a LinkedHashSet here to make it deterministic
445442
}
@@ -450,7 +447,7 @@ private static List<Property> findPropertiesByColumns(
450447
if ( columnOwner instanceof PersistentClass persistentClass ) {
451448
// Process ToOne associations after Components, Basic and Id properties
452449
final List<Property> toOneProperties = new ArrayList<>();
453-
for ( Property property : persistentClass.getReferenceableProperties() ) {
450+
for ( var property : persistentClass.getReferenceableProperties() ) {
454451
if ( property.getValue() instanceof ToOne ) {
455452
toOneProperties.add( property );
456453
}
@@ -464,16 +461,16 @@ private static List<Property> findPropertiesByColumns(
464461
else {
465462
// special case for entities with multiple @Id properties
466463
final Component key = persistentClass.getIdentifierMapper();
467-
for ( Property p : key.getProperties() ) {
464+
for ( var p : key.getProperties() ) {
468465
matchColumnsByProperty( p, columnsToProperty );
469466
}
470467
}
471-
for ( Property property : toOneProperties ) {
468+
for ( var property : toOneProperties ) {
472469
matchColumnsByProperty( property, columnsToProperty );
473470
}
474471
}
475472
else {
476-
for ( Property property : ((Join) columnOwner).getProperties() ) {
473+
for ( var property : ((Join) columnOwner).getProperties() ) {
477474
matchColumnsByProperty( property, columnsToProperty );
478475
}
479476
}
@@ -582,7 +579,7 @@ private static void matchColumnsByProperty(Property property, Map<Column, Set<Pr
582579
* If propertyName is null or empty, the IdentifierProperty is returned
583580
*/
584581
public static Property findPropertyByName(PersistentClass associatedClass, String propertyName) {
585-
final Property idProperty = associatedClass.getIdentifierProperty();
582+
final var idProperty = associatedClass.getIdentifierProperty();
586583
final String idName = idProperty == null ? null : idProperty.getName();
587584
try {
588585
return isEmpty( propertyName ) || propertyName.equals( idName )
@@ -732,8 +729,7 @@ public static Any buildAnyValue(
732729
any.setLazy( lazy );
733730
any.setOnDeleteAction( onDeleteAction );
734731

735-
final var discriminatorValueBinder =
736-
new BasicValueBinder( BasicValueBinder.Kind.ANY_DISCRIMINATOR, context );
732+
final var discriminatorValueBinder = new BasicValueBinder( ANY_DISCRIMINATOR, context );
737733

738734
// TODO: if there can be only one discriminator column,
739735
// why are we making a whole array of them??
@@ -755,7 +751,7 @@ public static Any buildAnyValue(
755751
discriminatorValueBinder.setColumns( discriminatorColumns );
756752

757753
discriminatorValueBinder.setReturnedClassName( inferredData.getTypeName() );
758-
discriminatorValueBinder.setType( memberDetails, memberDetails.getType(), null, null );
754+
discriminatorValueBinder.setType( memberDetails, memberDetails.getType() );
759755

760756
final BasicValue discriminator = discriminatorValueBinder.make();
761757
any.setDiscriminator( discriminator );
@@ -785,7 +781,7 @@ public static Any buildAnyValue(
785781
resolveImplicitDiscriminatorStrategy( anyDiscriminatorImplicitValues, context ) );
786782
}
787783

788-
final var keyValueBinder = new BasicValueBinder( BasicValueBinder.Kind.ANY_KEY, context );
784+
final var keyValueBinder = new BasicValueBinder( ANY_KEY, context );
789785
final var columns = keyColumns.getJoinColumns();
790786
assert columns.size() == 1;
791787
keyColumns.setTable( any.getTable() );
@@ -795,7 +791,7 @@ public static Any buildAnyValue(
795791
column.setNullable( false );
796792
}
797793
}
798-
keyValueBinder.setType( memberDetails, memberDetails.getType(), null, null );
794+
keyValueBinder.setType( memberDetails, memberDetails.getType() );
799795
final BasicValue keyDescriptor = keyValueBinder.make();
800796
any.setKey( keyDescriptor );
801797
keyValueBinder.fillSimpleValue();
@@ -848,7 +844,7 @@ public static Map<String,String> toAliasTableMap(SqlFragmentAlias[] aliases){
848844
final Map<String,String> result = new HashMap<>();
849845
for ( var aliasAnnotation : aliases ) {
850846
final String table = aliasAnnotation.table();
851-
if ( isNotBlank( table ) ) {
847+
if ( !table.isBlank() ) {
852848
result.put( aliasAnnotation.alias(), table );
853849
}
854850
}
@@ -903,7 +899,7 @@ public static EnumSet<CascadeType> aggregateCascadeTypes(
903899
private static EnumSet<CascadeType> convertToHibernateCascadeType(jakarta.persistence.CascadeType[] cascades) {
904900
final var cascadeTypes = EnumSet.noneOf( CascadeType.class );
905901
if ( cascades != null ) {
906-
for ( jakarta.persistence.CascadeType cascade: cascades ) {
902+
for ( var cascade: cascades ) {
907903
cascadeTypes.add( convertCascadeType( cascade ) );
908904
}
909905
}
@@ -963,7 +959,7 @@ public static void checkMappedByType(
963959
PropertyHolder propertyHolder,
964960
Map<String, PersistentClass> persistentClasses) {
965961
if ( targetValue instanceof Collection collection ) {
966-
final ToOne element = (ToOne) collection.getElement();
962+
final var element = (ToOne) collection.getElement();
967963
checkMappedByType( mappedBy, propertyName, propertyHolder, persistentClasses, element );
968964
}
969965
else if ( targetValue instanceof ToOne toOne ) {
@@ -982,8 +978,7 @@ private static void checkMappedByType(
982978
PersistentClass ownerClass = propertyHolder.getPersistentClass();
983979
while ( ownerClass != null ) {
984980
if ( checkReferencedClass( ownerClass, referencedClass ) ) {
985-
// the two entities map to the same table
986-
// so we are good
981+
// the two entities map to the same table, so we are good
987982
return;
988983
}
989984
ownerClass = ownerClass.getSuperPersistentClass();
@@ -1013,7 +1008,7 @@ public static boolean noConstraint(ForeignKey foreignKey, boolean noConstraintBy
10131008
return false;
10141009
}
10151010
else {
1016-
final ConstraintMode mode = foreignKey.value();
1011+
final var mode = foreignKey.value();
10171012
return mode == NO_CONSTRAINT
10181013
|| mode == PROVIDER_DEFAULT && noConstraintByDefault;
10191014
}

0 commit comments

Comments
 (0)