Search in sources :

Example 11 with MetadataBuilder

use of org.hibernate.boot.MetadataBuilder in project hibernate-orm by hibernate.

the class SchemaValidator method buildMetadata.

private static MetadataImplementor buildMetadata(CommandLineArgs parsedArgs, StandardServiceRegistry serviceRegistry) throws Exception {
    final MetadataSources metadataSources = new MetadataSources(serviceRegistry);
    for (String filename : parsedArgs.hbmXmlFiles) {
        metadataSources.addFile(filename);
    }
    for (String filename : parsedArgs.jarFiles) {
        metadataSources.addJar(new File(filename));
    }
    final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
    final StrategySelector strategySelector = serviceRegistry.getService(StrategySelector.class);
    if (parsedArgs.implicitNamingStrategy != null) {
        metadataBuilder.applyImplicitNamingStrategy(strategySelector.resolveStrategy(ImplicitNamingStrategy.class, parsedArgs.implicitNamingStrategy));
    }
    if (parsedArgs.physicalNamingStrategy != null) {
        metadataBuilder.applyPhysicalNamingStrategy(strategySelector.resolveStrategy(PhysicalNamingStrategy.class, parsedArgs.physicalNamingStrategy));
    }
    return (MetadataImplementor) metadataBuilder.build();
}
Also used : ImplicitNamingStrategy(org.hibernate.boot.model.naming.ImplicitNamingStrategy) MetadataBuilder(org.hibernate.boot.MetadataBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) File(java.io.File) StrategySelector(org.hibernate.boot.registry.selector.spi.StrategySelector) PhysicalNamingStrategy(org.hibernate.boot.model.naming.PhysicalNamingStrategy)

Example 12 with MetadataBuilder

use of org.hibernate.boot.MetadataBuilder in project hibernate-orm by hibernate.

the class BootstrapTest method test_basic_custom_type_register_BasicType_example.

//end::bootstrap-native-PersistenceUnitInfoImpl-example[]
@Test
public void test_basic_custom_type_register_BasicType_example() {
    try {
        //tag::basic-custom-type-register-BasicType-example[]
        ServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().build();
        MetadataSources sources = new MetadataSources(standardRegistry);
        MetadataBuilder metadataBuilder = sources.getMetadataBuilder();
        metadataBuilder.applyBasicType(BitSetType.INSTANCE);
    //end::basic-custom-type-register-BasicType-example[]
    } catch (Exception ignore) {
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataBuilder(org.hibernate.boot.MetadataBuilder) MetadataSources(org.hibernate.boot.MetadataSources) SessionFactoryServiceRegistry(org.hibernate.service.spi.SessionFactoryServiceRegistry) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) Test(org.junit.Test)

Example 13 with MetadataBuilder

use of org.hibernate.boot.MetadataBuilder in project hibernate-orm by hibernate.

the class Configuration method buildSessionFactory.

/**
	 * Create a {@link SessionFactory} using the properties and mappings in this configuration. The
	 * SessionFactory will be immutable, so changes made to this Configuration afterQuery building the
	 * SessionFactory will not affect it.
	 *
	 * @param serviceRegistry The registry of services to be used in creating this session factory.
	 *
	 * @return The built {@link SessionFactory}
	 *
	 * @throws HibernateException usually indicates an invalid configuration or invalid mapping information
	 */
public SessionFactory buildSessionFactory(ServiceRegistry serviceRegistry) throws HibernateException {
    log.debug("Building session factory using provided StandardServiceRegistry");
    final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder((StandardServiceRegistry) serviceRegistry);
    if (implicitNamingStrategy != null) {
        metadataBuilder.applyImplicitNamingStrategy(implicitNamingStrategy);
    }
    if (physicalNamingStrategy != null) {
        metadataBuilder.applyPhysicalNamingStrategy(physicalNamingStrategy);
    }
    if (sharedCacheMode != null) {
        metadataBuilder.applySharedCacheMode(sharedCacheMode);
    }
    if (!typeContributorRegistrations.isEmpty()) {
        for (TypeContributor typeContributor : typeContributorRegistrations) {
            metadataBuilder.applyTypes(typeContributor);
        }
    }
    if (!basicTypes.isEmpty()) {
        for (BasicType basicType : basicTypes) {
            metadataBuilder.applyBasicType(basicType);
        }
    }
    if (sqlFunctions != null) {
        for (Map.Entry<String, SQLFunction> entry : sqlFunctions.entrySet()) {
            metadataBuilder.applySqlFunction(entry.getKey(), entry.getValue());
        }
    }
    if (auxiliaryDatabaseObjectList != null) {
        for (AuxiliaryDatabaseObject auxiliaryDatabaseObject : auxiliaryDatabaseObjectList) {
            metadataBuilder.applyAuxiliaryDatabaseObject(auxiliaryDatabaseObject);
        }
    }
    if (attributeConverterDefinitionsByClass != null) {
        for (AttributeConverterDefinition attributeConverterDefinition : attributeConverterDefinitionsByClass.values()) {
            metadataBuilder.applyAttributeConverter(attributeConverterDefinition);
        }
    }
    final Metadata metadata = metadataBuilder.build();
    final SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
    if (interceptor != null && interceptor != EmptyInterceptor.INSTANCE) {
        sessionFactoryBuilder.applyInterceptor(interceptor);
    }
    if (getSessionFactoryObserver() != null) {
        sessionFactoryBuilder.addSessionFactoryObservers(getSessionFactoryObserver());
    }
    if (getEntityNotFoundDelegate() != null) {
        sessionFactoryBuilder.applyEntityNotFoundDelegate(getEntityNotFoundDelegate());
    }
    if (getEntityTuplizerFactory() != null) {
        sessionFactoryBuilder.applyEntityTuplizerFactory(getEntityTuplizerFactory());
    }
    if (getCurrentTenantIdentifierResolver() != null) {
        sessionFactoryBuilder.applyCurrentTenantIdentifierResolver(getCurrentTenantIdentifierResolver());
    }
    return sessionFactoryBuilder.build();
}
Also used : BasicType(org.hibernate.type.BasicType) MetadataBuilder(org.hibernate.boot.MetadataBuilder) SessionFactoryBuilder(org.hibernate.boot.SessionFactoryBuilder) Metadata(org.hibernate.boot.Metadata) SQLFunction(org.hibernate.dialect.function.SQLFunction) AuxiliaryDatabaseObject(org.hibernate.boot.model.relational.AuxiliaryDatabaseObject) Map(java.util.Map) HashMap(java.util.HashMap) TypeContributor(org.hibernate.boot.model.TypeContributor)

Aggregations

MetadataBuilder (org.hibernate.boot.MetadataBuilder)13 MetadataSources (org.hibernate.boot.MetadataSources)12 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)8 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)7 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)6 File (java.io.File)4 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)4 Test (org.junit.Test)4 Metadata (org.hibernate.boot.Metadata)3 ImplicitNamingStrategy (org.hibernate.boot.model.naming.ImplicitNamingStrategy)3 PhysicalNamingStrategy (org.hibernate.boot.model.naming.PhysicalNamingStrategy)3 StrategySelector (org.hibernate.boot.registry.selector.spi.StrategySelector)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 BuildException (org.apache.tools.ant.BuildException)2 HibernateException (org.hibernate.HibernateException)2 SessionFactoryBuilder (org.hibernate.boot.SessionFactoryBuilder)2 TypeContributor (org.hibernate.boot.model.TypeContributor)2 BootstrapServiceRegistryBuilder (org.hibernate.boot.registry.BootstrapServiceRegistryBuilder)2 ServiceRegistry (org.hibernate.service.ServiceRegistry)2