Java Code Examples for java.sql.ResultSet#deleteRow()

The following examples show how to use java.sql.ResultSet#deleteRow() . 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: SQLDistTxTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
protected boolean deleteRowSFU_URSTx(ResultSet updatableRs) {
  try {
    int cid = updatableRs.getInt("CID");
    updatableRs.deleteRow();
    Log.getLogWriter().info("delete from trade.networth for cid: " + cid);
  } catch (SQLException se) {
    if (isHATest && SQLHelper.gotTXNodeFailureException(se)) {
      Log.getLogWriter().info(
          "got node failure exception, needs to retry the op");
      return false;
    }
    SQLHelper.handleSQLException(se); // should not see exception as the row
                                      // should be locked
  }
  return true;
}
 
Example 2
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 3
Source File: SQLDistTxTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
protected boolean deleteRowSFU_URSTx(ResultSet updatableRs) {
  try {
    int cid = updatableRs.getInt("CID");
    updatableRs.deleteRow();
    Log.getLogWriter().info("delete from trade.networth for cid: " + cid);
  } catch (SQLException se) {
    if (isHATest && SQLHelper.gotTXNodeFailureException(se)) {
      Log.getLogWriter().info(
          "got node failure exception, needs to retry the op");
      return false;
    }
    SQLHelper.handleSQLException(se); // should not see exception as the row
                                      // should be locked
  }
  return true;
}
 
Example 4
Source File: SURTest.java    From gemfirexd-oss with Apache License 2.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 5
Source File: JdbcLiveTest.java    From tutorials with MIT License 5 votes vote down vote up
@After
public void closeConnection() throws SQLException {

    Statement updatableStmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    ResultSet updatableResultSet = updatableStmt.executeQuery("SELECT * FROM employees");

    while (updatableResultSet.next()) {
        updatableResultSet.deleteRow();
    }

    con.close();
}
 
Example 6
Source File: SQLDistTxTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected boolean deleteURSRowTx(ResultSet updatableRs) {
  try {
    int cid = updatableRs.getInt("CID");
    updatableRs.deleteRow();
    Log.getLogWriter().info("delete from trade.networth for cid: " + cid);
  } catch (SQLException se) {
    if (se.getSQLState().equals("X0Z02")) {
      SQLHelper.printSQLException(se);
      return false; // expected updatable result set
    } else
      SQLHelper.handleSQLException(se);
  }
  return true;
}
 
Example 7
Source File: SURQueryMixTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Delete a random sample of n records in the resultset
 * @param rs result set to be updated
 * @param rows map of rows, will also be updated
 * @param deletedRows set of rows being deleted (position in RS)
 * @param k number of records to be deleted
 */
private void deleteRandomSampleOfNRecords(final ResultSet rs, 
                                          final Map rows,
                                          final Set deletedRows,
                                          final int k) 
    throws SQLException
{
    List sampledKeys = createRandomSample(rows, k);
    println("Sampled keys:" + sampledKeys);
    ResultSetMetaData meta = rs.getMetaData();
    for (Iterator i = sampledKeys.iterator(); i.hasNext();) {
        Integer key = (Integer) i.next();
        rs.absolute(key.intValue());            
        if (rs.rowDeleted()) continue; // skip deleting row if already deleted
        if (positioned) {
            createStatement().executeUpdate
                    ("DELETE FROM T1 WHERE CURRENT OF \"" + cursorName + 
                     "\"");
        } else {
            rs.deleteRow();
        }
        rs.relative(0);
        println("Deleted row " + key);
        // Update the rows table
        rows.put(key, getRowString(rs));
        
        // Update the updatedRows set
        deletedRows.add(key);
    }
}
 
Example 8
Source File: SQLDistTxTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected boolean deleteURSRowTx(ResultSet updatableRs) {
  try {
    int cid = updatableRs.getInt("CID");
    updatableRs.deleteRow();
    Log.getLogWriter().info("delete from trade.networth for cid: " + cid);
  } catch (SQLException se) {
    if (se.getSQLState().equals("X0Z02")) {
      SQLHelper.printSQLException(se);
      return false; // expected updatable result set
    } else
      SQLHelper.handleSQLException(se);
  }
  return true;
}
 
Example 9
Source File: RoutinesDefinersRightsTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Test that PHB can actually update using {@code ResultSet.insertRow},
 * {@code ResultSet.updateRow} and {@code ResultSet.deleteRow}.
 * <p/>
 * Aside: This test is somewhat artificial here, since the middle manager
 * would not be allowed to do this, presumably; just added here to test
 * this functionality (which was initially broken by the first patch for
 * DERBY-4551).
 * <p/>
 * The problem was that the nested statement contexts used for SQL
 * substatements generated for these ResultSet operations were not
 * correctly set up, so the effective user id would not be the DEFINER
 * (DBO), and authorization would fail. Cf DERBY-4551 and DERBY-3327
 * for more detail.
 */
