Java Code Examples for java.sql.Statement#setCursorName()

The following examples show how to use java.sql.Statement#setCursorName() . 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: SURTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Test that you get a warning when specifying a query which is not
 * updatable and concurrency mode CONCUR_UPDATABLE.
 * In this case, the query contains a join.
 */
public void testConcurrencyModeWarning2()
    throws SQLException 
{
    Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY,
                                      ResultSet.CONCUR_UPDATABLE);
    s.setCursorName(getNextCursorName());
    ResultSet rs = s.executeQuery
        ("select * from t1 as table1,t1 as table2 where " +
         "table1.a=table2.a");
    
    SQLWarning warn = rs.getWarnings();
    assertEquals("Expected resultset to be read only",
                 ResultSet.CONCUR_READ_ONLY,
                 rs.getConcurrency());
    assertWarning(warn, QUERY_NOT_QUALIFIED_FOR_UPDATABLE_RESULTSET);
    scrollForward(rs);
    rs.close();
    s.close();
}
 
Example 2
Source File: SURTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Test that you get an exception when specifying update clause
 * "FOR UPDATE" along with a query which is not updatable.
 * In this case, the query contains a join
 */
public void testForUpdateException2()
    throws SQLException 
{
    Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY,
                                      ResultSet.CONCUR_UPDATABLE);
    try {
        String queryString =
            "select * from t1 as table1,t1 as table2" +
            " where table1.a=table2.a for update";
        s.setCursorName(getNextCursorName());
        ResultSet rs = s.executeQuery(queryString);
        
        assertTrue("Expected query '" + queryString + "' to fail",
                   false);
    } catch (SQLException e) {
        assertEquals("Unexpected SQLState", 
                     FOR_UPDATE_NOT_PERMITTED_SQL_STATE,
                     e.getSQLState());
    }
    rollback();
    s.close();
}
 
Example 3
Source File: SURTest.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Test that rowUpdated() and rowDeleted() methods both return true when
 * the row has first been updated and then deleted using the updateRow()
 * and deleteRow() methods.
 */
public void testRowUpdatedAndRowDeleted() throws SQLException {
    Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                       ResultSet.CONCUR_UPDATABLE);
    s.setCursorName(getNextCursorName());
    ResultSet rs = s.executeQuery("select a,b from t1");
    rs.next();
    rs.updateInt(1, rs.getInt(1) + 2 * recordCount);
    rs.updateRow();
    assertTrue("Expected rowUpdated() to return true", rs.rowUpdated());
    rs.deleteRow();
    rs.next();
    rs.previous();
    assertTrue("Expected rowUpdated() to return true", rs.rowUpdated());
    assertTrue("Expected rowDeleted() to return true", rs.rowDeleted());
    rs.next();
    assertFalse("Expected rowUpdated() to return false", rs.rowUpdated());
    assertFalse("Expected rowDeleted() to return false", rs.rowDeleted());
    rs.previous();
    assertTrue("Expected rowUpdated() to return true", rs.rowUpdated());
    assertTrue("Expected rowDeleted() to return true", rs.rowDeleted());
    rs.close();
    s.close();
}
 
Example 4
Source File: SURTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Test update of a scrollable resultset (without FOR UPDATE) 
 * Scrolling forward and backward.
 */
public void testScrollInsensitiveConcurUpdatableWithoutForUpdate2()
    throws SQLException 
{
    Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                      ResultSet.CONCUR_UPDATABLE);
    s.setCursorName(getNextCursorName());
    ResultSet rs = s.executeQuery("select * from t1");
    
    scrollForward(rs);
    scrollBackwardAndUpdate(rs);
    rs.close();
    s.close();
}
 
Example 5
Source File: SURTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Test that you can scroll forward and read all records in the
 * ResultSet
 */
public void testForwardOnlyReadOnly1()
    throws SQLException 
{
    Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY,
                                      ResultSet.CONCUR_READ_ONLY);
    s.setCursorName(getNextCursorName());
    ResultSet rs = s.executeQuery("select * from t1");
    
    scrollForward(rs);
    rs.close();
    s.close();
}
 
Example 6
Source File: SURTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 *  Test that you can scroll forward and update indexed records
 *  in the ResultSet (using FOR UPDATE).
 */
