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

The following examples show how to use java.sql.ResultSet#cancelRowUpdates() . 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: 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 assertCancelRowUpdates() throws SQLException {
    for (ResultSet each : resultSets) {
        each.cancelRowUpdates();
    }
}
 
Example 2
Source File: SURTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Test that you can correctly run multiple updateXXX() + updateRow() 
 * combined with cancelRowUpdates().
 */
public void testMultiUpdateRow1() 
    throws SQLException 
{
    Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
    s.setCursorName(getNextCursorName());
    ResultSet rs = s.executeQuery("select * from t1");
    rs.absolute(5);
    final int oldCol2 = rs.getInt(2);
    final int newCol2 = -2222;
    final int oldCol3 = rs.getInt(3);
    final int newCol3 = -3333;
            
    rs.updateInt(2, newCol2);
    assertEquals("Expected the resultset to be updated after updateInt",
                 newCol2, rs.getInt(2));
    rs.cancelRowUpdates();
    assertEquals("Expected updateXXX to have no effect after cancelRowUpdated",
                 oldCol2, rs.getInt(2));
    rs.updateInt(2, newCol2);
    assertEquals("Expected the resultset to be updated after updateInt", 
                 newCol2, rs.getInt(2));
    assertTrue("Expected rs.rowUpdated() to be false before updateRow", 
               !rs.rowUpdated());
    rs.updateRow();
    
    assertTrue("Expected rs.rowUpdated() to be true after updateRow", 
               rs.rowUpdated());
    assertEquals("Expected the resultset detect the updates of previous " + 
                 "updateRow", newCol2, rs.getInt(2));
    
    rs.updateInt(3, newCol3);
    
    assertEquals("Expected the resultset to be updated after updateInt", 
                 newCol3, rs.getInt(3));
    assertEquals("Expected the resultset detect the updates of previous " + 
                 "updateRow", newCol2, rs.getInt(2));
    
    rs.cancelRowUpdates();
    
    assertEquals("Expected updateXXX to have no effect after " +
                 "cancelRowUpdated", oldCol3, rs.getInt(3));
    assertEquals("Expected the resultset detect the updates of previous " +
                 "updateRow after cancelRowUpdated", newCol2, rs.getInt(2));
    rs.updateInt(3, newCol3);
    rs.updateRow();
    assertEquals("Expected the resultset to be updated after updateInt", 
                 newCol3, rs.getInt(3));
    rs.cancelRowUpdates();
    
    assertEquals("Expected the resultset detect the updates of previous" + 
                 "updateRow after cancelRowUpdates", newCol2, rs.getInt(2));
    assertEquals("Expected the resultset detect the updates of previous" + 
                 "updateRow after cancelRowUpdates", newCol3, rs.getInt(3));
    assertTrue("Expected rs.rowUpdated() to be true after " + 
               "updateRow and cancelRowUpdates", rs.rowUpdated());
    
    rs.close();
    s.close();
}
 
Example 3
Source File: SURTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Test that you can correctly run multiple updateNull() + updateRow() 
 * combined with cancelRowUpdates().
 */
