Java Code Examples for javax.sql.rowset.CachedRowSet

The following examples show how to use javax.sql.rowset.CachedRowSet. These examples are extracted from open source projects. 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
private void compareRowSets(CachedRowSet crs, CachedRowSet crs1) throws Exception {

        int rows = crs.size();
        assertTrue(rows == crs1.size());

        ResultSetMetaData rsmd = crs.getMetaData();

        compareMetaData(rsmd, crs1.getMetaData());
        int cols = rsmd.getColumnCount();

        for (int row = 1; row <= rows; row++) {
            crs.absolute((row));
            crs1.absolute(row);
            for (int col = 1; col <= cols; col++) {
                compareColumnValue(JDBCType.valueOf(rsmd.getColumnType(col)),
                        crs, crs1, col);
            }
        }

    }
 
Example 2
private void compareRowSets(CachedRowSet crs, CachedRowSet crs1) throws Exception {

        int rows = crs.size();
        assertTrue(rows == crs1.size());

        ResultSetMetaData rsmd = crs.getMetaData();

        compareMetaData(rsmd, crs1.getMetaData());
        int cols = rsmd.getColumnCount();

        for (int row = 1; row <= rows; row++) {
            crs.absolute((row));
            crs1.absolute(row);
            for (int col = 1; col <= cols; col++) {
                compareColumnValue(JDBCType.valueOf(rsmd.getColumnType(col)),
                        crs, crs1, col);
            }
        }

    }
 
Example 3
@Test(dataProvider = "rowsetUsingCoffeeHouses")
public void commonCachedRowSetTest0053(CachedRowSet rs) throws Exception {
    int rowToInsert = 1961;
    assertTrue(rs.size() == COFFEE_HOUSES_ROWS);
    // Add new row
    rs.moveToInsertRow();
    rs.updateInt(1, rowToInsert);
    rs.updateString(2, "GOTHAM");
    rs.updateInt(3, 3450);
    rs.updateInt(4, 2005);
    rs.updateInt(5, 5455);
    rs.insertRow();
    rs.moveToCurrentRow();
    // check that the number of rows has increased
    assertTrue(rs.size() == COFFEE_HOUSES_ROWS + 1);
    assertTrue(findRowByPrimaryKey(rs, rowToInsert, 1));
    rs.undoInsert();
    // Check to make sure the row is no longer there
    assertTrue(rs.size() == COFFEE_HOUSES_ROWS);
    assertFalse(findRowByPrimaryKey(rs, rowToInsert, 1));
    rs.close();
}
 
Example 4
@DataProvider(name = "rowsetUsingDataTypes")
protected Object[][] rowsetUsingDataTypes() throws Exception {

    CachedRowSet rs = createDataTypesRowSet();
    return new Object[][]{
        {rs, JDBCType.INTEGER},
        {rs, JDBCType.CHAR},
        {rs, JDBCType.VARCHAR},
        {rs, JDBCType.BIGINT},
        {rs, JDBCType.BOOLEAN},
        {rs, JDBCType.SMALLINT},
        {rs, JDBCType.DOUBLE},
        {rs, JDBCType.DECIMAL},
        {rs, JDBCType.REAL},
        {rs, JDBCType.TINYINT},
        {rs, JDBCType.DATE},
        {rs, JDBCType.TIME},
        {rs, JDBCType.TIMESTAMP},
        {rs, JDBCType.VARBINARY},
        {rs, JDBCType.ARRAY},
        {rs, JDBCType.REF},
        {rs, JDBCType.FLOAT}
    };
}
 
Example 5
@Test(dataProvider = "rowsetUsingCoffeeHouses")
public void commonCachedRowSetTest0053(CachedRowSet rs) throws Exception {
    int rowToInsert = 1961;
    assertTrue(rs.size() == COFFEE_HOUSES_ROWS);
    // Add new row
    rs.moveToInsertRow();
    rs.updateInt(1, rowToInsert);
    rs.updateString(2, "GOTHAM");
    rs.updateInt(3, 3450);
    rs.updateInt(4, 2005);
    rs.updateInt(5, 5455);
    rs.insertRow();
    rs.moveToCurrentRow();
    // check that the number of rows has increased
    assertTrue(rs.size() == COFFEE_HOUSES_ROWS + 1);
    assertTrue(findRowByPrimaryKey(rs, rowToInsert, 1));
    rs.undoInsert();
    // Check to make sure the row is no longer there
    assertTrue(rs.size() == COFFEE_HOUSES_ROWS);
    assertFalse(findRowByPrimaryKey(rs, rowToInsert, 1));
    rs.close();
}
 
