@Override public void cleanup() { if ( jdbcDatabaseMetaData != null ) { jdbcDatabaseMetaData = null; } if ( jdbcConnection != null ) { try { jdbcConnectionAccess.releaseConnection( jdbcConnection ); } catch (SQLException ignore) { } } } }
@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 ); } } }
connectionAccess.releaseConnection( connection );
@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" ); } } } }
connectionAccess.releaseConnection( connection );
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(); } }
@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(); }
@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 ) { } } } }
jdbcConnectionAccess().releaseConnection( connection );
jdbcConnectionAccess.releaseConnection( connection );
@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" ); } } } }
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... } } } }
private <T> T doTheWork(WorkExecutorVisitable<T> work) { try { // obtain our isolated connection Connection connection = jdbcConnectionAccess().obtainConnection(); try { // do the actual work return work.accept( new WorkExecutor<T>(), connection ); } catch (HibernateException e) { throw e; } catch (Exception e) { throw new HibernateException( "Unable to perform isolated work", e ); } finally { try { // no matter what, release the connection (handle) jdbcConnectionAccess().releaseConnection( connection ); } catch (Throwable ignore) { LOG.unableToReleaseIsolatedConnection( ignore ); } } } catch (SQLException e) { throw sqlExceptionHelper().convert( e, "unable to obtain isolated JDBC connection" ); } }
@Override public void cleanup() { if ( jdbcDatabaseMetaData != null ) { jdbcDatabaseMetaData = null; } if ( jdbcConnection != null ) { try { jdbcConnectionAccess.releaseConnection( jdbcConnection ); } catch (SQLException ignore) { } } } }
@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 ); } } }
@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" ); } } } }
@Override public <T> T delegateWork(WorkExecutorVisitable<T> work, boolean transacted) throws HibernateException { Callable<T> c = () -> { JdbcSessionOwner sessionOwner = owner.getJdbcSessionOwner(); Connection conn = sessionOwner.getJdbcConnectionAccess().obtainConnection(); try { return work.accept(new WorkExecutor<>(), conn); } finally { sessionOwner.getJdbcConnectionAccess().releaseConnection(conn); } }; try { if(transacted) { LOGGER.debug("Performing a query in a nested transaction"); return getTxControl().requiresNew(c); } else { LOGGER.debug("Suspending the current transaction to run a query"); return getTxControl().notSupported(c); } } finally { LOGGER.debug("The previous transaction has been resumed"); } } }
@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" ); } } } }
private void runLiquibaseUpdate() { withServiceRegistry(registry -> { final JdbcServices jdbcServices = registry.getService(JdbcServices.class); final JdbcConnectionAccess connectionAccess = jdbcServices.getBootstrapJdbcConnectionAccess(); try { final Connection connection = connectionAccess.obtainConnection(); try { Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection)); Liquibase liquibase = new liquibase.Liquibase(CrowdSpringLiquibase.MASTER_CHANGELOG, new ClassLoaderResourceAccessor(), database); liquibase.update(new Contexts(), new LabelExpression()); } finally { connectionAccess.releaseConnection(connection); } } catch (SQLException | LiquibaseException e) { throw new RuntimeException(e); } return null; }); }
private <T> T doTheWork(WorkExecutorVisitable<T> work) { try { // obtain our isolated connection Connection connection = jdbcConnectionAccess().obtainConnection(); try { // do the actual work return work.accept( new WorkExecutor<T>(), connection ); } catch (HibernateException e) { throw e; } catch (Exception e) { throw new HibernateException( "Unable to perform isolated work", e ); } finally { try { // no matter what, release the connection (handle) jdbcConnectionAccess().releaseConnection( connection ); } catch (Throwable ignore) { LOG.unableToReleaseIsolatedConnection( ignore ); } } } catch (SQLException e) { throw sqlExceptionHelper().convert( e, "unable to obtain isolated JDBC connection" ); } }