Package javax.sql.rowset

Examples of javax.sql.rowset.FilteredRowSet


    public void testPopulate() throws Exception {
        /*
         * Set Filter before populate()
         */
        RangeOne range = new RangeOne();
        FilteredRowSet filteredRowSet = newFilterRowSet();
        filteredRowSet.setFilter(range);
        assertSame(range, filteredRowSet.getFilter());

        rs = st.executeQuery("SELECT * FROM USER_INFO");
        filteredRowSet.populate(rs);

        assertTrue(filteredRowSet.first());
        assertEquals(2, filteredRowSet.getInt(1));

        filteredRowSet.setFilter(null);
        assertTrue(filteredRowSet.first());
        assertEquals(1, filteredRowSet.getInt(1));
    }
View Full Code Here


        }
        assertEquals(5, index);
    }

    public void testFilter_Update() throws Exception {
        FilteredRowSet filteredRowSet = newFilterRowSet();
        rs = st.executeQuery("SELECT * FROM USER_INFO");
        filteredRowSet.populate(rs);

        Predicate range = new RangeOne();
        filteredRowSet.setFilter(range);

        /*
         * Update the third row. Filter has no effect here.
         */
        assertTrue(filteredRowSet.last());
        assertEquals("test4", filteredRowSet.getString(2));
        filteredRowSet.updateString(2, "update4");
        filteredRowSet.updateRow();
        assertEquals("update4", filteredRowSet.getString(2));
        // the updated row becomes not visible through filter
        assertTrue(filteredRowSet.last());
        assertEquals("test3", filteredRowSet.getString(2));

        // commit to database
        filteredRowSet.acceptChanges(conn);
        rs = st
                .executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE NAME = 'update4'");
        assertTrue(rs.next());
        assertEquals(0, rs.getInt(1));

        /*
         * Remove filter
         */
        filteredRowSet.setFilter(null);
        assertTrue(filteredRowSet.last());
        assertEquals("update4", filteredRowSet.getString(2));
        /*
         * The forth row isn't updated to database, and it lost it's status
         * after acceptChanges().
         */
        assertFalse(filteredRowSet.rowUpdated());
    }
View Full Code Here

         */
        assertFalse(filteredRowSet.rowUpdated());
    }

    public void testFilter_Delete() throws Exception {
        FilteredRowSet filteredRowSet = newFilterRowSet();
        rs = st.executeQuery("SELECT * FROM USER_INFO");
        filteredRowSet.populate(rs);

        /*
         * Mark the first row as delete.
         */
        assertTrue(filteredRowSet.first());
        assertEquals(1, filteredRowSet.getInt(1));
        filteredRowSet.deleteRow();

        Predicate range = new RangeOne();
        filteredRowSet.setFilter(range);

        assertTrue(filteredRowSet.first());
        assertEquals(2, filteredRowSet.getInt(1));

        filteredRowSet.acceptChanges(conn);
        rs = st.executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE ID = 1");
        assertTrue(rs.next());
        assertEquals(1, rs.getInt(1));

        /*
         * Remove filter
         */
        filteredRowSet.setFilter(null);
        filteredRowSet.acceptChanges(conn);
        rs = st.executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE ID = 1");
        assertTrue(rs.next());
        assertEquals(1, rs.getInt(1));
        /*
         * The first row has been deleted from FilteredRowSet. However, it isn't
         * deleted from database.
         */
        filteredRowSet.setShowDeleted(true);
        assertTrue(filteredRowSet.first());
        assertEquals(2, filteredRowSet.getInt(1));
    }
View Full Code Here

    }

    public void testPaging() throws Exception {
        insertMoreData(4);

        FilteredRowSet filteredRowSet = newFilterRowSet();

        filteredRowSet.setCommand("select * from USER_INFO");
        filteredRowSet.setUrl(DERBY_URL);

        filteredRowSet.setPageSize(3);
        filteredRowSet.execute();

        Predicate filter = new OddRowFilter();

        filteredRowSet.setFilter(filter);

        assertEquals("select * from USER_INFO", filteredRowSet.getCommand());

        assertFalse(filteredRowSet.previousPage());

        assertTrue(filteredRowSet.next());
        assertEquals(1, filteredRowSet.getInt(1));

        assertTrue(filteredRowSet.next());
        assertEquals(3, filteredRowSet.getInt(1));

        assertFalse(filteredRowSet.next());
        assertTrue(filteredRowSet.isAfterLast());

        if (!"true".equals(System.getProperty("Testing Harmony"))) {
            // RI need nextPage one more time
            assertTrue(filteredRowSet.nextPage());
        }

        int index = 5;
        while (filteredRowSet.nextPage()) {
            while (filteredRowSet.next()) {
                assertEquals(index, filteredRowSet.getInt(1));
                index += 2;
            }
        }

        assertEquals(9, index);

        filteredRowSet = newFilterRowSet();
        filteredRowSet.setCommand("select * from USER_INFO");
        filteredRowSet.setUrl(DERBY_URL);

        filteredRowSet.setPageSize(3);
        filteredRowSet.execute();

        filteredRowSet.setFilter(filter);

        assertTrue(filteredRowSet.next());
        assertEquals(1, filteredRowSet.getInt(1));

        assertTrue(filteredRowSet.nextPage());
        if (!"true".equals(System.getProperty("Testing Harmony"))) {
            // RI need nextPage one more time
            assertTrue(filteredRowSet.nextPage());
        }

        assertTrue(filteredRowSet.next());

        assertEquals(5, filteredRowSet.getInt(1));

        assertTrue(filteredRowSet.nextPage());

        assertTrue(filteredRowSet.next());
        assertEquals(7, filteredRowSet.getInt(1));

        assertFalse(filteredRowSet.nextPage());

    }
