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);
}
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);
}
}
}
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);
}
}
}
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);
}
}
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));
}
Aggregations