Search in sources :

Example 1 with AnnotationMetadataSourceProcessorImpl

use of org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl in project hibernate-orm by hibernate.

the class MetadataBuildingProcess method complete.

/**
	 * Second step of 2-phase for MetadataSources->Metadata process
	 *
	 * @param managedResources The token/memento from 1st phase
	 * @param options The building options
	 *
	 * @return Token/memento representing all known users resources (classes, packages, mapping files, etc).
	 */
public static MetadataImplementor complete(final ManagedResources managedResources, final MetadataBuildingOptions options) {
    final BasicTypeRegistry basicTypeRegistry = handleTypes(options);
    final InFlightMetadataCollectorImpl metadataCollector = new InFlightMetadataCollectorImpl(options, new TypeResolver(basicTypeRegistry, new TypeFactory()));
    for (AttributeConverterDefinition attributeConverterDefinition : managedResources.getAttributeConverterDefinitions()) {
        metadataCollector.addAttributeConverter(attributeConverterDefinition);
    }
    final ClassLoaderService classLoaderService = options.getServiceRegistry().getService(ClassLoaderService.class);
    final ClassLoaderAccess classLoaderAccess = new ClassLoaderAccessImpl(options.getTempClassLoader(), classLoaderService);
    final MetadataBuildingContextRootImpl rootMetadataBuildingContext = new MetadataBuildingContextRootImpl(options, classLoaderAccess, metadataCollector);
    final IndexView jandexView = options.getJandexView();
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Set up the processors and start binding
    //		NOTE : this becomes even more simplified afterQuery we move purely
    // 		to unified model
    final MetadataSourceProcessor processor = new MetadataSourceProcessor() {

        private final HbmMetadataSourceProcessorImpl hbmProcessor = new HbmMetadataSourceProcessorImpl(managedResources, rootMetadataBuildingContext);

        private final AnnotationMetadataSourceProcessorImpl annotationProcessor = new AnnotationMetadataSourceProcessorImpl(managedResources, rootMetadataBuildingContext, jandexView);

        @Override
        public void prepare() {
            hbmProcessor.prepare();
            annotationProcessor.prepare();
        }

        @Override
        public void processTypeDefinitions() {
            hbmProcessor.processTypeDefinitions();
            annotationProcessor.processTypeDefinitions();
        }

        @Override
        public void processQueryRenames() {
            hbmProcessor.processQueryRenames();
            annotationProcessor.processQueryRenames();
        }

        @Override
        public void processNamedQueries() {
            hbmProcessor.processNamedQueries();
            annotationProcessor.processNamedQueries();
        }

        @Override
        public void processAuxiliaryDatabaseObjectDefinitions() {
            hbmProcessor.processAuxiliaryDatabaseObjectDefinitions();
            annotationProcessor.processAuxiliaryDatabaseObjectDefinitions();
        }

        @Override
        public void processIdentifierGenerators() {
            hbmProcessor.processIdentifierGenerators();
            annotationProcessor.processIdentifierGenerators();
        }

        @Override
        public void processFilterDefinitions() {
            hbmProcessor.processFilterDefinitions();
            annotationProcessor.processFilterDefinitions();
        }

        @Override
        public void processFetchProfiles() {
            hbmProcessor.processFetchProfiles();
            annotationProcessor.processFetchProfiles();
        }

        @Override
        public void prepareForEntityHierarchyProcessing() {
            for (MetadataSourceType metadataSourceType : options.getSourceProcessOrdering()) {
                if (metadataSourceType == MetadataSourceType.HBM) {
                    hbmProcessor.prepareForEntityHierarchyProcessing();
                }
                if (metadataSourceType == MetadataSourceType.CLASS) {
                    annotationProcessor.prepareForEntityHierarchyProcessing();
                }
            }
        }

        @Override
        public void processEntityHierarchies(Set<String> processedEntityNames) {
            for (MetadataSourceType metadataSourceType : options.getSourceProcessOrdering()) {
                if (metadataSourceType == MetadataSourceType.HBM) {
                    hbmProcessor.processEntityHierarchies(processedEntityNames);
                }
                if (metadataSourceType == MetadataSourceType.CLASS) {
                    annotationProcessor.processEntityHierarchies(processedEntityNames);
                }
            }
        }

        @Override
        public void postProcessEntityHierarchies() {
            for (MetadataSourceType metadataSourceType : options.getSourceProcessOrdering()) {
                if (metadataSourceType == MetadataSourceType.HBM) {
                    hbmProcessor.postProcessEntityHierarchies();
                }
                if (metadataSourceType == MetadataSourceType.CLASS) {
                    annotationProcessor.postProcessEntityHierarchies();
                }
            }
        }

        @Override
        public void processResultSetMappings() {
            hbmProcessor.processResultSetMappings();
            annotationProcessor.processResultSetMappings();
        }

        @Override
        public void finishUp() {
            hbmProcessor.finishUp();
            annotationProcessor.finishUp();
        }
    };
    processor.prepare();
    processor.processTypeDefinitions();
    processor.processQueryRenames();
    processor.processAuxiliaryDatabaseObjectDefinitions();
    processor.processIdentifierGenerators();
    processor.processFilterDefinitions();
    processor.processFetchProfiles();
    final Set<String> processedEntityNames = new HashSet<String>();
    processor.prepareForEntityHierarchyProcessing();
    processor.processEntityHierarchies(processedEntityNames);
    processor.postProcessEntityHierarchies();
    processor.processResultSetMappings();
    processor.processNamedQueries();
    processor.finishUp();
    for (MetadataContributor contributor : classLoaderService.loadJavaServices(MetadataContributor.class)) {
        log.tracef("Calling MetadataContributor : %s", contributor);
        contributor.contribute(metadataCollector, jandexView);
    }
    metadataCollector.processSecondPasses(rootMetadataBuildingContext);
    Iterable<AdditionalJaxbMappingProducer> producers = classLoaderService.loadJavaServices(AdditionalJaxbMappingProducer.class);
    if (producers != null) {
        final EntityHierarchyBuilder hierarchyBuilder = new EntityHierarchyBuilder();
        //			final MappingBinder mappingBinder = new MappingBinder( true );
        // We need to disable validation here.  It seems Envers is not producing valid (according to schema) XML
        final MappingBinder mappingBinder = new MappingBinder(classLoaderService, false);
        for (AdditionalJaxbMappingProducer producer : producers) {
            log.tracef("Calling AdditionalJaxbMappingProducer : %s", producer);
            Collection<MappingDocument> additionalMappings = producer.produceAdditionalMappings(metadataCollector, jandexView, mappingBinder, rootMetadataBuildingContext);
            for (MappingDocument mappingDocument : additionalMappings) {
                hierarchyBuilder.indexMappingDocument(mappingDocument);
            }
        }
        ModelBinder binder = ModelBinder.prepare(rootMetadataBuildingContext);
        for (EntityHierarchySourceImpl entityHierarchySource : hierarchyBuilder.buildHierarchies()) {
            binder.bindEntityHierarchy(entityHierarchySource);
        }
    }
    return metadataCollector.buildMetadataInstance(rootMetadataBuildingContext);
}
Also used : EntityHierarchySourceImpl(org.hibernate.boot.model.source.internal.hbm.EntityHierarchySourceImpl) HashSet(java.util.HashSet) Set(java.util.Set) TypeResolver(org.hibernate.type.TypeResolver) MappingDocument(org.hibernate.boot.model.source.internal.hbm.MappingDocument) MetadataSourceType(org.hibernate.cfg.MetadataSourceType) ClassLoaderAccessImpl(org.hibernate.boot.internal.ClassLoaderAccessImpl) EntityHierarchyBuilder(org.hibernate.boot.model.source.internal.hbm.EntityHierarchyBuilder) AnnotationMetadataSourceProcessorImpl(org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl) MappingBinder(org.hibernate.boot.jaxb.internal.MappingBinder) HbmMetadataSourceProcessorImpl(org.hibernate.boot.model.source.internal.hbm.HbmMetadataSourceProcessorImpl) InFlightMetadataCollectorImpl(org.hibernate.boot.internal.InFlightMetadataCollectorImpl) HashSet(java.util.HashSet) MetadataSourceProcessor(org.hibernate.boot.model.source.spi.MetadataSourceProcessor) IndexView(org.jboss.jandex.IndexView) MetadataContributor(org.hibernate.boot.spi.MetadataContributor) AdditionalJaxbMappingProducer(org.hibernate.boot.spi.AdditionalJaxbMappingProducer) ClassLoaderAccess(org.hibernate.boot.spi.ClassLoaderAccess) AttributeConverterDefinition(org.hibernate.cfg.AttributeConverterDefinition) BasicTypeRegistry(org.hibernate.type.BasicTypeRegistry) MetadataBuildingContextRootImpl(org.hibernate.boot.internal.MetadataBuildingContextRootImpl) TypeFactory(org.hibernate.type.TypeFactory) ModelBinder(org.hibernate.boot.model.source.internal.hbm.ModelBinder) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 2 with AnnotationMetadataSourceProcessorImpl

