Skip to content

Commit

Permalink
HHH-16012 - Develop an abstraction for domain model Class refs
Browse files Browse the repository at this point in the history
  • Loading branch information
sebersole committed Apr 4, 2023
1 parent fbdb8ba commit cc19cb6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ configurations.api {
}

dependencies {
api "org.hibernate.orm:hibernate-core:6.3.0-SNAPSHOT"
api( "org.hibernate.orm:hibernate-core:6.3.0-SNAPSHOT" ) {
setChanging(true)
}

implementation "org.jboss.logging:jboss-logging:3.5.0.Final"
implementation "org.hibernate.common:hibernate-commons-annotations:6.0.6.Final"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,12 @@ private void prepareClassBindings(
// a. could be a normal JPA mapping with specific "HQL import name"
// b. Hibernate entity-name mapping
//
// todo (annotation-source) : the only real option imo is a separate `<entity entity-name="..." .../>` attribute
//
// for the time being, assume "normal" mappings
// - none of these other scenarios are supported today anyway; its one of the goals of this
// annotation-source work to implement them

classBindingMap.put( mapping.getClazz(), new ClassProcessingContextImpl( mapping, documentContext ) );
} );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.java.JavaReflectionManager;
import org.hibernate.boot.model.internal.JPAXMLOverriddenMetadataProvider;
import org.hibernate.boot.models.source.spi.ClassDetails;
import org.hibernate.boot.models.source.spi.ClassDetailsBuilder;
import org.hibernate.boot.models.spi.ModelProcessingContext;
Expand All @@ -20,19 +22,26 @@
*/
public class ClassDetailsBuilderImpl implements ClassDetailsBuilder {
private final ClassLoaderAccess classLoaderAccess;
private final ReflectionManager hcannReflectionManager;
private final ReflectionManager reflectionManager;

public ClassDetailsBuilderImpl(ModelProcessingContext processingContext) {
this.classLoaderAccess = processingContext.getClassLoaderAccess();
this.hcannReflectionManager = processingContext.getMetadataBuildingContext()
.getBootstrapContext()
.getReflectionManager();
this.reflectionManager = generateReflectionManager( classLoaderAccess, processingContext );
}

private static ReflectionManager generateReflectionManager(ClassLoaderAccess classLoaderAccess, ModelProcessingContext processingContext) {
final JavaReflectionManager reflectionManager = new JavaReflectionManager();
reflectionManager.setMetadataProvider( new JPAXMLOverriddenMetadataProvider(
classLoaderAccess,
processingContext.getMetadataBuildingContext().getBootstrapContext()
) );
return reflectionManager;
}

@Override
public ClassDetails buildClassDetails(String name, ModelProcessingContext processingContext) {
final Class<?> classForName = classLoaderAccess.classForName( name );
final XClass xClassForName = hcannReflectionManager.toXClass( classForName );
final XClass xClassForName = reflectionManager.toXClass( classForName );
return new ClassDetailsImpl( xClassForName, processingContext );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ public ClassDetails buildClassDetails(String name, ModelProcessingContext proces

public static ClassDetails buildClassDetailsStatic(String name, ModelProcessingContext processingContext) {
return buildClassDetails(
processingContext.getMetadataBuildingContext()
.getBootstrapContext()
.getClassLoaderAccess()
.classForName( name ),
processingContext.getClassLoaderAccess().classForName( name ),
processingContext
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@
* @author Steve Ebersole
*/
public interface ModelProcessingContext {
/**
* Access larger boostrap context references
*/
MetadataBuildingContext getMetadataBuildingContext();

/**
* The registry of annotation descriptors
*/
Expand All @@ -39,8 +34,18 @@ public interface ModelProcessingContext {
*/
ClassDetailsRegistry getClassDetailsRegistry();

/**
* If model processing code needs to load things from the class-loader, they should
* really use this access. At this level, accessing the class-loader at all
* sh
*/
ClassLoaderAccess getClassLoaderAccess();

/**
* Access larger boostrap context references
*/
MetadataBuildingContext getMetadataBuildingContext();

void registerUsage(AnnotationUsage<?> usage);

<A extends Annotation> List<AnnotationUsage<A>> getAllUsages(AnnotationDescriptor<A> annotationDescriptor);
Expand Down

0 comments on commit cc19cb6

Please sign in to comment.