Package javax.sql.rowset

Examples of javax.sql.rowset.CachedRowSet


    }

    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(copy.getString(2), "updated");
        assertEquals(crset.getString(2), "test3");

        crset.updateString(2, "again");

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

        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);
            // TODO: wait the implementation of Writer
            // fail("Should throw SyncProviderException");
        } catch (SyncProviderException e) {
            // expected
        }

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

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


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

        CachedRowSet crsetCopy = crset.createCopy();
        crsetCopy.execute();
        assertEquals(12, 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

        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

        crset.addRowSetListener(listener);
        crset.absolute(3); // move to the third row for testing
        // TODO: when the cursor moved, notifyCursorMoved() should be called
        // assertEquals("cursorMoved", listener.getTag());

        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();
        crsetShared.acceptChanges();
        assertEquals("rowSetChanged", 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

        crset.setPassword("password");
        crset.setTypeMap(new HashMap<String, Class<?>>());
        crset.setMaxFieldSize(10);
        crset.setFetchDirection(ResultSet.FETCH_UNKNOWN);

        CachedRowSet copy = crset.createCopyNoConstraints();

        // default is ResultSet.CONCUR_UPDATABLE
        assertEquals(ResultSet.CONCUR_UPDATABLE, copy.getConcurrency());
        // default is ResultSet.TYPE_SCROLL_INSENSITIVE
        assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, copy.getType());
        // default is true
        assertTrue(copy.getEscapeProcessing());
        // default is 0
        assertEquals(0, copy.getMaxRows());
        // default is Connection.TRANSACTION_READ_COMMITTED
        assertEquals(Connection.TRANSACTION_READ_COMMITTED, copy
                .getTransactionIsolation());
        // default is 0
        assertEquals(0, copy.getQueryTimeout());
        // default is false
        assertFalse(copy.getShowDeleted());
        // default is 0
        assertEquals(0, copy.getMaxFieldSize());
        // default is null
        assertNull(copy.getPassword());
        // default is null
        assertNull(copy.getUsername());
        // default is null
        assertNull(copy.getTypeMap());

        if (crset.getKeyColumns() == null) {
            assertNull(copy.getKeyColumns());
        } else {
            int[] keyColumns = crset.getKeyColumns();
            int[] copyKeyColumns = copy.getKeyColumns();

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

        assertEquals(crset.getFetchDirection(), copy.getFetchDirection());
        assertEquals(crset.getPageSize(), copy.getPageSize());

        // TODO uncomment them after implemented
        // assertEquals(crset.isBeforeFirst(), crsetCopy.isBeforeFirst());
        // assertEquals(crset.isAfterLast(), crsetCopy.isAfterLast());
        // assertEquals(crset.isFirst(), crsetCopy.isFirst());
        // assertEquals(crset.isLast(), crsetCopy.isLast());
        // assertEquals(crset.getRow(), copy.getRow());
        // assertNotSame(crset.getWarnings(), copy.getWarnings());
        // assertEquals(crset.getStatement(), copy.getStatement());
        // try {
        // assertEquals(crset.getCursorName(), copy.getCursorName());
        // fail("Should throw SQLException");
        // } catch (SQLException e) {
        // // expected
        // }
        //
        // try {
        // assertEquals(crset.getMatchColumnIndexes(), copy
        // .getMatchColumnIndexes());
        // fail("Should throw SQLException");
        // } catch (SQLException e) {
        // // expected
        // }
        //
        // try {
        // assertEquals(crset.getMatchColumnNames(), copy
        // .getMatchColumnNames());
        // } catch (SQLException e) {
        // // expected
        // }

        assertEquals(crset.isReadOnly(), copy.isReadOnly());
        assertEquals(crset.size(), copy.size());

        // different metaData object
        assertNotSame(crset.getMetaData(), copy.getMetaData());

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

        assertEquals(crset.getCommand(), copy.getCommand());

        // check SyncProvider
        assertEquals(crset.getSyncProvider().getProviderID(), copy
                .getSyncProvider().getProviderID());
        assertEquals(crset.getSyncProvider().getProviderGrade(), copy
                .getSyncProvider().getProviderGrade());
        assertEquals(crset.getSyncProvider().getDataSourceLock(), copy
                .getSyncProvider().getDataSourceLock());
        assertEquals(crset.getSyncProvider().getVendor(), copy
                .getSyncProvider().getVendor());
        assertEquals(crset.getSyncProvider().getVersion(), copy
                .getSyncProvider().getVersion());

        assertEquals(crset.getTableName(), copy.getTableName());
        assertEquals(crset.getUrl(), copy.getUrl());

    }
View Full Code Here

        assertEquals("testUserName", crset.getUsername());
        assertFalse(crset.getEscapeProcessing());
        assertTrue(Arrays.equals(new int[] { 1 }, crset.getKeyColumns()));

        // after call createCopyNoConstraints
        CachedRowSet copy = crset.createCopyNoConstraints();
        assertEquals("testCommand", copy.getCommand());
        assertEquals(ResultSet.CONCUR_UPDATABLE, copy.getConcurrency());
        assertEquals("testDataSourceName", copy.getDataSourceName());
        assertEquals(ResultSet.FETCH_REVERSE, copy.getFetchDirection());
        assertEquals(0, copy.getFetchSize());
        assertEquals(0, copy.getMaxFieldSize());
        assertEquals(0, copy.getMaxRows());
        assertEquals(10, copy.getPageSize());
        assertNull(copy.getPassword());
        assertEquals(0, copy.getQueryTimeout());
        assertEquals("testTable", copy.getTableName());
        assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, copy
                .getTransactionIsolation());
        assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, copy.getType());
        assertNull(copy.getTypeMap());
        assertNull(copy.getUrl());
        assertNull(copy.getUsername());
        assertTrue(copy.getEscapeProcessing());
        assertTrue(Arrays.equals(new int[] { 1 }, copy.getKeyColumns()));
    }
