use of org.hibernate.engine.jdbc.connections.spi.ConnectionProvider in project hibernate-orm by hibernate.
the class TestExtraPhysicalTableTypes method buildInformationExtractorJdbcDatabaseMetaDataImplTest.
private InformationExtractorJdbcDatabaseMetaDataImplTest buildInformationExtractorJdbcDatabaseMetaDataImplTest() throws SQLException {
Database database = metadata.getDatabase();
final ConnectionProvider connectionProvider = ssr.getService(ConnectionProvider.class);
DatabaseInformation dbInfo = new DatabaseInformationImpl(ssr, database.getJdbcEnvironment(), new DdlTransactionIsolatorTestingImpl(ssr, new JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess(connectionProvider)), database.getDefaultNamespace().getName());
ExtractionContextImpl extractionContext = new ExtractionContextImpl(ssr, database.getJdbcEnvironment(), ssr.getService(JdbcServices.class).getBootstrapJdbcConnectionAccess(), (ExtractionContext.DatabaseObjectAccess) dbInfo, database.getDefaultNamespace().getPhysicalName().getCatalog(), database.getDefaultNamespace().getPhysicalName().getSchema());
return new InformationExtractorJdbcDatabaseMetaDataImplTest(extractionContext);
}
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(properties);
if (Startable.class.isInstance(provider)) {
((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 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(properties);
if (Startable.class.isInstance(provider)) {
((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 testSettingIsolationAsNumeric.
@Test
public void testSettingIsolationAsNumeric() throws Exception {
Properties properties = Environment.getProperties();
augmentConfigurationSettings(properties);
properties.put(AvailableSettings.ISOLATION, Connection.TRANSACTION_SERIALIZABLE);
ConnectionProvider provider = getConnectionProviderUnderTest();
try {
((Configurable) provider).configure(properties);
if (Startable.class.isInstance(provider)) {
((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 jOOQ by jOOQ.
the class JPADatabase method create0.
@SuppressWarnings("serial")
@Override
protected DSLContext create0() {
if (connection == null) {
String packages = getProperties().getProperty("packages");
if (isBlank(packages)) {
packages = "";
log.warn("No packages defined", "It is highly recommended that you provide explicit packages to scan");
}
try {
connection = DriverManager.getConnection("jdbc:h2:mem:jooq-meta-extensions", "sa", "");
MetadataSources metadata = new MetadataSources(new StandardServiceRegistryBuilder().applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect").applySetting("javax.persistence.schema-generation-connection", connection).applySetting(AvailableSettings.CONNECTION_PROVIDER, new ConnectionProvider() {
@SuppressWarnings("rawtypes")
@Override
public boolean isUnwrappableAs(Class unwrapType) {
return false;
}
@Override
public <T> T unwrap(Class<T> unwrapType) {
return null;
}
@Override
public Connection getConnection() {
return connection;
}
@Override
public void closeConnection(Connection conn) throws SQLException {
}
@Override
public boolean supportsAggressiveRelease() {
return true;
}
}).build());
ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true);
scanner.addIncludeFilter(new AnnotationTypeFilter(Entity.class));
// [#5845] Use the correct ClassLoader to load the jpa entity classes defined in the user project
ClassLoader cl = Thread.currentThread().getContextClassLoader();
for (String pkg : packages.split(",")) for (BeanDefinition def : scanner.findCandidateComponents(defaultIfBlank(pkg, "").trim())) metadata.addAnnotatedClass(Class.forName(def.getBeanClassName(), true, cl));
// This seems to be the way to do this in idiomatic Hibernate 5.0 API
// See also: http://stackoverflow.com/q/32178041/521799
// SchemaExport export = new SchemaExport((MetadataImplementor) metadata.buildMetadata(), connection);
// export.create(true, true);
// Hibernate 5.2 broke 5.0 API again. Here's how to do this now:
SchemaExport export = new SchemaExport();
export.create(EnumSet.of(TargetType.DATABASE), metadata.buildMetadata());
} catch (Exception e) {
throw new DataAccessException("Error while exporting schema", e);
}
}
return DSL.using(connection);
}
Aggregations