Search in sources :

Example 16 with BootstrapServiceRegistryBuilder

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

the class BootstrapTest method test_bootstrap_bootstrap_native_registry_BootstrapServiceRegistry_example.

@Test
public void test_bootstrap_bootstrap_native_registry_BootstrapServiceRegistry_example() {
    ClassLoader customClassLoader = Thread.currentThread().getContextClassLoader();
    Integrator customIntegrator = new BeanValidationIntegrator();
    //tag::bootstrap-bootstrap-native-registry-BootstrapServiceRegistry-example[]
    BootstrapServiceRegistryBuilder bootstrapRegistryBuilder = new BootstrapServiceRegistryBuilder();
    // add a custom ClassLoader
    bootstrapRegistryBuilder.applyClassLoader(customClassLoader);
    // manually add an Integrator
    bootstrapRegistryBuilder.applyIntegrator(customIntegrator);
    BootstrapServiceRegistry bootstrapRegistry = bootstrapRegistryBuilder.build();
//end::bootstrap-bootstrap-native-registry-BootstrapServiceRegistry-example[]
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) BeanValidationIntegrator(org.hibernate.cfg.beanvalidation.BeanValidationIntegrator) BeanValidationIntegrator(org.hibernate.cfg.beanvalidation.BeanValidationIntegrator) Integrator(org.hibernate.integrator.spi.Integrator) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) Test(org.junit.Test)

Example 17 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 18 with BootstrapServiceRegistryBuilder

use of org.hibernate.boot.registry.BootstrapServiceRegistryBuilder in project spring-framework by spring-projects.

the class LocalSessionFactoryBean method getMetadataSources.

/**
	 * Determine the Hibernate {@link MetadataSources} to use.
	 * <p>Can also be externally called to initialize and pre-populate a {@link MetadataSources}
	 * instance which is then going to be used for {@link SessionFactory} building.
	 * @return the MetadataSources to use (never {@code null})
	 * @since 4.3
	 * @see LocalSessionFactoryBuilder#LocalSessionFactoryBuilder(DataSource, ResourceLoader, MetadataSources)
	 */
public MetadataSources getMetadataSources() {
    this.metadataSourcesAccessed = true;
    if (this.metadataSources == null) {
        BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
        if (this.resourcePatternResolver != null) {
            builder = builder.applyClassLoader(this.resourcePatternResolver.getClassLoader());
        }
        this.metadataSources = new MetadataSources(builder.build());
    }
    return this.metadataSources;
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources)

Example 19 with BootstrapServiceRegistryBuilder

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

the class SFSBHibernateSFNaturalId method setupConfig.

public void setupConfig() {
    // static {
    try {
        // prepare the configuration
        Configuration configuration = new Configuration().setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
        configuration.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
        configuration.setProperty(Environment.DATASOURCE, "java:jboss/datasources/ExampleDS");
        // configuration.configure("hibernate.cfg.xml");
        // fetch the properties
        Properties properties = new Properties();
        properties.putAll(configuration.getProperties());
        Environment.verifyProperties(properties);
        ConfigurationHelper.resolvePlaceHolders(properties);
        // build the serviceregistry
        final BootstrapServiceRegistryBuilder bootstrapbuilder = new BootstrapServiceRegistryBuilder();
        ServiceRegistry serviceRegistry = builder.build();
        // Create the SessionFactory from Configuration
        sessionFactory = configuration.configure("hibernate.cfg.xml").buildSessionFactory(serviceRegistry);
    } catch (Throwable ex) {
        throw new RuntimeException("Could not setup config", ex);
    }
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) Configuration(org.hibernate.cfg.Configuration) ServiceRegistry(org.hibernate.service.ServiceRegistry) Properties(java.util.Properties)

Aggregations

BootstrapServiceRegistryBuilder (org.hibernate.boot.registry.BootstrapServiceRegistryBuilder)19 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)14 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)11 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)6 Test (org.junit.Test)6 Properties (java.util.Properties)5 Configuration (org.hibernate.cfg.Configuration)5 FileInputStream (java.io.FileInputStream)3 SessionFactory (org.hibernate.SessionFactory)3 MetadataSources (org.hibernate.boot.MetadataSources)3 Integrator (org.hibernate.integrator.spi.Integrator)3 Session (org.hibernate.Session)2 MetadataBuilder (org.hibernate.boot.MetadataBuilder)2 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)2 StrategyRegistrationProvider (org.hibernate.boot.registry.selector.StrategyRegistrationProvider)2 BeanValidationIntegrator (org.hibernate.cfg.beanvalidation.BeanValidationIntegrator)2 ServiceRegistry (org.hibernate.service.ServiceRegistry)2 Before (org.junit.Before)2 File (java.io.File)1 OutputStreamWriter (java.io.OutputStreamWriter)1