Search in sources :

Example 21 with BootstrapServiceRegistryBuilder

use of org.hibernate.boot.registry.BootstrapServiceRegistryBuilder in project dropwizard by dropwizard.

the class SessionFactoryFactory method buildSessionFactory.

private SessionFactory buildSessionFactory(HibernateBundle<?> bundle, PooledDataSourceFactory dbConfig, ConnectionProvider connectionProvider, Map<String, String> properties, List<Class<?>> entities) {
    final BootstrapServiceRegistry bootstrapServiceRegistry = configureBootstrapServiceRegistryBuilder(new BootstrapServiceRegistryBuilder()).build();
    final Configuration configuration = new Configuration(bootstrapServiceRegistry);
    configuration.setProperty(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, "managed");
    configuration.setProperty(AvailableSettings.USE_SQL_COMMENTS, Boolean.toString(dbConfig.isAutoCommentsEnabled()));
    configuration.setProperty(AvailableSettings.USE_GET_GENERATED_KEYS, "true");
    configuration.setProperty(AvailableSettings.GENERATE_STATISTICS, "true");
    configuration.setProperty(AvailableSettings.USE_REFLECTION_OPTIMIZER, "true");
    configuration.setProperty(AvailableSettings.ORDER_UPDATES, "true");
    configuration.setProperty(AvailableSettings.ORDER_INSERTS, "true");
    configuration.setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
    configuration.setProperty("jadira.usertype.autoRegisterUserTypes", "true");
    for (Map.Entry<String, String> property : properties.entrySet()) {
        configuration.setProperty(property.getKey(), property.getValue());
    }
    addAnnotatedClasses(configuration, entities);
    bundle.configure(configuration);
    final ServiceRegistry registry = new StandardServiceRegistryBuilder(bootstrapServiceRegistry).addService(ConnectionProvider.class, connectionProvider).applySettings(configuration.getProperties()).build();
    configure(configuration, registry);
    return configuration.buildSessionFactory(registry);
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) Configuration(org.hibernate.cfg.Configuration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) Map(java.util.Map)

Example 22 with BootstrapServiceRegistryBuilder

use of org.hibernate.boot.registry.BootstrapServiceRegistryBuilder in project hibernate-orm by hibernate.

the class DialectFactoryTest method setUp.

@Before
public void setUp() {
    final BootstrapServiceRegistry bootReg = new BootstrapServiceRegistryBuilder().applyClassLoader(DialectFactoryTest.class.getClassLoader()).build();
    registry = new StandardServiceRegistryBuilder(bootReg).build();
    dialectFactory = new DialectFactoryImpl();
    dialectFactory.injectServices((ServiceRegistryImplementor) registry);
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) DialectFactoryImpl(org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) Before(org.junit.Before)

Example 23 with BootstrapServiceRegistryBuilder

use of org.hibernate.boot.registry.BootstrapServiceRegistryBuilder in project hibernate-orm by hibernate.

the class SchemaExport method buildStandardServiceRegistry.

private static StandardServiceRegistry buildStandardServiceRegistry(CommandLineArgs commandLineArgs) throws Exception {
    final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
    final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder(bsr);
    if (commandLineArgs.cfgXmlFile != null) {
        ssrBuilder.configure(commandLineArgs.cfgXmlFile);
    }
    Properties properties = new Properties();
    if (commandLineArgs.propertiesFile != null) {
        properties.load(new FileInputStream(commandLineArgs.propertiesFile));
    }
    ssrBuilder.applySettings(properties);
    return ssrBuilder.build();
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Properties(java.util.Properties) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) FileInputStream(java.io.FileInputStream)

Example 24 with BootstrapServiceRegistryBuilder

use of org.hibernate.boot.registry.BootstrapServiceRegistryBuilder in project hibernate-orm by hibernate.

the class SchemaExportTask method doExecution.

