HHH-18522 Drop hard requirements on Jandex

This commit is contained in:
Andrea Boriero 2024-09-13 16:21:58 +02:00 committed by Steve Ebersole
parent cf0ab77cf2
commit 5280e15ba0
17 changed files with 41 additions and 175 deletions

View File

@ -21,7 +21,6 @@ import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
import org.hibernate.type.BasicType;
import org.hibernate.usertype.UserType;
import org.jboss.jandex.IndexView;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.SharedCacheMode;
@ -148,7 +147,7 @@ public interface MetadataBuilder {
*
* @return {@code this}, for method chaining
*/
MetadataBuilder applyIndexView(IndexView jandexView);
MetadataBuilder applyIndexView(Object jandexView);
/**
* Specify the options to be used in performing scanning.

View File

@ -38,7 +38,6 @@ import org.hibernate.resource.beans.spi.BeanInstanceProducer;
import org.hibernate.type.BasicType;
import org.hibernate.type.spi.TypeConfiguration;
import org.jboss.jandex.IndexView;
import org.jboss.logging.Logger;
/**
@ -66,7 +65,7 @@ public class BootstrapContextImpl implements BootstrapContext {
private Object scannerSetting;
private ArchiveDescriptorFactory archiveDescriptorFactory;
private IndexView jandexView;
private Object jandexView;
private HashMap<String,SqmFunctionDescriptor> sqlFunctionMap;
private ArrayList<AuxiliaryDatabaseObject> auxiliaryDatabaseObjectList;
@ -182,7 +181,7 @@ public class BootstrapContextImpl implements BootstrapContext {
}
@Override
public IndexView getJandexView() {
public Object getJandexView() {
return jandexView;
}
@ -300,7 +299,7 @@ public class BootstrapContextImpl implements BootstrapContext {
this.archiveDescriptorFactory = factory;
}
void injectJandexView(IndexView jandexView) {
void injectJandexView(Object jandexView) {
log.debugf( "Injecting Jandex IndexView [%s] into BootstrapContext; was [%s]", jandexView, this.jandexView );
this.jandexView = jandexView;
}

View File

@ -86,7 +86,6 @@ import org.hibernate.type.spi.TypeConfiguration;
import org.hibernate.usertype.CompositeUserType;
import org.hibernate.usertype.UserType;
import org.jboss.jandex.IndexView;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.ConstraintMode;
@ -213,7 +212,7 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
}
@Override
public MetadataBuilder applyIndexView(IndexView jandexView) {
public MetadataBuilder applyIndexView(Object jandexView) {
this.bootstrapContext.injectJandexView( jandexView );
return this;
}

View File

@ -71,10 +71,8 @@ import org.hibernate.engine.config.spi.StandardConverters;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.mapping.Table;
import org.hibernate.models.internal.MutableClassDetailsRegistry;
import org.hibernate.models.jandex.internal.JandexIndexerHelper;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.ClassDetailsRegistry;
import org.hibernate.models.spi.ClassLoading;
import org.hibernate.models.spi.SourceModelBuildingContext;
import org.hibernate.type.BasicType;
import org.hibernate.type.BasicTypeRegistry;
@ -99,9 +97,6 @@ import org.hibernate.type.internal.NamedBasicTypeImpl;
import org.hibernate.type.spi.TypeConfiguration;
import org.hibernate.usertype.CompositeUserType;
import org.jboss.jandex.CompositeIndex;
import org.jboss.jandex.IndexView;
import org.jboss.jandex.Indexer;
import jakarta.persistence.AttributeConverter;
@ -401,10 +396,6 @@ public class MetadataBuildingProcess {
} );
managedResources.getAnnotatedClassReferences().forEach( (clazz) -> allKnownClassNames.add( clazz.getName() ) );
// At this point we know all managed class names across all sources.
// Resolve the Jandex Index and build the SourceModelBuildingContext.
final IndexView jandexIndex = resolveJandexIndex( allKnownClassNames, bootstrapContext.getJandexView(), sourceModelBuildingContext.getClassLoading() );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// - process metadata-complete XML
// - collect overlay XML
@ -427,7 +418,6 @@ public class MetadataBuildingProcess {
final DomainModelCategorizationCollector modelCategorizationCollector = new DomainModelCategorizationCollector(
areIdGeneratorsGlobal,
metadataCollector.getGlobalRegistrations(),
jandexIndex,
sourceModelBuildingContext
);
@ -461,7 +451,6 @@ public class MetadataBuildingProcess {
return new DomainModelSource(
classDetailsRegistry,
jandexIndex,
allKnownClassNames,
modelCategorizationCollector.getGlobalRegistrations(),
rootMappingDefaults,
@ -494,31 +483,6 @@ public class MetadataBuildingProcess {
}
}
public static IndexView resolveJandexIndex(
List<String> allKnownClassNames,
IndexView suppliedJandexIndex,
ClassLoading classLoading) {
// todo : we could build a new Jandex (Composite)Index that includes the `managedResources#getAnnotatedClassNames`
// and all classes from `managedResources#getXmlMappingBindings`. Only really worth it in the case
// of runtime enhancement. This would definitely need to be toggle-able.
// +
// For now, let's not as it does not matter for this PoC
if ( 1 == 1 ) {
return suppliedJandexIndex;
}
final Indexer jandexIndexer = new Indexer();
for ( String knownClassName : allKnownClassNames ) {
JandexIndexerHelper.apply( knownClassName, jandexIndexer, classLoading );
}
if ( suppliedJandexIndex == null ) {
return jandexIndexer.complete();
}
return CompositeIndex.create( suppliedJandexIndex, jandexIndexer.complete() );
}
private static void processAdditionalMappingContributions(
InFlightMetadataCollectorImpl metadataCollector,
MetadataBuildingOptions options,

View File

@ -14,14 +14,11 @@ import org.hibernate.boot.models.spi.GlobalRegistrations;
import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata;
import org.hibernate.models.spi.ClassDetailsRegistry;
import org.jboss.jandex.IndexView;
/**
* @author Steve Ebersole
*/
public class DomainModelSource {
private final ClassDetailsRegistry classDetailsRegistry;
private final IndexView jandexIndex;
private final GlobalRegistrations globalRegistrations;
private final RootMappingDefaults effectiveMappingDefaults;
private final PersistenceUnitMetadata persistenceUnitMetadata;
@ -29,13 +26,11 @@ public class DomainModelSource {
public DomainModelSource(
ClassDetailsRegistry classDetailsRegistry,
IndexView jandexIndex,
List<String> allKnownClassNames,
GlobalRegistrations globalRegistrations,
RootMappingDefaults effectiveMappingDefaults,
PersistenceUnitMetadata persistenceUnitMetadata) {
this.classDetailsRegistry = classDetailsRegistry;
this.jandexIndex = jandexIndex;
this.allKnownClassNames = allKnownClassNames;
this.globalRegistrations = globalRegistrations;
this.effectiveMappingDefaults = effectiveMappingDefaults;
@ -46,10 +41,6 @@ public class DomainModelSource {
return classDetailsRegistry;
}
public IndexView getJandexIndex() {
return jandexIndex;
}
public GlobalRegistrations getGlobalRegistrations() {
return globalRegistrations;
}

View File

@ -15,8 +15,6 @@ import org.hibernate.models.spi.AnnotationDescriptorRegistry;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.ClassDetailsRegistry;
import org.jboss.jandex.IndexView;
/**
* @author Steve Ebersole
*/
@ -28,13 +26,11 @@ public class CategorizedDomainModelImpl implements CategorizedDomainModel {
private final ClassDetailsRegistry classDetailsRegistry;
private final AnnotationDescriptorRegistry annotationDescriptorRegistry;
private final IndexView jandexIndex;
private final PersistenceUnitMetadata persistenceUnitMetadata;
public CategorizedDomainModelImpl(
ClassDetailsRegistry classDetailsRegistry,
AnnotationDescriptorRegistry annotationDescriptorRegistry,
IndexView jandexIndex,
PersistenceUnitMetadata persistenceUnitMetadata,
Set<EntityHierarchy> entityHierarchies,
Map<String, ClassDetails> mappedSuperclasses,
@ -47,7 +43,6 @@ public class CategorizedDomainModelImpl implements CategorizedDomainModel {
this.mappedSuperclasses = mappedSuperclasses;
this.embeddables = embeddables;
this.globalRegistrations = globalRegistrations;
this.jandexIndex = jandexIndex;
}
@Override
@ -60,11 +55,6 @@ public class CategorizedDomainModelImpl implements CategorizedDomainModel {
return annotationDescriptorRegistry;
}
@Override
public IndexView getJandexIndex() {
return jandexIndex;
}
@Override
public PersistenceUnitMetadata getPersistenceUnitMetadata() {
return persistenceUnitMetadata;

View File

@ -15,8 +15,6 @@ import org.hibernate.models.spi.AnnotationDescriptorRegistry;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.ClassDetailsRegistry;
import org.jboss.jandex.IndexView;
/**
* The application's domain model, understood at a very rudimentary level - we know
* a class is an entity, a mapped-superclass, ... And we know about persistent attributes,
@ -38,8 +36,6 @@ public interface CategorizedDomainModel {
*/
AnnotationDescriptorRegistry getAnnotationDescriptorRegistry();
IndexView getJandexIndex();
PersistenceUnitMetadata getPersistenceUnitMetadata();
/**

View File

@ -30,15 +30,9 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.MetadataBuildingOptions;
import org.hibernate.models.internal.BasicModelBuildingContextImpl;
import org.hibernate.models.jandex.internal.JandexIndexerHelper;
import org.hibernate.models.spi.AnnotationDescriptorRegistry;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.ClassDetailsRegistry;
import org.hibernate.models.spi.ClassLoading;
import org.jboss.jandex.CompositeIndex;
import org.jboss.jandex.IndexView;
import org.jboss.jandex.Indexer;
import static org.hibernate.boot.models.categorize.internal.EntityHierarchyBuilder.createEntityHierarchies;
import static org.hibernate.internal.util.collections.CollectionHelper.mutableJoin;
@ -100,7 +94,6 @@ public class ManagedResourcesProcessor {
// At this point we know all managed class names across all sources.
// Resolve the Jandex Index and build the SourceModelBuildingContext.
final IndexView jandexIndex = resolveJandexIndex( allKnownClassNames, bootstrapContext.getJandexView(), classLoading );
final BasicModelBuildingContextImpl sourceModelBuildingContext = new BasicModelBuildingContextImpl(
classLoading,
ModelsHelper::preFillRegistries
@ -131,7 +124,6 @@ public class ManagedResourcesProcessor {
final DomainModelCategorizationCollector modelCategorizationCollector = new DomainModelCategorizationCollector(
areIdGeneratorsGlobal,
globalRegistrations,
jandexIndex,
sourceModelBuildingContext
);
@ -222,31 +214,6 @@ public class ManagedResourcesProcessor {
}
}
public static IndexView resolveJandexIndex(
List<String> allKnownClassNames,
IndexView suppliedJandexIndex,
ClassLoading classLoading) {
// todo : we could build a new Jandex (Composite)Index that includes the `managedResources#getAnnotatedClassNames`
// and all classes from `managedResources#getXmlMappingBindings`. Only really worth it in the case
// of runtime enhancement. This would definitely need to be toggle-able.
// +
// For now, let's not as it does not matter for this PoC
if ( 1 == 1 ) {
return suppliedJandexIndex;
}
final Indexer jandexIndexer = new Indexer();
for ( String knownClassName : allKnownClassNames ) {
JandexIndexerHelper.apply( knownClassName, jandexIndexer, classLoading );
}
if ( suppliedJandexIndex == null ) {
return jandexIndexer.complete();
}
return CompositeIndex.create( suppliedJandexIndex, jandexIndexer.complete() );
}
/**
* For testing use only
*/

View File

@ -24,8 +24,6 @@ import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.ClassDetailsRegistry;
import org.hibernate.models.spi.SourceModelBuildingContext;
import org.jboss.jandex.IndexView;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
import jakarta.persistence.Embeddable;
@ -40,7 +38,6 @@ import jakarta.persistence.MappedSuperclass;
public class DomainModelCategorizationCollector {
private final boolean areIdGeneratorsGlobal;
private final IndexView jandexIndex;
private final GlobalRegistrationsImpl globalRegistrations;
private final SourceModelBuildingContext modelsContext;
@ -52,10 +49,8 @@ public class DomainModelCategorizationCollector {
public DomainModelCategorizationCollector(
boolean areIdGeneratorsGlobal,
GlobalRegistrations globalRegistrations,
IndexView jandexIndex,
SourceModelBuildingContext modelsContext) {
this.areIdGeneratorsGlobal = areIdGeneratorsGlobal;
this.jandexIndex = jandexIndex;
this.globalRegistrations = (GlobalRegistrationsImpl) globalRegistrations;
this.modelsContext = modelsContext;
}
@ -176,7 +171,6 @@ public class DomainModelCategorizationCollector {
return new CategorizedDomainModelImpl(
classDetailsRegistry,
annotationDescriptorRegistry,
jandexIndex,
persistenceUnitMetadata,
entityHierarchies,
mappedSuperclasses,

View File

@ -8,17 +8,11 @@ import java.util.function.Supplier;
import org.hibernate.annotations.TenantId;
import org.hibernate.models.internal.MutableClassDetailsRegistry;
import org.hibernate.models.internal.jdk.JdkBuilders;
import org.hibernate.models.jandex.internal.JandexClassDetails;
import org.hibernate.models.jandex.spi.JandexModelBuildingContext;
import org.hibernate.models.spi.AnnotationDescriptorRegistry;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.ClassDetailsRegistry;
import org.hibernate.models.spi.RegistryPrimer;
import org.hibernate.models.spi.SourceModelBuildingContext;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.IndexView;
/**
* @author Steve Ebersole
@ -29,38 +23,38 @@ public class ModelsHelper {
buildingContext.getAnnotationDescriptorRegistry().getDescriptor( TenantId.class );
if ( buildingContext instanceof JandexModelBuildingContext ) {
final IndexView jandexIndex = buildingContext.as( JandexModelBuildingContext.class ).getJandexIndex();
if ( jandexIndex == null ) {
return;
}
final ClassDetailsRegistry classDetailsRegistry = buildingContext.getClassDetailsRegistry();
final AnnotationDescriptorRegistry annotationDescriptorRegistry = buildingContext.getAnnotationDescriptorRegistry();
for ( ClassInfo knownClass : jandexIndex.getKnownClasses() ) {
final String className = knownClass.name().toString();
if ( knownClass.isAnnotation() ) {
// it is always safe to load the annotation classes - we will never be enhancing them
//noinspection rawtypes
final Class annotationClass = buildingContext
.getClassLoading()
.classForName( className );
//noinspection unchecked
annotationDescriptorRegistry.resolveDescriptor(
annotationClass,
(t) -> JdkBuilders.buildAnnotationDescriptor( annotationClass, buildingContext )
);
}
resolveClassDetails(
className,
classDetailsRegistry,
() -> new JandexClassDetails( knownClass, buildingContext )
);
}
}
// if ( buildingContext instanceof JandexModelBuildingContext ) {
// final IndexView jandexIndex = buildingContext.as( JandexModelBuildingContext.class ).getJandexIndex();
// if ( jandexIndex == null ) {
// return;
// }
//
// final ClassDetailsRegistry classDetailsRegistry = buildingContext.getClassDetailsRegistry();
// final AnnotationDescriptorRegistry annotationDescriptorRegistry = buildingContext.getAnnotationDescriptorRegistry();
//
// for ( ClassInfo knownClass : jandexIndex.getKnownClasses() ) {
// final String className = knownClass.name().toString();
//
// if ( knownClass.isAnnotation() ) {
// // it is always safe to load the annotation classes - we will never be enhancing them
// //noinspection rawtypes
// final Class annotationClass = buildingContext
// .getClassLoading()
// .classForName( className );
// //noinspection unchecked
// annotationDescriptorRegistry.resolveDescriptor(
// annotationClass,
// (t) -> JdkBuilders.buildAnnotationDescriptor( annotationClass, buildingContext )
// );
// }
//
// resolveClassDetails(
// className,
// classDetailsRegistry,
// () -> new JandexClassDetails( knownClass, buildingContext )
// );
// }
// }
}
public static ClassDetails resolveClassDetails(

View File

@ -20,13 +20,10 @@ import org.hibernate.boot.models.HibernateAnnotations;
import org.hibernate.boot.models.JpaAnnotations;
import org.hibernate.boot.models.XmlAnnotations;
import org.hibernate.models.AnnotationAccessException;
import org.hibernate.models.jandex.spi.JandexModelBuildingContext;
import org.hibernate.models.jandex.spi.JandexValueExtractor;
import org.hibernate.models.spi.AnnotationDescriptor;
import org.hibernate.models.spi.AttributeDescriptor;
import org.hibernate.models.spi.SourceModelBuildingContext;
import org.jboss.jandex.AnnotationInstance;
/**
* @author Steve Ebersole
@ -72,22 +69,6 @@ public class OrmAnnotationHelper {
return extractJdkValue( jdkAnnotation, attributeDescriptor, modelContext );
}
public static <V> V extractJandexValue(AnnotationInstance jandexAnnotation, AttributeDescriptor<V> attributeDescriptor, SourceModelBuildingContext modelContext) {
final JandexValueExtractor<V> extractor = modelContext.as( JandexModelBuildingContext.class )
.getJandexValueExtractor( attributeDescriptor.getTypeDescriptor() );
return extractor.extractValue( jandexAnnotation, attributeDescriptor, modelContext );
// final AnnotationValue value = jandexAnnotation.value( attributeDescriptor.getName() );
// return attributeDescriptor
// .getTypeDescriptor()
// .createJandexValueConverter( modelContext )
// .convert( value, modelContext );
}
public static <V, A extends Annotation> V extractJandexValue(AnnotationInstance jandexAnnotation, AnnotationDescriptor<A> annotationDescriptor, String attributeName, SourceModelBuildingContext modelContext) {
final AttributeDescriptor<V> attributeDescriptor = annotationDescriptor.getAttribute( attributeName );
return extractJandexValue( jandexAnnotation, attributeDescriptor, modelContext );
}
public static List<Annotation> extractAnnotationTypeAnnotations(Class<? extends Annotation> annotationType) {
final ArrayList<Annotation> result = new ArrayList<>();
final Annotation[] annotationTypeAnnotations = annotationType.getAnnotations();

View File

@ -23,8 +23,6 @@ import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
import org.hibernate.type.BasicType;
import org.hibernate.usertype.UserType;
import org.jboss.jandex.IndexView;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.SharedCacheMode;
@ -98,7 +96,7 @@ public abstract class AbstractDelegatingMetadataBuilderImplementor<T extends Met
}
@Override
public MetadataBuilder applyIndexView(IndexView jandexView) {
public MetadataBuilder applyIndexView(Object jandexView) {
delegate.applyIndexView( jandexView );
return getThis();
}

View File

@ -25,8 +25,6 @@ import org.hibernate.resource.beans.spi.BeanInstanceProducer;
import org.hibernate.type.BasicType;
import org.hibernate.type.spi.TypeConfiguration;
import org.jboss.jandex.IndexView;
/**
* Defines a context for things available during the process of bootstrapping
* a {@link org.hibernate.SessionFactory} which are expected to be cleaned up
@ -151,14 +149,14 @@ public interface BootstrapContext {
/**
* Access to the Jandex index passed by call to
* {@link org.hibernate.boot.MetadataBuilder#applyIndexView(IndexView)}, if any.
* {@link org.hibernate.boot.MetadataBuilder#applyIndexView(Object)}, if any.
*
* @apiNote Jandex is currently not used, see
* <a href="https://github.com/hibernate/hibernate-orm/wiki/Roadmap7.0">the roadmap</a>
*
* @return The Jandex index
*/
IndexView getJandexView();
Object getJandexView();
/**
* Access to any SQL functions explicitly registered with the

View File

@ -104,7 +104,6 @@ public abstract class Ejb3XmlTestCase extends BaseUnitTestCase {
final DomainModelCategorizationCollector modelCategorizationCollector = new DomainModelCategorizationCollector(
true,
globalRegistrations,
null,
modelBuildingContext
);

View File

@ -297,7 +297,6 @@ public class SourceModelTestHelper {
final DomainModelCategorizationCollector modelCategorizationCollector = new DomainModelCategorizationCollector(
true,
globalRegistrations,
jandexIndex,
sourceModelBuildingContext
);

View File

@ -132,7 +132,6 @@ public class XmlProcessingSmokeTests {
final DomainModelCategorizationCollector collector = new DomainModelCategorizationCollector(
false,
new GlobalRegistrationsImpl( buildingContext, new BootstrapContextImpl() ),
null,
buildingContext
);
collectedXmlResources.getDocuments().forEach( jaxbEntityMappings -> {

View File

@ -29,7 +29,6 @@ import org.hibernate.resource.beans.spi.BeanInstanceProducer;
import org.hibernate.type.BasicType;
import org.hibernate.type.spi.TypeConfiguration;
import org.jboss.jandex.IndexView;
/**
* @author Andrea Boriero
@ -121,7 +120,7 @@ public class BootstrapContextImpl implements BootstrapContext {
}
@Override
public IndexView getJandexView() {
public Object getJandexView() {
return delegate.getJandexView();
}