public void prepare(boolean allowAggressiveRelease) throws SQLException { dialect = ConnectionProviderBuilder.getCorrespondingDialect(); connectionProvider = ConnectionProviderBuilder.buildConnectionProvider( allowAggressiveRelease ); sqlStatementLogger = new SqlStatementLogger( true, false ); Connection jdbcConnection = connectionProvider.getConnection(); try { jdbcEnvironment = new JdbcEnvironmentImpl( jdbcConnection.getMetaData(), dialect ); } finally { try { connectionProvider.closeConnection( jdbcConnection ); } catch (SQLException ignore) { } } this.jdbcConnectionAccess = new JdbcConnectionAccessImpl( connectionProvider ); }
@Override public <T> T unwrap(Class<T> unwrapType) { return connectionProvider.unwrap( unwrapType ); }
@Override public boolean supportsAggressiveRelease() { return connectionProvider.supportsAggressiveRelease(); } }
@Override public Connection getConnection() throws SQLException { return connectionProvider.getConnection(); }
@Override public void releaseConnection(Connection connection) throws SQLException { connectionProvider.closeConnection( connection ); }
@Override public Connection obtainConnection() throws SQLException { return connectionProvider.getConnection(); }
@Override public void releaseConnection(Connection connection) throws SQLException { connectionProvider.closeConnection( connection ); }
@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(); } }
@Override public Connection obtainConnection() throws SQLException { return connectionProvider.getConnection(); }
@Override public void closeConnection(Connection conn) throws SQLException { connectionProvider.closeConnection( conn ); }
ConnectionProvider cp = sfi.getServiceRegistry().getService(ConnectionProvider.class); if (cp != null) { return cp.unwrap(DataSource.class);
@Override public boolean supportsAggressiveRelease() { return connectionProvider.supportsAggressiveRelease(); } }
@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(); } }
public void prepare(boolean needsAutoCommit) throws SQLException { connection = provider.getConnection(); toggleAutoCommit = needsAutoCommit && !connection.getAutoCommit(); if ( toggleAutoCommit ) { try { connection.commit(); } catch( Throwable ignore ) { // might happen with a managed connection } connection.setAutoCommit( true ); } }
public void release() throws SQLException { // we only release the connection if ( connection != null ) { sqlExceptionHelper.logAndClearWarnings( connection ); if ( toggleAutoCommit ) { connection.setAutoCommit( false ); } provider.closeConnection( connection ); connection = null; } } }
ConnectionProvider cp = sfi.getServiceRegistry().getService(ConnectionProvider.class); if (cp != null) { return cp.unwrap(DataSource.class);
@Override public boolean supportsAggressiveRelease() { return connectionProvider.supportsAggressiveRelease(); } }
@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(); } }
@Override public Connection getConnection(String tenantIdentifier) throws SQLException { return selectConnectionProvider( tenantIdentifier ).getConnection(); }
@Override protected void done() throws Throwable { cp.closeConnection( connectionUnderTest ); }