View Full Code Here

    }

    public void testPagingInMemory() throws Exception {
        insertMoreData(10);
        FilteredRowSet filteredRowSet = newFilterRowSet();

        st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                ResultSet.CONCUR_UPDATABLE);
        rs = st.executeQuery("SELECT * FROM USER_INFO");

        // the max rows load into memory
        filteredRowSet.setMaxRows(5);
        filteredRowSet.setPageSize(3);

        filteredRowSet.populate(rs, 1);

        OddRowFilter filter = new OddRowFilter();
        filteredRowSet.setFilter(filter);

        if (!"true".equals(System.getProperty("Testing Harmony"))) {
            // RI need nextPage one more time
            assertTrue(filteredRowSet.nextPage());
        }

        assertTrue(filteredRowSet.next());
        assertEquals(1, filteredRowSet.getInt(1));

        assertTrue(filteredRowSet.next());
        assertEquals(3, filteredRowSet.getInt(1));

        assertFalse(filteredRowSet.next());
        assertTrue(filteredRowSet.isAfterLast());

        assertTrue(filteredRowSet.nextPage());

        filteredRowSet.beforeFirst();

        assertTrue(filteredRowSet.next());
        assertEquals(5, filteredRowSet.getInt(1));

        assertFalse(filteredRowSet.next());
        assertTrue(filteredRowSet.isAfterLast());

        assertFalse(filteredRowSet.nextPage());

        st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                ResultSet.CONCUR_UPDATABLE);
        rs = st.executeQuery("SELECT * FROM USER_INFO");

        filteredRowSet = newFilterRowSet();
        filteredRowSet.setFilter(filter);
        filteredRowSet.setPageSize(3);

        filteredRowSet.populate(rs, 1);

        if (!"true".equals(System.getProperty("Testing Harmony"))) {
            // RI need nextPage one more time
            assertTrue(filteredRowSet.nextPage());
        }

        assertTrue(filteredRowSet.next());
        assertEquals(1, filteredRowSet.getInt(1));

        assertTrue(filteredRowSet.next());
        assertEquals(3, filteredRowSet.getInt(1));

        assertFalse(filteredRowSet.next());
        assertTrue(filteredRowSet.isAfterLast());

        filteredRowSet.setPageSize(2);
        assertTrue(filteredRowSet.nextPage());

        assertTrue(filteredRowSet.isBeforeFirst());

        assertTrue(filteredRowSet.next());
        assertEquals(5, filteredRowSet.getInt(1));

        assertFalse(filteredRowSet.next());
        assertTrue(filteredRowSet.isAfterLast());

        filteredRowSet.setPageSize(5);
        assertTrue(filteredRowSet.nextPage());

        assertTrue(filteredRowSet.isBeforeFirst());

        assertTrue(filteredRowSet.next());
        assertEquals(7, filteredRowSet.getInt(1));

        assertTrue(filteredRowSet.next());
        assertEquals(9, filteredRowSet.getInt(1));

        assertFalse(filteredRowSet.next());
        assertTrue(filteredRowSet.isAfterLast());

        assertTrue(filteredRowSet.previousPage());

        assertTrue(filteredRowSet.isBeforeFirst());

        assertTrue(filteredRowSet.next());
        assertEquals(1, filteredRowSet.getInt(1));

        assertTrue(filteredRowSet.next());
        assertEquals(3, filteredRowSet.getInt(1));

        assertTrue(filteredRowSet.next());
        assertEquals(5, filteredRowSet.getInt(1));

        assertFalse(filteredRowSet.next());
        assertTrue(filteredRowSet.isAfterLast());

        assertFalse(filteredRowSet.previousPage());
    }
