/** * Close the given Connection, obtained from the given DataSource, * if it is not managed externally (that is, not bound to the thread). * @param con the Connection to close if necessary * (if this is {@code null}, the call will be ignored) * @param dataSource the DataSource that the Connection was obtained from * (may be {@code null}) * @see #getConnection */ public static void releaseConnection(@Nullable Connection con, @Nullable DataSource dataSource) { try { doReleaseConnection(con, dataSource); } catch (SQLException ex) { logger.debug("Could not close JDBC Connection", ex); } catch (Throwable ex) { logger.debug("Unexpected exception on closing JDBC Connection", ex); } }
DataSourceUtils.doReleaseConnection(this.target, this.targetDataSource); this.closed = true; return null; DataSourceUtils.doReleaseConnection(actualTarget, this.targetDataSource);
@Override public void releaseConnection(Connection connection) throws SQLException { if (logger.isDebugEnabled()) { logger.debug("Releasing DataSource ({}) JDBC Connection [{}]", getDatasourceId(), connection); } try { DataSourceUtils.doReleaseConnection(connection, DataSourceHolder.currentDataSource().getNative()); } catch (SQLException e) { logger.error(e.getMessage(), e); try { connection.close(); } catch (Exception e2) { logger.error(e2.getMessage(), e2); } } }
public static final void closeQuietly(DataSource dataSource, Connection conn) { if (conn == null && dataSource == null) { return; } Assert.notNull(dataSource, "dataSource is null but conn is not"); try { logger.debug("releasing connection"); DataSourceUtils.doReleaseConnection(conn, dataSource); } catch (SQLException e) { throw new IllegalStateException(e); } }
public static final void closeQuietly(DataSource dataSource, Connection conn) { if (conn == null && dataSource == null) { return; } Assert.notNull(dataSource, "dataSource is null but conn is not"); try { logger.trace("releasing connection"); DataSourceUtils.doReleaseConnection(conn, dataSource); } catch (SQLException e) { throw new IllegalStateException(e); } }
/** * Close the given Connection, obtained from the given DataSource, * if it is not managed externally (that is, not bound to the thread). * @param con the Connection to close if necessary * (if this is {@code null}, the call will be ignored) * @param dataSource the DataSource that the Connection was obtained from * (may be {@code null}) * @see #getConnection */ public static void releaseConnection(Connection con, DataSource dataSource) { try { doReleaseConnection(con, dataSource); } catch (SQLException ex) { logger.debug("Could not close JDBC Connection", ex); } catch (Throwable ex) { logger.debug("Unexpected exception on closing JDBC Connection", ex); } }
@Override public void releaseConnection(Connection connection, DataSource dataSource, ConnectionType connectionType) throws SQLException { DataSourceUtils.doReleaseConnection(connection, dataSource); LOGGER.debug(() -> "Spring-managed connection released: [" + connection + "]"); }
/** * Close the given Connection, obtained from the given DataSource, * if it is not managed externally (that is, not bound to the thread). * @param con the Connection to close if necessary * (if this is {@code null}, the call will be ignored) * @param dataSource the DataSource that the Connection was obtained from * (may be {@code null}) * @see #getConnection */ public static void releaseConnection(@Nullable Connection con, @Nullable DataSource dataSource) { try { doReleaseConnection(con, dataSource); } catch (SQLException ex) { logger.debug("Could not close JDBC Connection", ex); } catch (Throwable ex) { logger.debug("Unexpected exception on closing JDBC Connection", ex); } }
@Override public void releaseConnection(Connection connection) throws SQLException { if (logger.isDebugEnabled()) { logger.debug("Releasing DataSource ({}) JDBC Connection [{}]", getDatasourceId(), connection); } try { DataSourceUtils.doReleaseConnection(connection, DataSourceHolder.currentDataSource().getNative()); } catch (SQLException e) { logger.error(e.getMessage(), e); try { connection.close(); } catch (Exception e2) { logger.error(e2.getMessage(), e2); } } }
DataSourceUtils.doReleaseConnection(this.target, this.targetDataSource); this.closed = true; return null; DataSourceUtils.doReleaseConnection(actualTarget, this.targetDataSource);
DataSourceUtils.doReleaseConnection(this.target, this.targetDataSource); this.closed = true; return null; DataSourceUtils.doReleaseConnection(actualTarget, this.targetDataSource);
/** * Allows a developer to do a manual release of the connection, * this will cause a new connection to be obtained the next time a method is executed, * anything not yet committed for this connection will be rolled back and lost, * normally if you are using a DataSource which pools connections then you do not * need to worry about this too much, just do it at the end of your work unit * * @return true if the connection was closed */ public boolean closeConnection() { boolean success = false; try { Connection conn = getConnection(); try { conn.rollback(); } catch (Exception e) { // oh well, keep going } DataSourceUtils.doReleaseConnection(conn, getDataSource()); success = true; } catch (CannotGetJdbcConnectionException e) { logWarn("Could not close connection sucessfully: " + e.getMessage()); } catch (SQLException e) { logWarn("Could not close connection sucessfully: " + e.getMessage()); } return success; }
springCon.close(); } else { DataSourceUtils.doReleaseConnection(springCon, dataSource);
springCon.close(); } else { DataSourceUtils.doReleaseConnection(springCon, dataSource);