2727import org .hibernate .persister .entity .EntityPersister ;
2828import org .hibernate .service .ServiceRegistry ;
2929import org .hibernate .type .EntityType ;
30- import org .hibernate .type .Type ;
3130
3231import static org .hibernate .cfg .MappingSettings .ID_DB_STRUCTURE_NAMING_STRATEGY ;
3332import static org .hibernate .engine .internal .ForeignKeys .getEntityIdentifierIfNotUnsaved ;
@@ -83,7 +82,7 @@ else if ( integralType == BigDecimal.class ) {
8382
8483 public static Object getForeignId (
8584 String entityName , String propertyName , SharedSessionContractImplementor sessionImplementor , Object object ) {
86- final EntityPersister entityDescriptor =
85+ final var persister =
8786 sessionImplementor .getFactory ().getMappingMetamodel ()
8887 .getEntityDescriptor ( entityName );
8988 if ( sessionImplementor instanceof SessionImplementor statefulSession
@@ -93,8 +92,8 @@ public static Object getForeignId(
9392 //throw new IdentifierGenerationException("save associated object first, or disable cascade for inverse association");
9493 }
9594 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 ) );
9897 }
9998 }
10099
@@ -109,19 +108,19 @@ private static Object associatedEntity(
109108 }
110109
111110 private static Object identifier (
112- SharedSessionContractImplementor sessionImplementor ,
111+ SharedSessionContractImplementor session ,
113112 EntityType foreignValueSourceType ,
114113 Object associatedEntity ) {
115114 final String associatedEntityName = foreignValueSourceType .getAssociatedEntityName ();
116115 try {
117- return getEntityIdentifierIfNotUnsaved ( associatedEntityName , associatedEntity , sessionImplementor );
116+ return getEntityIdentifierIfNotUnsaved ( associatedEntityName , associatedEntity , session );
118117 }
119118 catch (TransientObjectException toe ) {
120- if ( sessionImplementor instanceof Session statefulSession ) {
119+ if ( session instanceof Session statefulSession ) {
121120 statefulSession .persist ( associatedEntityName , associatedEntity );
122- return sessionImplementor .getContextEntityIdentifier ( associatedEntity );
121+ return session .getContextEntityIdentifier ( associatedEntity );
123122 }
124- else if ( sessionImplementor instanceof StatelessSession statelessSession ) {
123+ else if ( session instanceof StatelessSession statelessSession ) {
125124 return statelessSession .insert ( associatedEntityName , associatedEntity );
126125 }
127126 else {
@@ -131,10 +130,9 @@ else if ( sessionImplementor instanceof StatelessSession statelessSession ) {
131130 }
132131
133132 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 ) {
136134 // the normal case
137- return ( EntityType ) propertyType ;
135+ return entityType ;
138136 }
139137 else {
140138 // try identifier mapper
@@ -246,7 +244,7 @@ public boolean gt(long value) {
246244 }
247245
248246 public IntegralDataTypeHolder copy () {
249- BasicHolder copy = new BasicHolder ( exactType );
247+ final var copy = new BasicHolder ( exactType );
250248 copy .value = value ;
251249 return copy ;
252250 }
@@ -301,14 +299,16 @@ public String toString() {
301299 }
302300
303301 @ Override
304- public boolean equals (Object o ) {
305- if ( this == o ) {
302+ public boolean equals (Object object ) {
303+ if ( this == object ) {
306304 return true ;
307305 }
308- if ( !(o instanceof BasicHolder that ) ) {
306+ else if ( !(object instanceof BasicHolder that ) ) {
309307 return false ;
310308 }
311- return value == that .value ;
309+ else {
310+ return this .value == that .value ;
311+ }
312312 }
313313
314314 @ Override
@@ -326,7 +326,7 @@ public IntegralDataTypeHolder initialize(long value) {
326326 }
327327
328328 public IntegralDataTypeHolder initialize (ResultSet resultSet , long defaultValue ) throws SQLException {
329- final BigDecimal rsValue = resultSet .getBigDecimal ( 1 );
329+ final var rsValue = resultSet .getBigDecimal ( 1 );
330330 if ( resultSet .wasNull () ) {
331331 return initialize ( defaultValue );
332332 }
@@ -411,7 +411,7 @@ public boolean gt(long value) {
411411 }
412412
413413 public IntegralDataTypeHolder copy () {
414- BigIntegerHolder copy = new BigIntegerHolder ();
414+ final var copy = new BigIntegerHolder ();
415415 copy .value = value ;
416416 return copy ;
417417 }
@@ -457,14 +457,16 @@ public String toString() {
457457 }
458458
459459 @ Override
460- public boolean equals (Object o ) {
461- if ( this == o ) {
460+ public boolean equals (Object object ) {
461+ if ( this == object ) {
462462 return true ;
463463 }
464- if ( !(o instanceof BigIntegerHolder that ) ) {
464+ else if ( !(object instanceof BigIntegerHolder that ) ) {
465465 return false ;
466466 }
467- return Objects .equals ( value , that .value );
467+ else {
468+ return Objects .equals ( this .value , that .value );
469+ }
468470 }
469471
470472 @ Override
@@ -482,7 +484,7 @@ public IntegralDataTypeHolder initialize(long value) {
482484 }
483485
484486 public IntegralDataTypeHolder initialize (ResultSet resultSet , long defaultValue ) throws SQLException {
485- final BigDecimal rsValue = resultSet .getBigDecimal ( 1 );
487+ final var rsValue = resultSet .getBigDecimal ( 1 );
486488 if ( resultSet .wasNull () ) {
487489 return initialize ( defaultValue );
488490 }
@@ -567,7 +569,7 @@ public boolean gt(long value) {
567569 }
568570
569571 public IntegralDataTypeHolder copy () {
570- BigDecimalHolder copy = new BigDecimalHolder ();
572+ final var copy = new BigDecimalHolder ();
571573 copy .value = value ;
572574 return copy ;
573575 }
@@ -613,14 +615,16 @@ public String toString() {
613615 }
614616
615617 @ Override
616- public boolean equals (Object o ) {
617- if ( this == o ) {
618+ public boolean equals (Object object ) {
619+ if ( this == object ) {
618620 return true ;
619621 }
620- if ( !(o instanceof BigDecimalHolder that ) ) {
622+ else if ( !(object instanceof BigDecimalHolder that ) ) {
621623 return false ;
622624 }
623- return Objects .equals ( this .value , that .value );
625+ else {
626+ return Objects .equals ( this .value , that .value );
627+ }
624628 }
625629
626630 @ Override
@@ -630,8 +634,6 @@ public int hashCode() {
630634 }
631635
632636 public static ImplicitDatabaseObjectNamingStrategy getNamingStrategy (Properties params , ServiceRegistry serviceRegistry ) {
633- final StrategySelector strategySelector = serviceRegistry .requireService ( StrategySelector .class );
634-
635637 final String namingStrategySetting = coalesceSuppliedValues (
636638 () -> {
637639 final String localSetting = getString ( ID_DB_STRUCTURE_NAMING_STRATEGY , params );
@@ -641,17 +643,17 @@ public static ImplicitDatabaseObjectNamingStrategy getNamingStrategy(Properties
641643 return localSetting ;
642644 },
643645 () -> {
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 );
646648 if ( globalSetting != null ) {
647649 INCUBATION_LOGGER .incubatingSetting ( ID_DB_STRUCTURE_NAMING_STRATEGY );
648650 }
649651 return globalSetting ;
650652 },
651653 StandardNamingStrategy .class ::getName
652654 );
653-
654- return strategySelector .resolveStrategy ( ImplicitDatabaseObjectNamingStrategy .class , namingStrategySetting );
655+ return serviceRegistry . requireService ( StrategySelector . class )
656+ .resolveStrategy ( ImplicitDatabaseObjectNamingStrategy .class , namingStrategySetting );
655657 }
656658
657659 /**
0 commit comments