Example 6
@Test(dataProvider = "rowsetUsingCoffeeHouses")
public void commonCachedRowSetTest0026(CachedRowSet rs) throws Exception {
    Object[] afterDelete = {
        10023, 33002, 10040, 32001, 10042, 10024, 10039, 10041,
        33005, 33010, 10037, 10034, 32004
    };
    int rowToDelete = 10035;
    // All rows should be found
    assertEquals(getPrimaryKeys(rs), COFFEE_HOUSES_PRIMARY_KEYS);
    // Delete the row
    assertTrue(deleteRowByPrimaryKey(rs, rowToDelete, 1));
    // With setShowDeleted(false) which is the default,
    // the deleted row should not be visible
    assertFalse(findRowByPrimaryKey(rs, rowToDelete, 1));
    assertEquals(getPrimaryKeys(rs), afterDelete);
    assertTrue(rs.size() == COFFEE_HOUSES_ROWS);
    // With setShowDeleted(true), the deleted row should be visible
    rs.setShowDeleted(true);
    assertTrue(findRowByPrimaryKey(rs, rowToDelete, 1));
    rs.close();
}
 
Example 7
Source Project: hottub   Source File: JoinRowSetTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name = "createCachedRowSetsToUse")
private Object[][] createCachedRowSetsToUse() throws SQLException {
    CachedRowSet crs = rsf.createCachedRowSet();
    initCoffeesMetaData(crs);
    createCoffeesRows(crs);
    // Make sure you are not on the insertRow
    crs.moveToCurrentRow();
    CachedRowSet crs1 = rsf.createCachedRowSet();
    initSuppliersMetaData(crs1);
    createSuppiersRows(crs1);
    // Make sure you are not on the insertRow
    crs1.moveToCurrentRow();
    return new Object[][]{
        {crs, crs1}
    };
}
 
Example 8
@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();
}
 
Example 9
@Test(dataProvider = "rowsetUsingCoffeeHouses",
        expectedExceptions = SQLException.class)
public void commonCachedRowSetTest0047(CachedRowSet rs) throws Exception {
    rs.insertRow();
    rs.undoUpdate();
    rs.close();
}
 
Example 10
@Test(dataProvider = "rowsetUsingCoffeeHouses",
        expectedExceptions = SQLException.class)
public void commonCachedRowSetTest0013(CachedRowSet rs) throws Exception {
    int[] cols = {1, -1};
    rs.setMatchColumn(cols);
    rs.close();
}
 
Example 11
@Test(dataProvider = "rowsetUsingCoffeeHouses", enabled = false)
public void commonCachedRowSetTest0017(CachedRowSet rs) throws Exception {
    int[] expectedCols = {1};
    String[] expectedColNames = {"ID"};
    rs.setMatchColumn(expectedColNames[0]);
    int[] actualCols = rs.getMatchColumnIndexes();
    String[] actualColNames = rs.getMatchColumnNames();
    assertEquals(actualCols, expectedCols);
    assertEquals(actualColNames, expectedColNames);
    rs.close();
}
 
Example 12
@Test(dataProvider = "rowsetUsingCoffeeHouses", enabled = false)
public void commonCachedRowSetTest0016(CachedRowSet rs) throws Exception {
    int[] expectedCols = {1};
    String[] expectedColNames = {"ID"};
    rs.setMatchColumn(1);
    int[] actualCols = rs.getMatchColumnIndexes();
    String[] actualColNames = rs.getMatchColumnNames();
    for (int i = 0; i < actualCols.length; i++) {
        System.out.println(actualCols[i]);
    }
    assertEquals(actualCols, expectedCols);
    assertEquals(actualColNames, expectedColNames);
    rs.close();
}
 
Example 13
@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();
}
 
Example 14
@Test(dataProvider = "rowSetType")
public void commonCachedRowSetTest0011(CachedRowSet rs) throws Exception {
    int[] pkeys = {1, 3};
    assertNull(rs.getKeyColumns());
    rs.setKeyColumns(pkeys);
    assertEquals(rs.getKeyColumns(), pkeys);
    rs.close();
}
 
Example 15
@Test(dataProvider = "rowsetUsingCoffeeHouses", enabled = false)
public void commonCachedRowSetTest0016(CachedRowSet rs) throws Exception {
    int[] expectedCols = {1};
    String[] expectedColNames = {"ID"};
    rs.setMatchColumn(1);
    int[] actualCols = rs.getMatchColumnIndexes();
    String[] actualColNames = rs.getMatchColumnNames();
    for (int i = 0; i < actualCols.length; i++) {
        System.out.println(actualCols[i]);
    }
    assertEquals(actualCols, expectedCols);
    assertEquals(actualColNames, expectedColNames);
    rs.close();
}
 