public void testMultiUpdateRow2() 
    throws SQLException 
{
    Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
    s.setCursorName(getNextCursorName());
    ResultSet rs = s.executeQuery("select * from t1");
    rs.absolute(5);
    final int oldCol2 = rs.getInt(2);
    final int oldCol3 = rs.getInt(3);
    
    rs.updateNull(2);
    assertEquals("Expected the resultset to be updated after updateNull",
                 0, rs.getInt(2));
    assertTrue("Expected wasNull to be true after updateNull", rs.wasNull());
    rs.cancelRowUpdates();
    assertEquals("Expected updateXXX to have no effect after cancelRowUpdated",
                 oldCol2, rs.getInt(2));
    rs.updateNull(2);
    assertEquals("Expected the resultset to be updated after updateNull", 
                 0, rs.getInt(2));
    assertTrue("Expected wasNull to be true after updateNull", rs.wasNull());
    assertTrue("Expected rs.rowUpdated() to be false before updateRow", 
               !rs.rowUpdated());
    rs.updateRow();
    
    assertTrue("Expected rs.rowUpdated() to be true after updateRow", 
               rs.rowUpdated());
    assertEquals("Expected the resultset detect the updates of previous " + 
                 "updateRow", 0, rs.getInt(2));
    
    rs.updateNull(3);
    
    assertEquals("Expected the resultset to be updated after updateNull", 
                 0, rs.getInt(3));
    assertTrue("Expected wasNull to be true after updateNull", rs.wasNull());
    assertEquals("Expected the resultset detect the updates of previous " + 
                 "updateRow", 0, rs.getInt(2));
    
    rs.cancelRowUpdates();
    
    assertEquals("Expected updateXXX to have no effect after " +
                 "cancelRowUpdated", oldCol3, rs.getInt(3));
    assertEquals("Expected the resultset detect the updates of previous " +
                 "updateRow after cancelRowUpdated", 0, rs.getInt(2));
    rs.updateNull(3);
    rs.updateRow();
    assertEquals("Expected the resultset to be updated after updateNull", 
                 0, rs.getInt(3));
    rs.cancelRowUpdates();
    
    assertEquals("Expected the resultset detect the updates of previous" + 
                 "updateRow after cancelRowUpdates", 0, rs.getInt(2));
    assertEquals("Expected the resultset detect the updates of previous" + 
                 "updateRow after cancelRowUpdates", 0, rs.getInt(3));
    assertTrue("Expected rs.rowUpdated() to be true after " + 
               "updateRow and cancelRowUpdates", rs.rowUpdated());
    
    rs.close();
    s.close();
}
 
Example 4
Source File: UnsupportedOperationResultSetTest.java    From shardingsphere with Apache License 2.0 4 votes vote down vote up
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertCancelRowUpdates() throws SQLException {
    for (ResultSet each : resultSets) {
        each.cancelRowUpdates();
    }
}
 
Example 5
Source File: SURTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Test that you can correctly run multiple updateXXX() + updateRow() 
 * combined with cancelRowUpdates().
 */
public void testMultiUpdateRow1() 
    throws SQLException 
{
    Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
    s.setCursorName(getNextCursorName());
    ResultSet rs = s.executeQuery("select * from t1");
    rs.absolute(5);
    final int oldCol2 = rs.getInt(2);
    final int newCol2 = -2222;
    final int oldCol3 = rs.getInt(3);
    final int newCol3 = -3333;
            
    rs.updateInt(2, newCol2);
    assertEquals("Expected the resultset to be updated after updateInt",
                 newCol2, rs.getInt(2));
    rs.cancelRowUpdates();
    assertEquals("Expected updateXXX to have no effect after cancelRowUpdated",
                 oldCol2, rs.getInt(2));
    rs.updateInt(2, newCol2);
    assertEquals("Expected the resultset to be updated after updateInt", 
                 newCol2, rs.getInt(2));
    assertTrue("Expected rs.rowUpdated() to be false before updateRow", 
               !rs.rowUpdated());
    rs.updateRow();
    
    assertTrue("Expected rs.rowUpdated() to be true after updateRow", 
               rs.rowUpdated());
    assertEquals("Expected the resultset detect the updates of previous " + 
                 "updateRow", newCol2, rs.getInt(2));
    
    rs.updateInt(3, newCol3);
    
    assertEquals("Expected the resultset to be updated after updateInt", 
                 newCol3, rs.getInt(3));
    assertEquals("Expected the resultset detect the updates of previous " + 
                 "updateRow", newCol2, rs.getInt(2));
    
    rs.cancelRowUpdates();
    
    assertEquals("Expected updateXXX to have no effect after " +
                 "cancelRowUpdated", oldCol3, rs.getInt(3));
    assertEquals("Expected the resultset detect the updates of previous " +
                 "updateRow after cancelRowUpdated", newCol2, rs.getInt(2));
    rs.updateInt(3, newCol3);
    rs.updateRow();
    assertEquals("Expected the resultset to be updated after updateInt", 
                 newCol3, rs.getInt(3));
    rs.cancelRowUpdates();
    
    assertEquals("Expected the resultset detect the updates of previous" + 
                 "updateRow after cancelRowUpdates", newCol2, rs.getInt(2));
    assertEquals("Expected the resultset detect the updates of previous" + 
                 "updateRow after cancelRowUpdates", newCol3, rs.getInt(3));
    assertTrue("Expected rs.rowUpdated() to be true after " + 
               "updateRow and cancelRowUpdates", rs.rowUpdated());
    
    rs.close();
    s.close();
}
 