public static void updateWage()
        throws SQLException
{
    Connection c = null;

    c = DriverManager.getConnection("jdbc:default:connection");
    Statement cStmt = c.createStatement(
        ResultSet.TYPE_SCROLL_INSENSITIVE,
        ResultSet.CONCUR_UPDATABLE);

    // Try nested statements by inserting, updating and deleting a bogus
    // row
    ResultSet rs = cStmt.executeQuery(
        "select * from s1.wages");
    assertTrue(rs.isBeforeFirst());
    rs.moveToInsertRow();
    rs.updateInt("EMPLOYEEID", 666);
    rs.updateInt("CATEGORY", 667);
    rs.updateDouble("SALARY", 666.0);
    rs.updateString("NAME", "N.N.");
    rs.insertRow();
    rs.close();

    rs = cStmt.executeQuery(
        "select * from s1.wages where name = 'N.N.'");
    rs.next();
    rs.updateDouble("SALARY", 666.1);
    rs.updateRow();
    rs.close();

    rs = cStmt.executeQuery(
        "select * from s1.wages where name = 'N.N.'");
    rs.next();
    rs.deleteRow();
    rs.close();

    cStmt.close();
    c.close();
}
 
Example 10
Source File: ResultSetIteratorTest.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests for remove.
 *
 * @throws SQLException in case of an unexpected problem
 */
@Test
public void testRemove() throws SQLException {
	ResultSet resultsetdelteThrowsException = createMock(ResultSet.class);
	resultsetdelteThrowsException.deleteRow();
	expectLastCall().andThrow(new SQLException());
	replay(resultsetdelteThrowsException);
	final ResultSetIterator<String> iter = new ResultSetIterImplementation(new StatementImplementation(),
			resultsetdelteThrowsException);
	iter.remove();
	assertTrue("no exception thrown", true);
	verify(resultsetdelteThrowsException);
}
 
Example 11
Source File: SURTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Test that you get cursor operation conflict warning if updating 
 * a row which has been deleted from the table.
 */
public void testCursorOperationConflictWarning1() 
    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);
    rs.updateInt(2, newValue);
    rs.updateRow();
    
    SQLWarning warn = rs.getWarnings();
    assertWarning(warn, CURSOR_OPERATION_CONFLICT);
    assertEquals("Did not expect the resultset to be updated", oldValue, rs.getInt(2));
    assertTrue("Expected rs.rowDeleted() to be false", !rs.rowDeleted());
    assertTrue("Expected rs.rowUpdated() to be false", !rs.rowUpdated());
    
    rs.clearWarnings();
    rs.deleteRow();
    warn = rs.getWarnings();
    assertWarning(warn, CURSOR_OPERATION_CONFLICT);
    rs.relative(0);
    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));
    
    rs.close();
    s.close();
}
 
Example 12
Source File: SURQueryMixTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Delete a random sample of n records in the resultset
 * @param rs result set to be updated
 * @param rows map of rows, will also be updated
 * @param deletedRows set of rows being deleted (position in RS)
 * @param k number of records to be deleted
 */
private void deleteRandomSampleOfNRecords(final ResultSet rs, 
                                          final Map rows,
                                          final Set deletedRows,
                                          final int k) 
    throws SQLException
{
    List sampledKeys = createRandomSample(rows, k);
    println("Sampled keys:" + sampledKeys);
    ResultSetMetaData meta = rs.getMetaData();
    for (Iterator i = sampledKeys.iterator(); i.hasNext();) {
        Integer key = (Integer) i.next();
        rs.absolute(key.intValue());            
        if (rs.rowDeleted()) continue; // skip deleting row if already deleted
        if (positioned) {
            createStatement().executeUpdate
                    ("DELETE FROM T1 WHERE CURRENT OF \"" + cursorName + 
                     "\"");
        } else {
            rs.deleteRow();
        }
        rs.relative(0);
        println("Deleted row " + key);
        // Update the rows table
        rows.put(key, getRowString(rs));
        
        // Update the updatedRows set
        deletedRows.add(key);
    }
}
 
Example 13
Source File: SURQueryMixTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Delete a random sample of n records in the resultset
 * @param rs result set to be updated
 * @param rows map of rows, will also be updated
 * @param deletedRows set of rows being deleted (position in RS)
 * @param k number of records to be deleted
 */
