Example usage for org.springframework.jdbc.datasource ConnectionHolder released

List of usage examples for org.springframework.jdbc.datasource ConnectionHolder released

Introduction

In this page you can find the example usage for org.springframework.jdbc.datasource ConnectionHolder released.

Prototype

@Override
public void released() 

Source Link

Document

Releases the current Connection held by this ConnectionHolder.

Usage

From source file:org.springframework.jdbc.datasource.DataSourceUtils.java

/**
 * Actually close the given Connection, obtained from the given DataSource.
 * Same as {@link #releaseConnection}, but throwing the original SQLException.
 * <p>Directly accessed by {@link TransactionAwareDataSourceProxy}.
 * @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})//from  w  w  w  .  j a va 2 s .c o  m
 * @throws SQLException if thrown by JDBC methods
 * @see #doGetConnection
 */
public static void doReleaseConnection(@Nullable Connection con, @Nullable DataSource dataSource)
        throws SQLException {
    if (con == null) {
        return;
    }
    if (dataSource != null) {
        ConnectionHolder conHolder = (ConnectionHolder) TransactionSynchronizationManager
                .getResource(dataSource);
        if (conHolder != null && connectionEquals(conHolder, con)) {
            // It's the transactional Connection: Don't close it.
            conHolder.released();
            return;
        }
    }
    logger.debug("Returning JDBC Connection to DataSource");
    doCloseConnection(con, dataSource);
}