Connection connection = connectionAccess.obtainConnection(); connectionAccess.releaseConnection( connection );
private PhysicalConnectionHandlingMode determineConnectionHandlingMode( PhysicalConnectionHandlingMode connectionHandlingMode, JdbcConnectionAccess jdbcConnectionAccess) { if ( connectionHandlingMode.getReleaseMode() == ConnectionReleaseMode.AFTER_STATEMENT && !jdbcConnectionAccess.supportsAggressiveRelease() ) { return PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION; } return connectionHandlingMode; }
@Override public Connection getIsolatedConnection() { try { return jdbcContext.getJdbcConnectionAccess().obtainConnection(); } catch (SQLException e) { // should never happen throw new SchemaManagementException( "Error accessing user-provided Connection via JdbcConnectionAccessProvidedConnectionImpl", e ); } }
@Override public void cleanup() { if ( jdbcDatabaseMetaData != null ) { jdbcDatabaseMetaData = null; } if ( jdbcConnection != null ) { try { jdbcConnectionAccess.releaseConnection( jdbcConnection ); } catch (SQLException ignore) { } } } }
@Override public Connection getJdbcConnection() { if ( jdbcConnection == null ) { try { jdbcConnection = jdbcConnectionAccess.obtainConnection(); } catch (SQLException e) { throw jdbcEnvironment.getSqlExceptionHelper().convert( e, "Unable to obtain JDBC Connection" ); } } return jdbcConnection; }
@Override public void release() { JdbcConnectionAccess connectionAccess = jdbcContext.getJdbcConnectionAccess(); if( !( connectionAccess instanceof JdbcConnectionAccessProvidedConnectionImpl ) ) { throw new IllegalStateException( "DdlTransactionIsolatorProvidedConnectionImpl should always use a JdbcConnectionAccessProvidedConnectionImpl" ); } try { // While passing the connection to the releaseConnection method might be suitable for other `JdbcConnectionAccess` implementations, // it has no meaning for JdbcConnectionAccessProvidedConnectionImpl because, in this case, the connection is wrapped // and we don't have access to it upon releasing via the DdlTransactionIsolatorProvidedConnectionImpl. connectionAccess.releaseConnection( null ); } catch (SQLException ignore) { LOG.unableToReleaseIsolatedConnection( ignore ); } } }
Connection connection; try { connection = connectionAccess.obtainConnection(); connectionAccess.releaseConnection( connection );
private Connection acquireConnectionIfNeeded() { if ( physicalConnection == null ) { // todo : is this the right place for these observer calls? observer.jdbcConnectionAcquisitionStart(); try { physicalConnection = jdbcConnectionAccess.obtainConnection(); } catch (SQLException e) { throw sqlExceptionHelper.convert( e, "Unable to acquire JDBC Connection" ); } finally { observer.jdbcConnectionAcquisitionEnd( physicalConnection ); } } return physicalConnection; }
@Override public void release() { if ( jdbcConnection != null ) { try { jdbcContext.getJdbcConnectionAccess().releaseConnection( jdbcConnection ); } catch (SQLException e) { throw jdbcContext.getSqlExceptionHelper().convert( e, "Unable to release JDBC Connection used for DDL execution" ); } } } }
private ConnectionReleaseMode determineConnectionReleaseMode( JdbcConnectionAccess jdbcConnectionAccess, boolean isUserSuppliedConnection, ConnectionReleaseMode connectionReleaseMode) { if ( isUserSuppliedConnection ) { return ConnectionReleaseMode.ON_CLOSE; } else if ( connectionReleaseMode == ConnectionReleaseMode.AFTER_STATEMENT && ! jdbcConnectionAccess.supportsAggressiveRelease() ) { LOG.debug( "Connection provider reports to not support aggressive release; overriding" ); return ConnectionReleaseMode.AFTER_TRANSACTION; } else { return connectionReleaseMode; } } @Override
@Override protected void cleanupTest() throws Exception { Connection connection = null; Statement stmnt = null; try { connection = services.getBootstrapJdbcConnectionAccess().obtainConnection(); stmnt = connection.createStatement(); stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" ); } finally { if ( stmnt != null ) { try { stmnt.close(); } catch ( SQLException ignore ) { } } if ( connection != null ) { try { services.getBootstrapJdbcConnectionAccess().releaseConnection( connection ); } catch ( SQLException ignore ) { } } } services.release(); }
try (Connection connection = ssr.getService( JdbcServices.class ) .getBootstrapJdbcConnectionAccess() .obtainConnection(); Statement statement = connection.createStatement()) { connection.setAutoCommit( true );
private void releaseConnection() { if ( physicalConnection == null ) { return; } // todo : is this the right place for these observer calls? observer.jdbcConnectionReleaseStart(); try { if ( !physicalConnection.isClosed() ) { sqlExceptionHelper.logAndClearWarnings( physicalConnection ); } jdbcConnectionAccess.releaseConnection( physicalConnection ); } catch (SQLException e) { throw sqlExceptionHelper.convert( e, "Unable to release JDBC Connection" ); } finally { observer.jdbcConnectionReleaseEnd(); physicalConnection = null; getResourceRegistry().releaseResources(); } }
private PhysicalConnectionHandlingMode determineConnectionHandlingMode( PhysicalConnectionHandlingMode connectionHandlingMode, JdbcConnectionAccess jdbcConnectionAccess) { if ( connectionHandlingMode.getReleaseMode() == ConnectionReleaseMode.AFTER_STATEMENT && !jdbcConnectionAccess.supportsAggressiveRelease() ) { return PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION; } return connectionHandlingMode; }
protected boolean isSerializableIsolationEnforced() throws Exception { JdbcConnectionAccess connectionAccess = sessionFactory().getServiceRegistry().getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess(); Connection conn = null; try { conn = connectionAccess.obtainConnection(); return conn.getTransactionIsolation() >= Connection.TRANSACTION_SERIALIZABLE; } finally { if ( conn != null ) { try { connectionAccess.releaseConnection( conn ); } catch ( Throwable ignore ) { // ignore... } } } }
if ( jdbcConnection == null ) { try { this.jdbcConnection = jdbcContext.getJdbcConnectionAccess().obtainConnection();
@Override public void release() { if ( jdbcConnection != null ) { try { jdbcContext.getJdbcConnectionAccess().releaseConnection( jdbcConnection ); } catch (SQLException e) { throw jdbcContext.getSqlExceptionHelper().convert( e, "Unable to release JDBC Connection used for DDL execution" ); } } if ( suspendedTransaction != null ) { try { jdbcContext.getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().resume( suspendedTransaction ); } catch (Exception e) { throw new HibernateException( "Unable to resume JTA transaction after DDL execution" ); } } } }
@Override protected void prepareTest() throws Exception { services.prepare( true ); Connection connection = null; Statement stmnt = null; try { connection = services.getBootstrapJdbcConnectionAccess().obtainConnection(); stmnt = connection.createStatement(); stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" ); stmnt.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" ); } finally { if ( stmnt != null ) { try { stmnt.close(); } catch ( SQLException ignore ) { } } if ( connection != null ) { try { services.getBootstrapJdbcConnectionAccess().releaseConnection( connection ); } catch ( SQLException ignore ) { } } } }
this.jdbcConnection = jdbcContext.getJdbcConnectionAccess().obtainConnection();
@Override public void cleanup() { if ( jdbcDatabaseMetaData != null ) { jdbcDatabaseMetaData = null; } if ( jdbcConnection != null ) { try { jdbcConnectionAccess.releaseConnection( jdbcConnection ); } catch (SQLException ignore) { } } } }