use of org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl in project hibernate-orm by hibernate.

the class MetadataBuildingProcess method complete.

/**
 * Second step of 2-phase for MetadataSources->Metadata process
 *
 * @param managedResources The token/memento from 1st phase
 * @param options The building options
 *
 * @return Token/memento representing all known users resources (classes, packages, mapping files, etc).
 */
public static MetadataImplementor complete(final ManagedResources managedResources, final BootstrapContext bootstrapContext, final MetadataBuildingOptions options) {
    final InFlightMetadataCollectorImpl metadataCollector = new InFlightMetadataCollectorImpl(bootstrapContext, options);
    handleTypes(bootstrapContext, options);
    final ClassLoaderService classLoaderService = options.getServiceRegistry().getService(ClassLoaderService.class);
    final MetadataBuildingContextRootImpl rootMetadataBuildingContext = new MetadataBuildingContextRootImpl(bootstrapContext, options, metadataCollector);
    for (AttributeConverterInfo converterInfo : managedResources.getAttributeConverterDefinitions()) {
        metadataCollector.addAttributeConverter(converterInfo.toConverterDescriptor(rootMetadataBuildingContext));
    }
    bootstrapContext.getTypeConfiguration().scope(rootMetadataBuildingContext);
    final IndexView jandexView = bootstrapContext.getJandexView();
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Set up the processors and start binding
    // NOTE : this becomes even more simplified after we move purely
    // to unified model
    final MetadataSourceProcessor processor = new MetadataSourceProcessor() {

        private final HbmMetadataSourceProcessorImpl hbmProcessor = new HbmMetadataSourceProcessorImpl(managedResources, rootMetadataBuildingContext);

        private final AnnotationMetadataSourceProcessorImpl annotationProcessor = new AnnotationMetadataSourceProcessorImpl(managedResources, rootMetadataBuildingContext, jandexView);

        @Override
        public void prepare() {
            hbmProcessor.prepare();
            annotationProcessor.prepare();
        }

        @Override
        public void processTypeDefinitions() {
            hbmProcessor.processTypeDefinitions();
            annotationProcessor.processTypeDefinitions();
        }

        @Override
        public void processQueryRenames() {
            hbmProcessor.processQueryRenames();
            annotationProcessor.processQueryRenames();
        }

        @Override
        public void processNamedQueries() {
            hbmProcessor.processNamedQueries();
            annotationProcessor.processNamedQueries();
        }

        @Override
        public void processAuxiliaryDatabaseObjectDefinitions() {
            hbmProcessor.processAuxiliaryDatabaseObjectDefinitions();
            annotationProcessor.processAuxiliaryDatabaseObjectDefinitions();
        }

        @Override
        public void processIdentifierGenerators() {
            hbmProcessor.processIdentifierGenerators();
            annotationProcessor.processIdentifierGenerators();
        }

        @Override
        public void processFilterDefinitions() {
            hbmProcessor.processFilterDefinitions();
            annotationProcessor.processFilterDefinitions();
        }

        @Override
        public void processFetchProfiles() {
            hbmProcessor.processFetchProfiles();
            annotationProcessor.processFetchProfiles();
        }

        @Override
        public void prepareForEntityHierarchyProcessing() {
            for (MetadataSourceType metadataSourceType : options.getSourceProcessOrdering()) {
                if (metadataSourceType == MetadataSourceType.HBM) {
                    hbmProcessor.prepareForEntityHierarchyProcessing();
                }
                if (metadataSourceType == MetadataSourceType.CLASS) {
                    annotationProcessor.prepareForEntityHierarchyProcessing();
                }
            }
        }

        @Override
        public void processEntityHierarchies(Set<String> processedEntityNames) {
            for (MetadataSourceType metadataSourceType : options.getSourceProcessOrdering()) {
                if (metadataSourceType == MetadataSourceType.HBM) {
                    hbmProcessor.processEntityHierarchies(processedEntityNames);
                }
                if (metadataSourceType == MetadataSourceType.CLASS) {
                    annotationProcessor.processEntityHierarchies(processedEntityNames);
                }
            }
        }

        @Override
        public void postProcessEntityHierarchies() {
            for (MetadataSourceType metadataSourceType : options.getSourceProcessOrdering()) {
                if (metadataSourceType == MetadataSourceType.HBM) {
                    hbmProcessor.postProcessEntityHierarchies();
                }
                if (metadataSourceType == MetadataSourceType.CLASS) {
                    annotationProcessor.postProcessEntityHierarchies();
                }
            }
        }

        @Override
        public void processResultSetMappings() {
            hbmProcessor.processResultSetMappings();
            annotationProcessor.processResultSetMappings();
        }

        @Override
        public void finishUp() {
            hbmProcessor.finishUp();
            annotationProcessor.finishUp();
        }
    };
    processor.prepare();
    processor.processTypeDefinitions();
    processor.processQueryRenames();
    processor.processAuxiliaryDatabaseObjectDefinitions();
    processor.processIdentifierGenerators();
    processor.processFilterDefinitions();
    processor.processFetchProfiles();
    final Set<String> processedEntityNames = new HashSet<>();
    processor.prepareForEntityHierarchyProcessing();
    processor.processEntityHierarchies(processedEntityNames);
    processor.postProcessEntityHierarchies();
    processor.processResultSetMappings();
    processor.processNamedQueries();
    processor.finishUp();
    for (MetadataContributor contributor : classLoaderService.loadJavaServices(MetadataContributor.class)) {
        log.tracef("Calling MetadataContributor : %s", contributor);
        contributor.contribute(metadataCollector, jandexView);
    }
    metadataCollector.processSecondPasses(rootMetadataBuildingContext);
    Iterable<AdditionalJaxbMappingProducer> producers = classLoaderService.loadJavaServices(AdditionalJaxbMappingProducer.class);
    if (producers != null) {
        final EntityHierarchyBuilder hierarchyBuilder = new EntityHierarchyBuilder();
        // final MappingBinder mappingBinder = new MappingBinder( true );
        // We need to disable validation here.  It seems Envers is not producing valid (according to schema) XML
        final MappingBinder mappingBinder = new MappingBinder(classLoaderService, false);
        for (AdditionalJaxbMappingProducer producer : producers) {
            log.tracef("Calling AdditionalJaxbMappingProducer : %s", producer);
            Collection<MappingDocument> additionalMappings = producer.produceAdditionalMappings(metadataCollector, jandexView, mappingBinder, rootMetadataBuildingContext);
            for (MappingDocument mappingDocument : additionalMappings) {
                hierarchyBuilder.indexMappingDocument(mappingDocument);
            }
        }
        ModelBinder binder = ModelBinder.prepare(rootMetadataBuildingContext);
        for (EntityHierarchySourceImpl entityHierarchySource : hierarchyBuilder.buildHierarchies()) {
            binder.bindEntityHierarchy(entityHierarchySource);
        }
    }
    return metadataCollector.buildMetadataInstance(rootMetadataBuildingContext);
}
Also used : MetadataSourceProcessor(org.hibernate.boot.model.source.spi.MetadataSourceProcessor) EntityHierarchySourceImpl(org.hibernate.boot.model.source.internal.hbm.EntityHierarchySourceImpl) HashSet(java.util.HashSet) Set(java.util.Set) AttributeConverterInfo(org.hibernate.boot.AttributeConverterInfo) IndexView(org.jboss.jandex.IndexView) MetadataContributor(org.hibernate.boot.spi.MetadataContributor) MappingDocument(org.hibernate.boot.model.source.internal.hbm.MappingDocument) MetadataSourceType(org.hibernate.cfg.MetadataSourceType) AdditionalJaxbMappingProducer(org.hibernate.boot.spi.AdditionalJaxbMappingProducer) EntityHierarchyBuilder(org.hibernate.boot.model.source.internal.hbm.EntityHierarchyBuilder) AnnotationMetadataSourceProcessorImpl(org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl) MappingBinder(org.hibernate.boot.jaxb.internal.MappingBinder) HbmMetadataSourceProcessorImpl(org.hibernate.boot.model.source.internal.hbm.HbmMetadataSourceProcessorImpl) InFlightMetadataCollectorImpl(org.hibernate.boot.internal.InFlightMetadataCollectorImpl) MetadataBuildingContextRootImpl(org.hibernate.boot.internal.MetadataBuildingContextRootImpl) ModelBinder(org.hibernate.boot.model.source.internal.hbm.ModelBinder) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)2 Set (java.util.Set)2 InFlightMetadataCollectorImpl (org.hibernate.boot.internal.InFlightMetadataCollectorImpl)2 MetadataBuildingContextRootImpl (org.hibernate.boot.internal.MetadataBuildingContextRootImpl)2 MappingBinder (org.hibernate.boot.jaxb.internal.MappingBinder)2 AnnotationMetadataSourceProcessorImpl (org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl)2 EntityHierarchyBuilder (org.hibernate.boot.model.source.internal.hbm.EntityHierarchyBuilder)2 EntityHierarchySourceImpl (org.hibernate.boot.model.source.internal.hbm.EntityHierarchySourceImpl)2 HbmMetadataSourceProcessorImpl (org.hibernate.boot.model.source.internal.hbm.HbmMetadataSourceProcessorImpl)2 MappingDocument (org.hibernate.boot.model.source.internal.hbm.MappingDocument)2 ModelBinder (org.hibernate.boot.model.source.internal.hbm.ModelBinder)2 MetadataSourceProcessor (org.hibernate.boot.model.source.spi.MetadataSourceProcessor)2 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)2 AdditionalJaxbMappingProducer (org.hibernate.boot.spi.AdditionalJaxbMappingProducer)2 MetadataContributor (org.hibernate.boot.spi.MetadataContributor)2 MetadataSourceType (org.hibernate.cfg.MetadataSourceType)2 IndexView (org.jboss.jandex.IndexView)2 AttributeConverterInfo (org.hibernate.boot.AttributeConverterInfo)1 ClassLoaderAccessImpl (org.hibernate.boot.internal.ClassLoaderAccessImpl)1 ClassLoaderAccess (org.hibernate.boot.spi.ClassLoaderAccess)1