Search in sources :

Example 1 with BasicTypeRegistry

use of org.hibernate.type.BasicTypeRegistry in project hibernate-orm by hibernate.

the class BasicTypeRegistryTest method testExpanding.

@Test
public void testExpanding() {
    BasicTypeRegistry registry = new BasicTypeRegistry();
    BasicType type = registry.getRegisteredType(SomeNoopType.INSTANCE.getName());
    assertNull(type);
    registry.register(SomeNoopType.INSTANCE);
    type = registry.getRegisteredType(SomeNoopType.INSTANCE.getName());
    assertNotNull(type);
    assertSame(SomeNoopType.INSTANCE, type);
}
Also used : BasicType(org.hibernate.type.BasicType) AbstractSingleColumnStandardBasicType(org.hibernate.type.AbstractSingleColumnStandardBasicType) BasicTypeRegistry(org.hibernate.type.BasicTypeRegistry) Test(org.junit.Test)

Example 2 with BasicTypeRegistry

use of org.hibernate.type.BasicTypeRegistry in project hibernate-orm by hibernate.

the class BasicTypeRegistryTest method testOverriding.

@Test
public void testOverriding() {
    BasicTypeRegistry registry = new BasicTypeRegistry();
    BasicType type = registry.getRegisteredType("uuid-binary");
    assertSame(UUIDBinaryType.INSTANCE, type);
    type = registry.getRegisteredType(UUID.class.getName());
    assertSame(UUIDBinaryType.INSTANCE, type);
    BasicType override = new UUIDCharType() {

        @Override
        protected boolean registerUnderJavaType() {
            return true;
        }
    };
    registry.register(override);
    type = registry.getRegisteredType(UUID.class.getName());
    assertNotSame(UUIDBinaryType.INSTANCE, type);
    assertSame(override, type);
}
Also used : BasicType(org.hibernate.type.BasicType) AbstractSingleColumnStandardBasicType(org.hibernate.type.AbstractSingleColumnStandardBasicType) BasicTypeRegistry(org.hibernate.type.BasicTypeRegistry) UUIDCharType(org.hibernate.type.UUIDCharType) Test(org.junit.Test)

Example 3 with BasicTypeRegistry

use of org.hibernate.type.BasicTypeRegistry in project hibernate-orm by hibernate.

the class BasicTypeRegistryTest method testRegisteringUserTypes.

@Test
public void testRegisteringUserTypes() {
    BasicTypeRegistry registry = new BasicTypeRegistry();
    registry.register(new TotallyIrrelevantUserType(), new String[] { "key" });
    BasicType type = registry.getRegisteredType("key");
    assertNotNull(type);
    assertEquals(CustomType.class, type.getClass());
    assertEquals(TotallyIrrelevantUserType.class, ((CustomType) type).getUserType().getClass());
    registry.register(new TotallyIrrelevantCompositeUserType(), new String[] { "key" });
    type = registry.getRegisteredType("key");
    assertNotNull(type);
    assertEquals(CompositeCustomType.class, type.getClass());
    assertEquals(TotallyIrrelevantCompositeUserType.class, ((CompositeCustomType) type).getUserType().getClass());
    type = registry.getRegisteredType(UUID.class.getName());
    assertSame(UUIDBinaryType.INSTANCE, type);
    registry.register(new TotallyIrrelevantUserType(), new String[] { UUID.class.getName() });
    type = registry.getRegisteredType(UUID.class.getName());
    assertNotSame(UUIDBinaryType.INSTANCE, type);
    assertEquals(CustomType.class, type.getClass());
}
Also used : CustomType(org.hibernate.type.CustomType) CompositeCustomType(org.hibernate.type.CompositeCustomType) BasicType(org.hibernate.type.BasicType) AbstractSingleColumnStandardBasicType(org.hibernate.type.AbstractSingleColumnStandardBasicType) CompositeCustomType(org.hibernate.type.CompositeCustomType) BasicTypeRegistry(org.hibernate.type.BasicTypeRegistry) UUID(java.util.UUID) Test(org.junit.Test)

Example 4 with BasicTypeRegistry

use of org.hibernate.type.BasicTypeRegistry in project hibernate-orm by hibernate.

the class MetadataBuildingProcess method handleTypes.

