Search in sources :

Example 26 with BootstrapServiceRegistryBuilder

use of org.hibernate.boot.registry.BootstrapServiceRegistryBuilder in project bw-calendar-engine by Bedework.

the class SchemaBuilderImpl method execute.

@Override
public void execute(final Properties props, final String outputFile, final boolean export, final String delimiter) throws CalFacadeException {
    try {
        SchemaExport se = new SchemaExport();
        if (delimiter != null) {
            se.setDelimiter(delimiter);
        }
        se.setFormat(true);
        se.setHaltOnError(false);
        se.setOutputFile(outputFile);
        final EnumSet<TargetType> targets = EnumSet.noneOf(TargetType.class);
        if (export) {
            targets.add(TargetType.DATABASE);
        } else {
            targets.add(TargetType.SCRIPT);
        }
        Properties allProps = getConfiguration(props).getProperties();
        final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
        final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder(bsr);
        ssrBuilder.applySettings(allProps);
        se.execute(targets, SchemaExport.Action.BOTH, null, ssrBuilder.getBootstrapServiceRegistry());
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) TargetType(org.hibernate.tool.schema.TargetType) Properties(java.util.Properties) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport)

Example 27 with BootstrapServiceRegistryBuilder

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

the class SingleRegisteredProviderTest method testConnectionsRegistered.

@Test
public void testConnectionsRegistered() {
    final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
    final Collection<Class<? extends ConnectionProvider>> implementors = bsr.getService(StrategySelector.class).getRegisteredStrategyImplementors(ConnectionProvider.class);
    assertThat(implementors.size(), equalTo(0));
    bsr.getService(StrategySelector.class).registerStrategyImplementor(ConnectionProvider.class, "testing", DriverManagerConnectionProviderImpl.class);
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder(bsr).build();
    final ConnectionProvider configuredProvider = ssr.getService(ConnectionProvider.class);
    assertThat(configuredProvider, instanceOf(DriverManagerConnectionProviderImpl.class));
}
Also used : DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl) BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) StrategySelector(org.hibernate.boot.registry.selector.spi.StrategySelector) ConnectionProvider(org.hibernate.engine.jdbc.connections.spi.ConnectionProvider) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 28 with BootstrapServiceRegistryBuilder

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

the class BaseNonConfigCoreFunctionalTestCase method constructStandardServiceRegistryBuilder.

protected final StandardServiceRegistryBuilder constructStandardServiceRegistryBuilder() {
    final BootstrapServiceRegistryBuilder bsrb = new BootstrapServiceRegistryBuilder();
    bsrb.applyClassLoader(getClass().getClassLoader());
    // by default we do not share the BootstrapServiceRegistry nor the StandardServiceRegistry,
    // so we want the BootstrapServiceRegistry to be automatically closed when the
    // StandardServiceRegistry is closed.
    bsrb.enableAutoClose();
    configureBootstrapServiceRegistryBuilder(bsrb);
    final BootstrapServiceRegistry bsr = bsrb.build();
    afterBootstrapServiceRegistryBuilt(bsr);
    final Map settings = new HashMap();
    addSettings(settings);
    final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder(bsr);
    initialize(ssrb);
    ssrb.applySettings(settings);
    configureStandardServiceRegistryBuilder(ssrb);
    return ssrb;
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) HashMap(java.util.HashMap) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) Map(java.util.Map) HashMap(java.util.HashMap)

Example 29 with BootstrapServiceRegistryBuilder

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

the class EntityManagerFactoryBuilderImpl method buildBootstrapServiceRegistry.

/**
 * Builds the {@link BootstrapServiceRegistry} used to eventually build the {@link org.hibernate.boot.registry.StandardServiceRegistryBuilder}; mainly
 * used here during instantiation to define class-loading behavior.
 *
 * @param integrationSettings Any integration settings passed by the EE container or SE application
 *
 * @return The built BootstrapServiceRegistry
 */