public void testIndexedUpdateCursor2()
    throws SQLException 
{
    Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY,
                                      ResultSet.CONCUR_UPDATABLE);
    s.setCursorName(getNextCursorName());
    ResultSet rs =
        s.executeQuery("select * from t1 where a=1 for update");
    
    assertTrue("Expected to get a tuple on rs.next()", rs.next());
    verifyTuple(rs);
    updateTuple(rs);
    s.close();
}
 
Example 7
Source File: SURTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Test update indexed records using other statement object
 * and using resultset.
 */
public void testOtherSecondaryKeyUpdate1()
    throws SQLException 
{
    Statement s = createStatement
        (ResultSet.TYPE_SCROLL_INSENSITIVE,
         ResultSet.CONCUR_UPDATABLE);
    s.setCursorName(getNextCursorName());
    ResultSet rs = s.executeQuery("select * from t1");
    
    rs.last();
    int indexedKey = rs.getInt(2);
    PreparedStatement ps =
        prepareStatement("update t1 set a = ? where a= ?");
    ps.setInt(1, -indexedKey);
    ps.setInt(2, indexedKey);
    assertEquals("Expected one row to be updated", 1,
                 ps.executeUpdate());
    
    rs.updateInt(1, -555);
    rs.updateInt(3, -777);
    rs.updateRow();
    
    PreparedStatement ps2 =
        prepareStatement("select * from t1 where a=?");
    ps2.setInt(1, -indexedKey);
    ResultSet rs2 = ps2.executeQuery();
    assertTrue("Expected query to have 1 row", rs2.next());
    println("T1: Read Tuple:(" + rs2.getInt(1) + "," +
            rs2.getInt(2) + "," +
            rs2.getInt(3) + ")");
    assertEquals("Expected id=-555", -555, rs2.getInt(1));
    assertEquals("Expected b=-777", -777, rs2.getInt(3));
    assertTrue("Did not expect more than 1 row, however " +
               "rs2.next() returned another row", !rs2.next());
    
    s.close();
    ps.close();
    ps2.close();
}
 
Example 8
Source File: BrokeredStatement.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
void setStatementState(Statement oldStatement, Statement newStatement) throws SQLException {
	if (cursorName != null)
		newStatement.setCursorName(cursorName);
	if (escapeProcessing != null)
		newStatement.setEscapeProcessing(escapeProcessing);

	newStatement.setFetchDirection(oldStatement.getFetchDirection());
	newStatement.setFetchSize(oldStatement.getFetchSize());
	newStatement.setMaxFieldSize(oldStatement.getMaxFieldSize());
	newStatement.setMaxRows(oldStatement.getMaxRows());
	newStatement.setQueryTimeout(oldStatement.getQueryTimeout());
}
 
Example 9
Source File: SURTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Test update indexed records using other statement object
 * and using resultset.
 */
public void testOtherSecondaryKeyUpdate1()
    throws SQLException 
{
    Statement s = createStatement
        (ResultSet.TYPE_SCROLL_INSENSITIVE,
         ResultSet.CONCUR_UPDATABLE);
    s.setCursorName(getNextCursorName());
    ResultSet rs = s.executeQuery("select * from t1");
    
    rs.last();
    int indexedKey = rs.getInt(2);
    PreparedStatement ps =
        prepareStatement("update t1 set a = ? where a= ?");
    ps.setInt(1, -indexedKey);
    ps.setInt(2, indexedKey);
    assertEquals("Expected one row to be updated", 1,
                 ps.executeUpdate());
    
    rs.updateInt(1, -555);
    rs.updateInt(3, -777);
    rs.updateRow();
    
    PreparedStatement ps2 =
        prepareStatement("select * from t1 where a=?");
    ps2.setInt(1, -indexedKey);
    ResultSet rs2 = ps2.executeQuery();
    assertTrue("Expected query to have 1 row", rs2.next());
    println("T1: Read Tuple:(" + rs2.getInt(1) + "," +
            rs2.getInt(2) + "," +
            rs2.getInt(3) + ")");
    assertEquals("Expected id=-555", -555, rs2.getInt(1));
    assertEquals("Expected b=-777", -777, rs2.getInt(3));
    assertTrue("Did not expect more than 1 row, however " +
               "rs2.next() returned another row", !rs2.next());
    
    s.close();
    ps.close();
    ps2.close();
}
 
