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 a0fd688dad..e0ba03c5e0 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 @@ -26,7 +26,6 @@ package org.hibernate.metamodel.internal; import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.jboss.logging.Logger; @@ -50,8 +49,12 @@ import org.hibernate.metamodel.MetadataSourceProcessingOrder; import org.hibernate.metamodel.MetadataSources; import org.hibernate.metamodel.SessionFactoryBuilder; import org.hibernate.metamodel.internal.source.AssociationResolver; +import org.hibernate.metamodel.internal.source.Binder; import org.hibernate.metamodel.internal.source.HibernateTypeResolver; import org.hibernate.metamodel.internal.source.IdentifierGeneratorResolver; +import org.hibernate.metamodel.internal.source.annotations.AnnotationMetadataSourceProcessorImpl; +import org.hibernate.metamodel.internal.source.hbm.HbmMetadataSourceProcessorImpl; +import org.hibernate.metamodel.spi.MetadataSourceProcessor; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.FetchProfile; @@ -61,12 +64,11 @@ import org.hibernate.metamodel.spi.binding.TypeDef; import org.hibernate.metamodel.spi.domain.BasicType; import org.hibernate.metamodel.spi.domain.Type; import org.hibernate.metamodel.spi.relational.Database; +import org.hibernate.metamodel.spi.source.EntityHierarchy; +import org.hibernate.metamodel.spi.source.FilterDefSource; import org.hibernate.metamodel.spi.source.MappingDefaults; import org.hibernate.metamodel.spi.source.MetaAttributeContext; import org.hibernate.metamodel.spi.source.MetadataImplementor; -import org.hibernate.metamodel.spi.source.MetadataSourceProcessor; -import org.hibernate.metamodel.internal.source.annotations.AnnotationMetadataSourceProcessorImpl; -import org.hibernate.metamodel.internal.source.hbm.HbmMetadataSourceProcessorImpl; import org.hibernate.metamodel.spi.source.TypeDescriptorSource; import org.hibernate.persister.spi.PersisterClassResolver; import org.hibernate.service.ServiceRegistry; @@ -161,14 +163,15 @@ public class MetadataImpl implements MetadataImplementor, Serializable { ); - final ArrayList processedEntityNames = new ArrayList(); prepare( metadataSourceProcessors, metadataSources ); processTypeDescriptors( metadataSourceProcessors, metadataSources ); + processFilterDefs( metadataSourceProcessors, metadataSources ); + processIdentifierGenerators( metadataSourceProcessors, metadataSources ); + + processMappings( metadataSourceProcessors, metadataSources ); - bindTypeDependentMetadata( metadataSourceProcessors, metadataSources ); - bindMappingMetadata( metadataSourceProcessors, metadataSources, processedEntityNames ); bindMappingDependentMetadata( metadataSourceProcessors, metadataSources ); // todo : remove this by coordinated ordering of entity processing @@ -202,18 +205,51 @@ public class MetadataImpl implements MetadataImplementor, Serializable { } } - private void bindTypeDependentMetadata(MetadataSourceProcessor[] metadataSourceProcessors, MetadataSources metadataSources) { - for ( MetadataSourceProcessor metadataSourceProcessor : metadataSourceProcessors ) { - metadataSourceProcessor.processTypeDependentMetadata( metadataSources ); + + // filter-defs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + private void processFilterDefs( + MetadataSourceProcessor[] metadataSourceProcessors, + MetadataSources metadataSources) { + for ( MetadataSourceProcessor processor : metadataSourceProcessors ) { + for ( FilterDefSource filterDefSource : processor.extractFilterDefSources( metadataSources ) ) { + addFilterDefinition( + new FilterDefinition( + filterDefSource.getName(), + filterDefSource.getCondition(), + null // the params, todo : need to figure out how to handle the type portion + ) + ); + } } } - private void bindMappingMetadata(MetadataSourceProcessor[] metadataSourceProcessors, MetadataSources metadataSources, List processedEntityNames) { - for ( MetadataSourceProcessor metadataSourceProcessor : metadataSourceProcessors ) { - metadataSourceProcessor.processMappingMetadata( metadataSources, processedEntityNames ); + + // identifier generators ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + private void processIdentifierGenerators( + MetadataSourceProcessor[] metadataSourceProcessors, + MetadataSources metadataSources) { + // HHH-7040 + } + + private void processMappings( + MetadataSourceProcessor[] metadataSourceProcessors, + MetadataSources metadataSources) { + final ArrayList processedEntityNames = new ArrayList(); + final Binder binder = new Binder( this, processedEntityNames ); + for ( MetadataSourceProcessor processor : metadataSourceProcessors ) { + for ( EntityHierarchy entityHierarchy : processor.extractEntityHierarchies( metadataSources ) ) { + binder.processEntityHierarchy( entityHierarchy ); + } } } + + + + + private void bindMappingDependentMetadata(MetadataSourceProcessor[] metadataSourceProcessors, MetadataSources metadataSources) { for ( MetadataSourceProcessor metadataSourceProcessor : metadataSourceProcessors ) { metadataSourceProcessor.processMappingDependentMetadata( metadataSources ); 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 2c07adac91..b6850c804b 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 @@ -27,7 +27,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; -import java.util.Set; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.Index; @@ -39,19 +38,17 @@ import org.hibernate.HibernateException; import org.hibernate.internal.jaxb.JaxbRoot; import org.hibernate.internal.jaxb.mapping.orm.JaxbEntityMappings; import org.hibernate.metamodel.MetadataSources; -import org.hibernate.metamodel.internal.source.Binder; import org.hibernate.metamodel.internal.MetadataImpl; -import org.hibernate.metamodel.spi.source.MetadataImplementor; -import org.hibernate.metamodel.spi.source.MetadataSourceProcessor; import org.hibernate.metamodel.internal.source.annotations.global.FetchProfileProcessor; import org.hibernate.metamodel.internal.source.annotations.global.FilterDefProcessor; -import org.hibernate.metamodel.internal.source.annotations.global.IdGeneratorProcessor; import org.hibernate.metamodel.internal.source.annotations.global.QueryProcessor; import org.hibernate.metamodel.internal.source.annotations.global.TableProcessor; -import org.hibernate.metamodel.internal.source.annotations.global.TypeDefProcessor; import org.hibernate.metamodel.internal.source.annotations.xml.PseudoJpaDotNames; import org.hibernate.metamodel.internal.source.annotations.xml.mocker.EntityMappingsMocker; +import org.hibernate.metamodel.spi.MetadataSourceProcessor; import org.hibernate.metamodel.spi.source.EntityHierarchy; +import org.hibernate.metamodel.spi.source.FilterDefSource; +import org.hibernate.metamodel.spi.source.MetadataImplementor; import org.hibernate.metamodel.spi.source.TypeDescriptorSource; import org.hibernate.service.classloading.spi.ClassLoaderService; @@ -138,21 +135,34 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc } @Override - public void processTypeDependentMetadata(MetadataSources sources) { + public Iterable extractFilterDefSources(MetadataSources sources) { assertBindingContextExists(); - IdGeneratorProcessor.bind( bindingContext ); + + List filterDefSources = new ArrayList(); + List annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.FILTER_DEF ); + for ( AnnotationInstance filterDef : annotations ) { + filterDefSources.add( new FilterDefSourceImpl( filterDef ) ); + } + + annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.FILTER_DEFS ); + for ( AnnotationInstance filterDefs : annotations ) { + AnnotationInstance[] filterDefAnnotations = JandexHelper.getValue( + filterDefs, + "value", + AnnotationInstance[].class + ); + for ( AnnotationInstance filterDef : filterDefAnnotations ) { + filterDefSources.add( new FilterDefSourceImpl( filterDef ) ); + } + } + return filterDefSources; } @Override - public void processMappingMetadata(MetadataSources sources, List processedEntityNames) { + public Iterable extractEntityHierarchies(MetadataSources sources) { assertBindingContextExists(); // need to order our annotated entities into an order we can process - Set hierarchies = EntityHierarchyBuilder.createEntityHierarchies( bindingContext ); - - Binder binder = new Binder( bindingContext.getMetadataImplementor(), new ArrayList() ); - for ( EntityHierarchy hierarchy : hierarchies ) { - binder.processEntityHierarchy( hierarchy ); - } + return EntityHierarchyBuilder.createEntityHierarchies( bindingContext ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/HbmMetadataSourceProcessorImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/HbmMetadataSourceProcessorImpl.java index 5935aca331..b5c53876cc 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/HbmMetadataSourceProcessorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/HbmMetadataSourceProcessorImpl.java @@ -29,13 +29,13 @@ import java.util.List; import org.hibernate.internal.jaxb.JaxbRoot; import org.hibernate.internal.jaxb.mapping.hbm.JaxbHibernateMapping; import org.hibernate.metamodel.MetadataSources; -import org.hibernate.metamodel.internal.source.Binder; +import org.hibernate.metamodel.spi.MetadataSourceProcessor; +import org.hibernate.metamodel.spi.source.FilterDefSource; import org.hibernate.metamodel.spi.source.MetadataImplementor; -import org.hibernate.metamodel.spi.source.MetadataSourceProcessor; import org.hibernate.metamodel.spi.source.TypeDescriptorSource; /** - * The {@link org.hibernate.metamodel.spi.source.MetadataSourceProcessor} implementation responsible for processing {@code hbm.xml} sources. + * The {@link org.hibernate.metamodel.spi.MetadataSourceProcessor} implementation responsible for processing {@code hbm.xml} sources. * * @author Steve Ebersole */ @@ -80,18 +80,17 @@ public class HbmMetadataSourceProcessorImpl implements MetadataSourceProcessor { } @Override - public void processTypeDependentMetadata(MetadataSources sources) { + public Iterable extractFilterDefSources(MetadataSources sources) { + final List filterDefSources = new ArrayList(); for ( HibernateMappingProcessor processor : processors ) { - processor.processTypeDependentMetadata(); + processor.collectFilterDefSources( filterDefSources ); } + return filterDefSources; } @Override - public void processMappingMetadata(MetadataSources sources, List processedEntityNames) { - Binder binder = new Binder( metadata, processedEntityNames ); - for ( EntityHierarchyImpl entityHierarchy : entityHierarchies ) { - binder.processEntityHierarchy( entityHierarchy ); - } + public Iterable extractEntityHierarchies(MetadataSources sources) { + return entityHierarchies; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/HibernateMappingProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/HibernateMappingProcessor.java index 43de12bc20..7fad29133a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/HibernateMappingProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/HibernateMappingProcessor.java @@ -23,37 +23,31 @@ */ package org.hibernate.metamodel.internal.source.hbm; -import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; -import org.hibernate.engine.spi.FilterDefinition; import org.hibernate.internal.jaxb.Origin; import org.hibernate.internal.jaxb.mapping.hbm.JaxbFetchProfileElement; import org.hibernate.internal.jaxb.mapping.hbm.JaxbHibernateMapping; -import org.hibernate.internal.jaxb.mapping.hbm.JaxbParamElement; import org.hibernate.internal.jaxb.mapping.hbm.JaxbQueryElement; import org.hibernate.internal.jaxb.mapping.hbm.JaxbSqlQueryElement; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.Value; import org.hibernate.metamodel.spi.binding.FetchProfile; -import org.hibernate.metamodel.spi.binding.TypeDef; import org.hibernate.metamodel.spi.relational.AuxiliaryDatabaseObject; import org.hibernate.metamodel.spi.relational.BasicAuxiliaryDatabaseObjectImpl; +import org.hibernate.metamodel.spi.source.FilterDefSource; import org.hibernate.metamodel.spi.source.MappingException; import org.hibernate.metamodel.spi.source.MetadataImplementor; import org.hibernate.metamodel.spi.source.TypeDescriptorSource; import org.hibernate.service.classloading.spi.ClassLoaderService; import org.hibernate.service.classloading.spi.ClassLoadingException; -import org.hibernate.type.Type; /** * Responsible for processing a {@code } element. Allows processing to be coordinated across * all hbm files in an ordered fashion. The order is essentially the same as defined in - * {@link org.hibernate.metamodel.spi.source.MetadataSourceProcessor} + * {@link org.hibernate.metamodel.spi.MetadataSourceProcessor} * * @author Steve Ebersole */ @@ -73,6 +67,7 @@ public class HibernateMappingProcessor { public HibernateMappingProcessor(MetadataImplementor metadata, MappingDocument mappingDocument) { this.metadata = metadata; this.mappingDocument = mappingDocument; + processDatabaseObjectDefinitions(); } private JaxbHibernateMapping mappingRoot() { @@ -91,10 +86,6 @@ public class HibernateMappingProcessor { return classLoaderService.getValue().classForName( bindingContext().qualifyClassName( name ) ); } - public void processIndependentMetadata() { - processDatabaseObjectDefinitions(); - } - private void processDatabaseObjectDefinitions() { if ( mappingRoot().getDatabaseObject() == null ) { return; @@ -140,53 +131,22 @@ public class HibernateMappingProcessor { return; } - for ( JaxbHibernateMapping.JaxbTypedef typedef : mappingRoot().getTypedef() ) { - typeDescriptorSources.add( new TypeDescriptorSourceImpl( typedef ) ); + for ( JaxbHibernateMapping.JaxbTypedef typeDefElement : mappingRoot().getTypedef() ) { + typeDescriptorSources.add( new TypeDescriptorSourceImpl( typeDefElement ) ); } } - public void processTypeDependentMetadata() { - processFilterDefinitions(); - processIdentifierGenerators(); - } - - private void processFilterDefinitions() { + public void collectFilterDefSources(List filterDefSources) { if ( mappingRoot().getFilterDef() == null ) { return; } - for ( JaxbHibernateMapping.JaxbFilterDef filterDefinition : mappingRoot().getFilterDef() ) { - final String name = filterDefinition.getName(); - final Map parameters = new HashMap(); - String condition = null; - for ( Object o : filterDefinition.getContent() ) { - if ( o instanceof String ) { - // represents the condition - if ( condition != null ) { - // log? - } - condition = (String) o; - } - else if ( o instanceof JaxbHibernateMapping.JaxbFilterDef.JaxbFilterParam ) { - final JaxbHibernateMapping.JaxbFilterDef.JaxbFilterParam paramElement = - JaxbHibernateMapping.JaxbFilterDef.JaxbFilterParam.class.cast( o ); - // todo : should really delay this resolution until later to allow typedef names - parameters.put( - paramElement.getName(), - metadata.getTypeResolver().heuristicType( paramElement.getType() ) - ); - } - else { - throw new MappingException( "Unrecognized nested filter content", origin() ); - } - } - if ( condition == null ) { - condition = filterDefinition.getCondition(); - } - metadata.addFilterDefinition( new FilterDefinition( name, condition, parameters ) ); + for ( JaxbHibernateMapping.JaxbFilterDef filterDefElement : mappingRoot().getFilterDef() ) { + filterDefSources.add( new FilterDefSourceImpl( filterDefElement ) ); } } + private void processIdentifierGenerators() { if ( mappingRoot().getIdentifierGenerator() == null ) { return; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/MetadataSourceProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetadataSourceProcessor.java similarity index 75% rename from hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/MetadataSourceProcessor.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetadataSourceProcessor.java index 978a13b483..96d7ea0134 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/MetadataSourceProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetadataSourceProcessor.java @@ -21,11 +21,12 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.spi.source; - -import java.util.List; +package org.hibernate.metamodel.spi; import org.hibernate.metamodel.MetadataSources; +import org.hibernate.metamodel.spi.source.EntityHierarchy; +import org.hibernate.metamodel.spi.source.FilterDefSource; +import org.hibernate.metamodel.spi.source.TypeDescriptorSource; /** * Handles the processing of metadata sources in a dependency-ordered manner. @@ -47,33 +48,31 @@ public interface MetadataSourceProcessor { * * @return The type descriptor sources. */ - public Iterable extractTypeDescriptorSources(MetadataSources sources); + public Iterable extractTypeDescriptorSources(MetadataSources sources); /** - * Process the parts of the metadata that depend on type information (type definitions) having been processed - * and available. + * Retrieve the sources pertaining to filter defs. * * @param sources The metadata sources. + * + * @return The filter def sources. */ - public void processTypeDependentMetadata(MetadataSources sources); + public Iterable extractFilterDefSources(MetadataSources sources); /** - * Process the mapping (entities, et al) metadata. + * Retrieve the entity hierarchies. * * @param sources The metadata sources. - * @param processedEntityNames Collection of any already processed entity names. * - * @see #processTypeDependentMetadata + * @return The entity hierarchies */ - public void processMappingMetadata(MetadataSources sources, List processedEntityNames); + public Iterable extractEntityHierarchies(MetadataSources sources); /** * Process the parts of the metadata that depend on mapping (entities, et al) information having been * processed and available. * * @param sources The metadata sources. - * - * @see #processMappingMetadata */ public void processMappingDependentMetadata(MetadataSources sources); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/FilterDefSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/FilterDefSource.java index 69815680e3..a9e3bbca91 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/FilterDefSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/FilterDefSource.java @@ -53,8 +53,6 @@ public interface FilterDefSource { * Retrieve parameter sources associated with this filer def. * * @return The parameter sources. Can be null. - * - * @see FilterSource#getParameterSources() */ public Iterable getParameterSources(); }