//	private static JandexInitManager buildJandexInitializer(
//			MetadataBuildingOptions options,
//			ClassLoaderAccess classLoaderAccess) {
//		final boolean autoIndexMembers = ConfigurationHelper.getBoolean(
//				org.hibernate.cfg.AvailableSettings.ENABLE_AUTO_INDEX_MEMBER_TYPES,
//				options.getServiceRegistry().getService( ConfigurationService.class ).getSettings(),
//				false
//		);
//
//		return new JandexInitManager( options.getJandexView(), classLoaderAccess, autoIndexMembers );
//	}
private static BasicTypeRegistry handleTypes(MetadataBuildingOptions options) {
    final ClassLoaderService classLoaderService = options.getServiceRegistry().getService(ClassLoaderService.class);
    // ultimately this needs to change a little bit to account for HHH-7792
    final BasicTypeRegistry basicTypeRegistry = new BasicTypeRegistry();
    final TypeContributions typeContributions = new TypeContributions() {

        @Override
        public void contributeType(org.hibernate.type.BasicType type) {
            basicTypeRegistry.register(type);
        }

        @Override
        public void contributeType(BasicType type, String... keys) {
            basicTypeRegistry.register(type, keys);
        }

        @Override
        public void contributeType(UserType type, String[] keys) {
            basicTypeRegistry.register(type, keys);
        }

        @Override
        public void contributeType(CompositeUserType type, String[] keys) {
            basicTypeRegistry.register(type, keys);
        }
    };
    // add Dialect contributed types
    final Dialect dialect = options.getServiceRegistry().getService(JdbcServices.class).getDialect();
    dialect.contributeTypes(typeContributions, options.getServiceRegistry());
    // add TypeContributor contributed types.
    for (TypeContributor contributor : classLoaderService.loadJavaServices(TypeContributor.class)) {
        contributor.contribute(typeContributions, options.getServiceRegistry());
    }
    // add explicit application registered types
    for (BasicTypeRegistration basicTypeRegistration : options.getBasicTypeRegistrations()) {
        basicTypeRegistry.register(basicTypeRegistration.getBasicType(), basicTypeRegistration.getRegistrationKeys());
    }
    return basicTypeRegistry;
}
Also used : BasicType(org.hibernate.type.BasicType) TypeContributions(org.hibernate.boot.model.TypeContributions) Dialect(org.hibernate.dialect.Dialect) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) BasicTypeRegistry(org.hibernate.type.BasicTypeRegistry) BasicTypeRegistration(org.hibernate.boot.spi.BasicTypeRegistration) CompositeUserType(org.hibernate.usertype.CompositeUserType) UserType(org.hibernate.usertype.UserType) CompositeUserType(org.hibernate.usertype.CompositeUserType) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService) TypeContributor(org.hibernate.boot.model.TypeContributor)

Example 5 with BasicTypeRegistry

use of org.hibernate.type.BasicTypeRegistry 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)

Aggregations

BasicTypeRegistry (org.hibernate.type.BasicTypeRegistry)5 BasicType (org.hibernate.type.BasicType)4 AbstractSingleColumnStandardBasicType (org.hibernate.type.AbstractSingleColumnStandardBasicType)3 Test (org.junit.Test)3 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 UUID (java.util.UUID)1 ClassLoaderAccessImpl (org.hibernate.boot.internal.ClassLoaderAccessImpl)1 InFlightMetadataCollectorImpl (org.hibernate.boot.internal.InFlightMetadataCollectorImpl)1 MetadataBuildingContextRootImpl (org.hibernate.boot.internal.MetadataBuildingContextRootImpl)1 MappingBinder (org.hibernate.boot.jaxb.internal.MappingBinder)1 TypeContributions (org.hibernate.boot.model.TypeContributions)1 TypeContributor (org.hibernate.boot.model.TypeContributor)1 AnnotationMetadataSourceProcessorImpl (org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl)1 EntityHierarchyBuilder (org.hibernate.boot.model.source.internal.hbm.EntityHierarchyBuilder)1 EntityHierarchySourceImpl (org.hibernate.boot.model.source.internal.hbm.EntityHierarchySourceImpl)1 HbmMetadataSourceProcessorImpl (org.hibernate.boot.model.source.internal.hbm.HbmMetadataSourceProcessorImpl)1 MappingDocument (org.hibernate.boot.model.source.internal.hbm.MappingDocument)1 ModelBinder (org.hibernate.boot.model.source.internal.hbm.ModelBinder)1