Search in sources :

Example 31 with BootstrapServiceRegistry

use of org.hibernate.boot.registry.BootstrapServiceRegistry 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 32 with BootstrapServiceRegistry

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

the class CollectionJoinTableNamingTest method testCollectionJoinTableNamingLegacyHbmStrategy.

@Test
@TestForIssue(jiraKey = "HHH-9908")
public void testCollectionJoinTableNamingLegacyHbmStrategy() {
    final MetadataSources metadataSources = new MetadataSources();
    try {
        metadataSources.addAnnotatedClass(Input.class);
        metadataSources.addAnnotatedClass(Ptx.class);
        final Metadata metadata = metadataSources.getMetadataBuilder().applyImplicitNamingStrategy(ImplicitNamingStrategyLegacyHbmImpl.INSTANCE).build();
        Collection inputs1Mapping = metadata.getCollectionBinding(Ptx.class.getName() + ".inputs1");
        assertEquals("ptx_inputs1", inputs1Mapping.getCollectionTable().getName());
        Collection inputs2Mapping = metadata.getCollectionBinding(Ptx.class.getName() + ".inputs2");
        assertEquals("ptx_inputs2", inputs2Mapping.getCollectionTable().getName());
    } finally {
        ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
        if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
            BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
        }
    }
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) Collection(org.hibernate.mapping.Collection) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 33 with BootstrapServiceRegistry

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

the class CollectionJoinTableNamingTest method testCollectionJoinTableNamingBase.

@Test
@TestForIssue(jiraKey = "HHH-9908")
public void testCollectionJoinTableNamingBase() {
    // really the same as the JPA compliant tests; here we just pick up the default ImplicitNamingStrategy
    final MetadataSources metadataSources = new MetadataSources();
    try {
        metadataSources.addAnnotatedClass(Input.class);
        metadataSources.addAnnotatedClass(Ptx.class);
        final Metadata metadata = metadataSources.getMetadataBuilder().build();
        assertSameTableUsed(metadata);
    } finally {
        ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
        if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
            BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
        }
    }
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 34 with BootstrapServiceRegistry

use of org.hibernate.boot.registry.BootstrapServiceRegistry 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 35 with BootstrapServiceRegistry

use of org.hibernate.boot.registry.BootstrapServiceRegistry 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)

Aggregations

BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)47 Test (org.junit.Test)33 BootstrapServiceRegistryBuilder (org.hibernate.boot.registry.BootstrapServiceRegistryBuilder)31 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)30 MetadataSources (org.hibernate.boot.MetadataSources)28 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)21 ServiceRegistry (org.hibernate.service.ServiceRegistry)15 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)13 SeContainer (javax.enterprise.inject.se.SeContainer)8 SeContainerInitializer (javax.enterprise.inject.se.SeContainerInitializer)6 Metadata (org.hibernate.boot.Metadata)5 TheEntity (org.hibernate.test.cdi.events.TheEntity)5 Properties (java.util.Properties)4 MappingException (org.hibernate.MappingException)4 StrategySelector (org.hibernate.boot.registry.selector.spi.StrategySelector)4 TestForIssue (org.hibernate.testing.TestForIssue)4 FileInputStream (java.io.FileInputStream)3 AnnotationException (org.hibernate.AnnotationException)3 RegionFactory (org.hibernate.cache.spi.RegionFactory)3 Configuration (org.hibernate.cfg.Configuration)3