39
39
import org .hibernate .engine .config .spi .ConfigurationService ;
40
40
import org .hibernate .engine .spi .FilterDefinition ;
41
41
import org .hibernate .engine .spi .SessionFactoryImplementor ;
42
- import org .hibernate .event .service .spi .EventListenerGroup ;
43
42
import org .hibernate .event .service .spi .EventListenerRegistry ;
44
43
import org .hibernate .event .spi .EventType ;
45
44
import org .hibernate .mapping .Collection ;
46
- import org .hibernate .mapping .Column ;
47
45
import org .hibernate .mapping .Component ;
48
46
import org .hibernate .mapping .FetchProfile ;
49
- import org .hibernate .mapping .ForeignKey ;
50
47
import org .hibernate .mapping .MappedSuperclass ;
51
48
import org .hibernate .mapping .PersistentClass ;
52
- import org .hibernate .mapping .PrimaryKey ;
53
- import org .hibernate .mapping .Property ;
54
49
import org .hibernate .mapping .Table ;
55
50
import org .hibernate .mapping .UserDefinedObjectType ;
56
51
import org .hibernate .mapping .UserDefinedType ;
59
54
import org .hibernate .query .named .NamedObjectRepository ;
60
55
import org .hibernate .query .sqm .function .SqmFunctionDescriptor ;
61
56
import org .hibernate .query .sqm .function .SqmFunctionRegistry ;
62
- import org .hibernate .service .spi .ServiceRegistryImplementor ;
63
57
import org .hibernate .tool .schema .Action ;
64
58
import org .hibernate .tool .schema .spi .SchemaManagementToolCoordinator .ActionGrouping ;
65
59
import org .hibernate .type .spi .TypeConfiguration ;
@@ -331,28 +325,23 @@ public Map<String, SqmFunctionDescriptor> getSqlFunctionMap() {
331
325
@ Override
332
326
public Set <String > getContributors () {
333
327
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 () ) {
341
332
contributors .add ( table .getContributor () );
342
333
}
343
-
344
- for ( Sequence sequence : namespace .getSequences () ) {
334
+ for ( var sequence : namespace .getSequences () ) {
345
335
contributors .add ( sequence .getContributor () );
346
336
}
347
337
}
348
-
349
338
return contributors ;
350
339
}
351
340
352
341
@ Override
353
342
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 () ) {
356
345
tables .addAll ( namespace .getTables () );
357
346
}
358
347
return tables ;
@@ -370,27 +359,27 @@ public NamedObjectRepository buildNamedQueryRepository() {
370
359
371
360
@ Override
372
361
public void orderColumns (boolean forceOrdering ) {
373
- final ColumnOrderingStrategy columnOrderingStrategy = metadataBuildingOptions .getColumnOrderingStrategy ();
362
+ final var columnOrderingStrategy = metadataBuildingOptions .getColumnOrderingStrategy ();
374
363
// No need to order columns when using the no-op strategy
375
364
if ( columnOrderingStrategy != ColumnOrderingStrategyLegacy .INSTANCE ) {
376
365
final boolean shouldOrderTableColumns = forceOrdering || shouldOrderTableColumns ();
377
- for ( Namespace namespace : database .getNamespaces () ) {
366
+ for ( var namespace : database .getNamespaces () ) {
378
367
if ( shouldOrderTableColumns ) {
379
- for ( Table table : namespace .getTables () ) {
368
+ for ( var table : namespace .getTables () ) {
380
369
handleTable ( table , columnOrderingStrategy );
381
370
handlePrimaryKey ( table , columnOrderingStrategy );
382
371
handleForeignKeys ( table , columnOrderingStrategy );
383
372
}
384
373
}
385
- for ( UserDefinedType userDefinedType : namespace .getUserDefinedTypes () ) {
374
+ for ( var userDefinedType : namespace .getUserDefinedTypes () ) {
386
375
handleUDT ( userDefinedType , columnOrderingStrategy );
387
376
}
388
377
}
389
378
}
390
379
}
391
380
392
381
private void handleTable (Table table , ColumnOrderingStrategy columnOrderingStrategy ) {
393
- final List < Column > tableColumns = columnOrderingStrategy .orderTableColumns ( table , this );
382
+ final var tableColumns = columnOrderingStrategy .orderTableColumns ( table , this );
394
383
if ( tableColumns != null ) {
395
384
table .reorderColumns ( tableColumns );
396
385
}
@@ -399,7 +388,7 @@ private void handleTable(Table table, ColumnOrderingStrategy columnOrderingStrat
399
388
private void handleUDT (UserDefinedType userDefinedType , ColumnOrderingStrategy columnOrderingStrategy ) {
400
389
if ( userDefinedType instanceof UserDefinedObjectType objectType
401
390
&& objectType .getColumns ().size () > 1 ) {
402
- final List < Column > objectTypeColumns =
391
+ final var objectTypeColumns =
403
392
columnOrderingStrategy .orderUserDefinedTypeColumns ( objectType , this );
404
393
if ( objectTypeColumns != null ) {
405
394
objectType .reorderColumns ( objectTypeColumns );
@@ -408,16 +397,16 @@ private void handleUDT(UserDefinedType userDefinedType, ColumnOrderingStrategy c
408
397
}
409
398
410
399
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 ();
413
402
if ( columns .size () > 1 ) {
414
403
if ( foreignKey .getReferencedColumns ().isEmpty () ) {
415
- final PrimaryKey targetPrimaryKey =
404
+ final var targetPrimaryKey =
416
405
foreignKey .getReferencedTable ().getPrimaryKey ();
417
406
// Make sure we order the columns of the primary key first,
418
407
// so that foreign key ordering can rely on this
419
408
if ( targetPrimaryKey .getOriginalOrder () == null ) {
420
- final List < Column > primaryKeyColumns =
409
+ final var primaryKeyColumns =
421
410
columnOrderingStrategy .orderConstraintColumns ( targetPrimaryKey , this );
422
411
if ( primaryKeyColumns != null ) {
423
412
targetPrimaryKey .reorderColumns ( primaryKeyColumns );
@@ -427,7 +416,7 @@ private void handleForeignKeys(Table table, ColumnOrderingStrategy columnOrderin
427
416
// Patch up the order of foreign keys based on new order of the target primary key
428
417
final int [] originalPrimaryKeyOrder = targetPrimaryKey .getOriginalOrder ();
429
418
if ( originalPrimaryKeyOrder != null ) {
430
- final ArrayList < Column > foreignKeyColumnsCopy = new ArrayList <>( columns );
419
+ final var foreignKeyColumnsCopy = new ArrayList <>( columns );
431
420
for ( int i = 0 ; i < foreignKeyColumnsCopy .size (); i ++ ) {
432
421
columns .set ( i , foreignKeyColumnsCopy .get ( originalPrimaryKeyOrder [i ] ) );
433
422
}
@@ -438,10 +427,11 @@ private void handleForeignKeys(Table table, ColumnOrderingStrategy columnOrderin
438
427
}
439
428
440
429
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 =
445
435
columnOrderingStrategy .orderConstraintColumns ( primaryKey , this );
446
436
if ( primaryKeyColumns != null ) {
447
437
primaryKey .reorderColumns ( primaryKeyColumns );
@@ -454,7 +444,7 @@ private boolean shouldOrderTableColumns() {
454
444
metadataBuildingOptions .getServiceRegistry ()
455
445
.requireService ( ConfigurationService .class )
456
446
.getSettings ();
457
- for ( ActionGrouping grouping : ActionGrouping .interpret ( this , settings ) ) {
447
+ for ( var grouping : ActionGrouping .interpret ( this , settings ) ) {
458
448
if ( isColumnOrderingRelevant ( grouping .scriptAction () )
459
449
|| isColumnOrderingRelevant ( grouping .databaseAction () ) ) {
460
450
return true ;
@@ -472,11 +462,11 @@ private static boolean isColumnOrderingRelevant(Action grouping) {
472
462
473
463
@ Override
474
464
public void validate () throws MappingException {
475
- for ( PersistentClass entityBinding : this .getEntityBindings () ) {
465
+ for ( var entityBinding : this .getEntityBindings () ) {
476
466
entityBinding .validate ( this );
477
467
}
478
468
479
- for ( Collection collectionBinding : this .getCollectionBindings () ) {
469
+ for ( var collectionBinding : this .getCollectionBindings () ) {
480
470
collectionBinding .validate ( this );
481
471
}
482
472
}
@@ -491,15 +481,15 @@ public Set<MappedSuperclass> getMappedSuperclassMappingsCopy() {
491
481
@ Override
492
482
public void initSessionFactory (SessionFactoryImplementor sessionFactory ) {
493
483
// must not use BootstrapContext services here
494
- final ServiceRegistryImplementor registry = sessionFactory .getServiceRegistry ();
484
+ final var registry = sessionFactory .getServiceRegistry ();
495
485
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 ();
499
489
configurationService .getSettings ().forEach ( (propertyName , value ) -> {
500
490
if ( propertyName .startsWith ( EVENT_LISTENER_PREFIX ) ) {
501
491
final String eventTypeName = propertyName .substring ( EVENT_LISTENER_PREFIX .length () + 1 );
502
- final EventType <?> eventType = EventType .resolveEventTypeByName ( eventTypeName );
492
+ final var eventType = EventType .resolveEventTypeByName ( eventTypeName );
503
493
final String listeners = (String ) value ;
504
494
appendListeners ( eventListenerRegistry , classLoaderService , listeners , eventType );
505
495
}
@@ -511,7 +501,7 @@ private <T> void appendListeners(
511
501
ClassLoaderService classLoaderService ,
512
502
String listeners ,
513
503
EventType <T > eventType ) {
514
- final EventListenerGroup < T > eventListenerGroup = eventListenerRegistry .getEventListenerGroup ( eventType );
504
+ final var eventListenerGroup = eventListenerRegistry .getEventListenerGroup ( eventType );
515
505
for ( String listenerImpl : splitAtCommas ( listeners ) ) {
516
506
@ SuppressWarnings ("unchecked" )
517
507
T listener = (T ) instantiate ( listenerImpl , classLoaderService );
@@ -551,36 +541,36 @@ public DiscriminatorType<?> resolveEmbeddableDiscriminatorType(
551
541
552
542
@ Override
553
543
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 ) {
556
546
throw new MappingException ( "Persistent class not known: " + entityName );
557
547
}
558
- return pc .getIdentifier ().getType ();
548
+ return persistentClass .getIdentifier ().getType ();
559
549
}
560
550
561
551
@ Override
562
552
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 ) {
565
555
throw new MappingException ( "Persistent class not known: " + entityName );
566
556
}
567
- if ( !pc .hasIdentifierProperty () ) {
557
+ if ( !persistentClass .hasIdentifierProperty () ) {
568
558
return null ;
569
559
}
570
- return pc .getIdentifierProperty ().getName ();
560
+ return persistentClass .getIdentifierProperty ().getName ();
571
561
}
572
562
573
563
@ Override
574
564
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 ) {
577
567
throw new MappingException ( "Persistent class not known: " + entityName );
578
568
}
579
- final Property prop = pc .getReferencedProperty ( propertyName );
580
- if ( prop == null ) {
569
+ final var referencedProperty = persistentClass .getReferencedProperty ( propertyName );
570
+ if ( referencedProperty == null ) {
581
571
throw new MappingException ( "Property not known: " + entityName + '.' + propertyName );
582
572
}
583
- return prop .getType ();
573
+ return referencedProperty .getType ();
584
574
}
585
575
586
576
//Specific for copies only:
0 commit comments