22
22
import org .hibernate .annotations .OnDeleteAction ;
23
23
import org .hibernate .annotations .SqlFragmentAlias ;
24
24
import org .hibernate .boot .registry .classloading .spi .ClassLoadingException ;
25
- import org .hibernate .boot .spi .InFlightMetadataCollector ;
26
25
import org .hibernate .boot .spi .MetadataBuildingContext ;
27
26
import org .hibernate .boot .spi .PropertyData ;
28
27
import org .hibernate .internal .util .collections .ArrayHelper ;
74
73
import static org .hibernate .models .spi .TypeDetailsHelper .resolveRawClass ;
75
74
import static org .hibernate .property .access .spi .BuiltInPropertyAccessStrategies .EMBEDDED ;
76
75
import static org .hibernate .property .access .spi .BuiltInPropertyAccessStrategies .NOOP ;
77
- import static org .hibernate .property .access .spi .BuiltInPropertyAccessStrategies .interpret ;
78
76
79
77
/**
80
78
* @author Emmanuel Bernard
@@ -268,29 +266,23 @@ private static void registerSyntheticProperty(
268
266
String propertyName ,
269
267
String syntheticPropertyName ,
270
268
MetadataBuildingContext context ) {
269
+ final var collector = context .getMetadataCollector ();
271
270
if ( value instanceof ToOne toOne ) {
272
271
toOne .setReferencedPropertyName ( syntheticPropertyName );
273
272
toOne .setReferenceToPrimaryKey ( false );
274
- context .getMetadataCollector ().addUniquePropertyReference (
275
- ownerEntity .getEntityName (),
276
- syntheticPropertyName
277
- );
273
+ collector .addUniquePropertyReference ( ownerEntity .getEntityName (), syntheticPropertyName );
278
274
}
279
275
else if ( value instanceof Collection collection ) {
280
276
collection .setReferencedPropertyName ( syntheticPropertyName );
281
277
//not unique because we could create a mtm wo association table
282
- context .getMetadataCollector ().addPropertyReference (
283
- ownerEntity .getEntityName (),
284
- syntheticPropertyName
285
- );
278
+ collector .addPropertyReference ( ownerEntity .getEntityName (), syntheticPropertyName );
286
279
}
287
280
else {
288
281
throw new AssertionFailure ( "Property ref on an unexpected Value type: " + value .getClass ().getName () );
289
282
}
290
283
final String associatedEntityName = associatedClass .getEntityName ();
291
284
final String generatedName = inverse ? "inverse__" + associatedEntityName : associatedEntityName ;
292
- context .getMetadataCollector ()
293
- .addPropertyReferencedAssociation ( generatedName , propertyName , syntheticPropertyName );
285
+ collector .addPropertyReferencedAssociation ( generatedName , propertyName , syntheticPropertyName );
294
286
}
295
287
296
288
private static String syntheticPropertyName (
@@ -311,12 +303,9 @@ private static String associationMessage(PersistentClass associatedEntity, Annot
311
303
}
312
304
else {
313
305
final PropertyHolder propertyHolder = joinColumns .getPropertyHolder ();
314
- if ( propertyHolder != null ) {
315
- return "'" + propertyHolder .getEntityName () + "." + joinColumns .getPropertyName () + "'" ;
316
- }
317
- else {
318
- return "" ;
319
- }
306
+ return propertyHolder != null
307
+ ? "'" + propertyHolder .getEntityName () + "." + joinColumns .getPropertyName () + "'"
308
+ : "" ;
320
309
}
321
310
}
322
311
@@ -354,7 +343,7 @@ else if ( persistentClassOrJoin instanceof Join join ) {
354
343
result .setUpdateable ( false );
355
344
result .setInsertable ( false );
356
345
result .setValue ( embeddedComponent );
357
- result .setPropertyAccessorName ( "embedded" );
346
+ result .setPropertyAccessorName ( EMBEDDED . getExternalName () );
358
347
if ( persistentClassOrJoin instanceof Join ) {
359
348
// the referenced column is in the joined table, add the synthetic property there
360
349
persistentClassOrJoin .addProperty ( result );
@@ -433,10 +422,10 @@ private static List<Property> findPropertiesByColumns(
433
422
// specified by the @JoinColumn annotations.
434
423
final List <Column > orderedColumns = new ArrayList <>( columns .getJoinColumns ().size () );
435
424
final Map <Column , Set <Property >> columnsToProperty = new HashMap <>();
436
- final InFlightMetadataCollector collector = context .getMetadataCollector ();
437
- for ( AnnotatedJoinColumn joinColumn : columns .getJoinColumns () ) {
425
+ final var collector = context .getMetadataCollector ();
426
+ for ( var joinColumn : columns .getJoinColumns () ) {
438
427
if ( joinColumn .isReferenceImplicit () ) {
439
- throw new AnnotationException ("Association " + associationMessage ( associatedEntity , columns )
428
+ throw new AnnotationException ( "Association " + associationMessage ( associatedEntity , columns )
440
429
+ " has a '@JoinColumn' which does not specify the 'referencedColumnName'"
441
430
+ " (when an association has multiple '@JoinColumn's, they must each specify their 'referencedColumnName')" );
442
431
}
@@ -554,28 +543,28 @@ else if ( orderedProperties.contains( property ) ) {
554
543
}
555
544
556
545
private static void matchColumnsByProperty (Property property , Map <Column , Set <Property >> columnsToProperty ) {
557
- if ( property != null
558
- && NOOP != interpret ( property .getPropertyAccessorName () )
559
- && EMBEDDED != interpret ( property .getPropertyAccessorName () ) ) {
560
- //TODO: we can't return subproperties because the caller
561
- // needs top level properties, but this results in
562
- // a limitation where I need to be referencing all
563
- // columns of an embeddable instead of just some
564
- // if ( property.isComposite() ) {
565
- // for ( Property sp : ( (Component) property.getValue() ).getProperties() ) {
566
- // matchColumnsByProperty( sp, columnsToProperty );
546
+ if ( property != null ) {
547
+ final String propertyAccessorName = property .getPropertyAccessorName ();
548
+ if ( !NOOP .getExternalName ().equals ( propertyAccessorName )
549
+ && !EMBEDDED .getExternalName ().equals ( propertyAccessorName ) ) {
550
+ //TODO: we can't return subproperties because the caller
551
+ // needs top level properties, but this results in
552
+ // a limitation where I need to be referencing all
553
+ // columns of an embeddable instead of just some
554
+ // if ( property.isComposite() ) {
555
+ // for ( Property sp : ( (Component) property.getValue() ).getProperties() ) {
556
+ // matchColumnsByProperty( sp, columnsToProperty );
557
+ // }
567
558
// }
568
- // }
569
- // else {
570
- for ( Selectable selectable : property .getSelectables () ) {
571
- //can be a Formula, so we don't cast
572
- //noinspection SuspiciousMethodCalls
573
- if ( columnsToProperty .containsKey ( selectable ) ) {
574
- //noinspection SuspiciousMethodCalls
575
- columnsToProperty .get ( selectable ).add ( property );
559
+ // else {
560
+ for ( Selectable selectable : property .getSelectables () ) {
561
+ if ( selectable instanceof Column column
562
+ && columnsToProperty .containsKey ( column ) ) {
563
+ columnsToProperty .get ( column ).add ( property );
564
+ }
576
565
}
566
+ // }
577
567
}
578
- // }
579
568
}
580
569
}
581
570
@@ -597,9 +586,9 @@ public static Property findPropertyByName(PersistentClass associatedClass, Strin
597
586
property = idProperty ;
598
587
propertyName = propertyName .substring ( idName .length () + 1 );
599
588
}
600
- final StringTokenizer tokens = new StringTokenizer ( propertyName , "." , false );
601
- while ( tokens .hasMoreElements () ) {
602
- String element = ( String ) tokens .nextElement ();
589
+ final var tokens = new StringTokenizer ( propertyName , "." , false );
590
+ while ( tokens .hasMoreTokens () ) {
591
+ final String element = tokens .nextToken ();
603
592
if ( property == null ) {
604
593
property = associatedClass .getProperty ( element );
605
594
}
@@ -614,13 +603,13 @@ public static Property findPropertyByName(PersistentClass associatedClass, Strin
614
603
}
615
604
catch ( MappingException e ) {
616
605
try {
617
- //if we do not find it try to check the identifier mapper
606
+ // if we do not find it, try to check the identifier mapper
618
607
if ( associatedClass .getIdentifierMapper () == null ) {
619
608
return null ;
620
609
}
621
- final StringTokenizer tokens = new StringTokenizer ( propertyName , "." , false );
622
- while ( tokens .hasMoreElements () ) {
623
- final String element = ( String ) tokens .nextElement ();
610
+ final var tokens = new StringTokenizer ( propertyName , "." , false );
611
+ while ( tokens .hasMoreTokens () ) {
612
+ final String element = tokens .nextToken ();
624
613
if ( property == null ) {
625
614
property = associatedClass .getIdentifierMapper ().getProperty ( element );
626
615
}
@@ -650,9 +639,9 @@ public static Property findPropertyByName(Component component, String propertyNa
650
639
return null ;
651
640
}
652
641
else {
653
- final StringTokenizer tokens = new StringTokenizer ( propertyName , "." , false );
654
- while ( tokens .hasMoreElements () ) {
655
- final String element = ( String ) tokens .nextElement ();
642
+ final var tokens = new StringTokenizer ( propertyName , "." , false );
643
+ while ( tokens .hasMoreTokens () ) {
644
+ final String element = tokens .nextToken ();
656
645
if ( property == null ) {
657
646
property = component .getProperty ( element );
658
647
}
@@ -667,13 +656,13 @@ public static Property findPropertyByName(Component component, String propertyNa
667
656
}
668
657
catch (MappingException e ) {
669
658
try {
670
- //if we do not find it try to check the identifier mapper
659
+ // if we do not find it, try to check the identifier mapper
671
660
if ( component .getOwner ().getIdentifierMapper () == null ) {
672
661
return null ;
673
662
}
674
- final StringTokenizer tokens = new StringTokenizer ( propertyName , "." , false );
675
- while ( tokens .hasMoreElements () ) {
676
- final String element = ( String ) tokens .nextElement ();
663
+ final var tokens = new StringTokenizer ( propertyName , "." , false );
664
+ while ( tokens .hasMoreTokens () ) {
665
+ final String element = tokens .nextToken ();
677
666
if ( property == null ) {
678
667
property = component .getOwner ().getIdentifierMapper ().getProperty ( element );
679
668
}
@@ -722,7 +711,7 @@ public static AttributeContainer findColumnOwner(
722
711
PersistentClass persistentClass ,
723
712
String columnName ,
724
713
MetadataBuildingContext context ) {
725
- final InFlightMetadataCollector metadataCollector = context .getMetadataCollector ();
714
+ final var metadataCollector = context .getMetadataCollector ();
726
715
PersistentClass current = persistentClass ;
727
716
while ( current != null ) {
728
717
try {
@@ -916,8 +905,7 @@ public static EnumSet<CascadeType> aggregateCascadeTypes(
916
905
Cascade cascadeAnnotation ,
917
906
boolean orphanRemoval ,
918
907
MetadataBuildingContext context ) {
919
- final EnumSet <CascadeType > cascades =
920
- convertToHibernateCascadeType ( cascadeTypes );
908
+ final var cascades = convertToHibernateCascadeType ( cascadeTypes );
921
909
final CascadeType [] hibernateCascades =
922
910
cascadeAnnotation == null
923
911
? null
@@ -937,7 +925,7 @@ public static EnumSet<CascadeType> aggregateCascadeTypes(
937
925
}
938
926
939
927
private static EnumSet <CascadeType > convertToHibernateCascadeType (jakarta .persistence .CascadeType [] cascades ) {
940
- final EnumSet < CascadeType > cascadeTypes = EnumSet .noneOf ( CascadeType .class );
928
+ final var cascadeTypes = EnumSet .noneOf ( CascadeType .class );
941
929
if ( cascades != null ) {
942
930
for ( jakarta .persistence .CascadeType cascade : cascades ) {
943
931
cascadeTypes .add ( convertCascadeType ( cascade ) );
@@ -1076,14 +1064,12 @@ public static <A extends Annotation> A extractFromPackage(
1076
1064
// where context.getMetadataCollector() can cache some of this - either the annotations themselves
1077
1065
// or even just the XPackage resolutions
1078
1066
1079
- final String declaringClassName = classDetails .getName ();
1080
- final String packageName = qualifier ( declaringClassName );
1067
+ final String packageName = qualifier ( classDetails .getName () );
1081
1068
if ( isEmpty ( packageName ) ) {
1082
1069
return null ;
1083
1070
}
1084
1071
else {
1085
- final ModelsContext modelsContext =
1086
- context .getBootstrapContext ().getModelsContext ();
1072
+ final var modelsContext = context .getBootstrapContext ().getModelsContext ();
1087
1073
try {
1088
1074
return modelsContext .getClassDetailsRegistry ()
1089
1075
.resolveClassDetails ( packageName + ".package-info" )
0 commit comments