@@ -461,8 +461,7 @@ private static <X, Y> AttributeMetadata<X, Y> determineAttributeMetadata(
461
461
propertyMapping ,
462
462
attributeContext .getOwnerType (),
463
463
member ,
464
- AttributeClassification .ANY ,
465
- context
464
+ AttributeClassification .ANY
466
465
);
467
466
}
468
467
else if ( type instanceof EntityType ) {
@@ -471,8 +470,7 @@ else if ( type instanceof EntityType ) {
471
470
propertyMapping ,
472
471
attributeContext .getOwnerType (),
473
472
member ,
474
- determineSingularAssociationClassification ( member ),
475
- context
473
+ determineSingularAssociationClassification ( member )
476
474
);
477
475
}
478
476
else if ( type instanceof CollectionType ) {
@@ -486,8 +484,7 @@ else if ( type instanceof CollectionType ) {
486
484
member ,
487
485
collectionClassification ( elementType , isManyToMany ),
488
486
elementClassification ( elementType , isManyToMany ),
489
- indexClassification ( value ),
490
- context
487
+ indexClassification ( value )
491
488
);
492
489
}
493
490
else if ( value instanceof OneToMany ) {
@@ -516,8 +513,7 @@ else if ( type instanceof ComponentType ) {
516
513
propertyMapping ,
517
514
attributeContext .getOwnerType (),
518
515
member ,
519
- AttributeClassification .EMBEDDED ,
520
- context
516
+ AttributeClassification .EMBEDDED
521
517
);
522
518
}
523
519
else {
@@ -527,8 +523,7 @@ else if ( type instanceof ComponentType ) {
527
523
propertyMapping ,
528
524
attributeContext .getOwnerType (),
529
525
member ,
530
- AttributeClassification .BASIC ,
531
- context
526
+ AttributeClassification .BASIC
532
527
);
533
528
}
534
529
throw new UnsupportedMappingException ( "oops, we are missing something: " + propertyMapping );
@@ -557,9 +552,9 @@ else if ( elementType instanceof ComponentType ) {
557
552
return AttributeClassification .EMBEDDED ;
558
553
}
559
554
else if ( elementType instanceof EntityType ) {
560
- return isManyToMany ?
561
- AttributeClassification .MANY_TO_MANY :
562
- AttributeClassification .ONE_TO_MANY ;
555
+ return isManyToMany
556
+ ? AttributeClassification .MANY_TO_MANY
557
+ : AttributeClassification .ONE_TO_MANY ;
563
558
}
564
559
else {
565
560
return AttributeClassification .BASIC ;
@@ -569,9 +564,9 @@ else if ( elementType instanceof EntityType ) {
569
564
private static AttributeClassification collectionClassification (
570
565
org .hibernate .type .Type elementType , boolean isManyToMany ) {
571
566
if ( elementType instanceof EntityType ) {
572
- return isManyToMany ?
573
- AttributeClassification .MANY_TO_MANY :
574
- AttributeClassification .ONE_TO_MANY ;
567
+ return isManyToMany
568
+ ? AttributeClassification .MANY_TO_MANY
569
+ : AttributeClassification .ONE_TO_MANY ;
575
570
}
576
571
else {
577
572
return AttributeClassification .ELEMENT_COLLECTION ;
@@ -680,7 +675,7 @@ private static EmbeddableRepresentationStrategy ownerRepresentationStrategy(
680
675
return ownerBootDescriptor .getBuildingContext ()
681
676
.getBootstrapContext ()
682
677
.getRepresentationStrategySelector ()
683
- .resolveStrategy (ownerBootDescriptor , null ,
678
+ .resolveStrategy ( ownerBootDescriptor , null ,
684
679
metadataContext .getRuntimeModelCreationContext () );
685
680
}
686
681
else {
@@ -728,66 +723,49 @@ private static Member resolveVirtualIdentifierMember( Property property, EntityP
728
723
final ManagedDomainType <?> ownerType = attributeContext .getOwnerType ();
729
724
final Property property = attributeContext .getPropertyMapping ();
730
725
final Type .PersistenceType persistenceType = ownerType .getPersistenceType ();
731
- if ( Type .PersistenceType .EMBEDDABLE == persistenceType ) {
732
- return embeddedMemberResolver .resolveMember ( attributeContext , metadataContext );
733
- }
734
- else if ( Type .PersistenceType .MAPPED_SUPERCLASS == persistenceType ) {
735
- return resolveMappedSuperclassMember (
736
- property ,
737
- (MappedSuperclassDomainType <?>) ownerType ,
738
- metadataContext
739
- );
740
- }
741
- else if ( Type .PersistenceType .ENTITY == persistenceType ) {
742
- return resolveEntityMember ( property , getDeclaringEntity ( (AbstractIdentifiableType <?>) ownerType , metadataContext ) );
743
- }
744
- else {
745
- throw new IllegalArgumentException ( "Unexpected owner type : " + persistenceType );
746
- }
726
+ return switch ( persistenceType ) {
727
+ case ENTITY ->
728
+ resolveEntityMember ( property ,
729
+ getDeclaringEntity ( (AbstractIdentifiableType <?>) ownerType , metadataContext ) );
730
+ case MAPPED_SUPERCLASS ->
731
+ resolveMappedSuperclassMember ( property , (MappedSuperclassDomainType <?>) ownerType , metadataContext );
732
+ case EMBEDDABLE ->
733
+ embeddedMemberResolver .resolveMember ( attributeContext , metadataContext );
734
+ default -> throw new IllegalArgumentException ( "Unexpected owner type : " + persistenceType );
735
+ };
747
736
};
748
737
749
738
private static Member resolveEntityMember (Property property , EntityPersister declaringEntity ) {
750
739
final String propertyName = property .getName ();
751
740
final AttributeMapping attributeMapping = declaringEntity .findAttributeMapping ( propertyName );
752
- if ( attributeMapping == null ) {
753
- // just like in #determineIdentifierJavaMember , this *should* indicate we have an IdClass mapping
754
- return resolveVirtualIdentifierMember ( property , declaringEntity );
755
- }
756
- else {
757
- final Getter getter = getter ( declaringEntity , property );
758
- return getter instanceof PropertyAccessMapImpl .GetterImpl
759
- ? new MapMember ( propertyName , property .getType ().getReturnedClass () )
760
- : getter .getMember ();
761
- }
741
+ return attributeMapping == null
742
+ // just like in #determineIdentifierJavaMember , this *should* indicate we have an IdClass mapping
743
+ ? resolveVirtualIdentifierMember ( property , declaringEntity )
744
+ : getter ( declaringEntity , property , propertyName , property .getType ().getReturnedClass () );
762
745
}
763
746
764
747
private static Member resolveMappedSuperclassMember (
765
748
Property property ,
766
749
MappedSuperclassDomainType <?> ownerType ,
767
- MetadataContext metadataContext ) {
768
- final EntityPersister declaringEntity = getDeclaringEntity ( (AbstractIdentifiableType <?>) ownerType , metadataContext );
750
+ MetadataContext context ) {
751
+ final EntityPersister declaringEntity =
752
+ getDeclaringEntity ( (AbstractIdentifiableType <?>) ownerType , context );
769
753
if ( declaringEntity != null ) {
770
754
return resolveEntityMember ( property , declaringEntity );
771
755
}
772
756
else {
773
757
final ManagedDomainType <?> subType = ownerType .getSubTypes ().iterator ().next ();
774
758
final Type .PersistenceType persistenceType = subType .getPersistenceType ();
775
- if ( persistenceType == Type .PersistenceType .ENTITY ) {
776
- return resolveEntityMember ( property , getDeclaringEntity ( (AbstractIdentifiableType <?>) subType , metadataContext ) );
777
- }
778
- else if ( persistenceType == Type .PersistenceType .EMBEDDABLE ) {
779
- return resolveEmbeddedMember ( property , (EmbeddableDomainType <?>) subType , metadataContext );
780
- }
781
- else if ( persistenceType == Type .PersistenceType .MAPPED_SUPERCLASS ) {
782
- return resolveMappedSuperclassMember (
783
- property ,
784
- (MappedSuperclassDomainType <?>) subType ,
785
- metadataContext
786
- );
787
- }
788
- else {
789
- throw new IllegalArgumentException ( "Unexpected subtype: " + persistenceType );
790
- }
759
+ return switch ( persistenceType ) {
760
+ case ENTITY ->
761
+ resolveEntityMember ( property ,
762
+ getDeclaringEntity ( (AbstractIdentifiableType <?>) subType , context ) );
763
+ case MAPPED_SUPERCLASS ->
764
+ resolveMappedSuperclassMember ( property , (MappedSuperclassDomainType <?>) subType , context );
765
+ case EMBEDDABLE ->
766
+ resolveEmbeddedMember ( property , (EmbeddableDomainType <?>) subType , context );
767
+ default -> throw new IllegalArgumentException ( "Unexpected PersistenceType: " + persistenceType );
768
+ };
791
769
}
792
770
}
793
771
@@ -797,18 +775,12 @@ else if ( persistenceType == Type.PersistenceType.MAPPED_SUPERCLASS ) {
797
775
final EntityPersister declaringEntityMapping = getDeclaringEntity ( identifiableType , metadataContext );
798
776
final EntityIdentifierMapping identifierMapping = declaringEntityMapping .getIdentifierMapping ();
799
777
final Property propertyMapping = attributeContext .getPropertyMapping ();
800
- if ( !propertyMapping .getName ().equals ( identifierMapping .getAttributeName () ) ) {
801
- // this *should* indicate processing part of an IdClass...
802
- return virtualIdentifierMemberResolver .resolveMember ( attributeContext , metadataContext );
803
- }
778
+ return !propertyMapping .getName ().equals ( identifierMapping .getAttributeName () )
779
+ // this *should* indicate processing part of an IdClass...
780
+ ? virtualIdentifierMemberResolver .resolveMember ( attributeContext , metadataContext )
781
+ : getter ( declaringEntityMapping , propertyMapping ,
782
+ identifierMapping .getAttributeName (), identifierMapping .getJavaType ().getJavaTypeClass () );
804
783
805
- final Getter getter = getter ( declaringEntityMapping , propertyMapping );
806
- if ( getter instanceof PropertyAccessMapImpl .GetterImpl ) {
807
- return new MapMember ( identifierMapping .getAttributeName (), identifierMapping .getJavaType ().getJavaTypeClass () );
808
- }
809
- else {
810
- return getter .getMember ();
811
- }
812
784
};
813
785
814
786
private final MemberResolver versionMemberResolver = (attributeContext , metadataContext ) -> {
@@ -824,20 +796,20 @@ else if ( persistenceType == Type.PersistenceType.MAPPED_SUPERCLASS ) {
824
796
// this should never happen, but to be safe...
825
797
throw new IllegalArgumentException ( "Given property did not match declared version property" );
826
798
}
827
-
828
- final Getter getter = getter ( entityPersister , attributeContext .getPropertyMapping () );
829
- if ( getter instanceof PropertyAccessMapImpl .GetterImpl ) {
830
- return new MapMember ( versionPropertyName , versionMapping .getJavaType ().getJavaTypeClass () );
831
- }
832
- else {
833
- return getter .getMember ();
834
- }
799
+ return getter ( entityPersister , attributeContext .getPropertyMapping (),
800
+ versionPropertyName , versionMapping .getJavaType ().getJavaTypeClass () );
835
801
};
836
802
837
- private static Getter getter (EntityPersister declaringEntityMapping , Property propertyMapping ) {
838
- return declaringEntityMapping .getRepresentationStrategy ()
839
- .resolvePropertyAccess ( propertyMapping )
840
- .getGetter ();
803
+ private static Member getter (EntityPersister persister , Property property , String name , Class <?> type ) {
804
+ final Getter getter = getter ( persister , property );
805
+ return getter instanceof PropertyAccessMapImpl .GetterImpl
806
+ ? new MapMember ( name , type )
807
+ : getter .getMember ();
841
808
}
842
809
810
+ private static Getter getter (EntityPersister persister , Property property ) {
811
+ return persister .getRepresentationStrategy ()
812
+ .resolvePropertyAccess ( property )
813
+ .getGetter ();
814
+ }
843
815
}
0 commit comments