View Full Code Here

         */
        // Listener listener = new Listener();
        // crset.addRowSetListener(listener);
        RowSetMetaData rsmd = (RowSetMetaData) crset.getMetaData();
        // the copy
        CachedRowSet crsetCopySchema = crset.createCopySchema();
        RowSetMetaData rsmdCopySchema = (RowSetMetaData) crsetCopySchema
                .getMetaData();

        // compare the meta data between the duplicate and the original
        assertNotSame(crset.getMetaData(), crsetCopySchema.getMetaData());
        assertNotSame(crset.getOriginal(), crsetCopySchema.getOriginal());
        // assertNotSame(crset.getSyncProvider(), crsetCopySchema
        // .getSyncProvider());

        assertEquals("USER_INFO", crset.getTableName());
        assertEquals("USER_INFO", rsmdCopySchema.getTableName(1));
        assertEquals(DEFAULT_COLUMN_COUNT, rsmdCopySchema.getColumnCount());
        assertEquals(rsmd.getColumnName(1), rsmdCopySchema.getColumnName(1));
        // check the primary key
        // TODO: RI doesn't evalute the keyColumns. The value of
        // crset.getKeyColumns() is null.
        assertEquals(crset.getKeyColumns(), crsetCopySchema.getKeyColumns());

        // check the attributes in the duplicate. These are supposed to be the
        // same as the original
        // System.out.println("crsetCopySchema: " + crsetCopySchema.getInt(1));
        assertFalse(crsetCopySchema.next());
        assertEquals("testCommand", crsetCopySchema.getCommand());
        assertEquals(ResultSet.CONCUR_UPDATABLE, crsetCopySchema
                .getConcurrency());
        assertEquals("testDataSource", crsetCopySchema.getDataSourceName());
        assertEquals(ResultSet.FETCH_UNKNOWN, crsetCopySchema
                .getFetchDirection());
        assertEquals(20, crsetCopySchema.getPageSize());
        assertEquals(20, crsetCopySchema.getMaxRows());

        // fill the duplicate CachedRowSet with data, check the listener
        Listener listener = new Listener();
        crsetCopySchema.addRowSetListener(listener);
        assertNull(listener.getTag());
        rs = st.executeQuery("select * from USER_INFO");
        crsetCopySchema.populate(rs);
        // TODO: in the Harmony implementation, need to call notifyRowSetChanged
        // at the suitable place
        // assertEquals("rowSetChanged", listener.getTag());
        listener.setTag(null);
        // the move of the original's cursor shouldn't affect the duplicate
