use of org.hibernate.engine.jdbc.connections.spi.ConnectionProvider in project hibernate-orm by hibernate.
the class ProxoolConnectionProviderTest method testPoolsClosed.
@Test
public void testPoolsClosed() {
// zero-length-vararg used as parameter
assertDefinedPools();
StandardServiceRegistry serviceRegistry = buildServiceRegistry("pool-one");
ConnectionProvider providerOne = serviceRegistry.getService(ConnectionProvider.class);
assertDefinedPools("pool-one");
StandardServiceRegistry serviceRegistryTwo = buildServiceRegistry("pool-two");
ConnectionProvider providerTwo = serviceRegistryTwo.getService(ConnectionProvider.class);
assertDefinedPools("pool-one", "pool-two");
StandardServiceRegistryBuilder.destroy(serviceRegistry);
assertDefinedPools("pool-two");
StandardServiceRegistryBuilder.destroy(serviceRegistryTwo);
assertDefinedPools();
}
use of org.hibernate.engine.jdbc.connections.spi.ConnectionProvider in project hibernate-orm by hibernate.
the class BaseTransactionIsolationConfigTest method testSettingIsolationAsName.
@Test
public void testSettingIsolationAsName() throws Exception {
Properties properties = Environment.getProperties();
augmentConfigurationSettings(properties);
properties.put(AvailableSettings.ISOLATION, "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 spring-framework by spring-projects.
the class SessionFactoryUtils method getDataSource.
/**
* Determine the DataSource of the given SessionFactory.
* @param sessionFactory the SessionFactory to check
* @return the DataSource, or {@code null} if none found
* @see ConnectionProvider
*/
public static DataSource getDataSource(SessionFactory sessionFactory) {
Method getProperties = ClassUtils.getMethodIfAvailable(sessionFactory.getClass(), "getProperties");
if (getProperties != null) {
Map<?, ?> props = (Map<?, ?>) ReflectionUtils.invokeMethod(getProperties, sessionFactory);
Object dataSourceValue = props.get(Environment.DATASOURCE);
if (dataSourceValue instanceof DataSource) {
return (DataSource) dataSourceValue;
}
}
if (sessionFactory instanceof SessionFactoryImplementor) {
SessionFactoryImplementor sfi = (SessionFactoryImplementor) sessionFactory;
try {
ConnectionProvider cp = sfi.getServiceRegistry().getService(ConnectionProvider.class);
if (cp != null) {
return cp.unwrap(DataSource.class);
}
} catch (UnknownServiceException ex) {
if (logger.isDebugEnabled()) {
logger.debug("No ConnectionProvider found - cannot determine DataSource for SessionFactory: " + ex);
}
}
}
return null;
}
use of org.hibernate.engine.jdbc.connections.spi.ConnectionProvider in project hibernate-orm by hibernate.
the class FooBarTest method testUserProvidedConnection.
@Test
@RequiresDialect(value = H2Dialect.class, comment = "this is more like a unit test")
public void testUserProvidedConnection() throws Exception {
ConnectionProvider dcp = ConnectionProviderBuilder.buildConnectionProvider();
Session s = sessionFactory().withOptions().connection(dcp.getConnection()).openSession();
Transaction tx = s.beginTransaction();
s.createQuery("from Fo").list();
tx.commit();
Connection c = s.disconnect();
assertTrue(c != null);
s.reconnect(c);
tx = s.beginTransaction();
s.createQuery("from Fo").list();
tx.commit();
c.close();
}
use of org.hibernate.engine.jdbc.connections.spi.ConnectionProvider in project jbosstools-hibernate by jbosstools.
the class MockConnectionProviderTest method testGetConnection.
@Test
public void testGetConnection() throws Exception {
assertNotNull(MockConnectionProvider.CONNECTION);
assertNotNull(MockConnectionProvider.DATABASE_META_DATA);
ConnectionProvider connectionProvider = new MockConnectionProvider();
Connection connection = connectionProvider.getConnection();
assertSame(MockConnectionProvider.CONNECTION, connection);
assertSame(MockConnectionProvider.DATABASE_META_DATA, connection.getMetaData());
}
Aggregations