Skip to content

Commit ecd7a91

Browse files
committed
use lots of 'var' in boot.model.internal
1 parent 84196c4 commit ecd7a91

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2031
-2427
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractEntityIdGeneratorResolver.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,24 @@
66

77
import java.lang.annotation.Annotation;
88
import java.util.HashMap;
9-
import java.util.List;
109
import java.util.Map;
1110

1211
import org.hibernate.MappingException;
1312
import org.hibernate.annotations.IdGeneratorType;
1413
import org.hibernate.boot.model.IdentifierGeneratorDefinition;
15-
import org.hibernate.boot.model.relational.Database;
1614
import org.hibernate.boot.spi.MetadataBuildingContext;
17-
import org.hibernate.dialect.Dialect;
18-
import org.hibernate.generator.Generator;
19-
import org.hibernate.internal.util.collections.CollectionHelper;
2015
import org.hibernate.mapping.Column;
2116
import org.hibernate.mapping.PersistentClass;
2217
import org.hibernate.mapping.SimpleValue;
2318
import org.hibernate.models.spi.AnnotationTarget;
24-
import org.hibernate.models.spi.ClassDetails;
2519
import org.hibernate.models.spi.MemberDetails;
2620

2721
import jakarta.persistence.GeneratedValue;
2822

2923
import static org.hibernate.boot.model.internal.GeneratorAnnotationHelper.handleIdGeneratorType;
24+
import static org.hibernate.boot.model.internal.GeneratorAnnotationHelper.handleIdentityStrategy;
25+
import static org.hibernate.boot.model.internal.GeneratorAnnotationHelper.locatePackageInfoDetails;
26+
import static org.hibernate.boot.model.internal.GeneratorBinder.createGeneratorFrom;
3027
import static org.hibernate.boot.model.internal.GeneratorParameters.identityTablesString;
3128
import static org.hibernate.boot.model.internal.GeneratorStrategies.mapLegacyNamedGenerator;
3229
import static org.hibernate.id.IdentifierGenerator.ENTITY_NAME;
@@ -35,6 +32,7 @@
3532
import static org.hibernate.id.PersistentIdentifierGenerator.PK;
3633
import static org.hibernate.id.PersistentIdentifierGenerator.TABLE;
3734
import static org.hibernate.id.PersistentIdentifierGenerator.TABLES;
35+
import static org.hibernate.internal.util.collections.CollectionHelper.size;
3836