View Full Code Here

        assertEquals(4, index);
        assertNull(filteredRowSet.getFilter());
    }

    public void testSetFilterOnFilteredRow() throws Exception {
        FilteredRowSet filteredRowSet = newFilterRowSet();
        rs = st.executeQuery("SELECT * FROM USER_INFO");
        filteredRowSet.populate(rs);

        filteredRowSet.next();
        assertEquals(1, filteredRowSet.getRow());
        Predicate range = new RangeOne();
        filteredRowSet.setFilter(range);

        // not filtered
        assertEquals(1, filteredRowSet.getRow());
        assertEquals("hermit", filteredRowSet.getString(2));

        filteredRowSet.updateString(2, "update");
        assertEquals("update", filteredRowSet.getString(2));

        filteredRowSet.next();
        assertEquals(2, filteredRowSet.getRow());
        assertEquals("test", filteredRowSet.getString(2));

        filteredRowSet.previous();
        assertTrue(filteredRowSet.isBeforeFirst());

        try {
            filteredRowSet.getString(2);
            fail("should should SQLException");
        } catch (SQLException e) {
            // expected, Not a valid cursor
        }

        filteredRowSet.setFilter(null);

        assertTrue(filteredRowSet.isBeforeFirst());

        assertTrue(filteredRowSet.next());
        assertEquals("update", filteredRowSet.getString(2));

        filteredRowSet.setFilter(range);
        assertEquals("update", filteredRowSet.getString(2));
        filteredRowSet.updateString(2, "testUpdate");

        filteredRowSet.next();
        assertEquals(2, filteredRowSet.getRow());
        assertEquals("test", filteredRowSet.getString(2));

        filteredRowSet.previous();
        assertEquals(1, filteredRowSet.getRow());
        assertEquals("testUpdate", filteredRowSet.getString(2));

    }
View Full Code Here

    public void testPopulate() throws Exception {
        /*
         * Set Filter before populate()
         */
        RangeOne range = new RangeOne();
        FilteredRowSet filteredRowSet = newFilterRowSet();
        filteredRowSet.setFilter(range);
        assertSame(range, filteredRowSet.getFilter());

        rs = st.executeQuery("SELECT * FROM USER_INFO");
        filteredRowSet.populate(rs);

        assertTrue(filteredRowSet.first());
        assertEquals(2, filteredRowSet.getInt(1));

        filteredRowSet.setFilter(null);
        assertTrue(filteredRowSet.first());
        assertEquals(1, filteredRowSet.getInt(1));
    }
View Full Code Here

        assertTrue(filteredRowSet.first());
        assertEquals(1, filteredRowSet.getInt(1));
    }

    public void testAbsolute() throws Exception {
        FilteredRowSet filteredRowSet = newFilterRowSet();
        rs = st.executeQuery("SELECT * FROM USER_INFO");
        filteredRowSet.populate(rs);
        /*
         * When running on RI, filteredRowSet.absolute(1) is false here.
         * However, the cursor moves to the first row already.
         */
        if ("true".equals(System.getProperty("Testing Harmony"))) {
            assertTrue(filteredRowSet.absolute(1));
        } else {
            assertFalse(filteredRowSet.absolute(1));
        }
        assertEquals("hermit", filteredRowSet.getString(2));

        RangeOne range = new RangeOne();
        filteredRowSet.setFilter(range);

        /*
         * When running on RI, filteredRowSet.absolute(1) is false.
         */
        if ("true".equals(System.getProperty("Testing Harmony"))) {
            assertTrue(filteredRowSet.absolute(1));
        } else {
            assertFalse(filteredRowSet.absolute(1));
        }
        assertEquals("test", filteredRowSet.getString(2));
        range.clear();
        assertTrue(filteredRowSet.absolute(2));
        assertEquals(3, filteredRowSet.getRow());
        assertEquals(3, filteredRowSet.getInt(1));
        assertEquals(EVALUATE_ROWSET, range.getTag());
        assertEquals(3, range.getCount());

        range.clear();
        assertTrue(filteredRowSet.absolute(2));
        assertEquals(3, filteredRowSet.getInt(1));
        assertEquals(EVALUATE_ROWSET, range.getTag());
        assertEquals(3, range.getCount());

        range.clear();
        assertTrue(filteredRowSet.absolute(3));
        assertEquals(4, filteredRowSet.getInt(1));
        assertEquals(EVALUATE_ROWSET, range.getTag());
        assertEquals(4, range.getCount());

        assertFalse(filteredRowSet.absolute(4));

        assertTrue(filteredRowSet.absolute(-2));
        assertEquals(3, filteredRowSet.getInt(1));

        assertTrue(filteredRowSet.absolute(-3));
        assertEquals(2, filteredRowSet.getInt(1));

        assertFalse(filteredRowSet.absolute(-4));
        assertTrue(filteredRowSet.isBeforeFirst());
    }
