@Override public void setQueryTimeout(int seconds) throws SQLException { rawStatement.setQueryTimeout(seconds); }
@Override public void setQueryTimeout(int seconds) throws SQLException { rawStatement.setQueryTimeout(seconds); }
/** {@inheritDoc} */ @Override public void setQueryTimeout(int seconds) throws SQLException { delegate.setQueryTimeout(seconds); }
@Override public void beforeExecution(final PreparedStatement stmt, final StatementContext ctx) throws SQLException { stmt.setQueryTimeout(seconds); } };
private void setStatementTimeout(PreparedStatement preparedStatement) throws SQLException { final int remainingTransactionTimeOutPeriod = jdbcCoordinator.determineRemainingTransactionTimeOutPeriod(); if ( remainingTransactionTimeOutPeriod > 0 ) { preparedStatement.setQueryTimeout( remainingTransactionTimeOutPeriod ); } } }
preparedStatement.setQueryTimeout(queryTimeoutSecs);
/** * Test Invalid parameter by giving negative timeout */ @Test public void testInvalidSetQueryTimeout() throws SQLException { try (PreparedStatement stmt = connection.prepareStatement(SYS_VERSION_SQL)) { //Setting negative value int valueToSet = -10; try { stmt.setQueryTimeout(valueToSet); } catch ( final SQLException e) { assertThat( e.getMessage(), containsString( "illegal timeout value") ); } } }
/** * Test setting timeout as zero and executing */ @Test public void testSetQueryTimeoutAsZero() throws SQLException { try (PreparedStatement stmt = connection.prepareStatement(SYS_RANDOM_SQL)) { stmt.setQueryTimeout(0); stmt.executeQuery(); ResultSet rs = stmt.getResultSet(); int rowCount = 0; while (rs.next()) { rs.getBytes(1); rowCount++; } assertEquals(3, rowCount); } }
/** * Test setting timeout that never gets triggered */ @Test public void testNonTriggeredQueryTimeout() throws SQLException { try (PreparedStatement stmt = connection.prepareStatement(SYS_VERSION_SQL)) { stmt.setQueryTimeout(60); stmt.executeQuery(); ResultSet rs = stmt.getResultSet(); int rowCount = 0; while (rs.next()) { rs.getBytes(1); rowCount++; } assertEquals(1, rowCount); } }
/** * Test setting a valid timeout */ @Test public void testValidSetQueryTimeout() throws SQLException { try (PreparedStatement stmt = connection.prepareStatement(SYS_VERSION_SQL)) { //Setting positive value int valueToSet = new Random(20150304).nextInt(59)+1; logger.info("Setting timeout as {} seconds", valueToSet); stmt.setQueryTimeout(valueToSet); assertEquals(valueToSet, stmt.getQueryTimeout()); } }
stmt.setQueryTimeout(defaultQueryTimeout); currentQueryTimeout = defaultQueryTimeout;
verify(this.preparedStatement).setQueryTimeout(queryTimeout.intValue());
verify(ps).setQueryTimeout(timeout - 1); verify(con).commit();
@Test @TestForIssue( jiraKey = "HHH-12075") public void testCreateQuerySetTimeoutHint() { doInHibernate( this::sessionFactory, session -> { Query query = session.createQuery( QUERY ); query.setHint( QueryHints.SPEC_HINT_TIMEOUT, 123000 ); query.executeUpdate(); try { verify( CONNECTION_PROVIDER.getPreparedStatement( QUERY ), times( 1 ) ).setQueryTimeout( 123 ); } catch (SQLException ex) { fail( "should not have thrown exception" ); } } ); }
@Test @TestForIssue( jiraKey = "HHH-12075") public void testCreateQuerySetTimeout() { doInHibernate( this::sessionFactory, session -> { Query query = session.createQuery( QUERY ); query.setTimeout( 123 ); query.executeUpdate(); try { verify( CONNECTION_PROVIDER.getPreparedStatement( QUERY ), times( 1 ) ).setQueryTimeout( 123 ); } catch (SQLException ex) { fail( "should not have thrown exception" ); } } ); }
@Test @TestForIssue( jiraKey = "HHH-12075") public void testCreateSQLQuerySetTimeout() { doInHibernate( this::sessionFactory, session -> { NativeQuery query = session.createSQLQuery( QUERY ); query.setTimeout( 123 ); query.executeUpdate(); try { verify( CONNECTION_PROVIDER.getPreparedStatement( QUERY ), times( 1 ) ).setQueryTimeout( 123 ); } catch (SQLException ex) { fail( "should not have thrown exception" ); } } ); }
@Test @TestForIssue( jiraKey = "HHH-12075") public void testCreateNativeQuerySetTimeoutHint() { doInHibernate( this::sessionFactory, session -> { NativeQuery query = session.createNativeQuery( QUERY ); query.setHint( QueryHints.SPEC_HINT_TIMEOUT, 123000 ); query.executeUpdate(); try { verify( CONNECTION_PROVIDER.getPreparedStatement( QUERY ), times( 1 ) ).setQueryTimeout( 123 ); } catch (SQLException ex) { fail( "should not have thrown exception" ); } } ); }
@Test @TestForIssue( jiraKey = "HHH-12075") public void testCreateSQLQuerySetTimeoutHint() { doInHibernate( this::sessionFactory, session -> { NativeQuery query = session.createSQLQuery( QUERY ); query.setHint( QueryHints.SPEC_HINT_TIMEOUT, 123000 ); query.executeUpdate(); try { verify( CONNECTION_PROVIDER.getPreparedStatement( QUERY ), times( 1 ) ).setQueryTimeout( 123 ); } catch (SQLException ex) { fail( "should not have thrown exception" ); } } ); }
@Test @TestForIssue( jiraKey = "HHH-12075") public void testCreateNativeQuerySetTimeout() { doInHibernate( this::sessionFactory, session -> { NativeQuery query = session.createNativeQuery( QUERY ); query.setTimeout( 123 ); query.executeUpdate(); try { verify( CONNECTION_PROVIDER.getPreparedStatement( QUERY ), times( 1 ) ).setQueryTimeout( 123 ); } catch (SQLException ex) { fail( "should not have thrown exception" ); } } ); }
st.setQueryTimeout( selection.getTimeout() );