use of org.hibernate.boot.registry.internal.StandardServiceRegistryImpl in project hibernate-orm by hibernate.
the class DeepCollectionElementTest method testInitialization.
@Test
public void testInitialization() throws Exception {
Configuration configuration = new Configuration();
configuration.addAnnotatedClass(A.class);
configuration.addAnnotatedClass(B.class);
configuration.addAnnotatedClass(C.class);
StandardServiceRegistryImpl serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(configuration.getProperties());
try {
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
sessionFactory.close();
} finally {
serviceRegistry.destroy();
}
}
use of org.hibernate.boot.registry.internal.StandardServiceRegistryImpl 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.internal.StandardServiceRegistryImpl in project hibernate-orm by hibernate.
the class ServiceBootstrappingTest method testBuildWithServiceOverride.
@Test
public void testBuildWithServiceOverride() {
StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings(ConnectionProviderBuilder.getConnectionProviderProperties()).build();
Properties props = ConnectionProviderBuilder.getConnectionProviderProperties();
props.setProperty(Environment.DIALECT, H2Dialect.class.getName());
try {
JdbcServices jdbcServices = serviceRegistry.getService(JdbcServices.class);
assertTrue(jdbcServices.getDialect() instanceof H2Dialect);
ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping(ConnectionProviderJdbcConnectionAccess.class, jdbcServices.getBootstrapJdbcConnectionAccess());
assertTrue(connectionAccess.getConnectionProvider().isUnwrappableAs(DriverManagerConnectionProviderImpl.class));
} finally {
serviceRegistry.destroy();
}
try {
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings(props).addService(ConnectionProvider.class, new UserSuppliedConnectionProviderImpl()).build();
JdbcServices jdbcServices = serviceRegistry.getService(JdbcServices.class);
assertTrue(jdbcServices.getDialect() instanceof H2Dialect);
ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping(ConnectionProviderJdbcConnectionAccess.class, jdbcServices.getBootstrapJdbcConnectionAccess());
assertTrue(connectionAccess.getConnectionProvider().isUnwrappableAs(UserSuppliedConnectionProviderImpl.class));
} finally {
serviceRegistry.destroy();
}
}
use of org.hibernate.boot.registry.internal.StandardServiceRegistryImpl in project hibernate-orm by hibernate.
the class StandardServiceRegistryBuilder method build.
/**
* Build the StandardServiceRegistry.
*
* @return The StandardServiceRegistry.
*/
@SuppressWarnings("unchecked")
public StandardServiceRegistry build() {
applyServiceContributingIntegrators();
applyServiceContributors();
final Map settingsCopy = new HashMap();
settingsCopy.putAll(settings);
settingsCopy.put(org.hibernate.boot.cfgxml.spi.CfgXmlAccessService.LOADED_CONFIG_KEY, aggregatedCfgXml);
Environment.verifyProperties(settingsCopy);
ConfigurationHelper.resolvePlaceHolders(settingsCopy);
return new StandardServiceRegistryImpl(autoCloseRegistry, bootstrapServiceRegistry, initiators, providedServices, settingsCopy);
}
use of org.hibernate.boot.registry.internal.StandardServiceRegistryImpl in project hibernate-orm by hibernate.
the class SQLServerDialectCollationTest method buildSessionFactory.
protected void buildSessionFactory() {
BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry();
StandardServiceRegistryImpl _serviceRegistry = buildServiceRegistry(bootRegistry, constructConfiguration());
try {
try (Connection connection = _serviceRegistry.getService(JdbcServices.class).getBootstrapJdbcConnectionAccess().obtainConnection();
Statement statement = connection.createStatement()) {
connection.setAutoCommit(true);
statement.executeUpdate("DROP DATABASE hibernate_orm_test_collation");
} catch (SQLException e) {
log.debug(e.getMessage());
}
try (Connection connection = _serviceRegistry.getService(JdbcServices.class).getBootstrapJdbcConnectionAccess().obtainConnection();
Statement statement = connection.createStatement()) {
connection.setAutoCommit(true);
statement.executeUpdate("CREATE DATABASE hibernate_orm_test_collation COLLATE Latin1_General_CS_AS");
statement.executeUpdate("ALTER DATABASE [hibernate_orm_test_collation] SET AUTO_CLOSE OFF ");
} catch (SQLException e) {
log.debug(e.getMessage());
}
} finally {
_serviceRegistry.destroy();
}
super.buildSessionFactory();
}
Aggregations