Example 6
Source File: SURTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Test that you can correctly run multiple updateNull() + updateRow() 
 * combined with cancelRowUpdates().
 */
public void testMultiUpdateRow2() 
    throws SQLException 
{
    Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
    s.setCursorName(getNextCursorName());
    ResultSet rs = s.executeQuery("select * from t1");
    rs.absolute(5);
    final int oldCol2 = rs.getInt(2);
    final int oldCol3 = rs.getInt(3);
    
    rs.updateNull(2);
    assertEquals("Expected the resultset to be updated after updateNull",
                 0, rs.getInt(2));
    assertTrue("Expected wasNull to be true after updateNull", rs.wasNull());
    rs.cancelRowUpdates();
    assertEquals("Expected updateXXX to have no effect after cancelRowUpdated",
                 oldCol2, rs.getInt(2));
    rs.updateNull(2);
    assertEquals("Expected the resultset to be updated after updateNull", 
                 0, rs.getInt(2));
    assertTrue("Expected wasNull to be true after updateNull", rs.wasNull());
    assertTrue("Expected rs.rowUpdated() to be false before updateRow", 
               !rs.rowUpdated());
    rs.updateRow();
    
    assertTrue("Expected rs.rowUpdated() to be true after updateRow", 
               rs.rowUpdated());
    assertEquals("Expected the resultset detect the updates of previous " + 
                 "updateRow", 0, rs.getInt(2));
    
    rs.updateNull(3);
    
    assertEquals("Expected the resultset to be updated after updateNull", 
                 0, rs.getInt(3));
    assertTrue("Expected wasNull to be true after updateNull", rs.wasNull());
    assertEquals("Expected the resultset detect the updates of previous " + 
                 "updateRow", 0, rs.getInt(2));
    
    rs.cancelRowUpdates();
    
    assertEquals("Expected updateXXX to have no effect after " +
                 "cancelRowUpdated", oldCol3, rs.getInt(3));
    assertEquals("Expected the resultset detect the updates of previous " +
                 "updateRow after cancelRowUpdated", 0, rs.getInt(2));
    rs.updateNull(3);
    rs.updateRow();
    assertEquals("Expected the resultset to be updated after updateNull", 
                 0, rs.getInt(3));
    rs.cancelRowUpdates();
    
    assertEquals("Expected the resultset detect the updates of previous" + 
                 "updateRow after cancelRowUpdates", 0, rs.getInt(2));
    assertEquals("Expected the resultset detect the updates of previous" + 
                 "updateRow after cancelRowUpdates", 0, rs.getInt(3));
    assertTrue("Expected rs.rowUpdated() to be true after " + 
               "updateRow and cancelRowUpdates", rs.rowUpdated());
    
    rs.close();
    s.close();
}
 
Example 7
Source File: SURTest.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Test that you can correctly run multiple updateXXX() + updateRow() 
 * combined with cancelRowUpdates().
 */