private void deleteRandomSampleOfNRecords(final ResultSet rs, 
                                          final Map rows,
                                          final Set deletedRows,
                                          final int k) 
    throws SQLException
{
    List sampledKeys = createRandomSample(rows, k);
    println("Sampled keys:" + sampledKeys);
    ResultSetMetaData meta = rs.getMetaData();
    for (Iterator i = sampledKeys.iterator(); i.hasNext();) {
        Integer key = (Integer) i.next();
        rs.absolute(key.intValue());            
        if (rs.rowDeleted()) continue; // skip deleting row if already deleted
        if (positioned) {
            createStatement().executeUpdate
                    ("DELETE FROM T1 WHERE CURRENT OF \"" + cursorName + 
                     "\"");
        } else {
            rs.deleteRow();
        }
        rs.relative(0);
        println("Deleted row " + key);
        // Update the rows table
        rows.put(key, getRowString(rs));
        
        // Update the updatedRows set
        deletedRows.add(key);
    }
}
 
Example 14
Source File: SelectForUpdateInTransactionDUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testSelectForUpdate_directDeleteNoPK() throws Exception {
  startVMs(2, 1);
  Connection conn = TestUtil.getConnection();
  conn.setTransactionIsolation(Connection.TRANSACTION_NONE);
  conn.setAutoCommit(false);
  Statement stmtForTableAndInsert = conn.createStatement();
  stmtForTableAndInsert.execute("create table Employee"
      + "(firstname varchar(50) not null, lastname varchar(50) not null, "
      + "workdept varchar(50), bonus decimal(10,4))");
  stmtForTableAndInsert
      .execute("insert into employee values('neeraj', 'kumar', 'rnd', 0.0), "
          + "('asif', 'shahid', 'rnd', 1.0), "
          + "('dada', 'ji', 'rnd', 2.0), ('sum', 'wale', 'rnd', 3.0)");
  Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
      ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT);
  ResultSet uprs = stmt.executeQuery("SELECT workdept, bonus "
      + "FROM EMPLOYEE FOR UPDATE of BONUS");

  while (uprs.next()) {
    uprs.deleteRow();
  }
  
  SQLWarning w = uprs.getWarnings();
  assertTrue("0A000".equals(w.getSQLState()));
  uprs.close();
  Statement stmt2 = conn.createStatement();
  ResultSet rs = stmt2.executeQuery("select * from employee");
  w = rs.getWarnings();
  assertNull(w);

  rs = stmt2.executeQuery("select * from employee");
  assertFalse(rs.next());
  
  conn.setTransactionIsolation(getIsolationLevel());
  conn.setAutoCommit(false);
  
  stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
      ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT);
  
  stmt.execute("insert into employee values('asif', 'shahid', 'rnd', 1.0), ('dada', 'ji', 'rnd', 2.0), ('sum', 'wale', 'rnd', 3.0)");
  
  uprs = stmt.executeQuery("SELECT * "
      + "FROM EMPLOYEE FOR UPDATE of BONUS");

  while (uprs.next()) {
    if (uprs.getString(1).equalsIgnoreCase("asif")) {
      uprs.deleteRow();
    }
  }

  w = uprs.getWarnings();
  assertNull(w);
  uprs.close();
  conn.commit();
  
  stmt2 = conn.createStatement();
  rs = stmt2.executeQuery("select * from employee");
  w = rs.getWarnings();
  assertNull(w);

  assertTrue(rs.next());
  assertTrue((rs.getString(1).equalsIgnoreCase("sum") || rs.getString(1)
      .equalsIgnoreCase("dada")));
  
  assertTrue(rs.next());
  
  assertTrue((rs.getString(1).equalsIgnoreCase("sum") || rs.getString(1)
      .equalsIgnoreCase("dada")));
  
  assertFalse(rs.next());
}
 
Example 15
Source File: SURTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Test that the JDBC detectability calls throw correct exceptions when
 * called in in wrong row states. 
 * This is done for both supported updatable result set types.
 */
