34
34
import org .hibernate .AssertionFailure ;
35
35
import org .hibernate .Version ;
36
36
import org .hibernate .bytecode .enhance .VersionMismatchException ;
37
- import org .hibernate .bytecode .enhance .internal .tracker .CompositeOwnerTracker ;
38
- import org .hibernate .bytecode .enhance .internal .tracker .DirtyTracker ;
39
37
import org .hibernate .bytecode .enhance .spi .EnhancementContext ;
40
38
import org .hibernate .bytecode .enhance .spi .EnhancementException ;
41
39
import org .hibernate .bytecode .enhance .spi .EnhancementInfo ;
42
40
import org .hibernate .bytecode .enhance .spi .Enhancer ;
43
41
import org .hibernate .bytecode .enhance .spi .EnhancerConstants ;
44
42
import org .hibernate .bytecode .enhance .spi .UnloadedField ;
45
43
import org .hibernate .bytecode .enhance .spi .UnsupportedEnhancementStrategy ;
46
- import org .hibernate .bytecode .enhance .spi .interceptor .LazyAttributeLoadingInterceptor ;
47
44
import org .hibernate .bytecode .internal .bytebuddy .ByteBuddyState ;
48
45
import org .hibernate .engine .spi .CompositeOwner ;
49
- import org .hibernate .engine .spi .CompositeTracker ;
50
46
import org .hibernate .engine .spi .ExtendedSelfDirtinessTracker ;
51
47
import org .hibernate .engine .spi .Managed ;
52
- import org .hibernate .engine .spi .ManagedComposite ;
53
- import org .hibernate .engine .spi .ManagedEntity ;
54
- import org .hibernate .engine .spi .ManagedMappedSuperclass ;
55
- import org .hibernate .engine .spi .PersistentAttributeInterceptable ;
56
- import org .hibernate .engine .spi .SelfDirtinessTracker ;
57
48
import org .hibernate .internal .CoreLogging ;
58
49
import org .hibernate .internal .CoreMessageLogger ;
59
50
@@ -105,7 +96,7 @@ public EnhancerImpl(final EnhancementContext enhancementContext, final ByteBuddy
105
96
* @param classLocator
106
97
*/
107
98
public EnhancerImpl (final EnhancementContext enhancementContext , final ByteBuddyState byteBuddyState , final EnhancerClassLocator classLocator ) {
108
- this .enhancementContext = new ByteBuddyEnhancementContext ( enhancementContext );
99
+ this .enhancementContext = new ByteBuddyEnhancementContext ( enhancementContext , byteBuddyState . getEnhancerConstants () );
109
100
this .byteBuddyState = Objects .requireNonNull ( byteBuddyState );
110
101
this .typePool = Objects .requireNonNull ( classLocator );
111
102
this .constants = byteBuddyState .getEnhancerConstants ();
@@ -205,8 +196,9 @@ private DynamicType.Builder<?> doEnhance(Supplier<DynamicType.Builder<?>> builde
205
196
206
197
log .tracef ( "Enhancing [%s] as Entity" , managedCtClass .getName () );
207
198
DynamicType .Builder <?> builder = builderSupplier .get ();
208
- builder = builder .implement ( ManagedEntity .class )
209
- .defineMethod ( EnhancerConstants .ENTITY_INSTANCE_GETTER_NAME , constants .TypeObject , constants .methodModifierPUBLIC )
199
+ builder = builder
200
+ .implement ( constants .INTERFACES_for_ManagedEntity )
201
+ .defineMethod ( EnhancerConstants .ENTITY_INSTANCE_GETTER_NAME , constants .TypeObject , constants .modifierPUBLIC )
210
202
.intercept ( FixedValue .self () );
211
203
212
204
builder = addFieldWithGetterAndSetter (
@@ -260,44 +252,44 @@ private DynamicType.Builder<?> doEnhance(Supplier<DynamicType.Builder<?>> builde
260
252
List <AnnotatedFieldDescription > collectionFields = collectCollectionFields ( managedCtClass );
261
253
262
254
if ( collectionFields .isEmpty () ) {
263
- builder = builder .implement ( SelfDirtinessTracker . class )
264
- .defineField ( EnhancerConstants .TRACKER_FIELD_NAME , DirtyTracker . class , constants .fieldModifierPRIVATE_TRANSIENT )
255
+ builder = builder .implement ( constants . INTERFACES_for_SelfDirtinessTracker )
256
+ .defineField ( EnhancerConstants .TRACKER_FIELD_NAME , constants . DirtyTrackerTypeDescription , constants .modifierPRIVATE_TRANSIENT )
265
257
.annotateField ( constants .TRANSIENT_ANNOTATION )
266
- .defineMethod ( EnhancerConstants .TRACKER_CHANGER_NAME , constants .TypeVoid , constants .methodModifierPUBLIC )
267
- .withParameters ( String . class )
258
+ .defineMethod ( EnhancerConstants .TRACKER_CHANGER_NAME , constants .TypeVoid , constants .modifierPUBLIC )
259
+ .withParameter ( constants . TypeString )
268
260
.intercept ( constants .implementationTrackChange )
269
- .defineMethod ( EnhancerConstants .TRACKER_GET_NAME , constants .Type_Array_String , constants .methodModifierPUBLIC )
261
+ .defineMethod ( EnhancerConstants .TRACKER_GET_NAME , constants .Type_Array_String , constants .modifierPUBLIC )
270
262
.intercept ( constants .implementationGetDirtyAttributesWithoutCollections )
271
- .defineMethod ( EnhancerConstants .TRACKER_HAS_CHANGED_NAME , constants .TypeBooleanPrimitive , constants .methodModifierPUBLIC )
263
+ .defineMethod ( EnhancerConstants .TRACKER_HAS_CHANGED_NAME , constants .TypeBooleanPrimitive , constants .modifierPUBLIC )
272
264
.intercept ( constants .implementationAreFieldsDirtyWithoutCollections )
273
- .defineMethod ( EnhancerConstants .TRACKER_CLEAR_NAME , constants .TypeVoid , constants .methodModifierPUBLIC )
265
+ .defineMethod ( EnhancerConstants .TRACKER_CLEAR_NAME , constants .TypeVoid , constants .modifierPUBLIC )
274
266
.intercept ( constants .implementationClearDirtyAttributesWithoutCollections )
275
- .defineMethod ( EnhancerConstants .TRACKER_SUSPEND_NAME , constants .TypeVoid , constants .methodModifierPUBLIC )
276
- .withParameters ( constants .TypeBooleanPrimitive )
267
+ .defineMethod ( EnhancerConstants .TRACKER_SUSPEND_NAME , constants .TypeVoid , constants .modifierPUBLIC )
268
+ .withParameter ( constants .TypeBooleanPrimitive )
277
269
.intercept ( constants .implementationSuspendDirtyTracking )
278
- .defineMethod ( EnhancerConstants .TRACKER_COLLECTION_GET_NAME , constants .TypeCollectionTracker , constants .methodModifierPUBLIC )
270
+ .defineMethod ( EnhancerConstants .TRACKER_COLLECTION_GET_NAME , constants .TypeCollectionTracker , constants .modifierPUBLIC )
279
271
.intercept ( constants .implementationGetCollectionTrackerWithoutCollections );
280
272
}
281
273
else {
282
274
//TODO es.enableInterfaceExtendedSelfDirtinessTracker ? Careful with consequences..
283
- builder = builder .implement ( ExtendedSelfDirtinessTracker . class )
284
- .defineField ( EnhancerConstants .TRACKER_FIELD_NAME , DirtyTracker . class , constants .fieldModifierPRIVATE_TRANSIENT )
275
+ builder = builder .implement ( constants . INTERFACES_for_ExtendedSelfDirtinessTracker )
276
+ .defineField ( EnhancerConstants .TRACKER_FIELD_NAME , constants . DirtyTrackerTypeDescription , constants .modifierPRIVATE_TRANSIENT )
285
277
.annotateField ( constants .TRANSIENT_ANNOTATION )
286
- .defineField ( EnhancerConstants .TRACKER_COLLECTION_NAME , constants .TypeCollectionTracker , constants .fieldModifierPRIVATE_TRANSIENT )
278
+ .defineField ( EnhancerConstants .TRACKER_COLLECTION_NAME , constants .TypeCollectionTracker , constants .modifierPRIVATE_TRANSIENT )
287
279
.annotateField ( constants .TRANSIENT_ANNOTATION )
288
- .defineMethod ( EnhancerConstants .TRACKER_CHANGER_NAME , constants .TypeVoid , constants .methodModifierPUBLIC )
289
- .withParameters ( String . class )
280
+ .defineMethod ( EnhancerConstants .TRACKER_CHANGER_NAME , constants .TypeVoid , constants .modifierPUBLIC )
281
+ .withParameter ( constants . TypeString )
290
282
.intercept ( constants .implementationTrackChange )
291
- .defineMethod ( EnhancerConstants .TRACKER_GET_NAME , constants .Type_Array_String , constants .methodModifierPUBLIC )
283
+ .defineMethod ( EnhancerConstants .TRACKER_GET_NAME , constants .Type_Array_String , constants .modifierPUBLIC )
292
284
.intercept ( constants .implementationGetDirtyAttributes )
293
- .defineMethod ( EnhancerConstants .TRACKER_HAS_CHANGED_NAME , constants .TypeBooleanPrimitive , constants .methodModifierPUBLIC )
285
+ .defineMethod ( EnhancerConstants .TRACKER_HAS_CHANGED_NAME , constants .TypeBooleanPrimitive , constants .modifierPUBLIC )
294
286
.intercept ( constants .implementationAreFieldsDirty )
295
- .defineMethod ( EnhancerConstants .TRACKER_CLEAR_NAME , constants .TypeVoid , constants .methodModifierPUBLIC )
287
+ .defineMethod ( EnhancerConstants .TRACKER_CLEAR_NAME , constants .TypeVoid , constants .modifierPUBLIC )
296
288
.intercept ( constants .implementationClearDirtyAttributes )
297
- .defineMethod ( EnhancerConstants .TRACKER_SUSPEND_NAME , constants .TypeVoid , constants .methodModifierPUBLIC )
298
- .withParameters ( constants .TypeBooleanPrimitive )
289
+ .defineMethod ( EnhancerConstants .TRACKER_SUSPEND_NAME , constants .TypeVoid , constants .modifierPUBLIC )
290
+ .withParameter ( constants .TypeBooleanPrimitive )
299
291
.intercept ( constants .implementationSuspendDirtyTracking )
300
- .defineMethod ( EnhancerConstants .TRACKER_COLLECTION_GET_NAME , constants .TypeCollectionTracker , constants .methodModifierPUBLIC )
292
+ .defineMethod ( EnhancerConstants .TRACKER_COLLECTION_GET_NAME , constants .TypeCollectionTracker , constants .modifierPUBLIC )
301
293
.intercept ( FieldAccessor .ofField ( EnhancerConstants .TRACKER_COLLECTION_NAME ) );
302
294
303
295
Implementation isDirty = StubMethod .INSTANCE , getDirtyNames = StubMethod .INSTANCE , clearDirtyNames = StubMethod .INSTANCE ;
@@ -359,17 +351,17 @@ private DynamicType.Builder<?> doEnhance(Supplier<DynamicType.Builder<?>> builde
359
351
clearDirtyNames = constants .adviceInitializeLazyAttributeLoadingInterceptor .wrap ( clearDirtyNames );
360
352
}
361
353
362
- builder = builder .defineMethod ( EnhancerConstants .TRACKER_COLLECTION_CHANGED_NAME , constants .TypeBooleanPrimitive , constants .methodModifierPUBLIC )
354
+ builder = builder .defineMethod ( EnhancerConstants .TRACKER_COLLECTION_CHANGED_NAME , constants .TypeBooleanPrimitive , constants .modifierPUBLIC )
363
355
.intercept ( isDirty )
364
- .defineMethod ( EnhancerConstants .TRACKER_COLLECTION_CHANGED_FIELD_NAME , constants .TypeVoid , constants .methodModifierPUBLIC )
365
- .withParameters ( DirtyTracker . class )
356
+ .defineMethod ( EnhancerConstants .TRACKER_COLLECTION_CHANGED_FIELD_NAME , constants .TypeVoid , constants .modifierPUBLIC )
357
+ .withParameter ( constants . DirtyTrackerTypeDescription )
366
358
.intercept ( getDirtyNames )
367
- .defineMethod ( EnhancerConstants .TRACKER_COLLECTION_CLEAR_NAME , constants .TypeVoid , constants .methodModifierPUBLIC )
359
+ .defineMethod ( EnhancerConstants .TRACKER_COLLECTION_CLEAR_NAME , constants .TypeVoid , constants .modifierPUBLIC )
368
360
.intercept ( Advice .withCustomMapping ()
369
361
.to ( CodeTemplates .ClearDirtyCollectionNames .class , constants .adviceLocator )
370
362
.wrap ( StubMethod .INSTANCE ) )
371
- .defineMethod ( ExtendedSelfDirtinessTracker .REMOVE_DIRTY_FIELDS_NAME , constants .TypeVoid , constants .methodModifierPUBLIC )
372
- .withParameters ( LazyAttributeLoadingInterceptor . class )
363
+ .defineMethod ( ExtendedSelfDirtinessTracker .REMOVE_DIRTY_FIELDS_NAME , constants .TypeVoid , constants .modifierPUBLIC )
364
+ .withParameter ( constants . TypeLazyAttributeLoadingInterceptor )
373
365
.intercept ( clearDirtyNames );
374
366
}
375
367
}
@@ -385,30 +377,30 @@ else if ( enhancementContext.isCompositeClass( managedCtClass ) ) {
385
377
log .tracef ( "Enhancing [%s] as Composite" , managedCtClass .getName () );
386
378
387
379
DynamicType .Builder <?> builder = builderSupplier .get ();
388
- builder = builder .implement ( ManagedComposite . class );
380
+ builder = builder .implement ( constants . INTERFACES_for_ManagedComposite );
389
381
builder = addInterceptorHandling ( builder , managedCtClass );
390
382
391
383
if ( enhancementContext .doDirtyCheckingInline () ) {
392
- builder = builder .implement ( CompositeTracker . class )
384
+ builder = builder .implement ( constants . INTERFACES_for_CompositeTracker )
393
385
.defineField (
394
386
EnhancerConstants .TRACKER_COMPOSITE_FIELD_NAME ,
395
- CompositeOwnerTracker . class ,
396
- constants .fieldModifierPRIVATE_TRANSIENT
387
+ constants . TypeCompositeOwnerTracker ,
388
+ constants .modifierPRIVATE_TRANSIENT
397
389
)
398
390
.annotateField ( constants .TRANSIENT_ANNOTATION )
399
391
.defineMethod (
400
392
EnhancerConstants .TRACKER_COMPOSITE_SET_OWNER ,
401
393
constants .TypeVoid ,
402
- constants .methodModifierPUBLIC
394
+ constants .modifierPUBLIC
403
395
)
404
396
.withParameters ( String .class , CompositeOwner .class )
405
397
.intercept ( constants .implementationSetOwner )
406
398
.defineMethod (
407
399
EnhancerConstants .TRACKER_COMPOSITE_CLEAR_OWNER ,
408
400
constants .TypeVoid ,
409
- constants .methodModifierPUBLIC
401
+ constants .modifierPUBLIC
410
402
)
411
- .withParameters ( String . class )
403
+ .withParameter ( constants . TypeString )
412
404
.intercept ( constants .implementationClearOwner );
413
405
}
414
406
@@ -423,7 +415,7 @@ else if ( enhancementContext.isMappedSuperclassClass( managedCtClass ) ) {
423
415
log .tracef ( "Enhancing [%s] as MappedSuperclass" , managedCtClass .getName () );
424
416
425
417
DynamicType .Builder <?> builder = builderSupplier .get ();
426
- builder = builder .implement ( ManagedMappedSuperclass . class );
418
+ builder = builder .implement ( constants . INTERFACES_for_ManagedMappedSuperclass );
427
419
return createTransformer ( managedCtClass ).applyTo ( builder );
428
420
}
429
421
else if ( enhancementContext .doExtendedEnhancement () ) {
@@ -658,7 +650,7 @@ private static boolean checkUnsupportedAttributeNaming(TypeDescription managedCt
658
650
}
659
651
660
652
private PersistentAttributeTransformer createTransformer (TypeDescription typeDescription ) {
661
- return PersistentAttributeTransformer .collectPersistentFields ( typeDescription , enhancementContext , typePool );
653
+ return PersistentAttributeTransformer .collectPersistentFields ( typeDescription , enhancementContext , typePool , constants );
662
654
}
663
655
664
656
// See HHH-10977 HHH-11284 HHH-11404 --- check for declaration of Managed interface on the class, not inherited
@@ -676,7 +668,7 @@ private DynamicType.Builder<?> addInterceptorHandling(DynamicType.Builder<?> bui
676
668
if ( enhancementContext .hasLazyLoadableAttributes ( managedCtClass ) ) {
677
669
log .tracef ( "Weaving in PersistentAttributeInterceptable implementation on [%s]" , managedCtClass .getName () );
678
670
679
- builder = builder .implement ( PersistentAttributeInterceptable . class );
671
+ builder = builder .implement ( constants . INTERFACES_for_PersistentAttributeInterceptable );
680
672
681
673
builder = addFieldWithGetterAndSetter (
682
674
builder ,
@@ -697,12 +689,12 @@ private DynamicType.Builder<?> addFieldWithGetterAndSetter(
697
689
String getterName ,
698
690
String setterName ) {
699
691
return builder
700
- .defineField ( fieldName , type , constants .fieldModifierPRIVATE_TRANSIENT )
692
+ .defineField ( fieldName , type , constants .modifierPRIVATE_TRANSIENT )
701
693
.annotateField ( constants .TRANSIENT_ANNOTATION )
702
- .defineMethod ( getterName , type , constants .methodModifierPUBLIC )
694
+ .defineMethod ( getterName , type , constants .modifierPUBLIC )
703
695
.intercept ( FieldAccessor .ofField ( fieldName ) )
704
- .defineMethod ( setterName , constants .TypeVoid , constants .methodModifierPUBLIC )
705
- .withParameters ( type )
696
+ .defineMethod ( setterName , constants .TypeVoid , constants .modifierPUBLIC )
697
+ .withParameter ( type )
706
698
.intercept ( FieldAccessor .ofField ( fieldName ) );
707
699
}
708
700
@@ -713,7 +705,7 @@ private DynamicType.Builder<?> addSetPersistenceInfoMethod(
713
705
TypeDefinition intType ) {
714
706
return builder
715
707
// returns previous entity entry
716
- .defineMethod ( EnhancerConstants .PERSISTENCE_INFO_SETTER_NAME , entityEntryType , constants .methodModifierPUBLIC )
708
+ .defineMethod ( EnhancerConstants .PERSISTENCE_INFO_SETTER_NAME , entityEntryType , constants .modifierPUBLIC )
717
709
// previous, next, instance-id
718
710
.withParameters ( entityEntryType , managedEntityType , managedEntityType , intType )
719
711
.intercept ( constants .implementationSetPersistenceInfo );
0 commit comments