public void testMultiUpdateRow1() 
    throws SQLException 
{
    Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
    s.setCursorName(getNextCursorName());
    ResultSet rs = s.executeQuery("select * from t1");
    rs.absolute(5);
    final int oldCol2 = rs.getInt(2);
    final int newCol2 = -2222;
    final int oldCol3 = rs.getInt(3);
    final int newCol3 = -3333;
            
    rs.updateInt(2, newCol2);
    assertEquals("Expected the resultset to be updated after updateInt",
                 newCol2, rs.getInt(2));
    rs.cancelRowUpdates();
    assertEquals("Expected updateXXX to have no effect after cancelRowUpdated",
                 oldCol2, rs.getInt(2));
    rs.updateInt(2, newCol2);
    assertEquals("Expected the resultset to be updated after updateInt", 
                 newCol2, rs.getInt(2));
    assertTrue("Expected rs.rowUpdated() to be false before updateRow", 
               !rs.rowUpdated());
    rs.updateRow();
    
    assertTrue("Expected rs.rowUpdated() to be true after updateRow", 
               rs.rowUpdated());
    assertEquals("Expected the resultset detect the updates of previous " + 
                 "updateRow", newCol2, rs.getInt(2));
    
    rs.updateInt(3, newCol3);
    
    assertEquals("Expected the resultset to be updated after updateInt", 
                 newCol3, rs.getInt(3));
    assertEquals("Expected the resultset detect the updates of previous " + 
                 "updateRow", newCol2, rs.getInt(2));
    
    rs.cancelRowUpdates();
    
    assertEquals("Expected updateXXX to have no effect after " +
                 "cancelRowUpdated", oldCol3, rs.getInt(3));
    assertEquals("Expected the resultset detect the updates of previous " +
                 "updateRow after cancelRowUpdated", newCol2, rs.getInt(2));
    rs.updateInt(3, newCol3);
    rs.updateRow();
    assertEquals("Expected the resultset to be updated after updateInt", 
                 newCol3, rs.getInt(3));
    rs.cancelRowUpdates();
    
    assertEquals("Expected the resultset detect the updates of previous" + 
                 "updateRow after cancelRowUpdates", newCol2, rs.getInt(2));
    assertEquals("Expected the resultset detect the updates of previous" + 
                 "updateRow after cancelRowUpdates", newCol3, rs.getInt(3));
    assertTrue("Expected rs.rowUpdated() to be true after " + 
               "updateRow and cancelRowUpdates", rs.rowUpdated());
    
    rs.close();
    s.close();
}
 
Example 8
Source File: SURTest.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Test that you can correctly run multiple updateNull() + updateRow() 
 * combined with cancelRowUpdates().
 */
public void testMultiUpdateRow2() 
    throws SQLException 
{
    Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
    s.setCursorName(getNextCursorName());
    ResultSet rs = s.executeQuery("select * from t1");
    rs.absolute(5);
    final int oldCol2 = rs.getInt(2);
    final int oldCol3 = rs.getInt(3);
    
    rs.updateNull(2);
    assertEquals("Expected the resultset to be updated after updateNull",
                 0, rs.getInt(2));
    assertTrue("Expected wasNull to be true after updateNull", rs.wasNull());
    rs.cancelRowUpdates();
    assertEquals("Expected updateXXX to have no effect after cancelRowUpdated",
                 oldCol2, rs.getInt(2));
    rs.updateNull(2);
    assertEquals("Expected the resultset to be updated after updateNull", 
                 0, rs.getInt(2));
    assertTrue("Expected wasNull to be true after updateNull", rs.wasNull());
    assertTrue("Expected rs.rowUpdated() to be false before updateRow", 
               !rs.rowUpdated());
    rs.updateRow();
    
    assertTrue("Expected rs.rowUpdated() to be true after updateRow", 
               rs.rowUpdated());
    assertEquals("Expected the resultset detect the updates of previous " + 
                 "updateRow", 0, rs.getInt(2));
    
    rs.updateNull(3);
    
    assertEquals("Expected the resultset to be updated after updateNull", 
                 0, rs.getInt(3));
    assertTrue("Expected wasNull to be true after updateNull", rs.wasNull());
    assertEquals("Expected the resultset detect the updates of previous " + 
                 "updateRow", 0, rs.getInt(2));
    
    rs.cancelRowUpdates();
    
    assertEquals("Expected updateXXX to have no effect after " +
                 "cancelRowUpdated", oldCol3, rs.getInt(3));
    assertEquals("Expected the resultset detect the updates of previous " +
                 "updateRow after cancelRowUpdated", 0, rs.getInt(2));
    rs.updateNull(3);
    rs.updateRow();
    assertEquals("Expected the resultset to be updated after updateNull", 
                 0, rs.getInt(3));
    rs.cancelRowUpdates();
    
    assertEquals("Expected the resultset detect the updates of previous" + 
                 "updateRow after cancelRowUpdates", 0, rs.getInt(2));
    assertEquals("Expected the resultset detect the updates of previous" + 
                 "updateRow after cancelRowUpdates", 0, rs.getInt(3));
    assertTrue("Expected rs.rowUpdated() to be true after " + 
               "updateRow and cancelRowUpdates", rs.rowUpdated());
    
    rs.close();
    s.close();
}