Skip to content

Commit edebc23

Browse files
committed
use 'var'
1 parent e413522 commit edebc23

File tree

6 files changed

+78
-88
lines changed

6 files changed

+78
-88
lines changed

hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataImpl.java

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,13 @@
3939
import org.hibernate.engine.config.spi.ConfigurationService;
4040
import org.hibernate.engine.spi.FilterDefinition;
4141
import org.hibernate.engine.spi.SessionFactoryImplementor;
42-
import org.hibernate.event.service.spi.EventListenerGroup;
4342
import org.hibernate.event.service.spi.EventListenerRegistry;
4443
import org.hibernate.event.spi.EventType;
4544
import org.hibernate.mapping.Collection;
46-
import org.hibernate.mapping.Column;
4745
import org.hibernate.mapping.Component;
4846
import org.hibernate.mapping.FetchProfile;
49-
import org.hibernate.mapping.ForeignKey;
5047
import org.hibernate.mapping.MappedSuperclass;
5148
import org.hibernate.mapping.PersistentClass;
52-
import org.hibernate.mapping.PrimaryKey;
53-
import org.hibernate.mapping.Property;
5449
import org.hibernate.mapping.Table;
5550
import org.hibernate.mapping.UserDefinedObjectType;
5651
import org.hibernate.mapping.UserDefinedType;
@@ -59,7 +54,6 @@
5954
import org.hibernate.query.named.NamedObjectRepository;
6055
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
6156
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
62-
import org.hibernate.service.spi.ServiceRegistryImplementor;
6357
import org.hibernate.tool.schema.Action;
6458
import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.ActionGrouping;
6559
import org.hibernate.type.spi.TypeConfiguration;
@@ -331,28 +325,23 @@ public Map<String, SqmFunctionDescriptor> getSqlFunctionMap() {
331325
@Override
332326
public Set<String> getContributors() {
333327
final HashSet<String> contributors = new HashSet<>();
334-
335-
entityBindingMap.forEach(
336-
(s, persistentClass) -> contributors.add( persistentClass.getContributor() )
337-
);
338-
339-
for ( Namespace namespace : database.getNamespaces() ) {
340-
for ( Table table : namespace.getTables() ) {
328+
entityBindingMap.forEach( (s, persistentClass)
329+
-> contributors.add( persistentClass.getContributor() ) );
330+
for ( var namespace : database.getNamespaces() ) {
331+
for ( var table : namespace.getTables() ) {
341332
contributors.add( table.getContributor() );
342333
}
343-
344-
for ( Sequence sequence : namespace.getSequences() ) {
334+
for ( var sequence : namespace.getSequences() ) {
345335
contributors.add( sequence.getContributor() );
346336
}
347337
}
348-
349338
return contributors;
350339
}
351340

352341
@Override
353342
public java.util.Collection<Table> collectTableMappings() {
354-
ArrayList<Table> tables = new ArrayList<>();
355-
for ( Namespace namespace : database.getNamespaces() ) {
343+
final ArrayList<Table> tables = new ArrayList<>();
344+
for ( var namespace : database.getNamespaces() ) {
356345
tables.addAll( namespace.getTables() );
357346
}
358347
return tables;
@@ -370,27 +359,27 @@ public NamedObjectRepository buildNamedQueryRepository() {
370359

371360
@Override
372361
public void orderColumns(boolean forceOrdering) {
373-
final ColumnOrderingStrategy columnOrderingStrategy = metadataBuildingOptions.getColumnOrderingStrategy();
362+
final var columnOrderingStrategy = metadataBuildingOptions.getColumnOrderingStrategy();
374363
// No need to order columns when using the no-op strategy
375364
if ( columnOrderingStrategy != ColumnOrderingStrategyLegacy.INSTANCE ) {
376365
final boolean shouldOrderTableColumns = forceOrdering || shouldOrderTableColumns();
377-
for ( Namespace namespace : database.getNamespaces() ) {
366+
for ( var namespace : database.getNamespaces() ) {
378367
if ( shouldOrderTableColumns ) {
379-
for ( Table table : namespace.getTables() ) {
368+
for ( var table : namespace.getTables() ) {
380369
handleTable( table, columnOrderingStrategy );
381370
handlePrimaryKey( table, columnOrderingStrategy );
382371
handleForeignKeys( table, columnOrderingStrategy );
383372
}
384373
}
385-
for ( UserDefinedType userDefinedType : namespace.getUserDefinedTypes() ) {
374+
for ( var userDefinedType : namespace.getUserDefinedTypes() ) {
386375
handleUDT( userDefinedType, columnOrderingStrategy );
387376
}
388377
}
389378
}
390379
}
391380

392381
private void handleTable(Table table, ColumnOrderingStrategy columnOrderingStrategy) {
393-
final List<Column> tableColumns = columnOrderingStrategy.orderTableColumns( table, this );
382+
final var tableColumns = columnOrderingStrategy.orderTableColumns( table, this );
394383
if ( tableColumns != null ) {
395384
table.reorderColumns( tableColumns );
396385
}
@@ -399,7 +388,7 @@ private void handleTable(Table table, ColumnOrderingStrategy columnOrderingStrat
399388
private void handleUDT(UserDefinedType userDefinedType, ColumnOrderingStrategy columnOrderingStrategy) {
400389
if ( userDefinedType instanceof UserDefinedObjectType objectType
401390
&& objectType.getColumns().size() > 1 ) {
402-
final List<Column> objectTypeColumns =
391+
final var objectTypeColumns =
403392
columnOrderingStrategy.orderUserDefinedTypeColumns( objectType, this );
404393
if ( objectTypeColumns != null ) {
405394
objectType.reorderColumns( objectTypeColumns );
@@ -408,16 +397,16 @@ private void handleUDT(UserDefinedType userDefinedType, ColumnOrderingStrategy c
408397
}
409398

410399
private void handleForeignKeys(Table table, ColumnOrderingStrategy columnOrderingStrategy) {
411-
for ( ForeignKey foreignKey : table.getForeignKeyCollection() ) {
412-
final List<Column> columns = foreignKey.getColumns();
400+
for ( var foreignKey : table.getForeignKeyCollection() ) {
401+
final var columns = foreignKey.getColumns();
413402
if ( columns.size() > 1 ) {
414403
if ( foreignKey.getReferencedColumns().isEmpty() ) {
415-
final PrimaryKey targetPrimaryKey =
404+
final var targetPrimaryKey =
416405
foreignKey.getReferencedTable().getPrimaryKey();
417406
// Make sure we order the columns of the primary key first,
418407
// so that foreign key ordering can rely on this
419408
if ( targetPrimaryKey.getOriginalOrder() == null ) {
420-
final List<Column> primaryKeyColumns =
409+
final var primaryKeyColumns =
421410
columnOrderingStrategy.orderConstraintColumns( targetPrimaryKey, this );
422411
if ( primaryKeyColumns != null ) {
423412
targetPrimaryKey.reorderColumns( primaryKeyColumns );
@@ -427,7 +416,7 @@ private void handleForeignKeys(Table table, ColumnOrderingStrategy columnOrderin
427416
// Patch up the order of foreign keys based on new order of the target primary key
428417
final int[] originalPrimaryKeyOrder = targetPrimaryKey.getOriginalOrder();
429418
if ( originalPrimaryKeyOrder != null ) {
430-
final ArrayList<Column> foreignKeyColumnsCopy = new ArrayList<>( columns );
419+
final var foreignKeyColumnsCopy = new ArrayList<>( columns );
431420
for ( int i = 0; i < foreignKeyColumnsCopy.size(); i++ ) {
432421
columns.set( i, foreignKeyColumnsCopy.get( originalPrimaryKeyOrder[i] ) );
433422
}
@@ -438,10 +427,11 @@ private void handleForeignKeys(Table table, ColumnOrderingStrategy columnOrderin
438427
}
439428

440429
private void handlePrimaryKey(Table table, ColumnOrderingStrategy columnOrderingStrategy) {
441-
final PrimaryKey primaryKey = table.getPrimaryKey();
442-
if ( primaryKey != null && primaryKey.getColumns()
443-
.size() > 1 && primaryKey.getOriginalOrder() == null ) {
444-
final List<Column> primaryKeyColumns =
430+
final var primaryKey = table.getPrimaryKey();
431+
if ( primaryKey != null
432+
&& primaryKey.getColumns().size() > 1
433+
&& primaryKey.getOriginalOrder() == null ) {
434+
final var primaryKeyColumns =
445435
columnOrderingStrategy.orderConstraintColumns( primaryKey, this );
446436
if ( primaryKeyColumns != null ) {
447437
primaryKey.reorderColumns( primaryKeyColumns );
@@ -454,7 +444,7 @@ private boolean shouldOrderTableColumns() {
454444
metadataBuildingOptions.getServiceRegistry()
455445
.requireService( ConfigurationService.class )
456446
.getSettings();
457-
for ( ActionGrouping grouping : ActionGrouping.interpret( this, settings ) ) {
447+
for ( var grouping : ActionGrouping.interpret( this, settings ) ) {
458448
if ( isColumnOrderingRelevant( grouping.scriptAction() )
459449
|| isColumnOrderingRelevant( grouping.databaseAction() ) ) {
460450
return true;
@@ -472,11 +462,11 @@ private static boolean isColumnOrderingRelevant(Action grouping) {
472462

473463
@Override
474464
public void validate() throws MappingException {
475-
for ( PersistentClass entityBinding : this.getEntityBindings() ) {
465+
for ( var entityBinding : this.getEntityBindings() ) {
476466
entityBinding.validate( this );
477467
}
478468

479-
for ( Collection collectionBinding : this.getCollectionBindings() ) {
469+
for ( var collectionBinding : this.getCollectionBindings() ) {
480470
collectionBinding.validate( this );
481471
}
482472
}
@@ -491,15 +481,15 @@ public Set<MappedSuperclass> getMappedSuperclassMappingsCopy() {
491481
@Override
492482
public void initSessionFactory(SessionFactoryImplementor sessionFactory) {
493483
// must not use BootstrapContext services here
494-
final ServiceRegistryImplementor registry = sessionFactory.getServiceRegistry();
484+
final var registry = sessionFactory.getServiceRegistry();
495485
assert registry != null;
496-
final ConfigurationService configurationService = registry.requireService( ConfigurationService.class );
497-
final ClassLoaderService classLoaderService = registry.requireService( ClassLoaderService.class );
498-
final EventListenerRegistry eventListenerRegistry = sessionFactory.getEventListenerRegistry();
486+
final var configurationService = registry.requireService( ConfigurationService.class );
487+
final var classLoaderService = registry.requireService( ClassLoaderService.class );
488+
final var eventListenerRegistry = sessionFactory.getEventListenerRegistry();
499489
configurationService.getSettings().forEach( (propertyName, value) -> {
500490
if ( propertyName.startsWith( EVENT_LISTENER_PREFIX ) ) {
501491
final String eventTypeName = propertyName.substring( EVENT_LISTENER_PREFIX.length() + 1 );
502-
final EventType<?> eventType = EventType.resolveEventTypeByName( eventTypeName );
492+
final var eventType = EventType.resolveEventTypeByName( eventTypeName );
503493
final String listeners = (String) value;
504494
appendListeners( eventListenerRegistry, classLoaderService, listeners, eventType );
505495
}
@@ -511,7 +501,7 @@ private <T> void appendListeners(
511501
ClassLoaderService classLoaderService,
512502
String listeners,
513503
EventType<T> eventType) {
514-
final EventListenerGroup<T> eventListenerGroup = eventListenerRegistry.getEventListenerGroup( eventType );
504+
final var eventListenerGroup = eventListenerRegistry.getEventListenerGroup( eventType );
515505
for ( String listenerImpl : splitAtCommas( listeners ) ) {
516506
@SuppressWarnings("unchecked")
517507
T listener = (T) instantiate( listenerImpl, classLoaderService );
@@ -551,36 +541,36 @@ public DiscriminatorType<?> resolveEmbeddableDiscriminatorType(
551541

552542
@Override
553543
public org.hibernate.type.Type getIdentifierType(String entityName) throws MappingException {
554-
final PersistentClass pc = entityBindingMap.get( entityName );
555-
if ( pc == null ) {
544+
final var persistentClass = entityBindingMap.get( entityName );
545+
if ( persistentClass == null ) {
556546
throw new MappingException( "Persistent class not known: " + entityName );
557547
}
558-
return pc.getIdentifier().getType();
548+
return persistentClass.getIdentifier().getType();
559549
}
560550

561551
@Override
562552
public String getIdentifierPropertyName(String entityName) throws MappingException {
563-
final PersistentClass pc = entityBindingMap.get( entityName );
564-
if ( pc == null ) {
553+
final var persistentClass = entityBindingMap.get( entityName );
554+
if ( persistentClass == null ) {
565555
throw new MappingException( "Persistent class not known: " + entityName );
566556
}
567-
if ( !pc.hasIdentifierProperty() ) {
557+
if ( !persistentClass.hasIdentifierProperty() ) {
568558
return null;
569559
}
570-
return pc.getIdentifierProperty().getName();
560+
return persistentClass.getIdentifierProperty().getName();
571561
}
572562

573563
@Override
574564
public org.hibernate.type.Type getReferencedPropertyType(String entityName, String propertyName) throws MappingException {
575-
final PersistentClass pc = entityBindingMap.get( entityName );
576-
if ( pc == null ) {
565+
final var persistentClass = entityBindingMap.get( entityName );
566+
if ( persistentClass == null ) {
577567
throw new MappingException( "Persistent class not known: " + entityName );
578568
}
579-
final Property prop = pc.getReferencedProperty( propertyName );
580-
if ( prop == null ) {
569+
final var referencedProperty = persistentClass.getReferencedProperty( propertyName );
570+
if ( referencedProperty == null ) {
581571
throw new MappingException( "Property not known: " + entityName + '.' + propertyName );
582572
}
583-
return prop.getType();
573+
return referencedProperty.getType();
584574
}
585575

586576
//Specific for copies only:

hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/AnnotationMetadataSourceProcessorImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ private static void applyManagedClasses(
263263
DomainModelSource domainModelSource,
264264
LinkedHashSet<ClassDetails> knownClasses) {
265265
final var classDetailsRegistry = domainModelSource.getClassDetailsRegistry();
266-
domainModelSource.getManagedClassNames().forEach( (className) -> {
267-
knownClasses.add( classDetailsRegistry.resolveClassDetails( className ) );
268-
} );
266+
domainModelSource.getManagedClassNames()
267+
.forEach( className -> knownClasses.add( classDetailsRegistry.resolveClassDetails( className ) ) );
269268
}
270269
}

hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/HbmMetadataSourceProcessorImpl.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ public HbmMetadataSourceProcessorImpl(
4141
public HbmMetadataSourceProcessorImpl(
4242
Collection<Binding<? extends JaxbBindableMappingDescriptor>> xmlBindings,
4343
MetadataBuildingContext rootBuildingContext) {
44-
final EntityHierarchyBuilder hierarchyBuilder = new EntityHierarchyBuilder();
44+
final var hierarchyBuilder = new EntityHierarchyBuilder();
4545

4646
mappingDocuments = new ArrayList<>();
4747

4848
for ( var xmlBinding : xmlBindings ) {
4949
if ( xmlBinding.getRoot() instanceof JaxbHbmHibernateMapping hibernateMapping ) {
50-
final MappingDocument mappingDocument = new MappingDocument(
50+
final var mappingDocument = new MappingDocument(
5151
"orm",
5252
hibernateMapping,
5353
xmlBinding.getOrigin(),
@@ -64,56 +64,56 @@ public HbmMetadataSourceProcessorImpl(
6464

6565
@Override
6666
public void prepare() {
67-
for ( MappingDocument mappingDocument : mappingDocuments ) {
67+
for ( var mappingDocument : mappingDocuments ) {
6868
mappingDocument.prepare();
6969
}
7070
}
7171

7272
@Override
7373
public void processTypeDefinitions() {
74-
for ( MappingDocument mappingDocument : mappingDocuments ) {
74+
for ( var mappingDocument : mappingDocuments ) {
7575
mappingDocument.processTypeDefinitions();
7676
}
7777
}
7878

7979
@Override
8080
public void processQueryRenames() {
81-
for ( MappingDocument mappingDocument : mappingDocuments ) {
81+
for ( var mappingDocument : mappingDocuments ) {
8282
mappingDocument.processQueryRenames();
8383
}
8484
}
8585

8686
@Override
8787
public void processNamedQueries() {
88-
for ( MappingDocument mappingDocument : mappingDocuments ) {
88+
for ( var mappingDocument : mappingDocuments ) {
8989
mappingDocument.processNamedQueries();
9090
}
9191
}
9292

9393
@Override
9494
public void processAuxiliaryDatabaseObjectDefinitions() {
95-
for ( MappingDocument mappingDocument : mappingDocuments ) {
95+
for ( var mappingDocument : mappingDocuments ) {
9696
mappingDocument.processAuxiliaryDatabaseObjectDefinitions();
9797
}
9898
}
9999

100100
@Override
101101
public void processFilterDefinitions() {
102-
for ( MappingDocument mappingDocument : mappingDocuments ) {
102+
for ( var mappingDocument : mappingDocuments ) {
103103
mappingDocument.processFilterDefinitions();
104104
}
105105
}
106106

107107
@Override
108108
public void processFetchProfiles() {
109-
for ( MappingDocument mappingDocument : mappingDocuments ) {
109+
for ( var mappingDocument : mappingDocuments ) {
110110
mappingDocument.processFetchProfiles();
111111
}
112112
}
113113

114114
@Override
115115
public void processIdentifierGenerators() {
116-
for ( MappingDocument mappingDocument : mappingDocuments ) {
116+
for ( var mappingDocument : mappingDocuments ) {
117117
mappingDocument.processIdentifierGenerators();
118118
}
119119
}
@@ -124,7 +124,7 @@ public void prepareForEntityHierarchyProcessing() {
124124

125125
@Override
126126
public void processEntityHierarchies(Set<String> processedEntityNames) {
127-
hierarchy_loop : for ( EntityHierarchySourceImpl entityHierarchy : entityHierarchies ) {
127+
hierarchy_loop : for ( var entityHierarchy : entityHierarchies ) {
128128
for ( String entityName : entityHierarchy.getContainedEntityNames() ) {
129129
if ( processedEntityNames.contains( entityName ) ) {
130130
if ( LOG.isDebugEnabled() ) {
@@ -148,14 +148,14 @@ public void postProcessEntityHierarchies() {}
148148

149149
@Override
150150
public void processResultSetMappings() {
151-
for ( MappingDocument mappingDocument : mappingDocuments ) {
151+
for ( var mappingDocument : mappingDocuments ) {
152152
mappingDocument.processResultSetMappings();
153153
}
154154
}
155155

156156
@Override
157157
public void finishUp() {
158-
for ( MappingDocument mappingDocument : mappingDocuments ) {
158+
for ( var mappingDocument : mappingDocuments ) {
159159
mappingDocument.finishUp();
160160
}
161161
}

0 commit comments

Comments
 (0)