Package javax.sql.rowset

Examples of javax.sql.rowset.CachedRowSet


         connection = dao_.getExoDatasource().getConnection();
         Statement statement =
            connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
         ResultSet resultSet = statement.executeQuery(query);

         CachedRowSet crs = new CachedRowSetImpl();
         crs.setPageSize(pageList.getPageSize());
         crs.populate(resultSet, (pageList.getCurrentPage() - 1) * pageList.getPageSize() + 1);

         while (crs.next())
         {
            T bean = dao_.createInstance();
            dao_.getDBObjectMapper().mapResultSet(crs, bean);
            currentListPage_.add(bean);
         }
View Full Code Here


        assertEquals(2, jrs.getInt(1));
    }

    public void testDeleteRow_MultipleRowSets() throws Exception {
        // Creates a new CachedRowSet from BOOKs
        CachedRowSet crset2 = newNoInitialInstance();
        rs = st.executeQuery("select * from BOOKS");
        crset2.populate(rs);

        jrs.addRowSet(crset, 1);
        jrs.addRowSet(crset2, 1);

        int rowNum = 0;
View Full Code Here

        assertEquals(5, rowNum);
    }

    public void testInsertRow_MultipleRowSets() throws Exception {
        // Creates a new CachedRowSet from BOOKs
        CachedRowSet crset2 = newNoInitialInstance();
        rs = st.executeQuery("select * from BOOKS");
        crset2.populate(rs);

        jrs.addRowSet(crset2, 1);

        int rowNum = 0;
        jrs.beforeFirst();
View Full Code Here

        // TODO: lack of the test for CachedRowSet.getOriginal() and
        // CachedRowSet.getOriginalRow()

        crset.absolute(3);

        CachedRowSet crsetCopy = crset.createCopy();

        crsetCopy.updateString(2, "copyTest3");
        crsetCopy.updateRow();
        crsetCopy.acceptChanges();

        assertEquals("copyTest3", crsetCopy.getString(2));

        assertEquals("test3", crset.getString(2));

        rs = st.executeQuery("select * from USER_INFO");
        rs.next();
        rs.next();
        rs.next();

        assertEquals("copyTest3", rs.getString(2));

        reloadCachedRowSet();
        crset.absolute(2);

        crsetCopy = crset.createCopy();

        assertEquals(crset.isReadOnly(), crsetCopy.isReadOnly());
        assertEquals(crset.isBeforeFirst(), crsetCopy.isBeforeFirst());
        assertEquals(crset.isAfterLast(), crsetCopy.isAfterLast());
        assertEquals(crset.isFirst(), crsetCopy.isFirst());
        assertEquals(crset.isLast(), crsetCopy.isLast());

        assertEquals(crset.size(), crsetCopy.size());
        // different metaData object
        assertNotSame(crset.getMetaData(), crsetCopy.getMetaData());

        isMetaDataEquals(crset.getMetaData(), crsetCopy.getMetaData());

        assertEquals(crset.getCommand(), crsetCopy.getCommand());
        assertEquals(crset.getConcurrency(), crsetCopy.getConcurrency());

        try {
            assertEquals(crset.getCursorName(), crsetCopy.getCursorName());
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        try {
            assertEquals(crset.getMatchColumnIndexes(), crsetCopy
                    .getMatchColumnIndexes());
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected
        }

        try {
            assertEquals(crset.getMatchColumnNames(), crsetCopy
                    .getMatchColumnNames());
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        assertEquals(crset.getRow(), crsetCopy.getRow());
        assertEquals(crset.getStatement(), crsetCopy.getStatement());

        assertEquals(crset.getEscapeProcessing(), crsetCopy
                .getEscapeProcessing());
        assertEquals(crset.getFetchDirection(), crsetCopy.getFetchDirection());
        assertEquals(crset.getFetchSize(), crsetCopy.getFetchSize());
        if (crset.getKeyColumns() != null && crset.getKeyColumns().length != 0) {
            int[] keyColumns = crset.getKeyColumns();
            int[] copyKeyColumns = crsetCopy.getKeyColumns();

            assertEquals(keyColumns.length, copyKeyColumns.length);
            for (int i = 0; i < keyColumns.length; i++) {
                assertEquals(keyColumns[i], copyKeyColumns[i]);
            }
            assertEquals(crset.getKeyColumns(), crsetCopy.getKeyColumns());
        }

        assertEquals(crset.getMaxFieldSize(), crsetCopy.getMaxFieldSize());
        assertEquals(crset.getMaxRows(), crsetCopy.getMaxRows());

        assertEquals(crset.getPageSize(), crsetCopy.getPageSize());
        assertEquals(crset.getPassword(), crsetCopy.getPassword());
        assertEquals(crset.getQueryTimeout(), crsetCopy.getQueryTimeout());
        assertEquals(crset.getShowDeleted(), crsetCopy.getShowDeleted());

        assertEquals(crset.getSyncProvider().getProviderID(), crsetCopy
                .getSyncProvider().getProviderID());
        assertEquals(crset.getSyncProvider().getProviderGrade(), crsetCopy
                .getSyncProvider().getProviderGrade());
        assertEquals(crset.getSyncProvider().getDataSourceLock(), crsetCopy
                .getSyncProvider().getDataSourceLock());
        assertEquals(crset.getSyncProvider().getVendor(), crsetCopy
                .getSyncProvider().getVendor());
        assertEquals(crset.getSyncProvider().getVersion(), crsetCopy
                .getSyncProvider().getVersion());

        assertEquals(crset.getTableName(), crsetCopy.getTableName());
        assertEquals(crset.getTransactionIsolation(), crsetCopy
                .getTransactionIsolation());
        assertEquals(crset.getType(), crsetCopy.getType());

        assertEquals(crset.getUrl(), crsetCopy.getUrl());
        assertEquals(crset.getUsername(), crsetCopy.getUsername());

    }
View Full Code Here

    }

    public void testCreateCopy2() throws Exception {

        CachedRowSet copy = crset.createCopy();

        copy.absolute(3);
        crset.absolute(3);

        copy.updateString(2, "updated");
        assertEquals("updated", copy.getString(2));
        assertEquals("test3", crset.getString(2));
        copy.updateRow();
        copy.acceptChanges();

        assertEquals("updated", copy.getString(2));
        assertEquals("test3", crset.getString(2));

        crset.updateString(2, "again");

        assertEquals("updated", copy.getString(2));
        assertEquals("again", crset.getString(2));

        crset.updateRow();
        try {
            /*
             * seems ri doesn't release lock when expception throw from
             * acceptChanges(), which will cause test case block at insertData()
             * when next test case setUp, so we must pass current connection to
             * it, and all resource would be released after connection closed.
             */
            crset.acceptChanges(conn);
            fail("Should throw SyncProviderException");
        } catch (SyncProviderException e) {
            SyncResolver resolver = e.getSyncResolver();
            assertEquals(0, resolver.getRow());

            try {
                resolver.getConflictValue(1);
                fail("Should throw SQLException");
            } catch (SQLException ex) {
                // expected, Invalid cursor position
            }

            assertTrue(resolver.nextConflict());
            assertEquals(3, resolver.getRow());

            assertEquals(SyncResolver.UPDATE_ROW_CONFLICT, resolver.getStatus());

            for (int i = 1; i <= DEFAULT_COLUMN_COUNT; ++i) {
                // all values are null
                assertNull(resolver.getConflictValue(i));
            }

            assertFalse(resolver.nextConflict());
        }

        assertEquals("updated", copy.getString(2));

        crset.absolute(3);
        // data doesn't change
        assertEquals("again", crset.getString(2));
    }
View Full Code Here

        assertEquals(DEFAULT_COLUMN_COUNT, crset.getMetaData().getColumnCount());
        assertTrue(crset.next());
        assertEquals("test3", crset.getString(2));
        assertFalse(crset.next());

        CachedRowSet crsetCopy = crset.createCopy();
        crsetCopy.execute();
        assertEquals(DEFAULT_COLUMN_COUNT, crsetCopy.getMetaData()
                .getColumnCount());
        assertTrue(crsetCopy.next());
        assertEquals("test3", crsetCopy.getString(2));
        assertFalse(crsetCopy.next());

        crsetCopy.setCommand("SELECT * FROM USER_INFO WHERE NAME = ?");
        crsetCopy.setString(1, "test4");
        crsetCopy.execute();
        assertTrue(crsetCopy.next());
        assertEquals(4, crsetCopy.getInt(1));
        assertFalse(crsetCopy.next());

        crset.execute();
        assertTrue(crset.next());
        assertEquals("test3", crset.getString(2));
        assertFalse(crset.next());
View Full Code Here

        assertTrue(crset.next());
        assertEquals(3, crset.getInt(1));
        assertFalse(crset.next());

        // deep copy
        CachedRowSet copyCrset = crset.createCopy();
        copyCrset.beforeFirst();
        assertTrue(copyCrset.next());
        assertEquals(3, copyCrset.getInt(1));
        assertFalse(copyCrset.next());
        copyCrset.execute();
        assertTrue(copyCrset.next());
        assertEquals(3, copyCrset.getInt(1));
        assertFalse(copyCrset.next());

        crset.setInt(1, 4);
        crset.execute();
        crset.beforeFirst();
        assertTrue(crset.next());
        assertEquals(4, crset.getInt(1));
        assertFalse(crset.next());

        copyCrset.beforeFirst();
        assertTrue(copyCrset.next());
        assertEquals(3, copyCrset.getInt(1));
        assertFalse(copyCrset.next());

        copyCrset.execute();
        copyCrset.beforeFirst();
        assertTrue(copyCrset.next());
        assertEquals(3, copyCrset.getInt(1));
        assertFalse(copyCrset.next());

        copyCrset.setInt(1, 1);
        copyCrset.execute();
        assertTrue(copyCrset.next());
        assertEquals(1, copyCrset.getInt(1));
        assertFalse(copyCrset.next());

        crset.beforeFirst();
        assertTrue(crset.next());
        assertEquals(4, crset.getInt(1));
        assertFalse(crset.next());
View Full Code Here

        rs = st.executeQuery("select * from USER_INFO");
        crset.close();
        crset.populate(rs);

        CachedRowSet crsetCopy = crset.createCopy();
        assertEquals(0, crsetCopy.getPageSize());
        noInitialCrset.setPageSize(5);
        // if it doesn't specify the startRow for method populate(), then the
        // pageSize wouldn't work.
        assertTrue(crsetCopy.isBeforeFirst());
        noInitialCrset.populate(crsetCopy);
        assertTrue(crsetCopy.isAfterLast());
        int cursorIndex = 0;
        while (noInitialCrset.next()) {
            cursorIndex++;
            for (int i = 1; i <= DEFAULT_COLUMN_COUNT; i++) {
                assertEquals(cursorIndex, noInitialCrset.getInt(1));
View Full Code Here

        out.close();

        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(
                bout.toByteArray()));

        CachedRowSet another = (CachedRowSet) in.readObject();
        in.close();

        isMetaDataEquals(crset.getMetaData(), another.getMetaData());

        assertEquals(crset.getRow(), another.getRow());
        assertEquals(crset.getString(2), another.getString(2));

        crset = newNoInitialInstance();
        crset.setCommand("SELECT * FROM USER_INFO");
        crset.setUrl(DERBY_URL);
        crset.execute();

        crset.absolute(3);

        bout = new ByteArrayOutputStream();
        out = new ObjectOutputStream(bout);
        out.writeObject(crset);

        out.close();

        in = new ObjectInputStream(new ByteArrayInputStream(bout.toByteArray()));

        another = (CachedRowSet) in.readObject();

        isMetaDataEquals(crset.getMetaData(), another.getMetaData());

        assertEquals(crset.getRow(), another.getRow());

        try {
            another.commit();
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
    }
View Full Code Here

        crset.absolute(3); // move to the third row for testing
        assertEquals(CachedRowSetListenerTest.EVENT_CURSOR_MOVED, listener
                .getTag());
        listener.clear();

        CachedRowSet crsetShared = (CachedRowSet) crset.createShared();
        assertEquals("testUsername", crsetShared.getUsername());
        assertEquals("testPassword", crsetShared.getPassword());
        assertEquals(5, crsetShared.getPageSize());
        // check whether modify the attribute of the original is visible to the
        // duplicate
        crset.setUsername("modifyUsername");
        crset.setPageSize(10);
        assertEquals("modifyUsername", crset.getUsername());
        assertEquals("testUsername", crsetShared.getUsername());
        assertEquals(10, crset.getPageSize());
        assertEquals(5, crsetShared.getPageSize());

        // compare the current row, that is the third row
        assertEquals(3, crset.getInt(1));
        assertEquals("test3", crset.getString(2));
        assertEquals(3, crsetShared.getInt(1));
        assertEquals("test3", crsetShared.getString(2));
        // check whether update the duplicate is visible to the original
        crsetShared.updateString(2, "modify3");
        assertEquals("modify3", crsetShared.getString(2));
        assertEquals("modify3", crset.getString(2));
        crsetShared.updateRow();
        listener.clear();
        crsetShared.acceptChanges();
        assertEquals(CachedRowSetListenerTest.EVENT_ROWSET_CHANGED, listener
                .getTag());

        // when move the duplicate's cursor, the original shouldn't be affected
        crsetShared.absolute(1);
        assertEquals(1, crsetShared.getInt(1));
        assertEquals(3, crset.getInt(1));
    }
View Full Code Here

TOP

Related Classes of javax.sql.rowset.CachedRowSet

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.