View Full Code Here

        crset.setTypeMap(new HashMap<String, Class<?>>());
        crset.setEscapeProcessing(false);
        crset.setKeyColumns(new int[] { 1 });

        // call createCopySchema()
        CachedRowSet copy = crset.createCopySchema();
        assertFalse(copy.next());
        assertEquals(crset.getCommand(), copy.getCommand());
        assertEquals(crset.getConcurrency(), copy.getConcurrency());
        assertEquals(crset.getDataSourceName(), copy.getDataSourceName());
        assertEquals(crset.getFetchDirection(), copy.getFetchDirection());
        assertEquals(crset.getMaxFieldSize(), copy.getMaxFieldSize());
        assertEquals(crset.getMaxRows(), copy.getMaxRows());
        assertEquals(crset.getPageSize(), copy.getPageSize());
        assertEquals(crset.getQueryTimeout(), copy.getQueryTimeout());
        assertEquals(crset.getTableName(), copy.getTableName());
        assertEquals(crset.getTransactionIsolation(), copy
                .getTransactionIsolation());
        assertEquals(crset.getType(), copy.getType());
        assertEquals(crset.getUrl(), copy.getUrl());
        assertEquals(crset.getEscapeProcessing(), copy.getEscapeProcessing());
        assertTrue(Arrays.equals(crset.getKeyColumns(), copy.getKeyColumns()));

        // compare the object reference
        assertNotSame(crset.getKeyColumns(), copy.getKeyColumns());
        assertNotSame(crset.getMetaData(), copy.getMetaData());
        assertNotSame(crset.getOriginal(), copy.getOriginal());
        assertNotSame(crset.getTypeMap(), copy.getTypeMap());
    }
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(crsetCopy.getString(2), "copyTest3");

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

        rs = st.executeQuery("select * from USER_INFO");
        rs.next();
        rs.next();
        rs.next();
        // TODO: Uncomment it when Writer is implemented fully.
        // assertEquals(rs.getString(2), "copyTest3");

        reloadCachedRowSet();
        crset.absolute(2);

        crsetCopy = crset.createCopy();

        assertEquals(crset.isReadOnly(), crsetCopy.isReadOnly());
        // TODO uncomment when isBeforeFirst is implemented
        // assertEquals(crset.isBeforeFirst(), crsetCopy.isBeforeFirst());
        // TODO uncomment when isAfterLast is implemented
        // assertEquals(crset.isAfterLast(), crsetCopy.isAfterLast());
        // TODO uncomment when isFirst is implemented
        // assertEquals(crset.isFirst(), crsetCopy.isFirst());
        // TODO uncomment when isLast is implemented
        // 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());

        // uncomment after implemented
        // 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());
        // } catch (SQLException e) {
        // // expected
        // }
        // assertEquals(crset.getRow(), crsetCopy.getRow());
        // assertEquals(crset.getStatement(), crsetCopy.getStatement());
        // assertNotSame(crset.getWarnings(), crsetCopy.getWarnings());

        assertEquals(crset.getEscapeProcessing(), crsetCopy
                .getEscapeProcessing());
        assertEquals(crset.getFetchDirection(), crsetCopy.getFetchDirection());
        assertEquals(crset.getFetchSize(), crsetCopy.getFetchSize());
        if (crset.getKeyColumns() == null) {
            assertNull(crsetCopy.getKeyColumns());
        } else {
            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

         */
        // Listener listener = new Listener();
        // crset.addRowSetListener(listener);
        RowSetMetaData rsmd = (RowSetMetaData) crset.getMetaData();
        // the copy
        CachedRowSet crsetCopySchema = crset.createCopySchema();
        RowSetMetaData rsmdCopySchema = (RowSetMetaData) crsetCopySchema
                .getMetaData();

        // compare the meta data between the duplicate and the original
        assertNotSame(crset.getMetaData(), crsetCopySchema.getMetaData());
        assertNotSame(crset.getOriginal(), crsetCopySchema.getOriginal());
        // assertNotSame(crset.getSyncProvider(), crsetCopySchema
        // .getSyncProvider());

        assertEquals("USER_INFO", crset.getTableName());
        assertEquals("USER_INFO", rsmdCopySchema.getTableName(1));
        assertEquals(DEFAULT_COLUMN_COUNT, rsmdCopySchema.getColumnCount());
        assertEquals(rsmd.getColumnName(1), rsmdCopySchema.getColumnName(1));
        // check the primary key
        // TODO: RI doesn't evalute the keyColumns. The value of
        // crset.getKeyColumns() is null.
        assertEquals(crset.getKeyColumns(), crsetCopySchema.getKeyColumns());

        // check the attributes in the duplicate. These are supposed to be the
        // same as the original
        // System.out.println("crsetCopySchema: " + crsetCopySchema.getInt(1));
        assertFalse(crsetCopySchema.next());
        assertEquals("testCommand", crsetCopySchema.getCommand());
        assertEquals(ResultSet.CONCUR_UPDATABLE, crsetCopySchema
                .getConcurrency());
        assertEquals("testDataSource", crsetCopySchema.getDataSourceName());
        assertEquals(ResultSet.FETCH_UNKNOWN, crsetCopySchema
                .getFetchDirection());
        assertEquals(20, crsetCopySchema.getPageSize());
        assertEquals(20, crsetCopySchema.getMaxRows());

        // fill the duplicate CachedRowSet with data, check the listener
        Listener listener = new Listener();
        crsetCopySchema.addRowSetListener(listener);
        assertNull(listener.getTag());
        rs = st.executeQuery("select * from USER_INFO");
        crsetCopySchema.populate(rs);
        // TODO: in the Harmony implementation, need to call notifyRowSetChanged
        // at the suitable place
        // assertEquals("rowSetChanged", listener.getTag());
        listener.setTag(null);
        // the move of the original's cursor shouldn't affect the duplicate
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.