Example 10
Source File: ForUpdateTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testUpdates2() throws SQLException {
      if (isAvoidGFXDBugs()) {
        // This testcase screws up testCursor5 if left active.
        fail("Failing test due to gemfirexd ticket 42849");
      }
        Statement stmt = createStatement();
stmt.executeUpdate("insert into t1 (i) values (1)");
stmt.setCursorName("C4");
ResultSet rs = stmt.executeQuery("select i from t1 s1 for update");
rs.next();
            assertEquals(rs.getString("I"), "1");

Statement stmt2 = createStatement();
try {
  stmt2.executeUpdate("delete from s1 where current of C4");
  fail("ForUpdateTest: should have thrown exception");
} catch (SQLException e) {
  assertSQLState("42X28", e);
}

Statement stmt3 = createStatement();
stmt3.executeUpdate("delete from t1 where current of C4");
rs.close();

JDBC.assertEmpty(stmt.executeQuery("select i from t1 for update of i, v, d, t"));
JDBC.assertEmpty(stmt.executeQuery("select i from t1 for update of v, i, t, d"));
JDBC.assertEmpty(stmt.executeQuery("select i from t1 for update of i, d"));
JDBC.assertEmpty(stmt.executeQuery("select i from t1 for update of t, v"));
JDBC.assertEmpty(stmt.executeQuery("select i from t1 for update of d"));
assertStatementError("42X04", stmt, "select i as z from t1 for update of z");
    stmt.close();
     }
 
Example 11
Source File: SURTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Test update of a keyed record using other both the
 * scrollable updatable resultset and using another statement
 * object.
 */
public void testOtherAndOwnPrimaryKeyUpdate1()
    throws SQLException 
{
    Statement s = createStatement
        (ResultSet.TYPE_SCROLL_INSENSITIVE,
         ResultSet.CONCUR_UPDATABLE);
    s.setCursorName(getNextCursorName());
    ResultSet rs = s.executeQuery("select * from t1");
    
    rs.last();
    int primaryKey = rs.getInt(1);
    PreparedStatement ps = prepareStatement
        ("update t1 set id = ? where id= ?");
    ps.setInt(1, -primaryKey);
    ps.setInt(2, primaryKey);
    assertEquals("Expected one row to be updated", 1,
                 ps.executeUpdate());
    rs.updateInt(1, primaryKey*10);
    rs.updateInt(2, -555);
    rs.updateInt(3, -777);
    rs.updateRow();
    
    PreparedStatement ps2 =
        prepareStatement("select * from t1 where id=?");
    ps2.setInt(1, primaryKey*10);
    ResultSet rs2 = ps2.executeQuery();
    assertTrue("Expected query to have 1 row", rs2.next());
    println("T1: Read Tuple:(" + rs2.getInt(1) + "," +
            rs2.getInt(2) + "," +
            rs2.getInt(3) + ")");
    assertEquals("Expected a=-555", -555, rs2.getInt(2));
    assertEquals("Expected b=-777", -777, rs2.getInt(3));
    assertTrue("Did not expect more than 1 row, however " +
               "rs2.next() returned another row", !rs2.next());
    
    s.close();
    ps.close();
    ps2.close();
}
 
Example 12
Source File: BrokeredStatement.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
void setStatementState(Statement oldStatement, Statement newStatement) throws SQLException {
	if (cursorName != null)
		newStatement.setCursorName(cursorName);
	if (escapeProcessing != null)
		newStatement.setEscapeProcessing(escapeProcessing.booleanValue());

	newStatement.setFetchDirection(oldStatement.getFetchDirection());
	newStatement.setFetchSize(oldStatement.getFetchSize());
	newStatement.setMaxFieldSize(oldStatement.getMaxFieldSize());
	newStatement.setMaxRows(oldStatement.getMaxRows());
	newStatement.setQueryTimeout(oldStatement.getQueryTimeout());
}
 
Example 13
Source File: SURTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Test update of a scrollable resultset (without FOR UPDATE) 
 * Scrolling forward and backward.
 */
public void testScrollInsensitiveConcurUpdatableWithoutForUpdate2()
    throws SQLException 
{
    Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                      ResultSet.CONCUR_UPDATABLE);
    s.setCursorName(getNextCursorName());
    ResultSet rs = s.executeQuery("select * from t1");
    
    scrollForward(rs);
    scrollBackwardAndUpdate(rs);
    rs.close();
    s.close();
}
 