3937
/**
4038
* Template support for IdGeneratorResolver implementations dealing with entity identifiers
@@ -65,7 +63,7 @@ public AbstractEntityIdGeneratorResolver(
6563
public final void doSecondPass(Map<String, PersistentClass> persistentClasses) throws MappingException {
6664
switch ( generatedValue.strategy() ) {
6765
case UUID -> handleUuidStrategy();
68-
case IDENTITY -> GeneratorAnnotationHelper.handleIdentityStrategy( idValue );
66+
case IDENTITY -> handleIdentityStrategy( idValue );
6967
case SEQUENCE -> handleSequenceStrategy();
7068
case TABLE -> handleTableStrategy();
7169
case AUTO -> handleAutoStrategy();
@@ -134,7 +132,8 @@ protected boolean handleAsMetaAnnotated() {
134132
return true;
135133
}
136134

137-
final ClassDetails packageInfoDetails = GeneratorAnnotationHelper.locatePackageInfoDetails( idMember.getDeclaringType(), buildingContext );
135+
final var packageInfoDetails =
136+
locatePackageInfoDetails( idMember.getDeclaringType(), buildingContext );
138137
if ( packageInfoDetails != null ) {
139138
final Annotation fromPackage = findGeneratorAnnotation( packageInfoDetails );
140139
if ( fromPackage != null ) {
@@ -147,26 +146,23 @@ protected boolean handleAsMetaAnnotated() {
147146
}
148147

149148
private Annotation findGeneratorAnnotation(AnnotationTarget annotationTarget) {
150-
final List<? extends Annotation> metaAnnotated =
149+
final var metaAnnotated =
151150
annotationTarget.getMetaAnnotated( IdGeneratorType.class,
152151
buildingContext.getBootstrapContext().getModelsContext() );
153-
if ( CollectionHelper.size( metaAnnotated ) > 0 ) {
154-
return metaAnnotated.get( 0 );
155-
}
152+
return size( metaAnnotated ) > 0 ? metaAnnotated.get( 0 ) : null;
156153

157-
return null;
158154
}
159155

160156
protected boolean handleAsLegacyGenerator() {
161157
// Handle a few legacy Hibernate generators...
162158
final String nameFromGeneratedValue = generatedValue.generator();
163159
if ( !nameFromGeneratedValue.isBlank() ) {
164-
final Class<? extends Generator> legacyNamedGenerator =
160+
final var legacyNamedGenerator =
165161
mapLegacyNamedGenerator( nameFromGeneratedValue, idValue );
166162
if ( legacyNamedGenerator != null ) {
167-
final Map<String,String> configuration = buildLegacyGeneratorConfig();
163+
final var configuration = buildLegacyGeneratorConfig();
168164
//noinspection unchecked,rawtypes
169-
GeneratorBinder.createGeneratorFrom(
165+
createGeneratorFrom(
170166
new IdentifierGeneratorDefinition( nameFromGeneratedValue,
171167
legacyNamedGenerator.getName(), configuration ),
172168
idValue,
@@ -181,15 +177,15 @@ protected boolean handleAsLegacyGenerator() {
181177
}
182178

183179
private HashMap<String, String> buildLegacyGeneratorConfig() {
184-
final Database database = buildingContext.getMetadataCollector().getDatabase();
185-
final Dialect dialect = database.getDialect();
180+
final var database = buildingContext.getMetadataCollector().getDatabase();
181+
final var dialect = database.getDialect();
186182

187183
final HashMap<String, String> configuration = new HashMap<>();
188184

189185
final String tableName = idValue.getTable().getQuotedName( dialect );
190186
configuration.put( TABLE, tableName );
191187

192-
final Column idColumn = (Column) idValue.getSelectables().get( 0);
188+
final var idColumn = (Column) idValue.getSelectables().get( 0);
193189
final String idColumnName = idColumn.getQuotedName( dialect );
194190
configuration.put( PK, idColumnName );
195191

hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractPropertyHolder.java

Lines changed: 58 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public abstract class AbstractPropertyHolder implements PropertyHolder {
8787

8888
@Override
8989
public ConverterDescriptor<?,?> resolveAttributeConverterDescriptor(MemberDetails attributeMember, boolean autoApply) {
90-
final AttributeConversionInfo info = locateAttributeConversionInfo( attributeMember );
90+
final var info = locateAttributeConversionInfo( attributeMember );
9191
if ( info != null ) {
9292
if ( info.isConversionDisabled() ) {
9393
return null;
@@ -101,11 +101,13 @@ public ConverterDescriptor<?,?> resolveAttributeConverterDescriptor(MemberDetail
101101
}
102102
}
103103
}
104-
105-
return !autoApply ? null : context.getMetadataCollector()
106-
.getConverterRegistry()
107-
.getAttributeConverterAutoApplyHandler()
108-
.findAutoApplyConverterForAttribute( attributeMember, context );
104+
else {
105+
return autoApply
106+
? context.getMetadataCollector().getConverterRegistry()
107+
.getAttributeConverterAutoApplyHandler()
108+
.findAutoApplyConverterForAttribute( attributeMember, context )
109+
: null;
110+
}
109111
}
110112

111113
protected IllegalStateException buildExceptionFromInstantiationError(AttributeConversionInfo info, Exception e) {
@@ -185,36 +187,36 @@ protected void setCurrentProperty(MemberDetails attributeMember) {
185187
// todo (jpa32) : some of this (association override handling esp) does the same work multiple times - consolidate
186188

187189
if ( attributeMember == null ) {
188-
this.currentPropertyColumnOverride = null;
189-
this.currentPropertyColumnTransformerOverride = null;
190-
this.currentPropertyJoinColumnOverride = null;
191-
this.currentPropertyJoinTableOverride = null;
192-
this.currentPropertyForeignKeyOverride = null;
190+
currentPropertyColumnOverride = null;
191+
currentPropertyColumnTransformerOverride = null;
192+
currentPropertyJoinColumnOverride = null;
193+
currentPropertyJoinTableOverride = null;
194+
currentPropertyForeignKeyOverride = null;
193195
}
194196
else {
195-
this.currentPropertyColumnOverride = buildColumnOverride( attributeMember, getPath(), context );
196-
if ( this.currentPropertyColumnOverride.isEmpty() ) {
197-
this.currentPropertyColumnOverride = null;
197+
currentPropertyColumnOverride = buildColumnOverride( attributeMember, getPath(), context );
198+
if ( currentPropertyColumnOverride.isEmpty() ) {
199+
currentPropertyColumnOverride = null;
198200
}
199201

200-
this.currentPropertyColumnTransformerOverride = buildColumnTransformerOverride( attributeMember, context );
201-
if ( this.currentPropertyColumnTransformerOverride.isEmpty() ) {
202-
this.currentPropertyColumnTransformerOverride = null;
202+
currentPropertyColumnTransformerOverride = buildColumnTransformerOverride( attributeMember, context );
203+
if ( currentPropertyColumnTransformerOverride.isEmpty() ) {
204+
currentPropertyColumnTransformerOverride = null;
203205
}
204206

205-
this.currentPropertyJoinColumnOverride = buildJoinColumnOverride( attributeMember, getPath(), context );
206-
if ( this.currentPropertyJoinColumnOverride.isEmpty() ) {
207-
this.currentPropertyJoinColumnOverride = null;
207+
currentPropertyJoinColumnOverride = buildJoinColumnOverride( attributeMember, getPath(), context );
208+
if ( currentPropertyJoinColumnOverride.isEmpty() ) {
209+
currentPropertyJoinColumnOverride = null;
208210
}
209211

210-
this.currentPropertyJoinTableOverride = buildJoinTableOverride( attributeMember, getPath(), context );
211-
if ( this.currentPropertyJoinTableOverride.isEmpty() ) {
212-
this.currentPropertyJoinTableOverride = null;
212+
currentPropertyJoinTableOverride = buildJoinTableOverride( attributeMember, getPath(), context );
213+
if ( currentPropertyJoinTableOverride.isEmpty() ) {
214+
currentPropertyJoinTableOverride = null;
213215
}
214216

215-
this.currentPropertyForeignKeyOverride = buildForeignKeyOverride( attributeMember, getPath(), context );
216-
if ( this.currentPropertyForeignKeyOverride.isEmpty() ) {
217-
this.currentPropertyForeignKeyOverride = null;
217+
currentPropertyForeignKeyOverride = buildForeignKeyOverride( attributeMember, getPath(), context );
218+
if ( currentPropertyForeignKeyOverride.isEmpty() ) {
219+
currentPropertyForeignKeyOverride = null;
218220
}
219221
}
220222
}
@@ -227,15 +229,11 @@ protected void setCurrentProperty(MemberDetails attributeMember) {
227229
*/
228230
@Override
229231
public Column[] getOverriddenColumn(String propertyName) {
230-
final Column[] result = getExactOverriddenColumn( propertyName );
231-
if ( result == null ) {
232-
if ( propertyName.contains( ".{element}." ) ) {
233-
//support for non map collections where no prefix is needed
234-
//TODO cache the underlying regexp
235-
return getExactOverriddenColumn( propertyName.replace( ".{element}.", "." ) );
236-
}
237-
}
238-
return result;
232+
final var overriddenColumn = getExactOverriddenColumn( propertyName );
233+
// support for non-map collections where no prefix is needed
234+
return overriddenColumn == null && propertyName.contains( ".{element}." )
235+
? getExactOverriddenColumn( propertyName.replace( ".{element}.", "." ) )
236+
: overriddenColumn;
239237
}
240238

