Java Code Examples for java.sql.CallableStatement#setQueryTimeout()
The following examples show how to use
java.sql.CallableStatement#setQueryTimeout() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueryTimeOutDUnit.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public void testQueryTimeOutStoredProc_1() throws Exception { startVMs(1, 2); Connection cxn = TestUtil.getConnection() ; Statement stmt = cxn.createStatement(); // create a procedure stmt.execute("CREATE PROCEDURE myProc1 " + "(IN timOutOnCallableStmt INTEGER, " + " OUT count INTEGER)" + "LANGUAGE JAVA PARAMETER STYLE JAVA " + "READS SQL DATA " + "DYNAMIC RESULT SETS 2 " + "EXTERNAL NAME '" + QueryTimeOutDUnit.class.getName() + ".myProc1'"); stmt.execute("create table MyTable(x int, y int) partition by column(x)"); stmt.execute("insert into MyTable values (1, 1), (2, 2), (3, 3), " + "(4, 4), (5, 5), (6, 6), (7, 7)"); int timOutOnCallableStmt = 1; // seconds // introduce an artificial delay in sproc to timeout the callable stmt CallableStatement callableStmt = cxn // first param to myProc1- timeOut to be set on callable stmt // CALL myProc(1, ?) ON TABLE MyTable .prepareCall("{CALL myProc1(" + timOutOnCallableStmt + ", ?) ON TABLE MyTable}"); callableStmt.registerOutParameter(1, Types.INTEGER); callableStmt.setQueryTimeout(timOutOnCallableStmt); addExpectedException(new int[] { 1 }, new int[] { 1, 2 }, SQLException.class); try { callableStmt.execute(); fail("This test should have thrown exception " + "due to query timeout (exception state XCL52)"); } catch (SQLException se) { if (!se.getSQLState().equals("XCL52")) { throw se; } } finally { removeExpectedException(new int[] { 1 }, new int[] { 1, 2, 3 }, SQLException.class); } // process the result // boolean moreResults = true; // ResultSet rs = null; // do { // rs = callableStmt.getResultSet(); // while (rs.next()); // rs.close(); // moreResults = callableStmt.getMoreResults(); // } while (moreResults); }
Example 2
Source File: QueryTimeOutDUnit.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public void testQueryTimeOutStoredProc_2() throws Exception { startVMs(1, 2); Connection cxn = TestUtil.getConnection() ; Statement stmt = cxn.createStatement(); // create a procedure stmt.execute("CREATE PROCEDURE myProc2 " + "(IN timOutOnCallableStmt INTEGER, " + " OUT count INTEGER)" + "LANGUAGE JAVA PARAMETER STYLE JAVA " + "READS SQL DATA " + "DYNAMIC RESULT SETS 2 " + "EXTERNAL NAME '" + QueryTimeOutDUnit.class.getName() + ".myProc2'"); stmt.execute("create table MyTable(x int, y int) partition by column(x)"); stmt.execute("insert into MyTable values (1, 1), (2, 2), (3, 3), " + "(4, 4), (5, 5), (6, 6), (7, 7)"); // set a large timeout on outer callable stmt so that it does not timeout int timOutOnCallableStmt = 10; // seconds CallableStatement callableStmt = cxn // first param to myProc2- timeOut to be set on callable stmt // CALL myProc2(10, ?) ON TABLE MyTable .prepareCall("{CALL myProc2(" + timOutOnCallableStmt + ", ?) ON TABLE MyTable}"); callableStmt.registerOutParameter(1, Types.INTEGER); callableStmt.setQueryTimeout(timOutOnCallableStmt); // suspend the execution to allow query get timed out CacheSerializableRunnable csr = new CacheSerializableRunnable( "_testTimeOut_") { @Override public void run2() { GemFireXDQueryObserver old = GemFireXDQueryObserverHolder .setInstance(new GemFireXDQueryObserverAdapter() { @Override public void onGetNextRowCoreOfBulkTableScan( com.pivotal.gemfirexd.internal.iapi.sql.ResultSet resultSet) { try { Thread.sleep(1500); } catch (InterruptedException e) { } } }); } }; // clientExecute(1, csr); serverExecute(1, csr); serverExecute(2, csr); addExpectedException(new int[] { 1 }, new int[] { 1, 2 }, SQLException.class); try { callableStmt.execute(); fail("This test should have thrown exception " + "due to query timeout (exception state XCL52)"); } catch (SQLException se) { if (!se.getSQLState().equals("XCL52")) { throw se; } assertEquals(10, callableStmt.getQueryTimeout()); } finally { removeExpectedException(new int[] { 1 }, new int[] { 1, 2 }, SQLException.class); } }
Example 3
Source File: QueryTimeOutDUnit.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public void testQueryTimeOutStoredProc_1() throws Exception { startVMs(1, 2); Connection cxn = TestUtil.getConnection() ; Statement stmt = cxn.createStatement(); // create a procedure stmt.execute("CREATE PROCEDURE myProc1 " + "(IN timOutOnCallableStmt INTEGER, " + " OUT count INTEGER)" + "LANGUAGE JAVA PARAMETER STYLE JAVA " + "READS SQL DATA " + "DYNAMIC RESULT SETS 2 " + "EXTERNAL NAME '" + QueryTimeOutDUnit.class.getName() + ".myProc1'"); stmt.execute("create table MyTable(x int, y int) partition by column(x)"); stmt.execute("insert into MyTable values (1, 1), (2, 2), (3, 3), " + "(4, 4), (5, 5), (6, 6), (7, 7)"); int timOutOnCallableStmt = 1; // seconds // introduce an artificial delay in sproc to timeout the callable stmt CallableStatement callableStmt = cxn // first param to myProc1- timeOut to be set on callable stmt // CALL myProc(1, ?) ON TABLE MyTable .prepareCall("{CALL myProc1(" + timOutOnCallableStmt + ", ?) ON TABLE MyTable}"); callableStmt.registerOutParameter(1, Types.INTEGER); callableStmt.setQueryTimeout(timOutOnCallableStmt); addExpectedException(new int[] { 1 }, new int[] { 1, 2 }, SQLException.class); try { callableStmt.execute(); fail("This test should have thrown exception " + "due to query timeout (exception state XCL52)"); } catch (SQLException se) { if (!se.getSQLState().equals("XCL52")) { throw se; } } finally { removeExpectedException(new int[] { 1 }, new int[] { 1, 2, 3 }, SQLException.class); } // process the result // boolean moreResults = true; // ResultSet rs = null; // do { // rs = callableStmt.getResultSet(); // while (rs.next()); // rs.close(); // moreResults = callableStmt.getMoreResults(); // } while (moreResults); }
Example 4
Source File: QueryTimeOutDUnit.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public void testQueryTimeOutStoredProc_2() throws Exception { startVMs(1, 2); Connection cxn = TestUtil.getConnection() ; Statement stmt = cxn.createStatement(); // create a procedure stmt.execute("CREATE PROCEDURE myProc2 " + "(IN timOutOnCallableStmt INTEGER, " + " OUT count INTEGER)" + "LANGUAGE JAVA PARAMETER STYLE JAVA " + "READS SQL DATA " + "DYNAMIC RESULT SETS 2 " + "EXTERNAL NAME '" + QueryTimeOutDUnit.class.getName() + ".myProc2'"); stmt.execute("create table MyTable(x int, y int) partition by column(x)"); stmt.execute("insert into MyTable values (1, 1), (2, 2), (3, 3), " + "(4, 4), (5, 5), (6, 6), (7, 7)"); // set a large timeout on outer callable stmt so that it does not timeout int timOutOnCallableStmt = 10; // seconds CallableStatement callableStmt = cxn // first param to myProc2- timeOut to be set on callable stmt // CALL myProc2(10, ?) ON TABLE MyTable .prepareCall("{CALL myProc2(" + timOutOnCallableStmt + ", ?) ON TABLE MyTable}"); callableStmt.registerOutParameter(1, Types.INTEGER); callableStmt.setQueryTimeout(timOutOnCallableStmt); // suspend the execution to allow query get timed out CacheSerializableRunnable csr = new CacheSerializableRunnable( "_testTimeOut_") { @Override public void run2() { GemFireXDQueryObserver old = GemFireXDQueryObserverHolder .setInstance(new GemFireXDQueryObserverAdapter() { @Override public void onGetNextRowCoreOfBulkTableScan( com.pivotal.gemfirexd.internal.iapi.sql.ResultSet resultSet) { try { Thread.sleep(1500); } catch (InterruptedException e) { } } }); } }; // clientExecute(1, csr); serverExecute(1, csr); serverExecute(2, csr); addExpectedException(new int[] { 1 }, new int[] { 1, 2 }, SQLException.class); try { callableStmt.execute(); fail("This test should have thrown exception " + "due to query timeout (exception state XCL52)"); } catch (SQLException se) { if (!se.getSQLState().equals("XCL52")) { throw se; } assertEquals(10, callableStmt.getQueryTimeout()); } finally { removeExpectedException(new int[] { 1 }, new int[] { 1, 2 }, SQLException.class); } }
Example 5
Source File: SWCallableStatementTest.java From skywalking with Apache License 2.0 | 4 votes |
@Test public void testCallableStatementConfig() throws SQLException { CallableStatement callableStatement = swConnection.prepareCall("INSERT INTO test VALUES( ? , ?)", 1, 1); callableStatement.setInt(1, 1); callableStatement.setString(2, "a"); callableStatement.getUpdateCount(); callableStatement.setFetchDirection(1); callableStatement.getFetchDirection(); callableStatement.getResultSetConcurrency(); callableStatement.getResultSetType(); callableStatement.isClosed(); callableStatement.setPoolable(false); callableStatement.isPoolable(); callableStatement.getWarnings(); callableStatement.clearWarnings(); callableStatement.setCursorName("test"); callableStatement.setMaxFieldSize(11); callableStatement.getMaxFieldSize(); callableStatement.setMaxRows(10); callableStatement.getMaxRows(); callableStatement.getParameterMetaData(); callableStatement.setEscapeProcessing(true); callableStatement.setFetchSize(1); callableStatement.getFetchSize(); callableStatement.setQueryTimeout(1); callableStatement.getQueryTimeout(); Connection connection = callableStatement.getConnection(); callableStatement.execute(); callableStatement.getMoreResults(); callableStatement.getMoreResults(1); callableStatement.getResultSetHoldability(); callableStatement.getMetaData(); callableStatement.getResultSet(); callableStatement.close(); verify(mysqlCallableStatement).getUpdateCount(); verify(mysqlCallableStatement).getMoreResults(); verify(mysqlCallableStatement).setFetchDirection(anyInt()); verify(mysqlCallableStatement).getFetchDirection(); verify(mysqlCallableStatement).getResultSetType(); verify(mysqlCallableStatement).isClosed(); verify(mysqlCallableStatement).setPoolable(anyBoolean()); verify(mysqlCallableStatement).getWarnings(); verify(mysqlCallableStatement).clearWarnings(); verify(mysqlCallableStatement).setCursorName(anyString()); verify(mysqlCallableStatement).setMaxFieldSize(anyInt()); verify(mysqlCallableStatement).getMaxFieldSize(); verify(mysqlCallableStatement).setMaxRows(anyInt()); verify(mysqlCallableStatement).getMaxRows(); verify(mysqlCallableStatement).setEscapeProcessing(anyBoolean()); verify(mysqlCallableStatement).getResultSetConcurrency(); verify(mysqlCallableStatement).getResultSetConcurrency(); verify(mysqlCallableStatement).getResultSetType(); verify(mysqlCallableStatement).getMetaData(); verify(mysqlCallableStatement).getParameterMetaData(); verify(mysqlCallableStatement).getMoreResults(anyInt()); verify(mysqlCallableStatement).setFetchSize(anyInt()); verify(mysqlCallableStatement).getFetchSize(); verify(mysqlCallableStatement).getQueryTimeout(); verify(mysqlCallableStatement).setQueryTimeout(anyInt()); verify(mysqlCallableStatement).getResultSet(); assertThat(connection, CoreMatchers.<Connection>is(swConnection)); }
Example 6
Source File: ModuleCommand.java From doma with Apache License 2.0 | 4 votes |
protected void setupOptions(CallableStatement preparedStatement) throws SQLException { if (query.getQueryTimeout() > 0) { preparedStatement.setQueryTimeout(query.getQueryTimeout()); } }