public void testDetectabilityExceptions() throws SQLException 
{
    Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                      ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = s.executeQuery("select * from t1");
    
    checkDetectabilityCallsOutsideRow(rs, "before positioning");

    rs.moveToInsertRow();
    checkDetectabilityCallsOutsideRow(rs, 
                                      "on insertRow before positioning");

    rs.next();
    rs.moveToInsertRow();
    checkDetectabilityCallsOutsideRow(rs, "on insertRow");
    rs.moveToCurrentRow(); // needed until to DERBY-1322 is fixed

    rs.beforeFirst();
    checkDetectabilityCallsOutsideRow(rs, "on beforeFirst row");

    rs.afterLast();
    checkDetectabilityCallsOutsideRow(rs, "on afterLast row");

    rs.first();
    rs.deleteRow();
    checkDetectabilityCallsOutsideRow(rs, "after deleteRow");

    rs.last();
    rs.deleteRow();
    checkDetectabilityCallsOutsideRow(rs, "after deleteRow of last row");

    rs.close();
    s.close();

    // Not strictly SUR, but fixed in same patch, so we test it here.
    s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                            ResultSet.CONCUR_UPDATABLE);
    rs = s.executeQuery("select * from t1");

    checkDetectabilityCallsOutsideRow(rs, "before FO positioning");

    rs.moveToInsertRow();
    checkDetectabilityCallsOutsideRow(rs, 
                                      "on insertRow before FO positioning");

    rs.next();
    rs.moveToInsertRow();
    checkDetectabilityCallsOutsideRow(rs, "on FO insertRow");

    rs.next();
    rs.updateInt(2, 666);
    rs.updateRow();
    checkDetectabilityCallsOutsideRow(rs, "after FO updateRow");

    rs.next();
    rs.deleteRow();
    checkDetectabilityCallsOutsideRow(rs, "after FO deleteRow");

    while (rs.next()) {};
    checkDetectabilityCallsOutsideRow(rs, "after FO emptied out");

    rs.close();
    s.close();
}
 
Example 16
Source File: JdbcReaderTest.java    From incubator-batchee with Apache License 2.0 4 votes vote down vote up
@Override
public Object map(final ResultSet resultSet) throws SQLException {
    final String name = resultSet.getString("name");
    resultSet.deleteRow();
    return name;
}
 
Example 17
Source File: UnsupportedOperationResultSetTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 4 votes vote down vote up
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertDeleteRow() throws SQLException {
    for (ResultSet each : resultSets) {
        each.deleteRow();
    }
}
 
Example 18
Source File: SelectForUpdateInTransactionDUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testSelectForUpdate_directDeleteNoPK() throws Exception {
  startVMs(2, 1);
  Connection conn = TestUtil.getConnection();
  conn.setTransactionIsolation(Connection.TRANSACTION_NONE);
  conn.setAutoCommit(false);
  Statement stmtForTableAndInsert = conn.createStatement();
  stmtForTableAndInsert.execute("create table Employee"
      + "(firstname varchar(50) not null, lastname varchar(50) not null, "
      + "workdept varchar(50), bonus decimal(10,4))");
  stmtForTableAndInsert
      .execute("insert into employee values('neeraj', 'kumar', 'rnd', 0.0), "
          + "('asif', 'shahid', 'rnd', 1.0), "
          + "('dada', 'ji', 'rnd', 2.0), ('sum', 'wale', 'rnd', 3.0)");
  Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
      ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT);
  ResultSet uprs = stmt.executeQuery("SELECT workdept, bonus "
      + "FROM EMPLOYEE FOR UPDATE of BONUS");

  while (uprs.next()) {
    uprs.deleteRow();
  }
  
  SQLWarning w = uprs.getWarnings();
  assertTrue("0A000".equals(w.getSQLState()));
  uprs.close();
  Statement stmt2 = conn.createStatement();
  ResultSet rs = stmt2.executeQuery("select * from employee");
  w = rs.getWarnings();
  assertNull(w);

  rs = stmt2.executeQuery("select * from employee");
  assertFalse(rs.next());
  
  conn.setTransactionIsolation(getIsolationLevel());
  conn.setAutoCommit(false);
  
  stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
      ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT);
  
  stmt.execute("insert into employee values('asif', 'shahid', 'rnd', 1.0), ('dada', 'ji', 'rnd', 2.0), ('sum', 'wale', 'rnd', 3.0)");
  
  uprs = stmt.executeQuery("SELECT * "
      + "FROM EMPLOYEE FOR UPDATE of BONUS");

  while (uprs.next()) {
    if (uprs.getString(1).equalsIgnoreCase("asif")) {
      uprs.deleteRow();
    }
  }

  w = uprs.getWarnings();
  assertNull(w);
  uprs.close();
  conn.commit();
  
  stmt2 = conn.createStatement();
  rs = stmt2.executeQuery("select * from employee");
  w = rs.getWarnings();
  assertNull(w);

  assertTrue(rs.next());
  assertTrue((rs.getString(1).equalsIgnoreCase("sum") || rs.getString(1)
      .equalsIgnoreCase("dada")));
  
  assertTrue(rs.next());
  
  assertTrue((rs.getString(1).equalsIgnoreCase("sum") || rs.getString(1)
      .equalsIgnoreCase("dada")));
  
  assertFalse(rs.next());
}
 