Example 16
Source Project: openjdk-jdk9   Source File: JoinRowSetTests.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "createCachedRowSetsToUse")
public void joinRowSetTests0005(CachedRowSet crs, CachedRowSet crs1)
        throws Exception {

    try (JoinRowSet jrs = newInstance()) {
        crs.setMatchColumn(JOIN_COLNAME);
        crs1.setMatchColumn(JOIN_COLNAME);
        jrs.addRowSet(crs);
        jrs.addRowSet(crs1);
        validateResults(jrs);
        crs.close();
        crs1.close();
    }
}
 
Example 17
Source Project: jdk8u60   Source File: JoinRowSetTests.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void initSuppliersMetaData(CachedRowSet crs) throws SQLException {
    RowSetMetaDataImpl rsmd = new RowSetMetaDataImpl();

    /*
     *  CREATE TABLE SUPPLIERS (
     *   SUP_ID INTEGER NOT NULL,
     *   SUP_NAME VARCHAR(32) NOT NULL,
     *   STREET VARCHAR(32) NOT NULL,
     *   CITY VARCHAR(32) NOT NULL,
     *   STATE CHAR(2) NOT NULL,
     *   ZIP CHAR(5) NOT NULL,
     *   PRIMARY KEY (SUP_ID))
     */
    rsmd.setColumnCount(6);
    rsmd.setColumnName(1, "SUP_ID");
    rsmd.setColumnName(2, "SUP_NAME");
    rsmd.setColumnName(3, "STREET");
    rsmd.setColumnName(4, "CITY");
    rsmd.setColumnName(5, "STATE");
    rsmd.setColumnName(6, "ZIP");

    rsmd.setColumnType(1, Types.INTEGER);
    rsmd.setColumnType(2, Types.VARCHAR);
    rsmd.setColumnType(3, Types.VARCHAR);
    rsmd.setColumnType(4, Types.VARCHAR);
    rsmd.setColumnType(5, Types.CHAR);
    rsmd.setColumnType(6, Types.CHAR);
    crs.setMetaData(rsmd);
    crs.setTableName(SUPPLIERS_TABLE);
}
 
Example 18
Source Project: cactoos-jdbc   Source File: StatementSelect.java    License: MIT License 5 votes vote down vote up
@Override
public ResultSet result() throws Exception {
    // @checkstyle NestedTryDepthCheck (10 lines)
    try (Connection conn = this.session.connection()) {
        try (PreparedStatement stmt = this.query.prepared(conn)) {
            try (ResultSet rset = stmt.executeQuery()) {
                final RowSetFactory rsf = RowSetProvider.newFactory();
                final CachedRowSet crs = rsf.createCachedRowSet();
                crs.populate(rset);
                return crs;
            }
        }
    }
}
 
Example 19
@Test(dataProvider = "createCachedRowSetsToUse")
public void joinRowSetTests0005(CachedRowSet crs, CachedRowSet crs1)
        throws Exception {

    try (JoinRowSet jrs = newInstance()) {
        crs.setMatchColumn(JOIN_COLNAME);
        crs1.setMatchColumn(JOIN_COLNAME);
        jrs.addRowSet(crs);
        jrs.addRowSet(crs1);
        validateResults(jrs);
        crs.close();
        crs1.close();
    }
}
 
Example 20
@Test(dataProvider = "rowsetUsingCoffeeHouses",
        expectedExceptions = SQLException.class)
public void commonCachedRowSetTest0052(CachedRowSet rs) throws Exception {
    rs.setShowDeleted(true);
    rs.afterLast();
    rs.undoInsert();
    rs.close();
}
 
Example 21
@Test(dataProvider = "rowsetUsingCoffeeHouses",
        expectedExceptions = SQLException.class)
public void commonCachedRowSetTest0045(CachedRowSet rs) throws Exception {
    rs.setShowDeleted(true);
    rs.beforeFirst();
    rs.undoDelete();
    rs.close();
}
 
Example 22
@Test(dataProvider = "rowsetUsingCoffeeHouses", enabled = false)
public void commonCachedRowSetTest0018(CachedRowSet rs) throws Exception {
    int[] expectedCols = {1, 3};
    String[] expectedColNames = {"COF_ID", "SUP_ID"};
    rs.setMatchColumn(expectedCols);
    int[] actualCols = rs.getMatchColumnIndexes();
    String[] actualColNames = rs.getMatchColumnNames();
    assertEquals(actualCols, expectedCols);
    assertEquals(actualColNames, expectedColNames);
    assertEquals(actualCols, expectedCols);
    rs.close();
}
 
