diff --git a/build.gradle b/build.gradle index 4f85fef9de..98ddba5eb7 100644 --- a/build.gradle +++ b/build.gradle @@ -62,7 +62,7 @@ libraries = [ // Annotations commons_annotations: 'org.hibernate.common:hibernate-commons-annotations:4.0.1.Final@jar', - jandex: 'org.jboss:jandex:1.0.3.Final', + jandex: 'org.jboss:jandex:1.1.0.Alpha1', classmate: 'com.fasterxml:classmate:0.5.4', // Dom4J diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/Metadata.java b/hibernate-core/src/main/java/org/hibernate/metamodel/Metadata.java index 58216c529f..e7c53fc72d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/Metadata.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/Metadata.java @@ -26,6 +26,7 @@ package org.hibernate.metamodel; import java.util.Map; import javax.persistence.SharedCacheMode; +import org.jboss.jandex.IndexView; import org.xml.sax.EntityResolver; import org.hibernate.MultiTenancyStrategy; @@ -60,6 +61,7 @@ public interface Metadata { public String getDefaultSchemaName(); public String getDefaultCatalogName(); public MultiTenancyStrategy getMultiTenancyStrategy(); + public IndexView getJandexView(); } /** diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataBuilder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataBuilder.java index 19e5350381..5ae2ed11d4 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataBuilder.java @@ -25,6 +25,7 @@ package org.hibernate.metamodel; import javax.persistence.SharedCacheMode; +import org.jboss.jandex.IndexView; import org.xml.sax.EntityResolver; import org.hibernate.cache.spi.access.AccessType; @@ -45,6 +46,8 @@ public interface MetadataBuilder { public MetadataBuilder with(AccessType accessType); + public MetadataBuilder with(IndexView jandexView); + public MetadataBuilder withNewIdentifierGeneratorsEnabled(boolean enabled); public Metadata buildMetadata(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataSources.java b/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataSources.java index a18d97bd32..6bfedaa925 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataSources.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataSources.java @@ -31,20 +31,28 @@ import java.io.InputStream; import java.net.URL; import java.util.ArrayList; import java.util.Enumeration; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; import java.util.jar.JarFile; import java.util.zip.ZipEntry; import org.jboss.logging.Logger; + +import org.jboss.jandex.IndexView; +import org.jboss.jandex.Indexer; import org.w3c.dom.Document; +import org.hibernate.HibernateException; import org.hibernate.boot.spi.CacheRegionDefinition; import org.hibernate.jaxb.internal.JaxbMappingProcessor; import org.hibernate.jaxb.spi.JaxbRoot; import org.hibernate.jaxb.spi.Origin; import org.hibernate.jaxb.spi.SourceType; +import org.hibernate.jaxb.spi.orm.JaxbEntityMappings; import org.hibernate.metamodel.internal.MetadataBuilderImpl; +import org.hibernate.metamodel.internal.source.annotations.xml.mocker.EntityMappingsMocker; import org.hibernate.metamodel.spi.source.MappingException; import org.hibernate.metamodel.spi.source.MappingNotFoundException; import org.hibernate.service.ServiceRegistry; @@ -59,18 +67,17 @@ import org.hibernate.service.classloading.spi.ClassLoaderService; public class MetadataSources { private static final Logger LOG = Logger.getLogger( MetadataSources.class ); + private final List externalCacheRegionDefinitions = new ArrayList(); + private final JaxbMappingProcessor jaxbProcessor; + private final ServiceRegistry serviceRegistry; + private final MetadataBuilderImpl metadataBuilder; + private List jaxbRootList = new ArrayList(); private LinkedHashSet> annotatedClasses = new LinkedHashSet>(); private LinkedHashSet annotatedClassNames = new LinkedHashSet(); private LinkedHashSet annotatedPackages = new LinkedHashSet(); - private final List externalCacheRegionDefinitions = new ArrayList(); - - private final JaxbMappingProcessor jaxbProcessor; - - private final ServiceRegistry serviceRegistry; - - private final MetadataBuilderImpl metadataBuilder; + private boolean hasOrmXmlJaxbRoots; /** * Create a metadata sources using the specified service registry. @@ -108,6 +115,11 @@ public class MetadataSources { return serviceRegistry; } + public boolean hasOrmXmlJaxbRoots() { + return hasOrmXmlJaxbRoots; + } + + /** * Get a builder for metadata where non-default options can be specified. * @@ -197,7 +209,7 @@ public class MetadataSources { private JaxbRoot add(InputStream inputStream, Origin origin, boolean close) { try { JaxbRoot jaxbRoot = jaxbProcessor.unmarshal( inputStream, origin ); - jaxbRootList.add( jaxbRoot ); + addJaxbRoot( jaxbRoot ); return jaxbRoot; } finally { @@ -336,10 +348,15 @@ public class MetadataSources { public MetadataSources addDocument(Document document) { final Origin origin = new Origin( SourceType.DOM, "" ); JaxbRoot jaxbRoot = jaxbProcessor.unmarshal( document, origin ); - jaxbRootList.add( jaxbRoot ); + addJaxbRoot( jaxbRoot ); return this; } + private void addJaxbRoot(JaxbRoot jaxbRoot) { + hasOrmXmlJaxbRoots = hasOrmXmlJaxbRoots || JaxbEntityMappings.class.isInstance( jaxbRoot.getRoot() ); + jaxbRootList.add( jaxbRoot ); + } + /** * Read all mappings from a jar file. *

@@ -412,4 +429,71 @@ public class MetadataSources { externalCacheRegionDefinitions.addAll( cacheRegionDefinitions ); return this; } + + @SuppressWarnings("unchecked") + public IndexView wrapJandexView(IndexView jandexView) { + if ( ! hasOrmXmlJaxbRoots ) { + // no need to wrap + return jandexView; + } + + final List collectedOrmXmlMappings = new ArrayList(); + for ( JaxbRoot jaxbRoot : getJaxbRootList() ) { + if ( JaxbEntityMappings.class.isInstance( jaxbRoot.getRoot() ) ) { + collectedOrmXmlMappings.add( ( (JaxbRoot) jaxbRoot ).getRoot() ); + } + } + + if ( collectedOrmXmlMappings.isEmpty() ) { + // log a warning or something + } + + return new EntityMappingsMocker( collectedOrmXmlMappings, jandexView, serviceRegistry ).mockNewIndex(); + } + + public IndexView buildJandexView() { + // create a jandex index from the annotated classes + + Indexer indexer = new Indexer(); + Set processedNames = new HashSet(); + + for ( Class clazz : getAnnotatedClasses() ) { + indexClass( clazz, indexer, processedNames ); + } + + for ( String className : getAnnotatedClassNames() ) { + indexResource( className.replace( '.', '/' ) + ".class", indexer, processedNames ); + } + + // add package-info from the configured packages + for ( String packageName : getAnnotatedPackages() ) { + indexResource( packageName.replace( '.', '/' ) + "/package-info.class", indexer, processedNames ); + } + + return wrapJandexView( indexer.complete() ); + } + + private void indexClass(Class clazz, Indexer indexer, Set processedNames) { + if ( clazz == null ) { + return; + } + + indexResource( clazz.getName().replace( '.', '/' ) + ".class", indexer, processedNames ); + + // index all super classes of the specified class. Using org.hibernate.cfg.Configuration it was not + // necessary to add all annotated classes. Entities would be enough. Mapped superclasses would be + // discovered while processing the annotations. To keep this behavior we index all classes in the + // hierarchy (see also HHH-7484) + indexClass( clazz.getSuperclass(), indexer, processedNames ); + } + + private void indexResource(String resourceName, Indexer indexer, Set processedNames) { + InputStream stream = serviceRegistry.getService( ClassLoaderService.class ).locateResourceStream( resourceName ); + try { + indexer.index( stream ); + } + catch ( IOException e ) { + throw new HibernateException( "Unable to open input stream for resource " + resourceName, e ); + } + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuilderImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuilderImpl.java index ead9cb7c12..8313a3cbe2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuilderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuilderImpl.java @@ -25,6 +25,7 @@ package org.hibernate.metamodel.internal; import javax.persistence.SharedCacheMode; +import org.jboss.jandex.IndexView; import org.xml.sax.EntityResolver; import org.hibernate.MultiTenancyStrategy; @@ -90,6 +91,12 @@ public class MetadataBuilderImpl implements MetadataBuilder { return this; } + @Override + public MetadataBuilder with(IndexView jandexView) { + this.options.jandexView = jandexView; + return this; + } + @Override public MetadataBuilder withNewIdentifierGeneratorsEnabled(boolean enabled) { this.options.useNewIdentifierGenerators = enabled; @@ -114,6 +121,7 @@ public class MetadataBuilderImpl implements MetadataBuilder { private String defaultSchemaName; private String defaultCatalogName; private MultiTenancyStrategy multiTenancyStrategy; + public IndexView jandexView; public OptionsImpl(ServiceRegistry serviceRegistry) { ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class ); @@ -215,5 +223,10 @@ public class MetadataBuilderImpl implements MetadataBuilder { public MultiTenancyStrategy getMultiTenancyStrategy() { return multiTenancyStrategy; } + + @Override + public IndexView getJandexView() { + return jandexView; + } } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataImpl.java index fb3995aa92..52356388ea 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataImpl.java @@ -29,6 +29,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.jboss.jandex.IndexView; + +import org.jboss.logging.Logger; + import org.hibernate.AssertionFailure; import org.hibernate.DuplicateMappingException; import org.hibernate.MappingException; @@ -45,8 +49,8 @@ import org.hibernate.engine.spi.SyntheticAttributeHelper; import org.hibernate.id.factory.IdentifierGeneratorFactory; import org.hibernate.id.factory.spi.MutableIdentifierGeneratorFactory; import org.hibernate.internal.CoreMessageLogger; -import org.hibernate.jaxb.spi.JaxbRoot; import org.hibernate.internal.util.ValueHolder; +import org.hibernate.jaxb.spi.JaxbRoot; import org.hibernate.metamodel.MetadataSourceProcessingOrder; import org.hibernate.metamodel.MetadataSources; import org.hibernate.metamodel.SessionFactoryBuilder; @@ -82,7 +86,6 @@ import org.hibernate.metamodel.spi.source.TypeDescriptorSource; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.classloading.spi.ClassLoaderService; import org.hibernate.type.TypeResolver; -import org.jboss.logging.Logger; /** * Container for configuration data collected during binding the metamodel. @@ -101,7 +104,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable { private final ServiceRegistry serviceRegistry; private final Options options; - private final ValueHolder classLoaderService; + private final ClassLoaderService classLoaderService; // private final ValueHolder persisterClassResolverService; private TypeResolver typeResolver = new TypeResolver(); @@ -147,28 +150,26 @@ public class MetadataImpl implements MetadataImplementor, Serializable { } }; + // todo : cache the built index if no inputs have changed (look at gradle-style hashing for up-to-date checking) + final IndexView jandexView = options.getJandexView() != null + ? metadataSources.wrapJandexView( options.getJandexView() ) + : metadataSources.buildJandexView(); + final MetadataSourceProcessor[] metadataSourceProcessors; if ( options.getMetadataSourceProcessingOrder() == MetadataSourceProcessingOrder.HBM_FIRST ) { metadataSourceProcessors = new MetadataSourceProcessor[] { new HbmMetadataSourceProcessorImpl( this, metadataSources ), - new AnnotationMetadataSourceProcessorImpl( this, metadataSources ) + new AnnotationMetadataSourceProcessorImpl( this, metadataSources, jandexView ) }; } else { metadataSourceProcessors = new MetadataSourceProcessor[] { - new AnnotationMetadataSourceProcessorImpl( this, metadataSources ), + new AnnotationMetadataSourceProcessorImpl( this, metadataSources, jandexView ), new HbmMetadataSourceProcessorImpl( this, metadataSources ) }; } - this.classLoaderService = new ValueHolder( - new ValueHolder.DeferredInitializer() { - @Override - public ClassLoaderService initialize() { - return serviceRegistry.getService( ClassLoaderService.class ); - } - } - ); + this.classLoaderService = serviceRegistry.getService( ClassLoaderService.class ); // this.persisterClassResolverService = new ValueHolder( // new ValueHolder.DeferredInitializer() { // @Override @@ -180,8 +181,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable { processTypeDefinitions( metadataSourceProcessors ); - for ( TypeContributor contributor : - serviceRegistry.getService( ClassLoaderService.class ).loadJavaServices( TypeContributor.class ) ) { + for ( TypeContributor contributor : classLoaderService.loadJavaServices( TypeContributor.class ) ) { contributor.contribute( this ); } @@ -190,17 +190,14 @@ public class MetadataImpl implements MetadataImplementor, Serializable { processMappings( metadataSourceProcessors ); bindMappingDependentMetadata( metadataSourceProcessors ); - for ( MetadataContributor contributor : - serviceRegistry.getService( ClassLoaderService.class ).loadJavaServices( MetadataContributor.class ) ) { - // todo : handle Jandex index here... - contributor.contribute( this, null ); + for ( MetadataContributor contributor : classLoaderService.loadJavaServices( MetadataContributor.class ) ) { + contributor.contribute( this, jandexView ); } final List jaxbRoots = new ArrayList(); - for ( AdditionalJaxbRootProducer producer : - serviceRegistry.getService( ClassLoaderService.class ).loadJavaServices( AdditionalJaxbRootProducer.class ) ) { + for ( AdditionalJaxbRootProducer producer : classLoaderService.loadJavaServices( AdditionalJaxbRootProducer.class ) ) { // todo : handle Jandex index here... - jaxbRoots.addAll( producer.produceRoots( this, null ) ); + jaxbRoots.addAll( producer.produceRoots( this, jandexView ) ); } final HbmMetadataSourceProcessorImpl processor = new HbmMetadataSourceProcessorImpl( this, jaxbRoots ); final Binder binder = new Binder( this, identifierGeneratorFactory ); @@ -208,6 +205,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable { } + // type definitions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ private void processTypeDefinitions(MetadataSourceProcessor[] metadataSourceProcessors) { @@ -216,7 +214,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable { addTypeDefinition( new TypeDefinition( typeDescriptorSource.getName(), - classLoaderService().classForName( typeDescriptorSource.getTypeImplementationClassName() ), + classLoaderService.classForName( typeDescriptorSource.getTypeImplementationClassName() ), typeDescriptorSource.getRegistrationKeys(), typeDescriptorSource.getParameters() ) @@ -318,7 +316,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable { @Override public void registerIdentifierGenerator(String name, String generatorClassName) { - identifierGeneratorFactory.register( name, classLoaderService().classForName( generatorClassName ) ); + identifierGeneratorFactory.register( name, classLoaderService.classForName( generatorClassName ) ); } private void processMappings(MetadataSourceProcessor[] metadataSourceProcessors) { @@ -409,8 +407,11 @@ public class MetadataImpl implements MetadataImplementor, Serializable { @Override public void addNamedNativeQuery(NamedSQLQueryDefinition def) { - if ( def == null || def.getName() == null ) { - throw new IllegalArgumentException( "Named native query definition object or name is null: " + def.getQueryString() ); + if ( def == null ) { + throw new IllegalArgumentException( "Named native query definition object is null" ); + } + if ( def.getName() == null ) { + throw new IllegalArgumentException( "Named native query definition name is null: " + def.getQueryString() ); } namedNativeQueryDefs.put( def.getName(), def ); } @@ -470,10 +471,6 @@ public class MetadataImpl implements MetadataImplementor, Serializable { return resultSetMappings; } - private ClassLoaderService classLoaderService() { - return classLoaderService.getValue(); - } - // private PersisterClassResolver persisterClassResolverService() { // return persisterClassResolverService.getValue(); // } @@ -491,7 +488,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable { @Override @SuppressWarnings( {"unchecked"}) public Class locateClassByName(String name) { - return classLoaderService().classForName( name ); + return classLoaderService.classForName( name ); } @Override @@ -506,7 +503,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable { new ValueHolder.DeferredInitializer>() { @Override public Class initialize() { - return classLoaderService.getValue().classForName( className ); + return classLoaderService.classForName( className ); } } ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/AnnotationBindingContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/AnnotationBindingContext.java index 5e7e76a066..bff7d1c9ff 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/AnnotationBindingContext.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/AnnotationBindingContext.java @@ -26,7 +26,7 @@ package org.hibernate.metamodel.internal.source.annotations; import com.fasterxml.classmate.ResolvedType; import com.fasterxml.classmate.ResolvedTypeWithMembers; import org.jboss.jandex.ClassInfo; -import org.jboss.jandex.Index; +import org.jboss.jandex.IndexView; import org.hibernate.metamodel.spi.binding.IdGenerator; import org.hibernate.metamodel.spi.source.BindingContext; @@ -39,7 +39,7 @@ import org.hibernate.metamodel.spi.source.IdentifierGeneratorSource; * @author Hardy Ferentschik */ public interface AnnotationBindingContext extends BindingContext { - Index getIndex(); + IndexView getIndex(); ClassInfo getClassInfo(String name); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/AnnotationBindingContextImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/AnnotationBindingContextImpl.java index 82df7cde83..189cb24f62 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/AnnotationBindingContextImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/AnnotationBindingContextImpl.java @@ -33,6 +33,7 @@ import com.fasterxml.classmate.TypeResolver; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; import org.jboss.jandex.Index; +import org.jboss.jandex.IndexView; import org.hibernate.cfg.NamingStrategy; import org.hibernate.internal.util.ValueHolder; @@ -50,13 +51,13 @@ import org.hibernate.service.classloading.spi.ClassLoaderService; public class AnnotationBindingContextImpl implements AnnotationBindingContext { private final MetadataImplementor metadata; private final ValueHolder classLoaderService; - private final Index index; + private final IndexView index; private final TypeResolver typeResolver = new TypeResolver(); private final Map, ResolvedType> resolvedTypeCache = new HashMap, ResolvedType>(); private final IdentifierGeneratorExtractionDelegate identifierGeneratorSourceCreationDelegate; - public AnnotationBindingContextImpl(MetadataImplementor metadata, Index index) { + public AnnotationBindingContextImpl(MetadataImplementor metadata, IndexView index) { this.metadata = metadata; this.classLoaderService = new ValueHolder( new ValueHolder.DeferredInitializer() { @@ -75,7 +76,7 @@ public class AnnotationBindingContextImpl implements AnnotationBindingContext { } @Override - public Index getIndex() { + public IndexView getIndex() { return index; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/AnnotationMetadataSourceProcessorImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/AnnotationMetadataSourceProcessorImpl.java index 94b0e5c31c..3915a937bd 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/AnnotationMetadataSourceProcessorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/AnnotationMetadataSourceProcessorImpl.java @@ -23,24 +23,15 @@ */ package org.hibernate.metamodel.internal.source.annotations; -import java.io.IOException; -import java.io.InputStream; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; import org.jboss.jandex.AnnotationInstance; -import org.jboss.jandex.Index; -import org.jboss.jandex.Indexer; +import org.jboss.jandex.IndexView; import org.hibernate.AssertionFailure; -import org.hibernate.HibernateException; -import org.hibernate.jaxb.spi.JaxbRoot; -import org.hibernate.jaxb.spi.Origin; -import org.hibernate.jaxb.spi.SourceType; -import org.hibernate.jaxb.spi.orm.JaxbEntityMappings; import org.hibernate.metamodel.MetadataSources; import org.hibernate.metamodel.internal.MetadataImpl; import org.hibernate.metamodel.internal.source.annotations.global.FetchProfileProcessor; @@ -52,16 +43,12 @@ import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotName import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; import org.hibernate.metamodel.internal.source.annotations.xml.PseudoJpaDotNames; -import org.hibernate.metamodel.internal.source.annotations.xml.mocker.EntityMappingsMocker; import org.hibernate.metamodel.spi.MetadataImplementor; import org.hibernate.metamodel.spi.MetadataSourceProcessor; import org.hibernate.metamodel.spi.source.EntityHierarchy; import org.hibernate.metamodel.spi.source.FilterDefinitionSource; import org.hibernate.metamodel.spi.source.IdentifierGeneratorSource; -import org.hibernate.metamodel.spi.source.MappingException; import org.hibernate.metamodel.spi.source.TypeDescriptorSource; -import org.hibernate.service.classloading.spi.ClassLoaderService; -import org.hibernate.service.classloading.spi.ClassLoadingException; /** * Main class responsible to creating and binding the Hibernate meta-model from annotations. @@ -73,57 +60,24 @@ import org.hibernate.service.classloading.spi.ClassLoadingException; */ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProcessor { private final MetadataImplementor metadata; + private final IndexView jandexView; private AnnotationBindingContext bindingContext; - public AnnotationMetadataSourceProcessorImpl(MetadataImpl metadata, MetadataSources metadataSources) { + public AnnotationMetadataSourceProcessorImpl( + MetadataImpl metadata, + MetadataSources metadataSources, + IndexView jandexView) { this.metadata = metadata; + this.jandexView = jandexView; - // todo : use the Jandex from JBoss/JPA if available... - // todo : cache the built index if no inputs have changed (look at gradle-style hashing for up-to-date checking) - - // create a jandex index from the annotated classes - Set processedNames = new HashSet(); - Indexer indexer = new Indexer(); - for ( Class clazz : metadataSources.getAnnotatedClasses() ) { - indexClass( indexer, clazz, processedNames ); - } - - for ( String className : metadataSources.getAnnotatedClassNames() ) { - Class clazz; - try { - clazz = metadata.getServiceRegistry().getService( ClassLoaderService.class ).classForName( className ); - } - catch ( ClassLoadingException e ) { - throw new MappingException( "Unable to load a configured class", new Origin( SourceType.FILE, null ) ); - } - indexClass( indexer, clazz, processedNames ); - } - - // add package-info from the configured packages - for ( String packageName : metadataSources.getAnnotatedPackages() ) { - indexClass( indexer, packageName.replace( '.', '/' ) + "/package-info.class", processedNames ); - } - - Index index = indexer.complete(); - - List> mappings = new ArrayList>(); - for ( JaxbRoot root : metadataSources.getJaxbRootList() ) { - if ( root.getRoot() instanceof JaxbEntityMappings ) { - mappings.add( ( JaxbRoot ) root ); - } - } - if ( !mappings.isEmpty() ) { - index = parseAndUpdateIndex( mappings, index ); - } - - if ( !index.getAnnotations( PseudoJpaDotNames.DEFAULT_DELIMITED_IDENTIFIERS ).isEmpty() ) { + if ( !jandexView.getAnnotations( PseudoJpaDotNames.DEFAULT_DELIMITED_IDENTIFIERS ).isEmpty() ) { // todo : this needs to move to AnnotationBindingContext // what happens right now is that specifying this in an orm.xml causes it to effect all orm.xmls metadata.setGloballyQuotedIdentifiers( true ); } - bindingContext = new AnnotationBindingContextImpl( metadata, index ); + bindingContext = new AnnotationBindingContextImpl( metadata, jandexView ); } @Override @@ -131,7 +85,7 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc assertBindingContextExists(); List typeDescriptorSources = new ArrayList(); - List annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.TYPE_DEF ); + Collection annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.TYPE_DEF ); for ( AnnotationInstance typeDef : annotations ) { typeDescriptorSources.add( new TypeDescriptorSourceImpl( typeDef ) ); } @@ -161,7 +115,7 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc assertBindingContextExists(); List filterDefinitionSources = new ArrayList(); - List annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.FILTER_DEF ); + Collection annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.FILTER_DEF ); for ( AnnotationInstance filterDef : annotations ) { filterDefinitionSources.add( new FilterDefinitionSourceImpl( filterDef ) ); } @@ -205,44 +159,6 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc } - private Index parseAndUpdateIndex(List> mappings, Index annotationIndex) { - List list = new ArrayList( mappings.size() ); - for ( JaxbRoot jaxbRoot : mappings ) { - list.add( jaxbRoot.getRoot() ); - } - return new EntityMappingsMocker( list, annotationIndex, metadata.getServiceRegistry() ).mockNewIndex(); - } - - - private void indexClass(Indexer indexer, Class clazz, Set processedNames) { - indexClass( indexer, clazz.getName().replace( '.', '/' ) + ".class", processedNames ); - - // index all super classes of the specified class. Using org.hibernate.cfg.Configuration it was not - // necessary to add all annotated classes. Entities would be enough. Mapped superclasses would be - // discovered while processing the annotations. To keep this behavior we index all classes in the - // hierarchy (see also HHH-7484) - clazz = clazz.getSuperclass(); - while ( clazz != null && !Object.class.equals( clazz ) ) { - indexClass( indexer, clazz.getName().replace( '.', '/' ) + ".class", processedNames ); - clazz = clazz.getSuperclass(); - } - } - - private void indexClass(Indexer indexer, String className, Set processedNames) { - if ( processedNames.contains( className ) ) { - return; - } - InputStream stream = metadata.getServiceRegistry().getService( ClassLoaderService.class ).locateResourceStream( - className - ); - try { - indexer.index( stream ); - } - catch ( IOException e ) { - throw new HibernateException( "Unable to open input stream for class " + className, e ); - } - } - private class GlobalIdentifierGeneratorSourceContainer implements IdentifierGeneratorSourceContainer { private final AnnotationBindingContext bindingContext; @@ -251,17 +167,17 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc } @Override - public List getSequenceGeneratorSources() { + public Collection getSequenceGeneratorSources() { return bindingContext.getIndex().getAnnotations( JPADotNames.SEQUENCE_GENERATOR ); } @Override - public List getTableGeneratorSources() { + public Collection getTableGeneratorSources() { return bindingContext.getIndex().getAnnotations( JPADotNames.TABLE_GENERATOR ); } @Override - public List getGenericGeneratorSources() { + public Collection getGenericGeneratorSources() { List annotations = new ArrayList(); annotations.addAll( bindingContext.getIndex().getAnnotations( HibernateDotNames.GENERIC_GENERATOR ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/IdentifierGeneratorExtractionDelegate.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/IdentifierGeneratorExtractionDelegate.java index f03a54e4e5..192cbe2eca 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/IdentifierGeneratorExtractionDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/IdentifierGeneratorExtractionDelegate.java @@ -25,6 +25,7 @@ package org.hibernate.metamodel.internal.source.annotations; import javax.persistence.GenerationType; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -90,7 +91,7 @@ public class IdentifierGeneratorExtractionDelegate { private void processSequenceGenerators( List identifierGeneratorSources, - List generatorAnnotations) { + Collection generatorAnnotations) { for ( AnnotationInstance generatorAnnotation : generatorAnnotations ) { final String generatorName = JandexHelper.getValue( generatorAnnotation, "name", String.class ); @@ -141,7 +142,7 @@ public class IdentifierGeneratorExtractionDelegate { private void processTableGenerators( List identifierGeneratorSources, - List annotations) { + Collection annotations) { for ( AnnotationInstance generatorAnnotation : annotations ) { final String generatorName = JandexHelper.getValue( generatorAnnotation, "name", String.class ); @@ -235,7 +236,7 @@ public class IdentifierGeneratorExtractionDelegate { private void processGenericGenerators( List identifierGeneratorSources, - List genericGeneratorSources) { + Collection genericGeneratorSources) { for ( AnnotationInstance generatorAnnotation : genericGeneratorSources ) { Map parameterMap = new HashMap(); AnnotationInstance[] parameterAnnotations = JandexHelper.getValue( diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/IdentifierGeneratorSourceContainer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/IdentifierGeneratorSourceContainer.java index 042738f979..6692789882 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/IdentifierGeneratorSourceContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/IdentifierGeneratorSourceContainer.java @@ -23,6 +23,7 @@ */ package org.hibernate.metamodel.internal.source.annotations; +import java.util.Collection; import java.util.List; import org.jboss.jandex.AnnotationInstance; @@ -34,9 +35,9 @@ import org.jboss.jandex.AnnotationInstance; * @author Steve Ebersole */ public interface IdentifierGeneratorSourceContainer { - public List getSequenceGeneratorSources(); + public Collection getSequenceGeneratorSources(); - public List getTableGeneratorSources(); + public Collection getTableGeneratorSources(); - public List getGenericGeneratorSources(); + public Collection getGenericGeneratorSources(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/entity/EntityBindingContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/entity/EntityBindingContext.java index cbe65fd8d7..db821dc403 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/entity/EntityBindingContext.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/entity/EntityBindingContext.java @@ -34,6 +34,7 @@ import com.fasterxml.classmate.ResolvedTypeWithMembers; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.Index; +import org.jboss.jandex.IndexView; import org.hibernate.cfg.NamingStrategy; import org.hibernate.jaxb.spi.Origin; @@ -183,7 +184,7 @@ public class EntityBindingContext implements LocalBindingContext, AnnotationBind } @Override - public Index getIndex() { + public IndexView getIndex() { return contextDelegate.getIndex(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/entity/EntityClass.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/entity/EntityClass.java index f8913b1f58..c743993a59 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/entity/EntityClass.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/entity/EntityClass.java @@ -26,6 +26,7 @@ package org.hibernate.metamodel.internal.source.annotations.entity; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -494,7 +495,7 @@ public class EntityClass extends ConfiguredClass { // Bind default JPA entity listener callbacks (unless excluded), using superclasses first (unless excluded) if ( JandexHelper.getSingleAnnotation( getClassInfo(), JPADotNames.EXCLUDE_DEFAULT_LISTENERS ) == null ) { - List defaultEntityListenerAnnotations = getLocalBindingContext().getIndex() + Collection defaultEntityListenerAnnotations = getLocalBindingContext().getIndex() .getAnnotations( PseudoJpaDotNames.DEFAULT_ENTITY_LISTENERS ); for ( AnnotationInstance annotation : defaultEntityListenerAnnotations ) { for ( Type callbackClass : annotation.value().asClassArray() ) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/FetchProfileProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/FetchProfileProcessor.java index 7e1b75aae1..f2e9d4c197 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/FetchProfileProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/FetchProfileProcessor.java @@ -23,8 +23,8 @@ */ package org.hibernate.metamodel.internal.source.annotations.global; +import java.util.Collection; import java.util.HashSet; -import java.util.List; import java.util.Set; import org.jboss.jandex.AnnotationInstance; @@ -32,12 +32,12 @@ import org.jboss.jandex.AnnotationInstance; import org.hibernate.MappingException; import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.FetchProfiles; +import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext; import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames; import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; +import org.hibernate.metamodel.spi.MetadataImplementor; import org.hibernate.metamodel.spi.binding.FetchProfile; import org.hibernate.metamodel.spi.binding.FetchProfile.Fetch; -import org.hibernate.metamodel.spi.MetadataImplementor; -import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext; /** * Binds fetch profiles found in annotations. @@ -57,7 +57,7 @@ public class FetchProfileProcessor { // TODO verify that association exists. See former VerifyFetchProfileReferenceSecondPass public static void bind(AnnotationBindingContext bindingContext) { - List annotations = bindingContext.getIndex() + Collection annotations = bindingContext.getIndex() .getAnnotations( HibernateDotNames.FETCH_PROFILE ); for ( AnnotationInstance fetchProfile : annotations ) { bind( bindingContext.getMetadataImplementor(), fetchProfile ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/IdGeneratorProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/IdGeneratorProcessor.java index 5cb9864a27..c491502799 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/IdGeneratorProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/IdGeneratorProcessor.java @@ -23,13 +23,14 @@ */ package org.hibernate.metamodel.internal.source.annotations.global; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import javax.persistence.GenerationType; import javax.persistence.SequenceGenerator; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import org.jboss.jandex.AnnotationInstance; + import org.jboss.logging.Logger; import org.hibernate.annotations.GenericGenerator; @@ -43,13 +44,13 @@ import org.hibernate.id.enhanced.SequenceStyleGenerator; import org.hibernate.id.enhanced.TableGenerator; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.StringHelper; +import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext; import org.hibernate.metamodel.internal.source.annotations.util.EnumConversionHelper; import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames; import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; import org.hibernate.metamodel.spi.MetadataImplementor; import org.hibernate.metamodel.spi.binding.IdGenerator; -import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext; /** * Binds {@link SequenceGenerator}, {@link javax.persistence.TableGenerator}, {@link GenericGenerator}, and @@ -74,7 +75,7 @@ public class IdGeneratorProcessor { * @param bindingContext the context for annotation binding */ public static void bind(AnnotationBindingContext bindingContext) { - List annotations = bindingContext.getIndex() + Collection annotations = bindingContext.getIndex() .getAnnotations( JPADotNames.SEQUENCE_GENERATOR ); for ( AnnotationInstance generator : annotations ) { bindSequenceGenerator( bindingContext.getMetadataImplementor(), generator ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/QueryProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/QueryProcessor.java index 98f9c0cfa9..2573f72e09 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/QueryProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/QueryProcessor.java @@ -23,15 +23,16 @@ */ package org.hibernate.metamodel.internal.source.annotations.global; -import java.util.HashMap; -import java.util.List; import javax.persistence.NamedNativeQueries; import javax.persistence.NamedNativeQuery; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; +import java.util.Collection; +import java.util.HashMap; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; + import org.jboss.logging.Logger; import org.hibernate.AnnotationException; @@ -47,11 +48,11 @@ import org.hibernate.engine.spi.NamedSQLQueryDefinition; import org.hibernate.engine.spi.NamedSQLQueryDefinitionBuilder; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.StringHelper; +import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext; import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames; import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; import org.hibernate.metamodel.spi.MetadataImplementor; -import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext; /** * Binds {@link NamedQuery}, {@link NamedQueries}, {@link NamedNativeQuery}, {@link NamedNativeQueries}, @@ -79,7 +80,7 @@ public class QueryProcessor { * @param bindingContext the context for annotation binding */ public static void bind(AnnotationBindingContext bindingContext) { - List annotations = bindingContext.getIndex().getAnnotations( JPADotNames.NAMED_QUERY ); + Collection annotations = bindingContext.getIndex().getAnnotations( JPADotNames.NAMED_QUERY ); for ( AnnotationInstance query : annotations ) { bindNamedQuery( bindingContext.getMetadataImplementor(), query ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/SqlResultSetProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/SqlResultSetProcessor.java index 016952373f..ee56ab0a72 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/SqlResultSetProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/SqlResultSetProcessor.java @@ -25,14 +25,15 @@ package org.hibernate.metamodel.internal.source.annotations.global; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; - import org.jboss.jandex.AnnotationInstance; + import org.jboss.logging.Logger; import org.hibernate.LockMode; @@ -40,7 +41,6 @@ import org.hibernate.MappingException; import org.hibernate.engine.ResultSetMappingDefinition; import org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn; import org.hibernate.engine.query.spi.sql.NativeSQLQueryScalarReturn; -import org.hibernate.id.EntityIdentifierNature; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; @@ -75,7 +75,7 @@ public class SqlResultSetProcessor { } public static void bind(final AnnotationBindingContext bindingContext) { - List annotations = bindingContext.getIndex() + Collection annotations = bindingContext.getIndex() .getAnnotations( JPADotNames.SQL_RESULT_SET_MAPPING ); for ( final AnnotationInstance sqlResultSetMappingAnnotationInstance : annotations ) { bindSqlResultSetMapping( bindingContext, sqlResultSetMappingAnnotationInstance ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/TableProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/TableProcessor.java index 8f4e4d508d..e96dddd95c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/TableProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/TableProcessor.java @@ -23,9 +23,10 @@ */ package org.hibernate.metamodel.internal.source.annotations.global; -import java.util.List; +import java.util.Collection; import org.jboss.jandex.AnnotationInstance; + import org.jboss.logging.Logger; import org.hibernate.AnnotationException; @@ -34,13 +35,13 @@ import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext; import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames; import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; +import org.hibernate.metamodel.spi.MetadataImplementor; import org.hibernate.metamodel.spi.relational.Column; import org.hibernate.metamodel.spi.relational.Index; import org.hibernate.metamodel.spi.relational.ObjectName; import org.hibernate.metamodel.spi.relational.Schema; import org.hibernate.metamodel.spi.relational.Table; import org.hibernate.metamodel.spi.relational.Value; -import org.hibernate.metamodel.spi.MetadataImplementor; /** * Binds table related information. This binder is called after the entities are bound. @@ -64,7 +65,7 @@ public class TableProcessor { * @param bindingContext the context for annotation binding */ public static void bind(AnnotationBindingContext bindingContext) { - List annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.TABLE ); + Collection annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.TABLE ); for ( AnnotationInstance tableAnnotation : annotations ) { bind( bindingContext.getMetadataImplementor(), tableAnnotation ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/EntityHierarchyBuilder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/EntityHierarchyBuilder.java index a9a6924ceb..fa248d355b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/EntityHierarchyBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/EntityHierarchyBuilder.java @@ -23,19 +23,20 @@ */ package org.hibernate.metamodel.internal.source.annotations.util; +import javax.persistence.AccessType; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import javax.persistence.AccessType; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; import org.jboss.jandex.FieldInfo; -import org.jboss.jandex.Index; +import org.jboss.jandex.IndexView; import org.jboss.jandex.MethodInfo; import org.hibernate.AnnotationException; @@ -73,7 +74,7 @@ public class EntityHierarchyBuilder { List processedEntities = new ArrayList(); Map> classToDirectSubClassMap = new HashMap>(); - Index index = bindingContext.getIndex(); + IndexView index = bindingContext.getIndex(); for ( ClassInfo classInfo : index.getKnownClasses() ) { if ( !isEntityClass( classInfo ) ) { continue; @@ -174,7 +175,7 @@ public class EntityHierarchyBuilder { * * @return Finds the root entity starting at the entity given by {@code info} */ - private static ClassInfo findRootEntityClassInfo(Index index, ClassInfo info) { + private static ClassInfo findRootEntityClassInfo(IndexView index, ClassInfo info) { ClassInfo rootEntity = info; DotName superName = info.superName(); @@ -190,7 +191,7 @@ public class EntityHierarchyBuilder { return rootEntity; } - private static List findMappedSuperclasses(Index index, ClassInfo info) { + private static List findMappedSuperclasses(IndexView index, ClassInfo info) { List mappedSuperclasses = new ArrayList( ); DotName superName = info.superName(); ClassInfo tmpInfo; @@ -226,7 +227,7 @@ public class EntityHierarchyBuilder { Map> classToDirectSubclassMap) { processedEntities.add( classInfo.name() ); rootClassWithAllSubclasses.add( classInfo ); - List subClasses = bindingContext.getIndex().getKnownDirectSubclasses( classInfo.name() ); + Collection subClasses = bindingContext.getIndex().getKnownDirectSubclasses( classInfo.name() ); // if there are no more subclasses we reached the leaf class. In order to properly resolve generics we // need to resolve the type information using this leaf class diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EntityMappingsMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EntityMappingsMocker.java index 8a5b1158bd..b87d25e62d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EntityMappingsMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EntityMappingsMocker.java @@ -28,6 +28,8 @@ import java.util.ArrayList; import java.util.List; import org.jboss.jandex.Index; +import org.jboss.jandex.IndexView; + import org.jboss.logging.Logger; import org.hibernate.internal.CoreMessageLogger; @@ -58,7 +60,7 @@ public class EntityMappingsMocker { private final IndexBuilder indexBuilder; private final GlobalAnnotations globalAnnotations; - public EntityMappingsMocker(List entityMappingsList, Index index, ServiceRegistry serviceRegistry) { + public EntityMappingsMocker(List entityMappingsList, IndexView index, ServiceRegistry serviceRegistry) { this.entityMappingsList = entityMappingsList; this.indexBuilder = new IndexBuilder( index, serviceRegistry ); this.globalAnnotations = new GlobalAnnotations(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/GlobalAnnotations.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/GlobalAnnotations.java index ca2361f867..d5dbf95c1f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/GlobalAnnotations.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/GlobalAnnotations.java @@ -24,6 +24,7 @@ package org.hibernate.metamodel.internal.source.annotations.xml.mocker; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -89,7 +90,7 @@ class GlobalAnnotations implements JPADotNames { } - void addIndexedAnnotationInstance(List annotationInstanceList) { + void addIndexedAnnotationInstance(Collection annotationInstanceList) { if ( CollectionHelper.isNotEmpty( annotationInstanceList ) ) { indexedAnnotationInstanceList.addAll( annotationInstanceList ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/IndexBuilder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/IndexBuilder.java index be542ac37c..991d0b4017 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/IndexBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/IndexBuilder.java @@ -24,6 +24,7 @@ package org.hibernate.metamodel.internal.source.annotations.xml.mocker; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -33,6 +34,8 @@ import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; import org.jboss.jandex.Index; +import org.jboss.jandex.IndexView; + import org.jboss.logging.Logger; import org.hibernate.AssertionFailure; @@ -55,12 +58,12 @@ public class IndexBuilder { private final Map> subclasses; private final Map> implementors; private final Map classes; - private Index index; + private IndexView index; private final Map>> classInfoAnnotationsMap; private final Map>> indexedClassInfoAnnotationsMap; private final ServiceRegistry serviceRegistry; - IndexBuilder(Index index, ServiceRegistry serviceRegistry) { + IndexBuilder(IndexView index, ServiceRegistry serviceRegistry) { this.index = index; this.serviceRegistry = serviceRegistry; this.annotations = new HashMap>(); @@ -167,9 +170,9 @@ public class IndexBuilder { void collectGlobalConfigurationFromIndex(GlobalAnnotations globalAnnotations) { for ( DotName annName : DefaultConfigurationHelper.GLOBAL_ANNOTATIONS ) { - List annotationInstanceList = index.getAnnotations( annName ); - if ( CollectionHelper.isNotEmpty( annotationInstanceList ) ) { - globalAnnotations.addIndexedAnnotationInstance( annotationInstanceList ); + Collection annotationInstances = index.getAnnotations( annName ); + if ( CollectionHelper.isNotEmpty( annotationInstances ) ) { + globalAnnotations.addIndexedAnnotationInstance( annotationInstances ); } } globalAnnotations.filterIndexedAnnotations(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/AdditionalJaxbRootProducer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/AdditionalJaxbRootProducer.java index 52024ee725..253ee41a96 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/AdditionalJaxbRootProducer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/AdditionalJaxbRootProducer.java @@ -25,7 +25,7 @@ package org.hibernate.metamodel.spi; import java.util.List; -import org.jboss.jandex.IndexResult; +import org.jboss.jandex.IndexView; import org.hibernate.jaxb.spi.JaxbRoot; @@ -44,5 +44,5 @@ public interface AdditionalJaxbRootProducer { * * @return List of additional mappings */ - public List produceRoots(MetadataImplementor metadata, IndexResult jandexIndex); + public List produceRoots(MetadataImplementor metadata, IndexView jandexIndex); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetadataContributor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetadataContributor.java index 945fd1500c..c243ba7d7e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetadataContributor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetadataContributor.java @@ -23,7 +23,7 @@ */ package org.hibernate.metamodel.spi; -import org.jboss.jandex.IndexResult; +import org.jboss.jandex.IndexView; /** * Contract for contributing MetadataSources. This hook occurs just after all processing of @@ -38,5 +38,5 @@ public interface MetadataContributor { * @param metadata The metadata * @param jandexIndex The Jandex index */ - public void contribute(MetadataImplementor metadata, IndexResult jandexIndex); + public void contribute(MetadataImplementor metadata, IndexView jandexIndex); } diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/AssertSourcesTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/AssertSourcesTest.java index c6e925852a..56f094e089 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/AssertSourcesTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/AssertSourcesTest.java @@ -72,7 +72,11 @@ public class AssertSourcesTest extends BaseUnitTestCase { MetadataSources ann = new MetadataSources( serviceRegistry ); ann.addAnnotatedClass( User.class ); - MetadataSourceProcessor annProcessor = new AnnotationMetadataSourceProcessorImpl( buildMetadata( ann ), ann ); + MetadataSourceProcessor annProcessor = new AnnotationMetadataSourceProcessorImpl( + buildMetadata( ann ), + ann, + ann.buildJandexView() + ); testUserEntitySources( annProcessor ); } @@ -179,7 +183,11 @@ public class AssertSourcesTest extends BaseUnitTestCase { ann.addAnnotatedClass( Order.class ); ann.addAnnotatedClass( Order.class ); ann.addAnnotatedClass( Order.OrderPk.class ); - MetadataSourceProcessor annProcessor = new AnnotationMetadataSourceProcessorImpl( buildMetadata( ann ), ann ); + MetadataSourceProcessor annProcessor = new AnnotationMetadataSourceProcessorImpl( + buildMetadata( ann ), + ann, + ann.buildJandexView() + ); testOrderEntitySources( annProcessor ); } @@ -204,7 +212,11 @@ public class AssertSourcesTest extends BaseUnitTestCase { ann.addAnnotatedClass( Order.class ); ann.addAnnotatedClass( Order.class ); ann.addAnnotatedClass( Order.OrderPk.class ); - MetadataSourceProcessor annProcessor = new AnnotationMetadataSourceProcessorImpl( buildMetadata( ann ), ann ); + MetadataSourceProcessor annProcessor = new AnnotationMetadataSourceProcessorImpl( + buildMetadata( ann ), + ann, + ann.buildJandexView() + ); testOrderNonAggregatedEntitySources( annProcessor ); } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/connection/DataSourceInjectionTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/connection/DataSourceInjectionTest.java index 5b30f3fcc5..9f5c7764e7 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/connection/DataSourceInjectionTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/connection/DataSourceInjectionTest.java @@ -22,12 +22,17 @@ */ package org.hibernate.jpa.test.connection; +import javax.persistence.EntityManagerFactory; import java.io.File; -import org.junit.Assert; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.jpa.HibernatePersistenceProvider; +import org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl; + import org.junit.Test; -import org.hibernate.ejb.HibernatePersistence; +import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; + /** * @author Emmanuel Bernard @@ -40,8 +45,12 @@ public class DataSourceInjectionTest { sub.mkdir(); PersistenceUnitInfoImpl info = new PersistenceUnitInfoImpl( sub.toURI().toURL(), new String[]{} ); try { - new HibernatePersistence().createContainerEntityManagerFactory( info, null ); - Assert.fail( "FakeDatasource should have been used" ); + EntityManagerFactory emf = new HibernatePersistenceProvider().createContainerEntityManagerFactory( info, null ); + DatasourceConnectionProviderImpl cp = assertTyping( + DatasourceConnectionProviderImpl.class, + emf.unwrap( SessionFactoryImplementor.class ).getConnectionProvider() + ); + assertTyping( FakeDataSource.class, cp.getDataSource() ); } catch (FakeDataSourceException fde) { //success diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/connection/PersistenceUnitInfoImpl.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/connection/PersistenceUnitInfoImpl.java index 803c1f15fa..fc3827af01 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/connection/PersistenceUnitInfoImpl.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/connection/PersistenceUnitInfoImpl.java @@ -35,7 +35,7 @@ import javax.persistence.spi.PersistenceUnitTransactionType; import javax.sql.DataSource; import org.hibernate.cfg.Environment; -import org.hibernate.ejb.HibernatePersistence; +import org.hibernate.jpa.HibernatePersistenceProvider; import org.hibernate.jpa.test.Distributor; import org.hibernate.jpa.test.Item; import org.hibernate.jpa.test.xml.Light; @@ -60,7 +60,7 @@ public class PersistenceUnitInfoImpl implements PersistenceUnitInfo { } public String getPersistenceProviderClassName() { - return HibernatePersistence.class.getName(); + return HibernatePersistenceProvider.class.getName(); } public DataSource getJtaDataSource() {