Search in sources :

Example 11 with CachedRowSet

use of javax.sql.rowset.CachedRowSet in project jdk8u_jdk by JetBrains.

the class CommonCachedRowSetTests method commonCachedRowSetTest0037.

/*
     * Validate that createCopySchema() returns the proper values
     */
@Test(dataProvider = "rowsetUsingCoffeeHouses")
public void commonCachedRowSetTest0037(CachedRowSet rs) throws Exception {
    try (CachedRowSet crs1 = rs.createCopySchema()) {
        assertTrue(crs1.size() == 0);
        compareMetaData(crs1.getMetaData(), rs.getMetaData());
    }
    rs.close();
}
Also used : CachedRowSet(javax.sql.rowset.CachedRowSet) Test(org.testng.annotations.Test)

Example 12 with CachedRowSet

use of javax.sql.rowset.CachedRowSet in project jdk8u_jdk by JetBrains.

the class CommonCachedRowSetTests method commonCachedRowSetTest0059.

/*
     * Validate that restoreOrginal will restore the RowSet to its
     * state prior to deleting a row
     */
@Test(dataProvider = "rowsetUsingCoffees", enabled = true)
public void commonCachedRowSetTest0059(CachedRowSet rs) throws Exception {
    int rowToDelete = 2;
    try (CachedRowSet crs1 = rsf.createCachedRowSet()) {
        rs.beforeFirst();
        crs1.populate(rs);
        TestRowSetListener rsl = new TestRowSetListener();
        crs1.addRowSetListener(rsl);
        // Delete a row, the PK is also the absolute position as a List
        // backs the RowSet
        crs1.absolute(rowToDelete);
        crs1.deleteRow();
        assertTrue(crs1.rowDeleted());
        assertFalse(findRowByPrimaryKey(crs1, rowToDelete, 1));
        // Restore back to our original state and the
        // previously deleted row should be there
        rsl.resetFlag();
        crs1.restoreOriginal();
        assertTrue(rsl.isNotified(TestRowSetListener.ROWSET_CHANGED));
        assertTrue(crs1.isBeforeFirst());
        crs1.absolute(rowToDelete);
        assertFalse(crs1.rowDeleted());
        assertTrue(findRowByPrimaryKey(crs1, rowToDelete, 1));
    }
    rs.close();
}
Also used : TestRowSetListener(util.TestRowSetListener) CachedRowSet(javax.sql.rowset.CachedRowSet) Test(org.testng.annotations.Test)

Example 13 with CachedRowSet

use of javax.sql.rowset.CachedRowSet in project jdk8u_jdk by JetBrains.

the class CommonCachedRowSetTests method commonCachedRowSetTest0058.

/*
     * Validate that restoreOrginal will restore the RowSet to its
     * state prior to the insert of a row
     */
@Test(dataProvider = "rowsetUsingCoffeeHouses")
public void commonCachedRowSetTest0058(CachedRowSet rs) throws Exception {
    int rowToInsert = 1961;
    assertTrue(rs.size() == COFFEE_HOUSES_ROWS);
    try (// Add new row
    CachedRowSet crs1 = rsf.createCachedRowSet()) {
        rs.beforeFirst();
        crs1.populate(rs);
        TestRowSetListener rsl = new TestRowSetListener();
        crs1.addRowSetListener(rsl);
        crs1.moveToInsertRow();
        crs1.updateInt(1, rowToInsert);
        crs1.updateString(2, "GOTHAM");
        crs1.updateInt(3, 3450);
        crs1.updateInt(4, 2005);
        crs1.updateInt(5, 5455);
        crs1.insertRow();
        assertTrue(rsl.isNotified(TestRowSetListener.ROW_CHANGED));
        crs1.moveToCurrentRow();
        assertTrue(findRowByPrimaryKey(crs1, rowToInsert, 1));
        // Restore back to our original state and the
        // previously inserted row should not be there
        rsl.resetFlag();
        crs1.restoreOriginal();
        assertTrue(rsl.isNotified(TestRowSetListener.ROWSET_CHANGED));
        assertTrue(crs1.isBeforeFirst());
        crs1.last();
        assertFalse(crs1.rowInserted());
        assertFalse(findRowByPrimaryKey(crs1, rowToInsert, 1));
    }
    rs.close();
}
Also used : TestRowSetListener(util.TestRowSetListener) CachedRowSet(javax.sql.rowset.CachedRowSet) Test(org.testng.annotations.Test)