Example 23
@Test(dataProvider = "rowsetUsingCoffees")
public void commonCachedRowSetTest0056(CachedRowSet rs) throws Exception {
    String coffee = "Hazelnut";
    int sales = 100;
    int id = 200;
    Object[] updatedPkeys = {1, id, 3, 4, 5};
    // Change the coffee name and sales total for row 2 and save the
    // previous values
    rs.absolute(2);
    int origId = rs.getInt(1);
    String origCoffee = rs.getString(2);
    int origSales = rs.getInt(5);
    rs.updateInt(1, id);
    rs.updateString(2, coffee);
    rs.updateInt(5, sales);
    // MetaData should match
    try ( // Get the original original RowSet and validate that the changes
            // are only made to the current, not the original
            ResultSet rs1 = rs.getOriginal()) {
        // MetaData should match
        compareMetaData(rs.getMetaData(), rs1.getMetaData());
        assertTrue(rs1.isBeforeFirst());
        assertTrue(rs1.getConcurrency() == ResultSet.CONCUR_UPDATABLE);
        assertTrue(rs1.getType() == ResultSet.TYPE_SCROLL_INSENSITIVE);
        rs1.absolute(2);
        // Check original rowset is not changed
        assertTrue(rs1.getInt(1) == origId);
        assertTrue(rs1.getString(2).equals(origCoffee));
        assertTrue(rs1.getInt(5) == origSales);
        assertEquals(getPrimaryKeys(rs1), COFFEES_PRIMARY_KEYS);
        // Check current rowset
        assertTrue(rs.getInt(1) == id);
        assertTrue(rs.getString(2).equals(coffee));
        assertTrue(rs.getInt(5) == sales);
        assertEquals(getPrimaryKeys(rs), updatedPkeys);
    }
    rs.close();
}
 
Example 24
protected <T extends RowSet> T createDataTypesRowSet() throws SQLException {
    T rs = (T) newInstance();
    initDataTypesMetaData((CachedRowSet) rs);
    createDataTypesRows(rs);
    // Make sure you are not on the insertRow
    rs.moveToCurrentRow();
    return rs;
}
 
Example 25
@Test(dataProvider = "rowsetUsingCoffeeHouses", enabled = false)
public void commonCachedRowSetTest0016(CachedRowSet rs) throws Exception {
    int[] expectedCols = {1};
    String[] expectedColNames = {"ID"};
    rs.setMatchColumn(1);
    int[] actualCols = rs.getMatchColumnIndexes();
    String[] actualColNames = rs.getMatchColumnNames();
    for (int i = 0; i < actualCols.length; i++) {
        System.out.println(actualCols[i]);
    }
    assertEquals(actualCols, expectedCols);
    assertEquals(actualColNames, expectedColNames);
    rs.close();
}
 
Example 26
@Test(dataProvider = "rowsetUsingCoffeeHouses")
public void commonCachedRowSetTest0061(CachedRowSet rs) throws Exception {
    try (CachedRowSet crs1 = rsf.createCachedRowSet()) {
        rs.beforeFirst();
        crs1.populate(rs);
        compareRowSets(rs, crs1);
    }
    rs.close();
}
 
Example 27
@Test(dataProvider = "createCachedRowSetsToUse")
public void joinRowSetTests0005(CachedRowSet crs, CachedRowSet crs1)
        throws Exception {

    try (JoinRowSet jrs = newInstance()) {
        crs.setMatchColumn(JOIN_COLNAME);
        crs1.setMatchColumn(JOIN_COLNAME);
        jrs.addRowSet(crs);
        jrs.addRowSet(crs1);
        validateResults(jrs);
        crs.close();
        crs1.close();
    }
}
 
Example 28
@Test(dataProvider = "createCachedRowSetsToUse")
public void joinRowSetTests0002(CachedRowSet crs, CachedRowSet crs1)
        throws Exception {

    try (JoinRowSet jrs = newInstance()) {
        RowSet[] rowsets = {crs, crs1};
        String[] joinCols = {JOIN_COLNAME, JOIN_COLNAME};
        jrs.addRowSet(rowsets, joinCols);
        validateResults(jrs);
        crs.close();
        crs1.close();
    }
}
 
Example 29
@Test(dataProvider = "rowsetUsingCoffeeHouses",
        expectedExceptions = SQLException.class)
public void commonCachedRowSetTest0045(CachedRowSet rs) throws Exception {
    rs.setShowDeleted(true);
    rs.beforeFirst();
    rs.undoDelete();
    rs.close();
}
 
Example 30
@Test(dataProvider = "rowsetUsingCoffeeHouses",
        expectedExceptions = SQLException.class)
public void commonCachedRowSetTest0020(CachedRowSet rs) throws Exception {
    rs.setMatchColumn(1);
    int[] actualCols = rs.getMatchColumnIndexes();
    assertTrue(actualCols != null);
    rs.unsetMatchColumn(1);
    actualCols = rs.getMatchColumnIndexes();
    rs.close();
}