Skip to content

Commit

Permalink
HHH-17460 - Ongoing JPA 32 work
Browse files Browse the repository at this point in the history
  • Loading branch information
sebersole committed Mar 27, 2024
1 parent d753cac commit fa4afd0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Modifier;
import java.util.List;

import org.hibernate.boot.ResourceStreamLocator;
Expand All @@ -19,15 +18,11 @@
import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.models.internal.ClassTypeDetailsImpl;
import org.hibernate.models.internal.dynamic.DynamicClassDetails;
import org.hibernate.models.internal.dynamic.DynamicFieldDetails;
import org.hibernate.models.internal.jdk.JdkClassDetails;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.ClassDetailsRegistry;
import org.hibernate.models.spi.MutableAnnotationUsage;
import org.hibernate.models.spi.MutableMemberDetails;
import org.hibernate.models.spi.TypeDetails;

import org.hibernate.testing.orm.junit.BootstrapServiceRegistry;
import org.hibernate.testing.orm.junit.BootstrapServiceRegistry.JavaService;
Expand Down Expand Up @@ -333,15 +328,14 @@ private static void contributeEntity5Details(
modelBuildingContext
);

final MutableAnnotationUsage<Entity> entityAnnotation = JpaAnnotations.ENTITY.createUsage(
jdkClassDetails,
jdkClassDetails.applyAnnotationUsage(
JpaAnnotations.ENTITY,
(entityUsage) -> entityUsage.setAttributeValue( "name", "___Entity5___" ),
modelBuildingContext
);
entityAnnotation.setAttributeValue( "name", "___Entity5___" );
jdkClassDetails.addAnnotationUsage( entityAnnotation );

final MutableMemberDetails idField = (MutableMemberDetails) jdkClassDetails.findFieldByName( "id" );
idField.addAnnotationUsage( JpaAnnotations.ID.createUsage( idField, modelBuildingContext ) );
idField.applyAnnotationUsage( JpaAnnotations.ID, modelBuildingContext );

return jdkClassDetails;
}
Expand Down Expand Up @@ -374,46 +368,32 @@ private void contributeEntity6Details(
assertThat( modelBuildingContext ).isSameAs( buildingContext.getMetadataCollector().getSourceModelBuildingContext() );

final DynamicClassDetails classDetails = new DynamicClassDetails( "Entity6", modelBuildingContext );

final MutableAnnotationUsage<Entity> entityAnnotation = JpaAnnotations.ENTITY.createUsage(
classDetails,
classDetails.applyAnnotationUsage(
JpaAnnotations.ENTITY,
(config) -> config.setAttributeValue( "name", "Entity6" ),
modelBuildingContext
);
classDetails.addAnnotationUsage( entityAnnotation );

final DynamicFieldDetails idFieldDetails = new DynamicFieldDetails(
classDetails.applyAttribute(
"id",
new ClassTypeDetailsImpl( classDetailsRegistry.resolveClassDetails( Integer.class.getName() ), TypeDetails.Kind.CLASS ),
classDetails,
dynamicFieldModifiers(),
classDetailsRegistry.resolveClassDetails( Integer.class.getName() ),
false,
false,
(fieldDetails) -> fieldDetails.applyAnnotationUsage( JpaAnnotations.ID, modelBuildingContext ),
modelBuildingContext
);
classDetails.addField( idFieldDetails );
idFieldDetails.addAnnotationUsage( JpaAnnotations.ID.createUsage( idFieldDetails, modelBuildingContext ) );

final DynamicFieldDetails nameFieldDetails = new DynamicFieldDetails(
classDetails.applyAttribute(
"name",
new ClassTypeDetailsImpl(
classDetailsRegistry.resolveClassDetails( String.class.getName() ),
TypeDetails.Kind.CLASS
),
classDetails,
dynamicFieldModifiers(),
classDetailsRegistry.resolveClassDetails( String.class.getName() ),
false,
false,
(fieldDetails) -> fieldDetails.applyAnnotationUsage( HibernateAnnotations.NATIONALIZED, modelBuildingContext ),
modelBuildingContext
);
classDetails.addField( nameFieldDetails );
nameFieldDetails.addAnnotationUsage( HibernateAnnotations.NATIONALIZED.createUsage( nameFieldDetails, modelBuildingContext ) );

return classDetails;
}
);
contributions.contributeManagedClass( entity6Details );
}

private static final int SYNTHETIC = 0x00001000;

private static int dynamicFieldModifiers() {
return ~Modifier.TRANSIENT & ~Modifier.ABSTRACT & ~Modifier.STATIC & ~SYNTHETIC;
}
}
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ dependencyResolutionManagement {
def byteBuddyVersion = version "byteBuddy", "1.14.12"
def classmateVersion = version "classmate", "1.5.1"
def geolatteVersion = version "geolatte", "1.8.2"
def hibernateModelsVersion = version "hibernateModels", "0.7.5"
def hibernateModelsVersion = version "hibernateModels", "0.7.6"
def jandexVersion = version "jandex", "3.1.2"
def hcannVersion = version "hcann", "6.0.6.Final"
def jacksonVersion = version "jackson", "2.14.1"
Expand Down

0 comments on commit fa4afd0

Please sign in to comment.