Example 14 with CachedRowSet

use of javax.sql.rowset.CachedRowSet in project jdk8u_jdk by JetBrains.

the class CommonCachedRowSetTests method commonCachedRowSetTest0039.

/*
     * Validate that createCopyNoConstraints() returns the proper values
     * and getMatchColumnIndexes should throw a SQLException. This test
     * specifies setMatchColumn(String)
     */
@Test(dataProvider = "rowsetUsingCoffeeHouses")
public void commonCachedRowSetTest0039(CachedRowSet rs) throws Exception {
    rs.setMatchColumn("ID");
    try (CachedRowSet crs1 = rs.createCopyNoConstraints()) {
        assertTrue(crs1.size() == COFFEE_HOUSES_ROWS);
        compareRowSets(rs, crs1);
        boolean recievedSQE = false;
        try {
            int[] indexes = crs1.getMatchColumnIndexes();
        } catch (SQLException e) {
            recievedSQE = true;
        }
        assertTrue(recievedSQE);
        recievedSQE = false;
        try {
            String[] colNames = crs1.getMatchColumnNames();
        } catch (SQLException e) {
            recievedSQE = true;
        }
        assertTrue(recievedSQE);
    }
    rs.close();
}
Also used : SQLException(java.sql.SQLException) CachedRowSet(javax.sql.rowset.CachedRowSet) Test(org.testng.annotations.Test)

Example 15 with CachedRowSet

use of javax.sql.rowset.CachedRowSet in project jdk8u_jdk by JetBrains.

the class CommonCachedRowSetTests method commonCachedRowSetTest0060.

/*
     * Validate that restoreOrginal will restore the RowSet to its
     * state prior to updating a row
     */
@Test(dataProvider = "rowsetUsingCoffees", enabled = true)
public void commonCachedRowSetTest0060(CachedRowSet rs) throws Exception {
    int rowToUpdate = 2;
    String coffee = "Hazelnut";
    try (CachedRowSet crs1 = rsf.createCachedRowSet()) {
        rs.beforeFirst();
        crs1.populate(rs);
        TestRowSetListener rsl = new TestRowSetListener();
        crs1.addRowSetListener(rsl);
        // Delete a row, the PK is also the absolute position as a List
        // backs the RowSet
        crs1.absolute(rowToUpdate);
        String origCoffee = crs1.getString(2);
        crs1.updateString(2, coffee);
        assertTrue(crs1.columnUpdated(2));
        crs1.updateRow();
        assertTrue(crs1.rowUpdated());
        assertFalse(origCoffee.equals(crs1.getString(2)));
        // Restore back to our original state and the
        // previous value for the column within the row should be there
        rsl.resetFlag();
        crs1.restoreOriginal();
        assertTrue(rsl.isNotified(TestRowSetListener.ROWSET_CHANGED));
        assertTrue(crs1.isBeforeFirst());
        // absolute() is failing for some reason so need to look at this later
        crs1.next();
        crs1.next();
        assertFalse(crs1.columnUpdated(2));
        assertFalse(crs1.rowUpdated());
        assertTrue(origCoffee.equals(crs1.getString(2)));
    }
    rs.close();
}
Also used : TestRowSetListener(util.TestRowSetListener) CachedRowSet(javax.sql.rowset.CachedRowSet) Test(org.testng.annotations.Test)

Aggregations

CachedRowSet (javax.sql.rowset.CachedRowSet)16 Test (org.testng.annotations.Test)11 OracleCachedRowSet (oracle.jdbc.rowset.OracleCachedRowSet)3 TestRowSetListener (util.TestRowSetListener)3 SQLException (java.sql.SQLException)2 RowSet (javax.sql.RowSet)2 JoinRowSet (javax.sql.rowset.JoinRowSet)2 WebRowSet (javax.sql.rowset.WebRowSet)2 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 ResultSetWrappingSqlRowSet (org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSet)1 DataProvider (org.testng.annotations.DataProvider)1