Example usage for org.springframework.jdbc.datasource DataSourceUtils applyTimeout

List of usage examples for org.springframework.jdbc.datasource DataSourceUtils applyTimeout

Introduction

In this page you can find the example usage for org.springframework.jdbc.datasource DataSourceUtils applyTimeout.

Prototype

public static void applyTimeout(Statement stmt, @Nullable DataSource dataSource, int timeout)
        throws SQLException 

Source Link

Document

Apply the specified timeout - overridden by the current transaction timeout, if any - to the given JDBC Statement object.

Usage

From source file:cc.tooyoung.common.db.JdbcTemplate.java

/**
 * Prepare the given JDBC Statement (or PreparedStatement or CallableStatement),
 * applying statement settings such as fetch size, max rows, and query timeout.
 * @param stmt the JDBC Statement to prepare
 * @throws SQLException if thrown by JDBC API
 * @see #setFetchSize/*from   w w  w.  j  a va  2  s  . com*/
 * @see #setMaxRows
 * @see #setQueryTimeout
 * @see org.springframework.jdbc.datasource.DataSourceUtils#applyTransactionTimeout
 */
protected void applyStatementSettings(DataSource dataSource, Statement stmt) throws SQLException {
    int fetchSize = getFetchSize();
    if (fetchSize > 0) {
        stmt.setFetchSize(fetchSize);
    }
    int maxRows = getMaxRows();
    if (maxRows > 0) {
        stmt.setMaxRows(maxRows);
    }
    DataSourceUtils.applyTimeout(stmt, dataSource, getQueryTimeout());
}

From source file:lib.JdbcTemplate.java

/**
 * Prepare the given JDBC Statement (or PreparedStatement or CallableStatement),
 * applying statement settings such as fetch size, max rows, and query timeout.
 * @param stmt the JDBC Statement to prepare
 * @throws SQLException if thrown by JDBC API
 * @see #setFetchSize//from w  w w .j  a  v a2 s  .  co m
 * @see #setMaxRows
 * @see #setQueryTimeout
 * @see org.springframework.jdbc.datasource.DataSourceUtils#applyTransactionTimeout
 */
protected void applyStatementSettings(Statement stmt) throws SQLException {
    int fetchSize = getFetchSize();
    if (fetchSize >= 0) {
        stmt.setFetchSize(fetchSize);
    }
    int maxRows = getMaxRows();
    if (maxRows >= 0) {
        stmt.setMaxRows(maxRows);
    }
    DataSourceUtils.applyTimeout(stmt, getDataSource(), getQueryTimeout());
}