View Full Code Here

        assertFalse(filteredRowSet.absolute(-4));
        assertTrue(filteredRowSet.isBeforeFirst());
    }

    public void testRelative() throws Exception {
        FilteredRowSet filteredRowSet = newFilterRowSet();
        rs = st.executeQuery("SELECT * FROM USER_INFO");
        filteredRowSet.populate(rs);

        assertTrue(filteredRowSet.absolute(3));
        assertEquals(3, filteredRowSet.getInt(1));
        assertFalse(filteredRowSet.relative(2));

        assertTrue(filteredRowSet.absolute(3));
        assertEquals(3, filteredRowSet.getInt(1));
        assertTrue(filteredRowSet.relative(1));
        assertEquals(4, filteredRowSet.getInt(1));

        assertTrue(filteredRowSet.absolute(3));
        assertEquals(3, filteredRowSet.getInt(1));
        assertTrue(filteredRowSet.relative(-1));
        assertEquals(2, filteredRowSet.getInt(1));
        assertFalse(filteredRowSet.relative(-2));

        RangeOne range = new RangeOne();
        filteredRowSet.setFilter(range);

        filteredRowSet.beforeFirst();
        assertTrue(filteredRowSet.relative(2));
        assertEquals(3, filteredRowSet.getInt(1));
        assertEquals(3, filteredRowSet.getRow());
        assertFalse(filteredRowSet.relative(-2));
        assertTrue(filteredRowSet.isBeforeFirst());
    }
View Full Code Here

        assertTrue(filteredRowSet.isBeforeFirst());
    }

    public void testCursorMove() throws Exception {
        insertMoreData(30);
        FilteredRowSet filteredRowSet = newFilterRowSet();
        rs = st.executeQuery("SELECT * FROM USER_INFO");
        filteredRowSet.populate(rs);
        RangeThree range = new RangeThree();
        filteredRowSet.setFilter(range);

        assertTrue(filteredRowSet.first());
        assertEquals("hermit", filteredRowSet.getString(2));
        /*
         * TODO It's really strange. When running on RI, filteredRowSet.first()
         * is true. The cursor stays on the first row. However,
         * filteredRowSet.absolute(1) is false. But the cursor still stays on
         * the first row.
         */
        if ("true".equals(System.getProperty("Testing Harmony"))) {
            assertTrue(filteredRowSet.absolute(1));
        } else {
            assertFalse(filteredRowSet.absolute(1));
        }
        assertEquals("hermit", filteredRowSet.getString(2));
        assertTrue(filteredRowSet.relative(1));
        assertEquals("test4", filteredRowSet.getString(2));
        /*
         * First call absolute(2), then call relative(-1), the cursor returns
         * the first row.
         */
        assertTrue(filteredRowSet.absolute(2));
        assertEquals("test4", filteredRowSet.getString(2));
        assertTrue(filteredRowSet.relative(-1));
        assertEquals("hermit", filteredRowSet.getString(2));

        assertTrue(filteredRowSet.last());
        assertEquals("test34", filteredRowSet.getString(2));

        assertTrue(filteredRowSet.previous());
        assertEquals("test32", filteredRowSet.getString(2));

        assertTrue(filteredRowSet.relative(-1));
        assertEquals("test30", filteredRowSet.getString(2));

        assertTrue(filteredRowSet.absolute(5));
        assertEquals("test10", filteredRowSet.getString(2));

        assertTrue(filteredRowSet.relative(3));
        assertEquals("test16", filteredRowSet.getString(2));

        assertTrue(filteredRowSet.relative(-3));
        assertEquals("test10", filteredRowSet.getString(2));

        assertTrue(filteredRowSet.relative(4));
        assertEquals("test18", filteredRowSet.getString(2));

        assertTrue(filteredRowSet.relative(13));
        assertEquals("test34", filteredRowSet.getString(2));

        assertFalse(filteredRowSet.next());
        assertTrue(filteredRowSet.isAfterLast());

        assertTrue(filteredRowSet.absolute(22));
        assertEquals("test34", filteredRowSet.getString(2));

        assertTrue(filteredRowSet.relative(-21));
        assertEquals("hermit", filteredRowSet.getString(2));

        assertFalse(filteredRowSet.relative(-1));
        assertTrue(filteredRowSet.isBeforeFirst());
    }
View Full Code Here

TOP

Related Classes of javax.sql.rowset.FilteredRowSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.