Example 19
Source File: SURTest.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Test that the JDBC detectability calls throw correct exceptions when
 * called in in wrong row states. 
 * This is done for both supported updatable result set types.
 */
public void testDetectabilityExceptions() throws SQLException 
{
    Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                      ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = s.executeQuery("select * from t1");
    
    checkDetectabilityCallsOutsideRow(rs, "before positioning");

    rs.moveToInsertRow();
    checkDetectabilityCallsOutsideRow(rs, 
                                      "on insertRow before positioning");

    rs.next();
    rs.moveToInsertRow();
    checkDetectabilityCallsOutsideRow(rs, "on insertRow");
    rs.moveToCurrentRow(); // needed until to DERBY-1322 is fixed

    rs.beforeFirst();
    checkDetectabilityCallsOutsideRow(rs, "on beforeFirst row");

    rs.afterLast();
    checkDetectabilityCallsOutsideRow(rs, "on afterLast row");

    rs.first();
    rs.deleteRow();
    checkDetectabilityCallsOutsideRow(rs, "after deleteRow");

    rs.last();
    rs.deleteRow();
    checkDetectabilityCallsOutsideRow(rs, "after deleteRow of last row");

    rs.close();
    s.close();

    // Not strictly SUR, but fixed in same patch, so we test it here.
    s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                            ResultSet.CONCUR_UPDATABLE);
    rs = s.executeQuery("select * from t1");

    checkDetectabilityCallsOutsideRow(rs, "before FO positioning");

    rs.moveToInsertRow();
    checkDetectabilityCallsOutsideRow(rs, 
                                      "on insertRow before FO positioning");

    rs.next();
    rs.moveToInsertRow();
    checkDetectabilityCallsOutsideRow(rs, "on FO insertRow");

    rs.next();
    rs.updateInt(2, 666);
    rs.updateRow();
    checkDetectabilityCallsOutsideRow(rs, "after FO updateRow");

    rs.next();
    rs.deleteRow();
    checkDetectabilityCallsOutsideRow(rs, "after FO deleteRow");

    while (rs.next()) {};
    checkDetectabilityCallsOutsideRow(rs, "after FO emptied out");

    rs.close();
    s.close();
}
 
Example 20
Source File: SURTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Test that the JDBC detectability calls throw correct exceptions when
 * called in in wrong row states. 
 * This is done for both supported updatable result set types.
 */
public void testDetectabilityExceptions() throws SQLException 
{
    Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                      ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = s.executeQuery("select * from t1");
    
    checkDetectabilityCallsOutsideRow(rs, "before positioning");

    rs.moveToInsertRow();
    checkDetectabilityCallsOutsideRow(rs, 
                                      "on insertRow before positioning");

    rs.next();
    rs.moveToInsertRow();
    checkDetectabilityCallsOutsideRow(rs, "on insertRow");
    rs.moveToCurrentRow(); // needed until to DERBY-1322 is fixed

    rs.beforeFirst();
    checkDetectabilityCallsOutsideRow(rs, "on beforeFirst row");

    rs.afterLast();
    checkDetectabilityCallsOutsideRow(rs, "on afterLast row");

    rs.first();
    rs.deleteRow();
    checkDetectabilityCallsOutsideRow(rs, "after deleteRow");

    rs.last();
    rs.deleteRow();
    checkDetectabilityCallsOutsideRow(rs, "after deleteRow of last row");

    rs.close();
    s.close();

    // Not strictly SUR, but fixed in same patch, so we test it here.
    s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                            ResultSet.CONCUR_UPDATABLE);
    rs = s.executeQuery("select * from t1");

    checkDetectabilityCallsOutsideRow(rs, "before FO positioning");

    rs.moveToInsertRow();
    checkDetectabilityCallsOutsideRow(rs, 
                                      "on insertRow before FO positioning");

    rs.next();
    rs.moveToInsertRow();
    checkDetectabilityCallsOutsideRow(rs, "on FO insertRow");

    rs.next();
    rs.updateInt(2, 666);
    rs.updateRow();
    checkDetectabilityCallsOutsideRow(rs, "after FO updateRow");

    rs.next();
    rs.deleteRow();
    checkDetectabilityCallsOutsideRow(rs, "after FO deleteRow");

    while (rs.next()) {};
    checkDetectabilityCallsOutsideRow(rs, "after FO emptied out");

    rs.close();
    s.close();
}