use of org.hibernate.engine.jdbc.connections.spi.ConnectionProvider in project hibernate-orm by hibernate.
the class SingleRegisteredProviderTest method testConnectionsRegistered.
@Test
public void testConnectionsRegistered() {
try (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 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 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());
}
String existingUrl = (String) Environment.getProperties().get(AvailableSettings.URL);
if (existingUrl.indexOf('?') == -1) {
existingUrl += "?";
} else {
existingUrl += "&";
}
StandardServiceRegistry ssr2 = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.URL, existingUrl + "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 with 1 increment by 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 BaseTransactionIsolationConfigTest method testSettingIsolationAsNumericString.
@Test
public void testSettingIsolationAsNumericString() throws Exception {
Properties properties = Environment.getProperties();
augmentConfigurationSettings(properties);
properties.put(AvailableSettings.ISOLATION, Integer.toString(Connection.TRANSACTION_SERIALIZABLE));
ConnectionProvider provider = getConnectionProviderUnderTest();
try {
((Configurable) provider).configure(PropertiesHelper.map(properties));
if (provider instanceof Startable) {
((Startable) provider).start();
}
Connection connection = provider.getConnection();
assertEquals(Connection.TRANSACTION_SERIALIZABLE, connection.getTransactionIsolation());
provider.closeConnection(connection);
} finally {
((Stoppable) provider).stop();
}
}
use of org.hibernate.engine.jdbc.connections.spi.ConnectionProvider in project hibernate-orm by hibernate.
the class BaseTransactionIsolationConfigTest method testSettingIsolationAsNameAlt.
@Test
public void testSettingIsolationAsNameAlt() throws Exception {
Properties properties = Environment.getProperties();
augmentConfigurationSettings(properties);
properties.put(AvailableSettings.ISOLATION, "SERIALIZABLE");
ConnectionProvider provider = getConnectionProviderUnderTest();
try {
((Configurable) provider).configure(PropertiesHelper.map(properties));
if (provider instanceof Startable) {
((Startable) provider).start();
}
Connection connection = provider.getConnection();
assertEquals(Connection.TRANSACTION_SERIALIZABLE, connection.getTransactionIsolation());
provider.closeConnection(connection);
} finally {
((Stoppable) provider).stop();
}
}
Aggregations