4
4
*/
5
5
package org .hibernate .boot .model .internal ;
6
6
7
- import java .lang .annotation .Annotation ;
8
7
import java .util .ArrayList ;
9
8
import java .util .HashMap ;
10
9
import java .util .List ;
24
23
import org .hibernate .boot .spi .MetadataBuildingContext ;
25
24
import org .hibernate .internal .CoreLogging ;
26
25
import org .hibernate .internal .util .StringHelper ;
27
- import org .hibernate .internal .util .collections .CollectionHelper ;
28
26
import org .hibernate .models .spi .AnnotationTarget ;
29
27
import org .hibernate .models .spi .ClassDetails ;
30
28
import org .hibernate .models .spi .MemberDetails ;
36
34
37
35
import jakarta .persistence .AssociationOverride ;
38
36
import jakarta .persistence .AttributeOverride ;
39
- import jakarta .persistence .CheckConstraint ;
40
37
import jakarta .persistence .Column ;
41
38
import jakarta .persistence .Embeddable ;
42
39
import jakarta .persistence .Entity ;
47
44
48
45
import static org .hibernate .boot .model .internal .TimeZoneStorageHelper .isOffsetTimeClass ;
49
46
import static org .hibernate .boot .model .internal .TimeZoneStorageHelper .useColumnForTimeZoneStorage ;
47
+ import static org .hibernate .internal .util .StringHelper .isNotBlank ;
50
48
import static org .hibernate .internal .util .StringHelper .qualify ;
49
+ import static org .hibernate .internal .util .collections .CollectionHelper .isEmpty ;
50
+ import static org .hibernate .internal .util .collections .CollectionHelper .isNotEmpty ;
51
51
52
52
/**
53
53
* @author Emmanuel Bernard
@@ -153,10 +153,12 @@ public boolean isInIdClass() {
153
153
if ( isInIdClass != null ) {
154
154
return isInIdClass ;
155
155
}
156
- if ( parent != null ) {
156
+ else if ( parent != null ) {
157
157
return parent .isInIdClass ();
158
158
}
159
- return false ;
159
+ else {
160
+ return false ;
161
+ }
160
162
}
161
163
162
164
@ Override
@@ -441,13 +443,15 @@ private static Map<String, Column[]> buildColumnOverride(
441
443
return result ;
442
444
}
443
445
444
- final SourceModelBuildingContext sourceModelContext = context .getMetadataCollector ().getSourceModelBuildingContext ();
446
+ final SourceModelBuildingContext sourceModelContext =
447
+ context .getMetadataCollector ().getSourceModelBuildingContext ();
445
448
final Map <String , List <Column >> columnOverrideMap = new HashMap <>();
446
449
447
- final AttributeOverride [] overrides = element .getRepeatedAnnotationUsages ( AttributeOverride .class , sourceModelContext );
448
- if ( CollectionHelper .isNotEmpty ( overrides ) ) {
450
+ final AttributeOverride [] overrides =
451
+ element .getRepeatedAnnotationUsages ( AttributeOverride .class , sourceModelContext );
452
+ if ( isNotEmpty ( overrides ) ) {
449
453
for ( AttributeOverride depAttr : overrides ) {
450
- final String qualifiedName = StringHelper . qualify ( path , depAttr .name () );
454
+ final String qualifiedName = qualify ( path , depAttr .name () );
451
455
final Column column = depAttr .column ();
452
456
453
457
if ( columnOverrideMap .containsKey ( qualifiedName ) ) {
@@ -529,7 +533,7 @@ private static Column createTemporalColumn(
529
533
int secondPrecision ;
530
534
final Column annotatedColumn = element .getDirectAnnotationUsage ( Column .class );
531
535
if ( annotatedColumn != null ) {
532
- if ( StringHelper . isNotEmpty ( annotatedColumn .name () ) ) {
536
+ if ( isNotBlank ( annotatedColumn .name () ) ) {
533
537
return annotatedColumn ;
534
538
}
535
539
precision = annotatedColumn .precision ();
@@ -564,7 +568,8 @@ public MetadataBuildingContext getBuildingContext() {
564
568
)
565
569
);
566
570
567
- final ColumnJpaAnnotation created = JpaAnnotations .COLUMN .createUsage ( context .getMetadataCollector ().getSourceModelBuildingContext () );
571
+ final ColumnJpaAnnotation created =
572
+ JpaAnnotations .COLUMN .createUsage ( context .getMetadataCollector ().getSourceModelBuildingContext () );
568
573
if ( StringHelper .isNotEmpty ( implicitName .getText () ) ) {
569
574
created .name ( implicitName .getText () );
570
575
}
@@ -587,12 +592,8 @@ private static Map<String, ColumnTransformer> buildColumnTransformerOverride(Ann
587
592
private static Map <String , JoinColumn []> buildJoinColumnOverride (AnnotationTarget element , String path , MetadataBuildingContext context ) {
588
593
final Map <String , JoinColumn []> columnOverride = new HashMap <>();
589
594
if ( element != null ) {
590
- final AssociationOverride [] overrides = buildAssociationOverrides ( element , path , context );
591
- for ( AssociationOverride override : overrides ) {
592
- columnOverride .put (
593
- qualify ( path , override .name () ),
594
- override .joinColumns ()
595
- );
595
+ for ( AssociationOverride override : buildAssociationOverrides ( element , path , context ) ) {
596
+ columnOverride .put ( qualify ( path , override .name () ), override .joinColumns () );
596
597
}
597
598
}
598
599
return columnOverride ;
@@ -601,12 +602,8 @@ private static Map<String, JoinColumn[]> buildJoinColumnOverride(AnnotationTarge
601
602
private static Map <String , ForeignKey > buildForeignKeyOverride (AnnotationTarget element , String path , MetadataBuildingContext context ) {
602
603
final Map <String , ForeignKey > foreignKeyOverride = new HashMap <>();
603
604
if ( element != null ) {
604
- final AssociationOverride [] overrides = buildAssociationOverrides ( element , path , context );
605
- for ( AssociationOverride override : overrides ) {
606
- foreignKeyOverride .put (
607
- qualify ( path , override .name () ),
608
- override .foreignKey ()
609
- );
605
+ for ( AssociationOverride override : buildAssociationOverrides ( element , path , context ) ) {
606
+ foreignKeyOverride .put ( qualify ( path , override .name () ), override .foreignKey () );
610
607
}
611
608
}
612
609
return foreignKeyOverride ;
@@ -619,14 +616,9 @@ private static AssociationOverride[] buildAssociationOverrides(AnnotationTarget
619
616
private static Map <String , JoinTable > buildJoinTableOverride (AnnotationTarget element , String path , MetadataBuildingContext context ) {
620
617
final Map <String , JoinTable > result = new HashMap <>();
621
618
if ( element != null ) {
622
- final AssociationOverride [] overrides = buildAssociationOverrides ( element , path , context );
623
- for ( AssociationOverride override : overrides ) {
624
- final JoinColumn [] joinColumns = override .joinColumns ();
625
- if ( CollectionHelper .isEmpty ( joinColumns ) ) {
626
- result .put (
627
- qualify ( path , override .name () ),
628
- override .joinTable ()
629
- );
619
+ for ( AssociationOverride override : buildAssociationOverrides ( element , path , context ) ) {
620
+ if ( isEmpty ( override .joinColumns () ) ) {
621
+ result .put ( qualify ( path , override .name () ), override .joinTable () );
630
622
}
631
623
}
632
624
}
@@ -637,113 +629,4 @@ private static Map<String, JoinTable> buildJoinTableOverride(AnnotationTarget el
637
629
public void setParentProperty (String parentProperty ) {
638
630
throw new AssertionFailure ( "Setting the parent property to a non component" );
639
631
}
640
-
641
- private static class ColumnImpl implements Column {
642
-
643
- private final String name ;
644
- private final boolean unique ;
645
- private final boolean nullable ;
646
- private final boolean insertable ;
647
- private final boolean updatable ;
648
- private final String columnDefinition ;
649
- private final String table ;
650
- private final int precision ;
651
- private final int secondPrecision ;
652
-
653
- private ColumnImpl (
654
- String name ,
655
- boolean unique ,
656
- boolean nullable ,
657
- boolean insertable ,
658
- boolean updatable ,
659
- String columnDefinition ,
660
- String table ,
661
- int precision ,
662
- int secondPrecision ) {
663
- this .name = name ;
664
- this .unique = unique ;
665
- this .nullable = nullable ;
666
- this .insertable = insertable ;
667
- this .updatable = updatable ;
668
- this .columnDefinition = columnDefinition ;
669
- this .table = table ;
670
- this .precision = precision ;
671
- this .secondPrecision = secondPrecision ;
672
- }
673
-
674
- @ Override
675
- public String name () {
676
- return name ;
677
- }
678
-
679
- @ Override
680
- public boolean unique () {
681
- return unique ;
682
- }
683
-
684
- @ Override
685
- public boolean nullable () {
686
- return nullable ;
687
- }
688
-
689
- @ Override
690
- public boolean insertable () {
691
- return insertable ;
692
- }
693
-
694
- @ Override
695
- public boolean updatable () {
696
- return updatable ;
697
- }
698
-
699
- @ Override
700
- public String columnDefinition () {
701
- return columnDefinition ;
702
- }
703
-
704
- @ Override
705
- public String options () {
706
- return "" ;
707
- }
708
-
709
- @ Override
710
- public String table () {
711
- return table ;
712
- }
713
-
714
- @ Override
715
- public int length () {
716
- return 255 ;
717
- }
718
-
719
- @ Override
720
- public int precision () {
721
- return precision ;
722
- }
723
-
724
- @ Override
725
- public int scale () {
726
- return 0 ;
727
- }
728
-
729
- @ Override
730
- public int secondPrecision () {
731
- return secondPrecision ;
732
- }
733
-
734
- @ Override
735
- public CheckConstraint [] check () {
736
- return new CheckConstraint [0 ];
737
- }
738
-
739
- @ Override
740
- public String comment () {
741
- return "" ;
742
- }
743
-
744
- @ Override
745
- public Class <? extends Annotation > annotationType () {
746
- return Column .class ;
747
- }
748
- }
749
632
}
0 commit comments