private BootstrapServiceRegistry buildBootstrapServiceRegistry(Map integrationSettings, ClassLoader providedClassLoader, ClassLoaderService providedClassLoaderService) {
    final BootstrapServiceRegistryBuilder bsrBuilder = new BootstrapServiceRegistryBuilder();
    final IntegratorProvider integratorProvider = (IntegratorProvider) integrationSettings.get(INTEGRATOR_PROVIDER);
    if (integratorProvider != null) {
        for (Integrator integrator : integratorProvider.getIntegrators()) {
            bsrBuilder.applyIntegrator(integrator);
        }
    }
    final StrategyRegistrationProviderList strategyRegistrationProviderList = (StrategyRegistrationProviderList) integrationSettings.get(STRATEGY_REGISTRATION_PROVIDERS);
    if (strategyRegistrationProviderList != null) {
        for (StrategyRegistrationProvider strategyRegistrationProvider : strategyRegistrationProviderList.getStrategyRegistrationProviders()) {
            bsrBuilder.applyStrategySelectors(strategyRegistrationProvider);
        }
    }
    if (providedClassLoaderService != null) {
        bsrBuilder.applyClassLoaderService(providedClassLoaderService);
    } else {
        if (persistenceUnit.getClassLoader() != null) {
            bsrBuilder.applyClassLoader(persistenceUnit.getClassLoader());
        }
        if (providedClassLoader != null) {
            bsrBuilder.applyClassLoader(providedClassLoader);
        }
        final ClassLoader appClassLoader = (ClassLoader) integrationSettings.get(org.hibernate.cfg.AvailableSettings.APP_CLASSLOADER);
        if (appClassLoader != null) {
            LOG.debugf("Found use of deprecated `%s` setting; use `%s` instead.", org.hibernate.cfg.AvailableSettings.APP_CLASSLOADER, org.hibernate.cfg.AvailableSettings.CLASSLOADERS);
        }
        final Object classLoadersSetting = integrationSettings.get(org.hibernate.cfg.AvailableSettings.CLASSLOADERS);
        if (classLoadersSetting != null) {
            if (java.util.Collection.class.isInstance(classLoadersSetting)) {
                for (ClassLoader classLoader : (java.util.Collection<ClassLoader>) classLoadersSetting) {
                    bsrBuilder.applyClassLoader(classLoader);
                }
            } else if (classLoadersSetting.getClass().isArray()) {
                for (ClassLoader classLoader : (ClassLoader[]) classLoadersSetting) {
                    bsrBuilder.applyClassLoader(classLoader);
                }
            } else if (ClassLoader.class.isInstance(classLoadersSetting)) {
                bsrBuilder.applyClassLoader((ClassLoader) classLoadersSetting);
            }
        }
        // configurationValues not assigned yet, using directly the properties of the PU
        Properties puProperties = persistenceUnit.getProperties();
        if (puProperties != null) {
            final String tcclLookupPrecedence = puProperties.getProperty(org.hibernate.cfg.AvailableSettings.TC_CLASSLOADER);
            if (tcclLookupPrecedence != null) {
                bsrBuilder.applyTcclLookupPrecedence(TcclLookupPrecedence.valueOf(tcclLookupPrecedence.toUpperCase(Locale.ROOT)));
            }
        }
    }
    return bsrBuilder.build();
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StrategyRegistrationProvider(org.hibernate.boot.registry.selector.StrategyRegistrationProvider) BeanValidationIntegrator(org.hibernate.cfg.beanvalidation.BeanValidationIntegrator) Integrator(org.hibernate.integrator.spi.Integrator) Properties(java.util.Properties) IntegratorProvider(org.hibernate.jpa.boot.spi.IntegratorProvider) StrategyRegistrationProviderList(org.hibernate.jpa.boot.spi.StrategyRegistrationProviderList)

Example 30 with BootstrapServiceRegistryBuilder

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

the class NonRegistryManagedExtendedCdiSupportTest method buildSessionFactory.

private SessionFactoryImplementor buildSessionFactory(ExtendedBeanManagerImpl standIn, NonRegistryManagedBeanConsumingIntegrator beanConsumingIntegrator) {
    BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().applyIntegrator(beanConsumingIntegrator).build();
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder(bsr).applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).applySetting(AvailableSettings.CDI_BEAN_MANAGER, standIn).build();
    try {
        return (SessionFactoryImplementor) new MetadataSources(ssr).addAnnotatedClass(TheEntity.class).buildMetadata().getSessionFactoryBuilder().build();
    } catch (Exception e) {
        StandardServiceRegistryBuilder.destroy(ssr);
        throw e;
    }
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) MetadataSources(org.hibernate.boot.MetadataSources) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

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