use of org.hibernate.engine.jdbc.connections.spi.ConnectionProvider 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));
}
use of org.hibernate.engine.jdbc.connections.spi.ConnectionProvider in project hibernate-orm by hibernate.
the class PostgreSQLMultipleSchemaSequenceTest method test.
@Test
@TestForIssue(jiraKey = "HHH-5538")
public void test() {
StandardServiceRegistry ssr1 = new StandardServiceRegistryBuilder().build();
final String extraSchemaName = "extra_schema_sequence_validation";
try {
final MetadataImplementor metadata1 = (MetadataImplementor) new MetadataSources(ssr1).addAnnotatedClass(Box.class).buildMetadata();
try {
new SchemaExport().setOutputFile(output.getAbsolutePath()).create(EnumSet.of(TargetType.DATABASE, TargetType.SCRIPT), metadata1);
final ConnectionProvider connectionProvider1 = ssr1.getService(ConnectionProvider.class);
DdlTransactionIsolatorTestingImpl ddlTransactionIsolator1 = new DdlTransactionIsolatorTestingImpl(ssr1, new JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess(connectionProvider1));
try (Statement statement = ddlTransactionIsolator1.getIsolatedConnection().createStatement()) {
statement.execute(String.format("DROP SCHEMA IF EXISTS %s CASCADE", extraSchemaName));
statement.execute(String.format("CREATE SCHEMA %s", extraSchemaName));
try (ResultSet resultSet = statement.executeQuery("SELECT NEXTVAL('SEQ_TEST')")) {
while (resultSet.next()) {
Long sequenceValue = resultSet.getLong(1);
assertEquals(Long.valueOf(1L), sequenceValue);
}
}
} catch (SQLException e) {
fail(e.getMessage());
}
StandardServiceRegistry ssr2 = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.URL, Environment.getProperties().get(AvailableSettings.URL) + "?currentSchema=" + extraSchemaName).build();
try {
final MetadataImplementor metadata2 = (MetadataImplementor) new MetadataSources(ssr2).addAnnotatedClass(Box.class).buildMetadata();
try {
new SchemaExport().setOutputFile(output.getAbsolutePath()).create(EnumSet.of(TargetType.DATABASE, TargetType.SCRIPT), metadata2);
} finally {
final ConnectionProvider connectionProvider2 = ssr2.getService(ConnectionProvider.class);
DdlTransactionIsolatorTestingImpl ddlTransactionIsolator2 = new DdlTransactionIsolatorTestingImpl(ssr2, new JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess(connectionProvider2));
try (Statement statement = ddlTransactionIsolator2.getIsolatedConnection().createStatement()) {
try (ResultSet resultSet = statement.executeQuery("SELECT NEXTVAL('SEQ_TEST')")) {
while (resultSet.next()) {
Long sequenceValue = resultSet.getLong(1);
assertEquals(Long.valueOf(1L), sequenceValue);
}
}
statement.execute(String.format("DROP SCHEMA IF EXISTS %s CASCADE", extraSchemaName));
} catch (SQLException e) {
fail(e.getMessage());
}
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata2);
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr2);
}
} finally {
// clean up
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata1);
}
final List<String> sqlLines = Files.readAllLines(output.toPath(), Charset.defaultCharset());
assertEquals(2, sqlLines.stream().filter(s -> s.equalsIgnoreCase("create sequence SEQ_TEST start 1 increment 1")).count());
} catch (IOException e) {
fail(e.getMessage());
} finally {
StandardServiceRegistryBuilder.destroy(ssr1);
}
}
use of org.hibernate.engine.jdbc.connections.spi.ConnectionProvider in project hibernate-orm by hibernate.
the class SchemaBasedMultiTenancyTest method testUnwrappingConnectionProvider.
@Test
@TestForIssue(jiraKey = "HHH-11651")
public void testUnwrappingConnectionProvider() {
final MultiTenantConnectionProvider multiTenantConnectionProvider = serviceRegistry.getService(MultiTenantConnectionProvider.class);
final ConnectionProvider connectionProvider = multiTenantConnectionProvider.unwrap(ConnectionProvider.class);
assertThat(connectionProvider, is(notNullValue()));
}
use of org.hibernate.engine.jdbc.connections.spi.ConnectionProvider in project dropwizard by dropwizard.
the class SessionFactoryFactory method build.
public SessionFactory build(HibernateBundle<?> bundle, Environment environment, PooledDataSourceFactory dbConfig, ManagedDataSource dataSource, List<Class<?>> entities) {
final ConnectionProvider provider = buildConnectionProvider(dataSource, dbConfig.getProperties());
final SessionFactory factory = buildSessionFactory(bundle, dbConfig, provider, dbConfig.getProperties(), entities);
final SessionFactoryManager managedFactory = new SessionFactoryManager(factory, dataSource);
environment.lifecycle().manage(managedFactory);
return factory;
}
Aggregations