@Override public void execute(final Statement statement) throws SQLException { statement.setQueryTimeout(seconds); } });
@Override public void setQueryTimeout(int seconds) throws SQLException { targetStatement.setQueryTimeout(seconds); }
@Override public void setQueryTimeout(int seconds) throws SQLException { statement.setQueryTimeout(seconds); }
public boolean isValidConnection(final Connection c, String validateQuery, int validationQueryTimeout) throws Exception { if (c.isClosed()) { return false; } Statement stmt = null; try { stmt = c.createStatement(); if (validationQueryTimeout > 0) { stmt.setQueryTimeout(validationQueryTimeout); } stmt.execute(validateQuery); return true; } catch (SQLException e) { throw e; } finally { JdbcUtils.close(stmt); } }
/** * 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 */ 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); } }
@Override public Object call() throws Exception { stmt.setQueryTimeout(-1); return null; } },
@Override public boolean isValidConnection(Connection conn, String query, int validationQueryTimeout) throws Exception { if (query == null || query.length() == 0) { return true; } Statement stmt = null; ResultSet rs = null; try { stmt = conn.createStatement(); if (validationQueryTimeout > 0) { stmt.setQueryTimeout(validationQueryTimeout); } rs = stmt.executeQuery(query); return true; } finally { JdbcUtils.close(rs); JdbcUtils.close(stmt); } }
@Override public void run() throws Exception { stmt.setQueryTimeout(timeout); } });
@Override public void run() throws Exception { stmt.setQueryTimeout(10); } });
@Override public void setQueryTimeout(int seconds) throws SQLException { checkOpen(); try { stmt.setQueryTimeout(seconds); } catch (Throwable t) { throw checkException(t); } }
void initStatement(DruidPooledConnection conn, Statement stmt) throws SQLException { boolean transaction = !conn.getConnectionHolder().underlyingAutoCommit; int queryTimeout = transaction ? getTransactionQueryTimeout() : getQueryTimeout(); if (queryTimeout > 0) { stmt.setQueryTimeout(queryTimeout); } }
@Override public void statement_setQueryTimeout(StatementProxy statement, int seconds) throws SQLException { if (this.pos < filterSize) { nextFilter().statement_setQueryTimeout(this, statement, seconds); return; } statement.getRawObject().setQueryTimeout(seconds); }
try { stmt = conn.createStatement(); stmt.setQueryTimeout(queryTimeout); rs = stmt.executeQuery(validateQuery); return true;
try { stmt = conn.createStatement(); stmt.setQueryTimeout(queryTimeout); rs = stmt.executeQuery(validateQuery); return true;
/** * Trying to set zero timeout. Zero timeout means no timeout, so no exception is expected. * * @throws Exception If failed. */ @Test public void testSettingZeroQueryTimeout() throws Exception { stmt.setQueryTimeout(0); stmt.executeQuery("select sleep_func(1000);"); }
Statement createStatement() throws SQLException { Statement stmnt = getDatabaseConnection().getConnection().createStatement(); if (getOpts().timeout > -1) { stmnt.setQueryTimeout(getOpts().timeout); } if (signalHandler != null) { signalHandler.setStatement(stmnt); } return stmnt; }
/** * Setting timeout that is greater than query execution time. <code>SQLTimeoutException</code> is expected. * * @throws Exception If failed. */ @Test public void testQueryTimeout() throws Exception { stmt.setQueryTimeout(2); GridTestUtils.assertThrows(log, () -> { stmt.executeQuery("select sleep_func(10) from Integer;"); return null; }, SQLTimeoutException.class, "The query was cancelled while executing."); }
/** * Setting timeout that is greater than update query execution time. * <code>SQLTimeoutException</code> is expected. * * @throws Exception If failed. */ @Test public void testExecuteUpdateTimeout() throws Exception { stmt.setQueryTimeout(1); GridTestUtils.assertThrows(log, () -> stmt.executeUpdate("update Integer set _val=1 where _key > sleep_func(10)"), SQLTimeoutException.class, "The query was cancelled while executing."); }
/** * Trying to set negative timeout. <code>SQLException</> with message "Invalid timeout value." is expected. */ @Test public void testSettingNegativeQueryTimeout() { GridTestUtils.assertThrows(log, () -> { stmt.setQueryTimeout(-1); return null; }, SQLException.class, "Invalid timeout value."); }
protected void afterCreateStatement(Statement stat, DaoStatement st) throws SQLException { if (st.getContext().getFetchSize() != 0) stat.setFetchSize(st.getContext().getFetchSize()); if (st.getContext().getQueryTimeout() > 0) stat.setQueryTimeout(st.getContext().getQueryTimeout()); } }