166
166
import org .hibernate .internal .util .StringHelper ;
167
167
import org .hibernate .internal .util .collections .CollectionHelper ;
168
168
import org .hibernate .mapping .BasicValue ;
169
- import org .hibernate .mapping .CheckConstraint ;
170
169
import org .hibernate .mapping .Collection ;
171
170
import org .hibernate .mapping .Column ;
172
171
import org .hibernate .mapping .Component ;
@@ -227,16 +226,15 @@ public static List<Binding<JaxbEntityMappingsImpl>> transform(
227
226
MetadataImplementor bootModel ,
228
227
UnsupportedFeatureHandling unsupportedFeatureHandling ) {
229
228
// perform a first pass over the hbm.xml bindings building much of the transformation-state
230
- final TransformationState transformationState = new TransformationState ();
231
- final List <Binding <JaxbEntityMappingsImpl >> transformations =
232
- XmlPreprocessor .preprocessHbmXml ( hbmXmlBindings , transformationState );
229
+ final var transformationState = new TransformationState ();
230
+ final var transformations = XmlPreprocessor .preprocessHbmXml ( hbmXmlBindings , transformationState );
233
231
234
232
// build and perform a pass over the boot model building the rest of the transformation-state
235
233
BootModelPreprocessor .preprocessBooModel ( bootModel , transformationState );
236
234
237
235
// now we are ready to fully build the mapping.xml transformations
238
236
for ( int i = 0 ; i < hbmXmlBindings .size (); i ++ ) {
239
- final HbmXmlTransformer hbmXmlTransformer = new HbmXmlTransformer (
237
+ final var hbmXmlTransformer = new HbmXmlTransformer (
240
238
hbmXmlBindings .get ( i ),
241
239
transformations .get ( i ),
242
240
transformationState ,
@@ -275,8 +273,8 @@ private HbmXmlTransformer(
275
273
276
274
277
275
private void performTransformation () {
278
- final JaxbHbmHibernateMapping hbmXmlRoot = hbmXmlBinding .getRoot ();
279
- final JaxbEntityMappingsImpl mappingXmlRoot = mappingXmlBinding .getRoot ();
276
+ final var hbmXmlRoot = hbmXmlBinding .getRoot ();
277
+ final var mappingXmlRoot = mappingXmlBinding .getRoot ();
280
278
281
279
TransformationHelper .transfer ( hbmXmlRoot ::getPackage , mappingXmlRoot ::setPackage );
282
280
TransformationHelper .transfer ( hbmXmlRoot ::getCatalog , mappingXmlRoot ::setCatalog );
@@ -295,53 +293,53 @@ private void performTransformation() {
295
293
296
294
hbmXmlRoot .getClazz ().forEach ( (hbmEntity ) -> {
297
295
final String entityName = TransformationHelper .determineEntityName ( hbmEntity , hbmXmlRoot );
298
- final JaxbEntityImpl mappingEntity = transformationState .getMappingEntityByName ().get ( entityName );
299
- final EntityTypeInfo bootEntityInfo = transformationState .getEntityInfoByName ().get ( entityName );
296
+ final var mappingEntity = transformationState .getMappingEntityByName ().get ( entityName );
297
+ final var bootEntityInfo = transformationState .getEntityInfoByName ().get ( entityName );
300
298
assert mappingEntity != null : "Unable to locate JaxbEntityImpl for " + entityName ;
301
- assert bootEntityInfo != null : "Unable to locate EntityTypeInfo for " + entityName ;
299
+ assert bootEntityInfo != null : "Unable to locate EntityTypeInfo for " + entityName ;
302
300
303
301
transferRootEntity ( hbmEntity , mappingEntity , bootEntityInfo );
304
302
} );
305
303
306
304
hbmXmlRoot .getSubclass ().forEach ( (hbmSubclass ) -> {
307
305
final String entityName = TransformationHelper .determineEntityName ( hbmSubclass , hbmXmlRoot );
308
- final JaxbEntityImpl mappingEntity = transformationState .getMappingEntityByName ().get ( entityName );
309
- final EntityTypeInfo bootEntityInfo = transformationState .getEntityInfoByName ().get ( entityName );
306
+ final var mappingEntity = transformationState .getMappingEntityByName ().get ( entityName );
307
+ final var bootEntityInfo = transformationState .getEntityInfoByName ().get ( entityName );
310
308
assert mappingEntity != null : "Unable to locate JaxbEntityImpl for " + entityName ;
311
- assert bootEntityInfo != null : "Unable to locate EntityTypeInfo for " + entityName ;
309
+ assert bootEntityInfo != null : "Unable to locate EntityTypeInfo for " + entityName ;
312
310
313
311
transferDiscriminatorSubclass ( hbmSubclass , mappingEntity , bootEntityInfo );
314
312
315
313
final String rootEntityName = bootEntityInfo .getPersistentClass ().getRootClass ().getEntityName ();
316
- final JaxbEntityImpl rootMappingEntity = transformationState .getMappingEntityByName ().get ( rootEntityName );
314
+ final var rootMappingEntity = transformationState .getMappingEntityByName ().get ( rootEntityName );
317
315
defineInheritance ( rootMappingEntity , InheritanceType .SINGLE_TABLE );
318
316
} );
319
317
320
318
hbmXmlRoot .getJoinedSubclass ().forEach ( (hbmSubclass ) -> {
321
319
final String entityName = TransformationHelper .determineEntityName ( hbmSubclass , hbmXmlRoot );
322
- final JaxbEntityImpl mappingEntity = transformationState .getMappingEntityByName ().get ( entityName );
323
- final EntityTypeInfo bootEntityInfo = transformationState .getEntityInfoByName ().get ( entityName );
320
+ final var mappingEntity = transformationState .getMappingEntityByName ().get ( entityName );
321
+ final var bootEntityInfo = transformationState .getEntityInfoByName ().get ( entityName );
324
322
assert mappingEntity != null : "Unable to locate JaxbEntityImpl for " + entityName ;
325
- assert bootEntityInfo != null : "Unable to locate EntityTypeInfo for " + entityName ;
323
+ assert bootEntityInfo != null : "Unable to locate EntityTypeInfo for " + entityName ;
326
324
327
325
transferJoinedSubclass ( hbmSubclass , mappingEntity , bootEntityInfo );
328
326
329
327
final String rootEntityName = bootEntityInfo .getPersistentClass ().getRootClass ().getEntityName ();
330
- final JaxbEntityImpl rootMappingEntity = transformationState .getMappingEntityByName ().get ( rootEntityName );
328
+ final var rootMappingEntity = transformationState .getMappingEntityByName ().get ( rootEntityName );
331
329
defineInheritance ( rootMappingEntity , InheritanceType .JOINED );
332
330
} );
333
331
334
332
hbmXmlRoot .getUnionSubclass ().forEach ( (hbmSubclass ) -> {
335
333
final String entityName = TransformationHelper .determineEntityName ( hbmSubclass , hbmXmlRoot );
336
- final JaxbEntityImpl mappingEntity = transformationState .getMappingEntityByName ().get ( entityName );
337
- final EntityTypeInfo bootEntityInfo = transformationState .getEntityInfoByName ().get ( entityName );
334
+ final var mappingEntity = transformationState .getMappingEntityByName ().get ( entityName );
335
+ final var bootEntityInfo = transformationState .getEntityInfoByName ().get ( entityName );
338
336
assert mappingEntity != null : "Unable to locate JaxbEntityImpl for " + entityName ;
339
- assert bootEntityInfo != null : "Unable to locate EntityTypeInfo for " + entityName ;
337
+ assert bootEntityInfo != null : "Unable to locate EntityTypeInfo for " + entityName ;
340
338
341
339
transferUnionSubclass ( hbmSubclass , mappingEntity , bootEntityInfo );
342
340
343
341
final String rootEntityName = bootEntityInfo .getPersistentClass ().getRootClass ().getEntityName ();
344
- final JaxbEntityImpl rootMappingEntity = transformationState .getMappingEntityByName ().get ( rootEntityName );
342
+ final var rootMappingEntity = transformationState .getMappingEntityByName ().get ( rootEntityName );
345
343
defineInheritance ( rootMappingEntity , InheritanceType .TABLE_PER_CLASS );
346
344
} );
347
345
@@ -352,10 +350,10 @@ private void performTransformation() {
352
350
353
351
private static void dumpTransformed (Origin origin , JaxbEntityMappingsImpl ormRoot ) {
354
352
try {
355
- JAXBContext ctx = JAXBContext .newInstance ( JaxbEntityMappingsImpl .class );
356
- Marshaller marshaller = ctx .createMarshaller ();
353
+ var ctx = JAXBContext .newInstance ( JaxbEntityMappingsImpl .class );
354
+ var marshaller = ctx .createMarshaller ();
357
355
marshaller .setProperty ( Marshaller .JAXB_FORMATTED_OUTPUT , true );
358
- final StringWriter stringWriter = new StringWriter ();
356
+ final var stringWriter = new StringWriter ();
359
357
marshaller .marshal ( ormRoot , stringWriter );
360
358
TRANSFORMATION_LOGGER .debugf ( "Transformed hbm.xml (%s):\n %s" , origin , stringWriter .toString () );
361
359
}
@@ -376,8 +374,8 @@ private void transferRootEntity(
376
374
377
375
applyTable ( entityInfo .getPersistentClass (), mappingEntity );
378
376
379
- for ( JaxbHbmSynchronizeType hbmSync : hbmClass .getSynchronize () ) {
380
- final JaxbSynchronizedTableImpl sync = new JaxbSynchronizedTableImpl ();
377
+ for ( var hbmSync : hbmClass .getSynchronize () ) {
378
+ final var sync = new JaxbSynchronizedTableImpl ();
381
379
sync .setTable ( hbmSync .getTable () );
382
380
mappingEntity .getSynchronizeTables ().add ( sync );
383
381
}
@@ -422,55 +420,57 @@ private void transferRootEntity(
422
420
transformEntityCaching ( hbmClass , mappingEntity );
423
421
}
424
422
425
- for ( JaxbHbmNamedQueryType hbmQuery : hbmClass .getQuery () ) {
426
- mappingEntity .getNamedQueries ().add ( transformNamedQuery ( hbmQuery , mappingEntity .getName () + "." + hbmQuery .getName () ) );
423
+ for ( var hbmQuery : hbmClass .getQuery () ) {
424
+ final String name = mappingEntity .getName () + "." + hbmQuery .getName ();
425
+ mappingEntity .getNamedQueries ().add ( transformNamedQuery ( hbmQuery , name ) );
427
426
}
428
427
429
- for ( JaxbHbmNamedNativeQueryType hbmQuery : hbmClass .getSqlQuery () ) {
430
- mappingEntity .getNamedNativeQueries ().add (
431
- transformNamedNativeQuery ( hbmQuery , mappingEntity .getName () + "." + hbmQuery .getName () )
432
- );
428
+ for ( var hbmQuery : hbmClass .getSqlQuery () ) {
429
+ final String name = mappingEntity .getName () + "." + hbmQuery .getName ();
430
+ mappingEntity .getNamedNativeQueries ().add ( transformNamedNativeQuery ( hbmQuery , name ) );
433
431
}
434
432
435
- for ( JaxbHbmFilterType hbmFilter : hbmClass .getFilter ()) {
436
- mappingEntity .getFilters ().add ( convert ( hbmFilter ) );
433
+ final var filters = mappingEntity .getFilters ();
434
+ for ( var hbmFilter : hbmClass .getFilter ()) {
435
+ filters .add ( convert ( hbmFilter ) );
437
436
}
438
437
439
- for ( JaxbHbmFetchProfileType hbmFetchProfile : hbmClass .getFetchProfile () ) {
440
- mappingEntity .getFetchProfiles ().add ( transferFetchProfile ( hbmFetchProfile ) );
438
+ final var fetchProfiles = mappingEntity .getFetchProfiles ();
439
+ for ( var hbmFetchProfile : hbmClass .getFetchProfile () ) {
440
+ fetchProfiles .add ( transferFetchProfile ( hbmFetchProfile ) );
441
441
}
442
442
443
- for ( JaxbHbmDiscriminatorSubclassEntityType hbmSubclass : hbmClass .getSubclass () ) {
443
+ for ( var hbmSubclass : hbmClass .getSubclass () ) {
444
444
final String subclassEntityName = TransformationHelper .determineEntityName ( hbmSubclass , hbmXmlBinding .getRoot () );
445
- final JaxbEntityImpl mappingSubclassEntity = transformationState .getMappingEntityByName ().get ( subclassEntityName );
446
- final EntityTypeInfo subclassEntityInfo = transformationState .getEntityInfoByName ().get ( subclassEntityName );
445
+ final var mappingSubclassEntity = transformationState .getMappingEntityByName ().get ( subclassEntityName );
446
+ final var subclassEntityInfo = transformationState .getEntityInfoByName ().get ( subclassEntityName );
447
447
transferDiscriminatorSubclass ( hbmSubclass , mappingSubclassEntity , subclassEntityInfo );
448
448
defineInheritance ( mappingEntity , InheritanceType .SINGLE_TABLE );
449
449
}
450
450
451
- for ( JaxbHbmJoinedSubclassEntityType hbmSubclass : hbmClass .getJoinedSubclass () ) {
451
+ for ( var hbmSubclass : hbmClass .getJoinedSubclass () ) {
452
452
final String subclassEntityName = TransformationHelper .determineEntityName ( hbmSubclass , hbmXmlBinding .getRoot () );
453
- final JaxbEntityImpl mappingSubclassEntity = transformationState .getMappingEntityByName ().get ( subclassEntityName );
454
- final EntityTypeInfo subclassEntityInfo = transformationState .getEntityInfoByName ().get ( subclassEntityName );
453
+ final var mappingSubclassEntity = transformationState .getMappingEntityByName ().get ( subclassEntityName );
454
+ final var subclassEntityInfo = transformationState .getEntityInfoByName ().get ( subclassEntityName );
455
455
transferJoinedSubclass ( hbmSubclass , mappingSubclassEntity , subclassEntityInfo );
456
456
defineInheritance ( mappingEntity , InheritanceType .TABLE_PER_CLASS );
457
457
}
458
458
459
- for (JaxbHbmUnionSubclassEntityType hbmSubclass : hbmClass .getUnionSubclass () ) {
459
+ for ( var hbmSubclass : hbmClass .getUnionSubclass () ) {
460
460
final String subclassEntityName = TransformationHelper .determineEntityName ( hbmSubclass , hbmXmlBinding .getRoot () );
461
- final JaxbEntityImpl mappingSubclassEntity = transformationState .getMappingEntityByName ().get ( subclassEntityName );
462
- final EntityTypeInfo subclassEntityInfo = transformationState .getEntityInfoByName ().get ( subclassEntityName );
461
+ final var mappingSubclassEntity = transformationState .getMappingEntityByName ().get ( subclassEntityName );
462
+ final var subclassEntityInfo = transformationState .getEntityInfoByName ().get ( subclassEntityName );
463
463
transferUnionSubclass ( hbmSubclass , mappingSubclassEntity , subclassEntityInfo );
464
464
defineInheritance ( mappingEntity , InheritanceType .JOINED );
465
465
}
466
466
467
- for ( JaxbHbmNamedQueryType hbmQuery : hbmClass .getQuery () ) {
467
+ for ( var hbmQuery : hbmClass .getQuery () ) {
468
468
// Tests implied this was the case...
469
469
final String name = hbmClass .getName () + "." + hbmQuery .getName ();
470
470
mappingXmlBinding .getRoot ().getNamedQueries ().add ( transformNamedQuery ( hbmQuery , name ) );
471
471
}
472
472
473
- for ( JaxbHbmNamedNativeQueryType hbmQuery : hbmClass .getSqlQuery () ) {
473
+ for ( var hbmQuery : hbmClass .getSqlQuery () ) {
474
474
// Tests implied this was the case...
475
475
final String name = hbmClass .getName () + "." + hbmQuery .getName ();
476
476
mappingXmlBinding .getRoot ().getNamedNativeQueries ().add ( transformNamedNativeQuery ( hbmQuery , name ) );
@@ -503,10 +503,10 @@ private void transferDiscriminatorSubclass(
503
503
transferBaseEntityAttributes ( hbmSubclass , subclassEntity , subclassEntityInfo );
504
504
505
505
if ( !hbmSubclass .getSubclass ().isEmpty () ) {
506
- for ( JaxbHbmDiscriminatorSubclassEntityType nestedHbmSubclass : hbmSubclass .getSubclass () ) {
506
+ for ( var nestedHbmSubclass : hbmSubclass .getSubclass () ) {
507
507
final String nestedSubclassEntityName = TransformationHelper .determineEntityName ( nestedHbmSubclass , hbmXmlBinding .getRoot () );
508
- final JaxbEntityImpl nestedSubclassSubclassEntity = transformationState .getMappingEntityByName ().get ( nestedSubclassEntityName );
509
- final EntityTypeInfo nestedSubclassInfo = transformationState .getEntityInfoByName ().get ( nestedSubclassEntityName );
508
+ final var nestedSubclassSubclassEntity = transformationState .getMappingEntityByName ().get ( nestedSubclassEntityName );
509
+ final var nestedSubclassInfo = transformationState .getEntityInfoByName ().get ( nestedSubclassEntityName );
510
510
transferDiscriminatorSubclass ( nestedHbmSubclass , nestedSubclassSubclassEntity , nestedSubclassInfo );
511
511
}
512
512
}
@@ -523,20 +523,20 @@ private void transferJoinedSubclass(
523
523
524
524
applyTable ( subclassEntityInfo .getPersistentClass (), subclassEntity );
525
525
526
- final JaxbHbmKeyType key = hbmSubclass .getKey ();
526
+ final var key = hbmSubclass .getKey ();
527
527
if ( key != null ) {
528
- final JaxbPrimaryKeyJoinColumnImpl joinColumn = new JaxbPrimaryKeyJoinColumnImpl ();
528
+ final var joinColumn = new JaxbPrimaryKeyJoinColumnImpl ();
529
529
// todo (7.0) : formula and multiple columns
530
530
joinColumn .setName ( key .getColumnAttribute () );
531
531
subclassEntity .getPrimaryKeyJoinColumns ().add ( joinColumn );
532
532
joinColumn .setForeignKey ( transformForeignKey ( key .getForeignKey () ) );
533
533
}
534
534
535
535
if ( !hbmSubclass .getJoinedSubclass ().isEmpty () ) {
536
- for ( JaxbHbmJoinedSubclassEntityType nestedHbmSubclass : hbmSubclass .getJoinedSubclass () ) {
536
+ for ( var nestedHbmSubclass : hbmSubclass .getJoinedSubclass () ) {
537
537
final String nestedSubclassEntityName = TransformationHelper .determineEntityName ( nestedHbmSubclass , hbmXmlBinding .getRoot () );
538
- final JaxbEntityImpl nestedSubclassSubclassEntity = transformationState .getMappingEntityByName ().get ( nestedSubclassEntityName );
539
- final EntityTypeInfo nestedSubclassInfo = transformationState .getEntityInfoByName ().get ( nestedSubclassEntityName );
538
+ final var nestedSubclassSubclassEntity = transformationState .getMappingEntityByName ().get ( nestedSubclassEntityName );
539
+ final var nestedSubclassInfo = transformationState .getEntityInfoByName ().get ( nestedSubclassEntityName );
540
540
transferJoinedSubclass ( nestedHbmSubclass , nestedSubclassSubclassEntity , nestedSubclassInfo );
541
541
}
542
542
}
@@ -555,10 +555,10 @@ private void transferUnionSubclass(
555
555
applyTable ( subclassEntityInfo .getPersistentClass (), subclassEntity );
556
556
557
557
if ( !hbmSubclass .getUnionSubclass ().isEmpty () ) {
558
- for ( JaxbHbmUnionSubclassEntityType nestedHbmSubclass : hbmSubclass .getUnionSubclass () ) {
558
+ for ( var nestedHbmSubclass : hbmSubclass .getUnionSubclass () ) {
559
559
final String nestedSubclassEntityName = TransformationHelper .determineEntityName ( nestedHbmSubclass , hbmXmlBinding .getRoot () );
560
- final JaxbEntityImpl nestedSubclassSubclassEntity = transformationState .getMappingEntityByName ().get ( nestedSubclassEntityName );
561
- final EntityTypeInfo nestedSubclassInfo = transformationState .getEntityInfoByName ().get ( nestedSubclassEntityName );
560
+ final var nestedSubclassSubclassEntity = transformationState .getMappingEntityByName ().get ( nestedSubclassEntityName );
561
+ final var nestedSubclassInfo = transformationState .getEntityInfoByName ().get ( nestedSubclassEntityName );
562
562
transferUnionSubclass ( nestedHbmSubclass , nestedSubclassSubclassEntity , nestedSubclassInfo );
563
563
}
564
564
}
@@ -570,7 +570,7 @@ private void transferBaseEntityInformation(
570
570
EntityTypeInfo bootEntityInfo ) {
571
571
mappingEntity .setMetadataComplete ( true );
572
572
573
- final PersistentClass persistentClass = bootEntityInfo .getPersistentClass ();
573
+ final var persistentClass = bootEntityInfo .getPersistentClass ();
574
574
if ( persistentClass .getSuperclass () != null ) {
575
575
mappingEntity .setExtends ( persistentClass .getSuperclass ().getEntityName () );
576
576
}
@@ -621,21 +621,19 @@ private void applyBasicTypeMapping(
621
621
}
622
622
else if ( type instanceof CustomType <?> ) {
623
623
if ( isNotEmpty ( hbmTypeAttribute ) ) {
624
- final JaxbUserTypeImpl typeNode = interpretBasicType (
624
+ jaxbBasicMapping . setType ( interpretBasicType (
625
625
hbmTypeAttribute ,
626
626
null ,
627
627
transformationState .getTypeDefMap ().get ( hbmTypeAttribute )
628
- );
629
- jaxbBasicMapping .setType ( typeNode );
628
+ ) );
630
629
}
631
630
632
631
if ( hbmType != null ) {
633
- final JaxbUserTypeImpl typeNode = interpretBasicType (
632
+ jaxbBasicMapping . setType ( interpretBasicType (
634
633
hbmType .getName (),
635
634
hbmType ,
636
635
transformationState .getTypeDefMap ().get ( hbmType .getName () )
637
- );
638
- jaxbBasicMapping .setType ( typeNode );
636
+ ) );
639
637
}
640
638
}
641
639
else if ( type instanceof ConvertedBasicType <?> convertedType ) {
@@ -659,7 +657,7 @@ else if ( table.isView() ) {
659
657
jaxbEntity .setTableExpression ( table .getViewQuery () );
660
658
}
661
659
else {
662
- final JaxbTableImpl jaxbTable = new JaxbTableImpl ();
660
+ final var jaxbTable = new JaxbTableImpl ();
663
661
jaxbEntity .setTable ( jaxbTable );
664
662
jaxbTable .setName ( table .getName () );
665
663
jaxbTable .setComment ( table .getComment () );
@@ -671,8 +669,8 @@ private static void transferBaseTableInfo(Table table, JaxbTableMapping jaxbTabl
671
669
jaxbTableMapping .setCatalog ( table .getCatalog () );
672
670
jaxbTableMapping .setSchema ( table .getSchema () );
673
671
674
- for ( CheckConstraint check : table .getChecks () ) {
675
- final JaxbCheckConstraintImpl jaxbCheckConstraint = new JaxbCheckConstraintImpl ();
672
+ for ( var check : table .getChecks () ) {
673
+ final var jaxbCheckConstraint = new JaxbCheckConstraintImpl ();
676
674
jaxbTableMapping .getCheckConstraints ().add ( jaxbCheckConstraint );
677
675
jaxbCheckConstraint .setName ( check .getName () );
678
676
jaxbCheckConstraint .setConstraint ( check .getConstraint () );
0 commit comments