Example 14
Source File: SURTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Test update of a scrollable resultset (with FOR UPDATE)
 * Only scrolling forward
 */
public void testScrollInsensitiveConcurUpdatableWithForUpdate1()
    throws SQLException 
{
    Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                      ResultSet.CONCUR_UPDATABLE);
    s.setCursorName(getNextCursorName());
    ResultSet rs = s.executeQuery("select * from t1 for update");
    scrollForwardAndUpdate(rs);
    rs.close();
    s.close();
}
 
Example 15
Source File: SQLDistTxClientTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
protected boolean updateSelectForUpdateTx(Connection conn, int tid, int lowCid, int highCid) {       
  try {
    Statement s = isTicket41738Fixed ? conn.createStatement() : 
      conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
    s.setCursorName("updateCursor");
    String sql = "select * from trade.networth where cid > " 
      + lowCid + " and cid <= " + highCid + " FOR UPDATE OF securities"; 
    Log.getLogWriter().info(sql);
    ResultSet updatableRs = s.executeQuery(sql);
    PreparedStatement psCurrentOf = null;
    PreparedStatement psPK = null;
    if (isTicket41738Fixed) 
      psCurrentOf = conn.prepareStatement("update trade.networth set securities = securities + ? "
       + " where current of updateCursor");
    
    psPK = conn.prepareStatement("update trade.networth set securities = securities + ? "
        + " where cid = ? ");
    
    boolean success = false;
    if (isTicket41738Fixed && isTicket43188Fixed) {
      success = updateSelectForUpdateTx(updatableRs, psCurrentOf, tid);
      updatableRs.close();
      return success;
    }
    else {
      if (random.nextBoolean()) {
        success = updateSelectForUpdatePKTx(updatableRs, psPK, tid);
        updatableRs.close();
        return success;
      }
      else {
        if (!isTicket43188Fixed) {
          success = updateSelectForUpdatePKTx(updatableRs, psPK, tid);
          updatableRs.close();
          return success;            
        } else {
          success = updateSelectForUpdateRsTx(updatableRs, tid);
          updatableRs.close();
          return success;
        }
      }
    }
        
  } catch (SQLException se) {
    if (se.getSQLState().equals("X0Z02")) {
      SQLHelper.printSQLException(se);
      
      return false; //expected conflict issue during query execution for acquiring the locks 
    } else SQLHelper.handleSQLException(se); 
  }
  return true;
}
 
Example 16
Source File: SURTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Test that you get cursor operation conflict warning if updating 
 * a row which has been deleted from the table, now using 
 * positioned updates / deletes.
 */
public void testCursorOperationConflictWarning2() 
    throws SQLException 
{
    Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
    s.setCursorName(getNextCursorName());
    ResultSet rs = s.executeQuery("select * from t1");
    rs.next();
    createStatement().executeUpdate ("delete from t1 where id=" +
                                         rs.getString("ID"));
    
    final int newValue = -3333;
    final int oldValue = rs.getInt(2);
    
    Statement s3 = createStatement();
    int updateCount = s3.executeUpdate
        ("update t1 set A=" + newValue + 
         " where current of " + rs.getCursorName());
    
    rs.relative(0);
    SQLWarning warn = s3.getWarnings();
    assertWarning(warn, CURSOR_OPERATION_CONFLICT);
    assertTrue("Expected rs.rowUpdated() to be false", !rs.rowUpdated());
    assertTrue("Expected rs.rowDeleted() to be false", !rs.rowDeleted());
    assertEquals("Did not expect the resultset to be updated", oldValue, rs.getInt(2));
    assertEquals("Expected update count to be 0", 0, updateCount);
    
    Statement s4 = createStatement();
    updateCount = s4.executeUpdate("delete from t1 where current of " +
                                   rs.getCursorName());
    
    rs.relative(0);
    warn = s4.getWarnings();
    assertWarning(warn, CURSOR_OPERATION_CONFLICT);
    assertTrue("Expected rs.rowUpdated() to be false", !rs.rowUpdated());
    assertTrue("Expected rs.rowDeleted() to be false", !rs.rowDeleted());
    assertEquals("Did not expect the resultset to be updated", oldValue, rs.getInt(2));
    assertEquals("Expected update count to be 0", 0, updateCount);
    
    rs.close();
    s.close();
    s3.close();
    s4.close();
}
 
