27
27
import org .hibernate .persister .entity .EntityPersister ;
28
28
import org .hibernate .service .ServiceRegistry ;
29
29
import org .hibernate .type .EntityType ;
30
- import org .hibernate .type .Type ;
31
30
32
31
import static org .hibernate .cfg .MappingSettings .ID_DB_STRUCTURE_NAMING_STRATEGY ;
33
32
import static org .hibernate .engine .internal .ForeignKeys .getEntityIdentifierIfNotUnsaved ;
@@ -83,7 +82,7 @@ else if ( integralType == BigDecimal.class ) {
83
82
84
83
public static Object getForeignId (
85
84
String entityName , String propertyName , SharedSessionContractImplementor sessionImplementor , Object object ) {
86
- final EntityPersister entityDescriptor =
85
+ final var persister =
87
86
sessionImplementor .getFactory ().getMappingMetamodel ()
88
87
.getEntityDescriptor ( entityName );
89
88
if ( sessionImplementor instanceof SessionImplementor statefulSession
@@ -93,8 +92,8 @@ public static Object getForeignId(
93
92
//throw new IdentifierGenerationException("save associated object first, or disable cascade for inverse association");
94
93
}
95
94
else {
96
- return identifier ( sessionImplementor , entityType ( propertyName , entityDescriptor ),
97
- associatedEntity ( entityName , propertyName , object , entityDescriptor ) );
95
+ return identifier ( sessionImplementor , entityType ( propertyName , persister ),
96
+ associatedEntity ( entityName , propertyName , object , persister ) );
98
97
}
99
98
}
100
99
@@ -109,19 +108,19 @@ private static Object associatedEntity(
109
108
}
110
109
111
110
private static Object identifier (
112
- SharedSessionContractImplementor sessionImplementor ,
111
+ SharedSessionContractImplementor session ,
113
112
EntityType foreignValueSourceType ,
114
113
Object associatedEntity ) {
115
114
final String associatedEntityName = foreignValueSourceType .getAssociatedEntityName ();
116
115
try {
117
- return getEntityIdentifierIfNotUnsaved ( associatedEntityName , associatedEntity , sessionImplementor );
116
+ return getEntityIdentifierIfNotUnsaved ( associatedEntityName , associatedEntity , session );
118
117
}
119
118
catch (TransientObjectException toe ) {
120
- if ( sessionImplementor instanceof Session statefulSession ) {
119
+ if ( session instanceof Session statefulSession ) {
121
120
statefulSession .persist ( associatedEntityName , associatedEntity );
122
- return sessionImplementor .getContextEntityIdentifier ( associatedEntity );
121
+ return session .getContextEntityIdentifier ( associatedEntity );
123
122
}
124
- else if ( sessionImplementor instanceof StatelessSession statelessSession ) {
123
+ else if ( session instanceof StatelessSession statelessSession ) {
125
124
return statelessSession .insert ( associatedEntityName , associatedEntity );
126
125
}
127
126
else {
@@ -131,10 +130,9 @@ else if ( sessionImplementor instanceof StatelessSession statelessSession ) {
131
130
}
132
131
133
132
private static EntityType entityType (String propertyName , EntityPersister entityDescriptor ) {
134
- final Type propertyType = entityDescriptor .getPropertyType ( propertyName );
135
- if ( propertyType instanceof EntityType ) {
133
+ if ( entityDescriptor .getPropertyType ( propertyName ) instanceof EntityType entityType ) {
136
134
// the normal case
137
- return ( EntityType ) propertyType ;
135
+ return entityType ;
138
136
}
139
137
else {
140
138
// try identifier mapper
@@ -246,7 +244,7 @@ public boolean gt(long value) {
246
244
}
247
245
248
246
public IntegralDataTypeHolder copy () {
249
- BasicHolder copy = new BasicHolder ( exactType );
247
+ final var copy = new BasicHolder ( exactType );
250
248
copy .value = value ;
251
249
return copy ;
252
250
}
@@ -301,14 +299,16 @@ public String toString() {
301
299
}
302
300
303
301
@ Override
304
- public boolean equals (Object o ) {
305
- if ( this == o ) {
302
+ public boolean equals (Object object ) {
303
+ if ( this == object ) {
306
304
return true ;
307
305
}
308
- if ( !(o instanceof BasicHolder that ) ) {
306
+ else if ( !(object instanceof BasicHolder that ) ) {
309
307
return false ;
310
308
}
311
- return value == that .value ;
309
+ else {
310
+ return this .value == that .value ;
311
+ }
312
312
}
313
313
314
314
@ Override
@@ -326,7 +326,7 @@ public IntegralDataTypeHolder initialize(long value) {
326
326
}
327
327
328
328
public IntegralDataTypeHolder initialize (ResultSet resultSet , long defaultValue ) throws SQLException {
329
- final BigDecimal rsValue = resultSet .getBigDecimal ( 1 );
329
+ final var rsValue = resultSet .getBigDecimal ( 1 );
330
330
if ( resultSet .wasNull () ) {
331
331
return initialize ( defaultValue );
332
332
}
@@ -411,7 +411,7 @@ public boolean gt(long value) {
411
411
}
412
412
413
413
public IntegralDataTypeHolder copy () {
414
- BigIntegerHolder copy = new BigIntegerHolder ();
414
+ final var copy = new BigIntegerHolder ();
415
415
copy .value = value ;
416
416
return copy ;
417
417
}
@@ -457,14 +457,16 @@ public String toString() {
457
457
}
458
458
459
459
@ Override
460
- public boolean equals (Object o ) {
461
- if ( this == o ) {
460
+ public boolean equals (Object object ) {
461
+ if ( this == object ) {
462
462
return true ;
463
463
}
464
- if ( !(o instanceof BigIntegerHolder that ) ) {
464
+ else if ( !(object instanceof BigIntegerHolder that ) ) {
465
465
return false ;
466
466
}
467
- return Objects .equals ( value , that .value );
467
+ else {
468
+ return Objects .equals ( this .value , that .value );
469
+ }
468
470
}
469
471
470
472
@ Override
@@ -482,7 +484,7 @@ public IntegralDataTypeHolder initialize(long value) {
482
484
}
483
485
484
486
public IntegralDataTypeHolder initialize (ResultSet resultSet , long defaultValue ) throws SQLException {
485
- final BigDecimal rsValue = resultSet .getBigDecimal ( 1 );
487
+ final var rsValue = resultSet .getBigDecimal ( 1 );
486
488
if ( resultSet .wasNull () ) {
487
489
return initialize ( defaultValue );
488
490
}
@@ -567,7 +569,7 @@ public boolean gt(long value) {
567
569
}
568
570
569
571
public IntegralDataTypeHolder copy () {
570
- BigDecimalHolder copy = new BigDecimalHolder ();
572
+ final var copy = new BigDecimalHolder ();
571
573
copy .value = value ;
572
574
return copy ;
573
575
}
@@ -613,14 +615,16 @@ public String toString() {
613
615
}
614
616
615
617
@ Override
616
- public boolean equals (Object o ) {
617
- if ( this == o ) {
618
+ public boolean equals (Object object ) {
619
+ if ( this == object ) {
618
620
return true ;
619
621
}
620
- if ( !(o instanceof BigDecimalHolder that ) ) {
622
+ else if ( !(object instanceof BigDecimalHolder that ) ) {
621
623
return false ;
622
624
}
623
- return Objects .equals ( this .value , that .value );
625
+ else {
626
+ return Objects .equals ( this .value , that .value );
627
+ }
624
628
}
625
629
626
630
@ Override
@@ -630,8 +634,6 @@ public int hashCode() {
630
634
}
631
635
632
636
public static ImplicitDatabaseObjectNamingStrategy getNamingStrategy (Properties params , ServiceRegistry serviceRegistry ) {
633
- final StrategySelector strategySelector = serviceRegistry .requireService ( StrategySelector .class );
634
-
635
637
final String namingStrategySetting = coalesceSuppliedValues (
636
638
() -> {
637
639
final String localSetting = getString ( ID_DB_STRUCTURE_NAMING_STRATEGY , params );
@@ -641,17 +643,17 @@ public static ImplicitDatabaseObjectNamingStrategy getNamingStrategy(Properties
641
643
return localSetting ;
642
644
},
643
645
() -> {
644
- final ConfigurationService configurationService = serviceRegistry .requireService ( ConfigurationService .class );
645
- final String globalSetting = getString ( ID_DB_STRUCTURE_NAMING_STRATEGY , configurationService . getSettings () );
646
+ final var settings = serviceRegistry .requireService ( ConfigurationService .class ). getSettings ( );
647
+ final String globalSetting = getString ( ID_DB_STRUCTURE_NAMING_STRATEGY , settings );
646
648
if ( globalSetting != null ) {
647
649
INCUBATION_LOGGER .incubatingSetting ( ID_DB_STRUCTURE_NAMING_STRATEGY );
648
650
}
649
651
return globalSetting ;
650
652
},
651
653
StandardNamingStrategy .class ::getName
652
654
);
653
-
654
- return strategySelector .resolveStrategy ( ImplicitDatabaseObjectNamingStrategy .class , namingStrategySetting );
655
+ return serviceRegistry . requireService ( StrategySelector . class )
656
+ .resolveStrategy ( ImplicitDatabaseObjectNamingStrategy .class , namingStrategySetting );
655
657
}
656
658
657
659
/**
0 commit comments