Search in sources :

Example 11 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();
    // 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) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 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();
    bsrBuilder.applyIntegrator(new JpaIntegrator());
    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) Properties(java.util.Properties) StrategyRegistrationProviderList(org.hibernate.jpa.boot.spi.StrategyRegistrationProviderList) StrategyRegistrationProvider(org.hibernate.boot.registry.selector.StrategyRegistrationProvider) JpaIntegrator(org.hibernate.jpa.event.spi.JpaIntegrator) BeanValidationIntegrator(org.hibernate.cfg.beanvalidation.BeanValidationIntegrator) Integrator(org.hibernate.integrator.spi.Integrator) JpaIntegrator(org.hibernate.jpa.event.spi.JpaIntegrator) IntegratorProvider(org.hibernate.jpa.boot.spi.IntegratorProvider)

Example 13 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 14 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 15 with BootstrapServiceRegistryBuilder

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

the class BootstrapTest method test_bootstrap_bootstrap_native_registry_StandardServiceRegistryBuilder_example_2.

@Test
public void test_bootstrap_bootstrap_native_registry_StandardServiceRegistryBuilder_example_2() {
    //tag::bootstrap-bootstrap-native-registry-StandardServiceRegistryBuilder-example[]
    // An example using an explicitly built BootstrapServiceRegistry
    BootstrapServiceRegistry bootstrapRegistry = new BootstrapServiceRegistryBuilder().build();
    StandardServiceRegistryBuilder standardRegistryBuilder = new StandardServiceRegistryBuilder(bootstrapRegistry);
//end::bootstrap-bootstrap-native-registry-StandardServiceRegistryBuilder-example[]
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) Test(org.junit.Test)

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