Example 17
Source File: StatementCachingTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testQuotedCursorsUpdate() throws SQLException {
  Connection conn = getConnection();
  Statement stmt = conn.createStatement();
  
  stmt.executeUpdate("create table \"my table\" (x int)");
  stmt.executeUpdate("insert into \"my table\" values (1), (2), (3) ");
  
  stmt.close();
  
  stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
      ResultSet.CONCUR_UPDATABLE);
  stmt.setCursorName("\"\"my quoted cursor\"\" \"\"with quotes "
      + "in middle\"\"and last \"\"");
  ResultSet rs = stmt.executeQuery("select * from \"my table\"");
  rs.next();

  // remember which int was updated
  int updatedInt = rs.getInt(1);

  rs.updateInt(1, 4);
  rs.updateRow();
  rs.close();
  
  rs = stmt.executeQuery("select * from \"my table\" order by x");
  

  // in GemFireXD, queries are not guaranteed to return results
  // in the same order they were inserted, so changing this test
  // to not assume which x was updated
  List<Integer> expected = new ArrayList<Integer>(Arrays.asList(1, 2, 3));
  expected.remove((Integer)updatedInt);
  expected.add(4);
  
  for (int i=2; i<=4; i++) {
      assertTrue("there is a row", rs.next());
      assertTrue("row contains correct value",
               expected.remove((Integer)rs.getInt(1)));
  }
  assertTrue("table correct size", expected.isEmpty());
  
  rs.close();
  stmt.close();        
}
 
Example 18
Source File: DropTableTest.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
public void testDropTableIndexesDropped() throws SQLException{
    // make sure that indexes are dropped for drop table
    
    Statement st = createStatement();
    setAutoCommit(false);
    
    st.executeUpdate( "create table t2(a int not null primary key)");
    st.executeUpdate(
        "create table reft2(a int constraint ref1 references t2)");
    
    // count should be 2
    
    JDBC.assertSingleValueResultSet( st.executeQuery(
        "select count(*) from (sys.sysconglomerates c), (sys.systables t) "
        + "where t.tableid = c.tableid and "
        + "t.tablename = 'REFT2'"), "2");
    
    // drop dependent referential constraint
    
    st.executeUpdate( "alter table reft2 drop constraint ref1");
    
    // should work since dependent constraint was previously 
    // dropped
    
    st.executeUpdate( "drop table t2");
    
    // count should be 1
    
    JDBC.assertSingleValueResultSet( st.executeQuery(
        "select count(*) "
        + "from (sys.sysconglomerates c), (sys.systables t) "
        + "where t.tableid = c.tableid and "
        + "t.tablename = 'REFT2'"), "1");

    rollback();
    
    // unsuccessful drop table should not affect open cursor 
    // beetle 4393
    
    st.executeUpdate(
        " create table T1 (i int, c varchar(255), d varchar(255))");
    st.executeUpdate( " insert into T1(i) values(1)");
    st.executeUpdate( " insert into T1(i) values(2)");
    
    Statement st1 = createStatement();
    st1.setCursorName("X1");
    
    ResultSet rs1 = st1.executeQuery( "select i from t1 for update of c"); 
    PreparedStatement pSt =
        prepareStatement("update t1 set c = CHAR(i) where current of X1");
    
    assertStatementError("X0X95",st,"drop table T1");
    
    rs1.next();      
    
    pSt.executeUpdate();
    
    ResultSet rs = st.executeQuery("select * from T1");
    String[] expColNames = new String[]{"I","C","D"};
    JDBC.assertColumnNames(rs, expColNames);
    
    String[][] expRS = new String[][]{
        {"1","1",null},
        {"2",null,null}
    };
    JDBC.assertFullResultSet(rs, expRS);
    
    st1.close();
    st.executeUpdate("drop table T1"); // Clean up

    //pretend all of the above didn't happen
    setAutoCommit(true);
}
 