private void doExecution() throws Exception {
    final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
    final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder(bsr);
    final MetadataSources metadataSources = new MetadataSources(bsr);
    if (configurationFile != null) {
        ssrBuilder.configure(configurationFile);
    }
    if (propertiesFile != null) {
        ssrBuilder.loadProperties(propertiesFile);
    }
    ssrBuilder.applySettings(getProject().getProperties());
    for (String fileName : getFiles()) {
        if (fileName.endsWith(".jar")) {
            metadataSources.addJar(new File(fileName));
        } else {
            metadataSources.addFile(fileName);
        }
    }
    ssrBuilder.applySetting(AvailableSettings.HBM2DDL_DELIMITER, delimiter);
    ExportType exportType = ExportType.interpret(drop, create);
    Target output = Target.interpret(!quiet, !text);
    if (output.doScript()) {
        ssrBuilder.applySetting(AvailableSettings.HBM2DDL_SCRIPTS_ACTION, exportType.getAction());
        final Object scriptTarget;
        if (outputFile == null) {
            scriptTarget = new OutputStreamWriter(System.out);
        } else {
            scriptTarget = outputFile;
        }
        if (exportType.doCreate()) {
            ssrBuilder.applySetting(AvailableSettings.HBM2DDL_SCRIPTS_CREATE_TARGET, scriptTarget);
        }
        if (exportType.doDrop()) {
            ssrBuilder.applySetting(AvailableSettings.HBM2DDL_SCRIPTS_DROP_TARGET, scriptTarget);
        }
    }
    if (output.doExport()) {
        ssrBuilder.applySetting(AvailableSettings.HBM2DDL_DATABASE_ACTION, exportType.getAction());
    }
    final StandardServiceRegistryImpl ssr = (StandardServiceRegistryImpl) ssrBuilder.build();
    final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder(ssr);
    ClassLoaderService classLoaderService = bsr.getService(ClassLoaderService.class);
    if (implicitNamingStrategy != null) {
        metadataBuilder.applyImplicitNamingStrategy((ImplicitNamingStrategy) classLoaderService.classForName(implicitNamingStrategy).newInstance());
    }
    if (physicalNamingStrategy != null) {
        metadataBuilder.applyPhysicalNamingStrategy((PhysicalNamingStrategy) classLoaderService.classForName(physicalNamingStrategy).newInstance());
    }
    final MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();
    metadata.validate();
    SchemaManagementToolCoordinator.process(metadata, ssr, ssr.getService(ConfigurationService.class).getSettings(), DelayedDropRegistryNotAvailableImpl.INSTANCE);
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataBuilder(org.hibernate.boot.MetadataBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) StandardServiceRegistryImpl(org.hibernate.boot.registry.internal.StandardServiceRegistryImpl) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 25 with BootstrapServiceRegistryBuilder

use of org.hibernate.boot.registry.BootstrapServiceRegistryBuilder in project wildfly by wildfly.

the class SFSBHibernateSFNaturalId method setupConfig.

public void setupConfig() {
    try {
        final ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(new BootstrapServiceRegistryBuilder().build()).configure("hibernate.cfg.xml").applySetting(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true").applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop").applySetting(AvailableSettings.DATASOURCE, "java:jboss/datasources/ExampleDS").build();
        final Metadata metadata = new MetadataSources(serviceRegistry).buildMetadata();
        sessionFactory = metadata.buildSessionFactory();
    } catch (Throwable ex) {
        throw new RuntimeException("Could not setup config", ex);
    }
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) ServiceRegistry(org.hibernate.service.ServiceRegistry)

Aggregations

BootstrapServiceRegistryBuilder (org.hibernate.boot.registry.BootstrapServiceRegistryBuilder)39 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)34 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)31 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)23 Test (org.junit.Test)21 MetadataSources (org.hibernate.boot.MetadataSources)16 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)12 SeContainer (javax.enterprise.inject.se.SeContainer)8 SeContainerInitializer (javax.enterprise.inject.se.SeContainerInitializer)6 Properties (java.util.Properties)5 Configuration (org.hibernate.cfg.Configuration)5 TheEntity (org.hibernate.test.cdi.events.TheEntity)5 StrategySelector (org.hibernate.boot.registry.selector.spi.StrategySelector)4 Integrator (org.hibernate.integrator.spi.Integrator)4 FileInputStream (java.io.FileInputStream)3 SessionFactory (org.hibernate.SessionFactory)3 RegionFactory (org.hibernate.cache.spi.RegionFactory)3 ServiceRegistry (org.hibernate.service.ServiceRegistry)3 Map (java.util.Map)2 Session (org.hibernate.Session)2