241239
@Override
@@ -291,7 +289,9 @@ public JoinColumn[] getOverriddenJoinColumn(String propertyName) {
291289
//TODO cache the underlying regexp
292290
return getExactOverriddenJoinColumn( propertyName.replace( ".{element}.", "." ) );
293291
}
294-
return result;
292+
else {
293+
return result;
294+
}
295295
}
296296

297297
/**
@@ -349,10 +349,9 @@ private ForeignKey getExactOverriddenForeignKey(String propertyName) {
349349
public JoinTable getJoinTable(MemberDetails attributeMember) {
350350
final String propertyName = qualify( getPath(), attributeMember.getName() );
351351
final JoinTable result = getOverriddenJoinTable( propertyName );
352-
if ( result == null ) {
353-
return attributeMember.getDirectAnnotationUsage( JoinTable.class );
354-
}
355-
return result;
352+
return result == null
353+
? attributeMember.getDirectAnnotationUsage( JoinTable.class )
354+
: result;
356355
}
357356

358357
/**
@@ -368,7 +367,9 @@ public JoinTable getOverriddenJoinTable(String propertyName) {
368367
//TODO cache the underlying regexp
369368
return getExactOverriddenJoinTable( propertyName.replace( ".{element}.", "." ) );
370369
}
371-
return result;
370+
else {
371+
return result;
372+
}
372373
}
373374

374375
/**
@@ -435,12 +436,10 @@ private static Map<String, Column[]> buildColumnOverride(
435436
return result;
436437
}
437438

438-
final ModelsContext sourceModelContext =
439-
context.getBootstrapContext().getModelsContext();
439+
final var modelContext = context.getBootstrapContext().getModelsContext();
440440
final Map<String, List<Column>> columnOverrideMap = new HashMap<>();
441441

442-
final AttributeOverride[] overrides =
443-
element.getRepeatedAnnotationUsages( AttributeOverride.class, sourceModelContext );
442+
final var overrides = element.getRepeatedAnnotationUsages( AttributeOverride.class, modelContext );
444443
if ( isNotEmpty( overrides ) ) {
445444
for ( AttributeOverride depAttr : overrides ) {
446445
final String qualifiedName = qualify( path, depAttr.name() );
@@ -459,7 +458,7 @@ private static Map<String, Column[]> buildColumnOverride(
459458
}
460459
}
461460
else if ( useColumnForTimeZoneStorage( element, context ) ) {
462-
final Column column = createTemporalColumn( element, path, context );
461+
final var column = createTemporalColumn( element, path, context );
463462
if ( isOffsetTimeClass( element ) ) {
464463
columnOverrideMap.put(
465464
path + "." + OffsetTimeCompositeUserType.LOCAL_TIME_NAME,
@@ -472,7 +471,7 @@ else if ( useColumnForTimeZoneStorage( element, context ) ) {
472471
List.of( column )
473472
);
474473
}
475-
final Column offsetColumn = createTimeZoneColumn( element, column, context );
474+
final var offsetColumn = createTimeZoneColumn( element, column, context );
476475
columnOverrideMap.put(
477476
path + "." + AbstractTimeZoneStorageCompositeUserType.ZONE_OFFSET_NAME,
478477
List.of( offsetColumn )
@@ -489,11 +488,13 @@ private static Column createTimeZoneColumn(
489488
AnnotationTarget element,
490489
Column column,
491490
MetadataBuildingContext context) {
492-
final TimeZoneColumn timeZoneColumn = element.getDirectAnnotationUsage( TimeZoneColumn.class );
493-
final ColumnJpaAnnotation created = JpaAnnotations.COLUMN.createUsage( context.getBootstrapContext().getModelsContext() );
494-
final String columnName = timeZoneColumn != null
495-
? timeZoneColumn.name()
496-
: column.name() + "_tz";
491+
final var timeZoneColumn = element.getDirectAnnotationUsage( TimeZoneColumn.class );
492+
final ColumnJpaAnnotation created =
493+
JpaAnnotations.COLUMN.createUsage( context.getBootstrapContext().getModelsContext() );
494+
final String columnName =
495+
timeZoneColumn != null
496+
? timeZoneColumn.name()
497+
: column.name() + "_tz";
497498
created.name( columnName );
498499
created.nullable( column.nullable() );
499500

@@ -523,7 +524,7 @@ private static Column createTemporalColumn(
523524
MetadataBuildingContext context) {
524525
int precision;
525526
int secondPrecision;
526-
final Column annotatedColumn = element.getDirectAnnotationUsage( Column.class );
527+
final var annotatedColumn = element.getDirectAnnotationUsage( Column.class );
527528
if ( annotatedColumn != null ) {
528529
if ( isNotBlank( annotatedColumn.name() ) ) {
529530
return annotatedColumn;
@@ -571,7 +572,7 @@ public MetadataBuildingContext getBuildingContext() {
571572
}
572573

573574
private static Map<String, ColumnTransformer> buildColumnTransformerOverride(AnnotationTarget element, MetadataBuildingContext context) {
574-
final ModelsContext sourceModelContext = context.getBootstrapContext().getModelsContext();
575+
final var sourceModelContext = context.getBootstrapContext().getModelsContext();
575576
final Map<String, ColumnTransformer> columnOverride = new HashMap<>();
576577
if ( element != null ) {
577578
element.forEachAnnotationUsage( ColumnTransformer.class, sourceModelContext, (usage) -> {
@@ -584,7 +585,7 @@ private static Map<String, ColumnTransformer> buildColumnTransformerOverride(Ann
584585
private static Map<String, JoinColumn[]> buildJoinColumnOverride(AnnotationTarget element, String path, MetadataBuildingContext context) {
585586
final Map<String, JoinColumn[]> columnOverride = new HashMap<>();
586587
if ( element != null ) {
587-
for ( AssociationOverride override : buildAssociationOverrides( element, path, context ) ) {
588+
for ( var override : buildAssociationOverrides( element, path, context ) ) {
588589
columnOverride.put( qualify( path, override.name() ), override.joinColumns() );
589590
}
590591
}
@@ -594,7 +595,7 @@ private static Map<String, JoinColumn[]> buildJoinColumnOverride(AnnotationTarge
594595
private static Map<String, ForeignKey> buildForeignKeyOverride(AnnotationTarget element, String path, MetadataBuildingContext context) {
595596
final Map<String, ForeignKey> foreignKeyOverride = new HashMap<>();
596597
if ( element != null ) {
597-
for ( AssociationOverride override : buildAssociationOverrides( element, path, context ) ) {
598+
for ( var override : buildAssociationOverrides( element, path, context ) ) {
598599
foreignKeyOverride.put( qualify( path, override.name() ), override.foreignKey() );
599600
}
600601
}
@@ -608,7 +609,7 @@ private static AssociationOverride[] buildAssociationOverrides(AnnotationTarget
608609
private static Map<String, JoinTable> buildJoinTableOverride(AnnotationTarget element, String path, MetadataBuildingContext context) {
609610
final Map<String, JoinTable> result = new HashMap<>();
610611
if ( element != null ) {
611-
for ( AssociationOverride override : buildAssociationOverrides( element, path, context ) ) {
612+
for ( var override : buildAssociationOverrides( element, path, context ) ) {
612613
if ( isEmpty( override.joinColumns() ) ) {
613614
result.put( qualify( path, override.name() ), override.joinTable() );
614615
}

0 commit comments

Comments
 (0)