public void testCreateCopy() throws Exception { FilteredRowSet filteredRowSet = newFilterRowSet(); rs = st.executeQuery("SELECT * FROM USER_INFO"); filteredRowSet.populate(rs); Predicate range = new RangeOne(); filteredRowSet.setFilter(range); if ("true".equals(System.getProperty("Testing Harmony"))) { filteredRowSet.createCopy(); } else { try { filteredRowSet.createCopy(); fail("should throw SQLException"); } catch (SQLException e) { // expected } } }
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)); }
public void testNextAndPrevious() throws Exception { FilteredRowSet filteredRowSet = newFilterRowSet(); rs = st.executeQuery("SELECT * FROM USER_INFO"); filteredRowSet.populate(rs); RangeOne range = new RangeOne(); filteredRowSet.setFilter(range); assertTrue(filteredRowSet.next()); assertEquals(2, filteredRowSet.getInt(1)); assertEquals(EVALUATE_ROWSET, range.getTag()); assertEquals(2, range.getCount()); range.clear(); assertTrue(filteredRowSet.next()); assertEquals(3, filteredRowSet.getInt(1)); assertEquals(EVALUATE_ROWSET, range.getTag()); assertEquals(1, range.getCount()); range.clear(); assertTrue(filteredRowSet.previous()); assertEquals(2, filteredRowSet.getInt(1)); assertEquals(1, range.getCount()); range.clear(); assertFalse(filteredRowSet.previous()); assertEquals(EVALUATE_ROWSET, range.getTag()); }
public void testCreateShared() throws Exception { FilteredRowSet filteredRowSet = newFilterRowSet(); rs = st.executeQuery("SELECT * FROM USER_INFO"); filteredRowSet.populate(rs); Predicate range = new RangeOne(); filteredRowSet.setFilter(range); FilteredRowSet copyFilteredRs = (FilteredRowSet) filteredRowSet .createShared(); assertSame(range, copyFilteredRs.getFilter()); }
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()); }
public void testNoFilter_Insert() throws Exception { FilteredRowSet filteredRowSet = newFilterRowSet(); rs = st.executeQuery("SELECT * FROM USER_INFO"); filteredRowSet.populate(rs); /* * TODO Call updateXXX() would throw NullPointerException on insert row * when running on RI. */ filteredRowSet.moveToInsertRow(); filteredRowSet.updateInt(1, 10); filteredRowSet.updateString(2, "insert10"); filteredRowSet.insertRow(); filteredRowSet.moveToCurrentRow(); }
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()); }
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)); }
protected FilteredRowSet newFilterRowSet() throws Exception { try { return (FilteredRowSet) Class.forName( "com.sun.rowset.FilteredRowSetImpl").newInstance(); } catch (ClassNotFoundException e) { return (FilteredRowSet) Class .forName( "org.apache.harmony.sql.internal.rowset.FilteredRowSetImpl") .newInstance(); } }
public FilteredRowSet createFilteredRowSet() throws SQLException { return new com.sun.rowset.FilteredRowSetImpl(); }
@Override public FilteredRowSet createFilteredRowSet() throws SQLException { return new StubFilteredRowSetImpl(); }
protected FilteredRowSet newInstance() throws SQLException { return rsf.createFilteredRowSet(); }