|
8 | 8 |
|
9 | 9 | import java.io.IOException;
|
10 | 10 | import java.io.InputStream;
|
11 |
| -import java.lang.reflect.Modifier; |
12 | 11 | import java.util.List;
|
13 | 12 |
|
14 | 13 | import org.hibernate.boot.ResourceStreamLocator;
|
|
19 | 18 | import org.hibernate.boot.spi.InFlightMetadataCollector;
|
20 | 19 | import org.hibernate.boot.spi.MetadataBuildingContext;
|
21 | 20 | import org.hibernate.mapping.PersistentClass;
|
22 |
| -import org.hibernate.models.internal.ClassTypeDetailsImpl; |
23 | 21 | import org.hibernate.models.internal.dynamic.DynamicClassDetails;
|
24 |
| -import org.hibernate.models.internal.dynamic.DynamicFieldDetails; |
25 | 22 | import org.hibernate.models.internal.jdk.JdkClassDetails;
|
26 | 23 | import org.hibernate.models.spi.ClassDetails;
|
27 | 24 | import org.hibernate.models.spi.ClassDetailsRegistry;
|
28 |
| -import org.hibernate.models.spi.MutableAnnotationUsage; |
29 | 25 | import org.hibernate.models.spi.MutableMemberDetails;
|
30 |
| -import org.hibernate.models.spi.TypeDetails; |
31 | 26 |
|
32 | 27 | import org.hibernate.testing.orm.junit.BootstrapServiceRegistry;
|
33 | 28 | import org.hibernate.testing.orm.junit.BootstrapServiceRegistry.JavaService;
|
@@ -333,15 +328,14 @@ private static void contributeEntity5Details(
|
333 | 328 | modelBuildingContext
|
334 | 329 | );
|
335 | 330 |
|
336 |
| - final MutableAnnotationUsage<Entity> entityAnnotation = JpaAnnotations.ENTITY.createUsage( |
337 |
| - jdkClassDetails, |
| 331 | + jdkClassDetails.applyAnnotationUsage( |
| 332 | + JpaAnnotations.ENTITY, |
| 333 | + (entityUsage) -> entityUsage.setAttributeValue( "name", "___Entity5___" ), |
338 | 334 | modelBuildingContext
|
339 | 335 | );
|
340 |
| - entityAnnotation.setAttributeValue( "name", "___Entity5___" ); |
341 |
| - jdkClassDetails.addAnnotationUsage( entityAnnotation ); |
342 | 336 |
|
343 | 337 | final MutableMemberDetails idField = (MutableMemberDetails) jdkClassDetails.findFieldByName( "id" );
|
344 |
| - idField.addAnnotationUsage( JpaAnnotations.ID.createUsage( idField, modelBuildingContext ) ); |
| 338 | + idField.applyAnnotationUsage( JpaAnnotations.ID, modelBuildingContext ); |
345 | 339 |
|
346 | 340 | return jdkClassDetails;
|
347 | 341 | }
|
@@ -374,46 +368,32 @@ private void contributeEntity6Details(
|
374 | 368 | assertThat( modelBuildingContext ).isSameAs( buildingContext.getMetadataCollector().getSourceModelBuildingContext() );
|
375 | 369 |
|
376 | 370 | final DynamicClassDetails classDetails = new DynamicClassDetails( "Entity6", modelBuildingContext );
|
377 |
| - |
378 |
| - final MutableAnnotationUsage<Entity> entityAnnotation = JpaAnnotations.ENTITY.createUsage( |
379 |
| - classDetails, |
| 371 | + classDetails.applyAnnotationUsage( |
| 372 | + JpaAnnotations.ENTITY, |
| 373 | + (config) -> config.setAttributeValue( "name", "Entity6" ), |
380 | 374 | modelBuildingContext
|
381 | 375 | );
|
382 |
| - classDetails.addAnnotationUsage( entityAnnotation ); |
383 |
| - |
384 |
| - final DynamicFieldDetails idFieldDetails = new DynamicFieldDetails( |
| 376 | + classDetails.applyAttribute( |
385 | 377 | "id",
|
386 |
| - new ClassTypeDetailsImpl( classDetailsRegistry.resolveClassDetails( Integer.class.getName() ), TypeDetails.Kind.CLASS ), |
387 |
| - classDetails, |
388 |
| - dynamicFieldModifiers(), |
| 378 | + classDetailsRegistry.resolveClassDetails( Integer.class.getName() ), |
| 379 | + false, |
| 380 | + false, |
| 381 | + (fieldDetails) -> fieldDetails.applyAnnotationUsage( JpaAnnotations.ID, modelBuildingContext ), |
389 | 382 | modelBuildingContext
|
390 | 383 | );
|
391 |
| - classDetails.addField( idFieldDetails ); |
392 |
| - idFieldDetails.addAnnotationUsage( JpaAnnotations.ID.createUsage( idFieldDetails, modelBuildingContext ) ); |
393 |
| - |
394 |
| - final DynamicFieldDetails nameFieldDetails = new DynamicFieldDetails( |
| 384 | + classDetails.applyAttribute( |
395 | 385 | "name",
|
396 |
| - new ClassTypeDetailsImpl( |
397 |
| - classDetailsRegistry.resolveClassDetails( String.class.getName() ), |
398 |
| - TypeDetails.Kind.CLASS |
399 |
| - ), |
400 |
| - classDetails, |
401 |
| - dynamicFieldModifiers(), |
| 386 | + classDetailsRegistry.resolveClassDetails( String.class.getName() ), |
| 387 | + false, |
| 388 | + false, |
| 389 | + (fieldDetails) -> fieldDetails.applyAnnotationUsage( HibernateAnnotations.NATIONALIZED, modelBuildingContext ), |
402 | 390 | modelBuildingContext
|
403 | 391 | );
|
404 |
| - classDetails.addField( nameFieldDetails ); |
405 |
| - nameFieldDetails.addAnnotationUsage( HibernateAnnotations.NATIONALIZED.createUsage( nameFieldDetails, modelBuildingContext ) ); |
406 | 392 |
|
407 | 393 | return classDetails;
|
408 | 394 | }
|
409 | 395 | );
|
410 | 396 | contributions.contributeManagedClass( entity6Details );
|
411 | 397 | }
|
412 |
| - |
413 |
| - private static final int SYNTHETIC = 0x00001000; |
414 |
| - |
415 |
| - private static int dynamicFieldModifiers() { |
416 |
| - return ~Modifier.TRANSIENT & ~Modifier.ABSTRACT & ~Modifier.STATIC & ~SYNTHETIC; |
417 |
| - } |
418 | 398 | }
|
419 | 399 | }
|
0 commit comments