public void execute() throws BuildException { Configuration configuration = AntHelper.getConfiguration(config, properties); SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) configuration.buildSessionFactory(); ConnectionProvider connectionProvider = sessionFactory.getConnectionProvider(); try { Connection connection = connectionProvider.getConnection(); Statement statement = connection.createStatement(); log("shutting down database"); statement.executeUpdate("SHUTDOWN"); connectionProvider.closeConnection(connection); } catch (SQLException e) { throw new BuildException("could not shut down database", e); } finally { connectionProvider.close(); } }
public void release() throws SQLException { if ( connection!=null ) { JDBCExceptionReporter.logAndClearWarnings(connection); connectionProvider.closeConnection( connection ); connectionProvider.close(); } connection = null; } }
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 ); } }
Connection conn = connections.getConnection(); try { DatabaseMetaData meta = conn.getMetaData(); connections.closeConnection(conn); if ( releaseMode == ConnectionReleaseMode.AFTER_STATEMENT && !connections.supportsAggressiveRelease() ) { log.warn( "Overriding release mode as connection provider does not support 'after_statement'" ); releaseMode = ConnectionReleaseMode.AFTER_TRANSACTION;
connection = connectionProvider.getConnection(); if ( !connection.getAutoCommit() ) { connection.commit(); if (!autoCommitWasEnabled) connection.setAutoCommit(false); if (connection!=null) connection.close(); if (connectionProvider!=null) connectionProvider.close();
public void release() throws SQLException { // we only release the connection if ( connection != null ) { JDBCExceptionReporter.logAndClearWarnings( connection ); if ( toggleAutoCommit ) { connection.setAutoCommit( false ); } provider.closeConnection( connection ); connection = null; } } }
settings.getConnectionProvider().close();
connections = new UserSuppliedConnectionProvider(); connections.configure(properties); return connections;
public void release() throws SQLException { if ( connection != null ) { try { JDBCExceptionReporter.logAndClearWarnings( connection ); connectionProvider.closeConnection( connection ); } finally { connectionProvider.close(); } } connection = null; } }
public void prepare(boolean needsAutoCommit) throws SQLException { connectionProvider = ConnectionProviderFactory.newConnectionProvider( cfgProperties ); connection = connectionProvider.getConnection(); if ( needsAutoCommit && !connection.getAutoCommit() ) { connection.commit(); connection.setAutoCommit( true ); } }
Connection conn = connections.getConnection(); try { DatabaseMetaData meta = conn.getMetaData(); connections.closeConnection(conn); if ( releaseMode == ConnectionReleaseMode.AFTER_STATEMENT && !connections.supportsAggressiveRelease() ) { log.warn( "Overriding release mode as connection provider does not support 'after_statement'" ); releaseMode = ConnectionReleaseMode.AFTER_TRANSACTION;
try { log.info("fetching database metadata"); connection = connectionProvider.getConnection(); if (!connection.getAutoCommit()) { connection.commit(); if (!autoCommitWasEnabled) connection.setAutoCommit(false); if (connection != null) connection.close(); if (connectionProvider != null) connectionProvider.close();
/** * Physically closes the JDBC Connection. */ private void closeConnection() { if ( log.isDebugEnabled() ) { log.debug( "closing JDBC connection [" + batcher.openResourceStatsAsString() + "]" ); } try { if ( !connection.isClosed() ) { JDBCExceptionReporter.logAndClearWarnings( connection ); } factory.getConnectionProvider().closeConnection( connection ); connection = null; } catch (SQLException sqle) { throw JDBCExceptionHelper.convert( factory.getSQLExceptionConverter(), sqle, "Cannot close connection" ); } }
settings.getConnectionProvider().close();
connections.configure(properties); return connections;
@Override public void apply(final Object target, final WireContext wireContext) { final Configuration configuration = (Configuration) target; final Properties cfgProperties = configuration.getProperties(); final Dialect dialect = Dialect.getDialect(cfgProperties); final ConnectionProvider connectionProvider = ConnectionProviderFactory.newConnectionProvider(cfgProperties); try { final Connection connection = connectionProvider.getConnection(); try { final DatabaseMetadata metadata = new DatabaseMetadata(connection, dialect); final String[] updateScript = configuration.generateSchemaUpdateScript(dialect, metadata); if (LOG.isLoggable(Level.FINE)) { LOG.fine("updating db schema"); } executeScript(connection, updateScript); } finally { connectionProvider.closeConnection(connection); } } catch (final SQLException e) { final String message = ExceptionManager.getInstance().getFullMessage("bp_HCD_5"); throw new JDBCException(message, e); } finally { connectionProvider.close(); } }
private void closeConnection(Connection connection) { if (connectionProvider != null) { try { if (connection != null) { JDBCExceptionReporter.logAndClearWarnings(connection); connectionProvider.closeConnection(connection); } } catch (SQLException e) { exceptions.add(e); JDBCExceptionReporter.logExceptions(e); } finally { connectionProvider.close(); connectionProvider = null; } } }
public Connection getConnection() throws SQLException { if ( connection == null ) { connectionProvider = ConnectionProviderFactory.newConnectionProvider( cfgProperties ); connection = connectionProvider.getConnection(); if ( !connection.getAutoCommit() ) { connection.commit(); connection.setAutoCommit( true ); } } return connection; }
public void closeConnection(Connection conn) throws HibernateException { if ( log.isDebugEnabled() ) { log.debug( "closing JDBC connection" + preparedStatementCountsToString() + resultSetCountsToString() ); } try { if ( !conn.isClosed() ) { JDBCExceptionReporter.logAndClearWarnings(conn); } factory.getConnectionProvider().closeConnection(conn); } catch (SQLException sqle) { throw JDBCExceptionHelper.convert( factory.getSQLExceptionConverter(), sqle, "Cannot close connection" ); } }
/** * Allows to shut down the hibernate configuration Closing all pools and connections * * @param context * @throws HibernateException */ public void shutdownHibernate(XWikiContext context) throws HibernateException { Session session = getSession(context); preCloseSession(session); closeSession(session); if (getSessionFactory() != null) { ((SessionFactoryImpl) getSessionFactory()).getConnectionProvider().close(); } }