Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions hibernate-core/hibernate-core.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ dependencies {
api jakartaLibs.jta

implementation libs.hibernateModels
implementation libs.hibernateModelsJandex
implementation libs.jandex
implementation libs.classmate
implementation libs.byteBuddy

Expand All @@ -50,8 +48,12 @@ dependencies {
// annotationProcessor project( ":annotation-descriptor-generator" )
compileOnly project( ":annotation-descriptor-generator" )

runtimeOnly project(':hibernate-scan-jandex')

testImplementation project(':hibernate-testing')
testImplementation project(':hibernate-ant')
testImplementation project(':hibernate-scan-jandex')

testImplementation testLibs.shrinkwrapApi
testImplementation testLibs.shrinkwrap
testImplementation testLibs.shrinkwrapDescriptors
Expand All @@ -71,6 +73,7 @@ dependencies {
testRuntimeOnly libs.byteBuddy
testRuntimeOnly testLibs.weld
testRuntimeOnly testLibs.wildFlyTxnClient
testImplementation libs.jandex
testImplementation jakartaLibs.jsonb
testImplementation libs.jackson
testRuntimeOnly libs.jacksonXml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.hibernate.type.BasicType;
import org.hibernate.usertype.UserType;

import org.jboss.jandex.IndexView;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.SharedCacheMode;
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
package org.hibernate.boot.archive.scan.internal;

import java.util.Collections;
import java.util.Set;

import org.hibernate.boot.archive.scan.spi.ClassDescriptor;
import org.hibernate.boot.archive.scan.spi.MappingFileDescriptor;
import org.hibernate.boot.archive.scan.spi.PackageDescriptor;
import org.hibernate.boot.archive.scan.spi.ScanEnvironment;
import org.hibernate.boot.archive.scan.spi.ScanOptions;
import org.hibernate.boot.archive.scan.spi.ScanParameters;
Expand All @@ -19,11 +23,22 @@
* @author Petteri Pitkanen
*/
public class DisabledScanner implements Scanner {
private static final ScanResult emptyScanResult = new ScanResultImpl(
Collections.emptySet(),
Collections.emptySet(),
Collections.emptySet()
);
private static final ScanResult emptyScanResult = new ScanResult() {
@Override
public Set<PackageDescriptor> getLocatedPackages() {
return Collections.emptySet();
}

@Override
public Set<ClassDescriptor> getLocatedClasses() {
return Collections.emptySet();
}

@Override
public Set<MappingFileDescriptor> getLocatedMappingFiles() {
return Collections.emptySet();
}
};

@Override
public ScanResult scan(final ScanEnvironment environment, final ScanOptions options, final ScanParameters parameters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
package org.hibernate.boot.archive.scan.spi;

import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory;

/**
* Defines the contract for Hibernate to be able to scan for classes, packages and resources inside a
* persistence unit.
Expand All @@ -29,4 +31,8 @@ public interface Scanner {
* @param params The parameters for scanning
*/
ScanResult scan(ScanEnvironment environment, ScanOptions options, ScanParameters params);

default void setArchiveDescriptorFactory(ArchiveDescriptorFactory archiveDescriptorFactory){
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.boot.archive.scan.spi;

import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.service.Service;

public interface ScannerFactory extends Service {
Scanner getScanner(ArchiveDescriptorFactory archiveDescriptorFactory);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.hibernate.type.BasicType;
import org.hibernate.type.spi.TypeConfiguration;

import org.jboss.jandex.IndexView;
import org.jboss.logging.Logger;

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -182,7 +181,7 @@ public Object getScanner() {
}

@Override
public IndexView getJandexView() {
public Object getJandexView() {
return jandexView;
}

Expand Down Expand Up @@ -300,7 +299,7 @@ void injectArchiveDescriptorFactory(ArchiveDescriptorFactory factory) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
import org.hibernate.usertype.CompositeUserType;
import org.hibernate.usertype.UserType;

import org.jboss.jandex.IndexView;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.ConstraintMode;
Expand Down Expand Up @@ -213,7 +212,7 @@ public MetadataBuilder applyAccessType(AccessType implicitCacheAccessType) {
}

@Override
public MetadataBuilder applyIndexView(IndexView jandexView) {
public MetadataBuilder applyIndexView(Object jandexView) {
this.bootstrapContext.injectJandexView( jandexView );
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.hibernate.boot.MappingException;
import org.hibernate.boot.archive.internal.StandardArchiveDescriptorFactory;
import org.hibernate.boot.archive.internal.UrlInputStreamAccess;
import org.hibernate.boot.archive.scan.internal.DisabledScanner;
import org.hibernate.boot.archive.scan.internal.StandardScanParameters;
import org.hibernate.boot.archive.scan.internal.StandardScanner;
import org.hibernate.boot.archive.scan.spi.ClassDescriptor;
import org.hibernate.boot.archive.scan.spi.MappingFileDescriptor;
import org.hibernate.boot.archive.scan.spi.PackageDescriptor;
import org.hibernate.boot.archive.scan.spi.ScanEnvironment;
import org.hibernate.boot.archive.scan.spi.ScanResult;
import org.hibernate.boot.archive.scan.spi.Scanner;
import org.hibernate.boot.archive.scan.spi.ScannerFactory;
import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.boot.internal.ClassLoaderAccessImpl;
import org.hibernate.boot.jaxb.Origin;
Expand Down Expand Up @@ -86,11 +88,18 @@ private static Scanner buildScanner(BootstrapContext bootstrapContext, ClassLoad

if ( scannerSetting == null ) {
// No custom Scanner specified, use the StandardScanner
if ( archiveDescriptorFactory == null ) {
return new StandardScanner();
final Iterator<ScannerFactory> iterator = bootstrapContext.getServiceRegistry()
.requireService( ClassLoaderService.class )
.loadJavaServices( ScannerFactory.class )
.iterator();
if ( iterator.hasNext() ) {
// todo: check for multiple scanner and in case raise a warning?
final ScannerFactory factory = iterator.next();
return factory.getScanner( archiveDescriptorFactory );
}
else {
return new StandardScanner( archiveDescriptorFactory );
// todo: add a debug message that there is no Scanner?
return new DisabledScanner();
}
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@
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;
Expand All @@ -96,9 +94,6 @@
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;

Expand Down Expand Up @@ -399,10 +394,6 @@ public static DomainModelSource processManagedResources(
} );
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
Expand All @@ -425,7 +416,6 @@ public static DomainModelSource processManagedResources(
final DomainModelCategorizationCollector modelCategorizationCollector = new DomainModelCategorizationCollector(
areIdGeneratorsGlobal,
metadataCollector.getGlobalRegistrations(),
jandexIndex,
sourceModelBuildingContext
);

Expand Down Expand Up @@ -459,7 +449,6 @@ public static DomainModelSource processManagedResources(

return new DomainModelSource(
classDetailsRegistry,
jandexIndex,
allKnownClassNames,
modelCategorizationCollector.getGlobalRegistrations(),
rootMappingDefaults,
Expand Down Expand Up @@ -492,31 +481,6 @@ private static void applyKnownClass(
}
}

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,23 @@
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;
private final List<String> allKnownClassNames;

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;
Expand All @@ -46,10 +41,6 @@ public ClassDetailsRegistry getClassDetailsRegistry() {
return classDetailsRegistry;
}

public IndexView getJandexIndex() {
return jandexIndex;
}

public GlobalRegistrations getGlobalRegistrations() {
return globalRegistrations;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.ClassDetailsRegistry;

import org.jboss.jandex.IndexView;

/**
* @author Steve Ebersole
*/
Expand All @@ -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,
Expand All @@ -47,7 +43,6 @@ public CategorizedDomainModelImpl(
this.mappedSuperclasses = mappedSuperclasses;
this.embeddables = embeddables;
this.globalRegistrations = globalRegistrations;
this.jandexIndex = jandexIndex;
}

@Override
Expand All @@ -60,11 +55,6 @@ public AnnotationDescriptorRegistry getAnnotationDescriptorRegistry() {
return annotationDescriptorRegistry;
}

@Override
public IndexView getJandexIndex() {
return jandexIndex;
}

@Override
public PersistenceUnitMetadata getPersistenceUnitMetadata() {
return persistenceUnitMetadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
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,
Expand All @@ -38,8 +36,6 @@ public interface CategorizedDomainModel {
*/
AnnotationDescriptorRegistry getAnnotationDescriptorRegistry();

IndexView getJandexIndex();

PersistenceUnitMetadata getPersistenceUnitMetadata();

/**
Expand Down
Loading
Loading