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

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

Introduction

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

Prototype

public int getTimeToLiveInSeconds() 

Source Link

Document

Return the time to live for this object in seconds.

Usage

From source file:org.cfr.capsicum.datasource.DataSourceUtils.java

/**
 * Apply the specified timeout - overridden by the current transaction timeout,
 * if any - to the given JDBC Statement object.
 * @param stmt the JDBC Statement object
 * @param dataSource the DataSource that the Connection was obtained from
 * @param timeout the timeout to apply (or 0 for no timeout outside of a transaction)
 * @throws SQLException if thrown by JDBC methods
 * @see java.sql.Statement#setQueryTimeout
 *//*from w  w  w . j a  v a2 s . co m*/
public static void applyTimeout(Statement stmt, DataSource dataSource, int timeout) throws SQLException {
    Assert.notNull(stmt, "No Statement specified");
    Assert.notNull(dataSource, "No DataSource specified");
    ConnectionHolder holder = (ConnectionHolder) TransactionSynchronizationManager.getResource(dataSource);
    if (holder != null && holder.hasTimeout()) {
        // Remaining transaction timeout overrides specified value.
        stmt.setQueryTimeout(holder.getTimeToLiveInSeconds());
    } else if (timeout > 0) {
        // No current transaction timeout -> apply specified value.
        stmt.setQueryTimeout(timeout);
    }
}

From source file:org.mybatis.spring.transaction.SpringManagedTransaction.java

/**
 * {@inheritDoc}//  ww  w .  ja  v  a  2 s. com
 */
@Override
public Integer getTimeout() throws SQLException {
    ConnectionHolder holder = (ConnectionHolder) TransactionSynchronizationManager.getResource(dataSource);
    if (holder != null && holder.hasTimeout()) {
        return holder.getTimeToLiveInSeconds();
    }
    return null;
}

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

/**
 * Apply the specified timeout - overridden by the current transaction timeout,
 * if any - to the given JDBC Statement object.
 * @param stmt the JDBC Statement object
 * @param dataSource the DataSource that the Connection was obtained from
 * @param timeout the timeout to apply (or 0 for no timeout outside of a transaction)
 * @throws SQLException if thrown by JDBC methods
 * @see java.sql.Statement#setQueryTimeout
 *//*from   w w  w  . j  a v a2s .co m*/
public static void applyTimeout(Statement stmt, @Nullable DataSource dataSource, int timeout)
        throws SQLException {
    Assert.notNull(stmt, "No Statement specified");
    ConnectionHolder holder = null;
    if (dataSource != null) {
        holder = (ConnectionHolder) TransactionSynchronizationManager.getResource(dataSource);
    }
    if (holder != null && holder.hasTimeout()) {
        // Remaining transaction timeout overrides specified value.
        stmt.setQueryTimeout(holder.getTimeToLiveInSeconds());
    } else if (timeout >= 0) {
        // No current transaction timeout -> apply specified value.
        stmt.setQueryTimeout(timeout);
    }
}