Example 19
Source File: SWStatementTest.java    From skywalking with Apache License 2.0 4 votes vote down vote up
@Test
public void testPreparedStatementConfig() throws SQLException {
    Statement statement = swConnection.createStatement();
    statement.cancel();
    statement.getUpdateCount();
    statement.setFetchDirection(1);
    statement.getFetchDirection();
    statement.getResultSetConcurrency();
    statement.getResultSetType();
    statement.isClosed();
    statement.setPoolable(false);
    statement.isPoolable();
    statement.getWarnings();
    statement.clearWarnings();
    statement.setCursorName("test");
    statement.setMaxFieldSize(11);
    statement.getMaxFieldSize();
    statement.setMaxRows(10);
    statement.getMaxRows();
    statement.setEscapeProcessing(true);
    statement.setFetchSize(1);
    statement.getFetchSize();
    statement.setQueryTimeout(1);
    statement.getQueryTimeout();
    Connection connection = statement.getConnection();

    statement.execute("SELECT * FROM test");
    statement.getMoreResults();
    statement.getMoreResults(1);
    statement.getResultSetHoldability();
    statement.getResultSet();

    statement.close();
    verify(mysqlStatement).getUpdateCount();
    verify(mysqlStatement).getMoreResults();
    verify(mysqlStatement).setFetchDirection(anyInt());
    verify(mysqlStatement).getFetchDirection();
    verify(mysqlStatement).getResultSetType();
    verify(mysqlStatement).isClosed();
    verify(mysqlStatement).setPoolable(anyBoolean());
    verify(mysqlStatement).getWarnings();
    verify(mysqlStatement).clearWarnings();
    verify(mysqlStatement).setCursorName(anyString());
    verify(mysqlStatement).setMaxFieldSize(anyInt());
    verify(mysqlStatement).getMaxFieldSize();
    verify(mysqlStatement).setMaxRows(anyInt());
    verify(mysqlStatement).getMaxRows();
    verify(mysqlStatement).setEscapeProcessing(anyBoolean());
    verify(mysqlStatement).getResultSetConcurrency();
    verify(mysqlStatement).getResultSetConcurrency();
    verify(mysqlStatement).getResultSetType();
    verify(mysqlStatement).getMoreResults(anyInt());
    verify(mysqlStatement).setFetchSize(anyInt());
    verify(mysqlStatement).getFetchSize();
    verify(mysqlStatement).getQueryTimeout();
    verify(mysqlStatement).setQueryTimeout(anyInt());
    verify(mysqlStatement).getResultSet();
    assertThat(connection, CoreMatchers.<Connection>is(swConnection));

    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/Statement/execute", "SELECT * FROM test");
}
 
Example 20
Source File: SURTest.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Test that you get cursor operation conflict warning if updating 
 * a row which has been deleted from the table, now using 
 * positioned updates / deletes.
 */
public void testCursorOperationConflictWarning2() 
    throws SQLException 
{
    Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
    s.setCursorName(getNextCursorName());
    ResultSet rs = s.executeQuery("select * from t1");
    rs.next();
    createStatement().executeUpdate ("delete from t1 where id=" +
                                         rs.getString("ID"));
    
    final int newValue = -3333;
    final int oldValue = rs.getInt(2);
    
    Statement s3 = createStatement();
    int updateCount = s3.executeUpdate
        ("update t1 set A=" + newValue + 
         " where current of " + rs.getCursorName());
    
    rs.relative(0);
    SQLWarning warn = s3.getWarnings();
    assertWarning(warn, CURSOR_OPERATION_CONFLICT);
    assertTrue("Expected rs.rowUpdated() to be false", !rs.rowUpdated());
    assertTrue("Expected rs.rowDeleted() to be false", !rs.rowDeleted());
    assertEquals("Did not expect the resultset to be updated", oldValue, rs.getInt(2));
    assertEquals("Expected update count to be 0", 0, updateCount);
    
    Statement s4 = createStatement();
    updateCount = s4.executeUpdate("delete from t1 where current of " +
                                   rs.getCursorName());
    
    rs.relative(0);
    warn = s4.getWarnings();
    assertWarning(warn, CURSOR_OPERATION_CONFLICT);
    assertTrue("Expected rs.rowUpdated() to be false", !rs.rowUpdated());
    assertTrue("Expected rs.rowDeleted() to be false", !rs.rowDeleted());
    assertEquals("Did not expect the resultset to be updated", oldValue, rs.getInt(2));
    assertEquals("Expected update count to be 0", 0, updateCount);
    
    rs.close();
    s.close();
    s3.close();
    s4.close();
}