Package javax.sql.rowset

Examples of javax.sql.rowset.JdbcRowSet


        assertTrue(rs.next());
        assertEquals(1, rs.getInt(1));
    }

    public void testGetRowSetWarnings() throws Exception {
        JdbcRowSet jrs = newJdbcRowSet();
        jrs.setCommand("SELECT * FROM USER_INFO");
        jrs.setUrl(DERBY_URL);
        jrs.execute();

        /*
         * TODO not sure when and how will cause RowSetWarning
         */
        assertNull(jrs.getRowSetWarnings());

        jrs.close();

        jrs = newJdbcRowSet();
        RowSetWarning warning = jrs.getRowSetWarnings();
        super.assertNull(warning);

        // TODO Try to produce warnings.

        jrs.close();
        // Checks for Exception after closing jrs.

        assertNull(rs.getWarnings());
        assertNull(jrs.getRowSetWarnings());
    }
View Full Code Here


        assertNull(rs.getWarnings());
        assertNull(jrs.getRowSetWarnings());
    }

    public void testConstructor() throws Exception {
        JdbcRowSet jrs = newJdbcRowSet();
        try {
            jrs.absolute(3);
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        jrs.addRowSetListener(new Listener());
        try {
            jrs.afterLast();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        try {
            jrs.beforeFirst();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        try {
            jrs.cancelRowUpdates();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        jrs.clearParameters();
        try {
            jrs.clearWarnings();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        jrs.close();

        // after close
        try {
            jrs.commit();
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
        try {
            jrs.deleteRow();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        try {
            jrs.findColumn("abc");
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        try {
            jrs.first();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        try {
            jrs.getString(1);
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        try {
            jrs.getAutoCommit();
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
        jrs.getCommand();
        try {
            jrs.getConcurrency();
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
        try {
            jrs.getCursorName();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        jrs.getDataSourceName();
        jrs.getEscapeProcessing();
        try {
            jrs.getFetchDirection();
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
        jrs.getFetchSize();
        try {
            jrs.getMatchColumnIndexes();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        try {
            jrs.getMatchColumnNames();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        jrs.getMaxFieldSize();
        jrs.getMaxRows();
        try {
            jrs.getMetaData();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        jrs.getPassword();
        jrs.getQueryTimeout();
        try {
            jrs.getRow();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        jrs.getRowSetWarnings();
        jrs.getShowDeleted();
        jrs.getStatement();
        jrs.getTransactionIsolation();
        jrs.getType();
        jrs.getTypeMap();
        jrs.getUrl();
        jrs.getUsername();
        try {
            jrs.getWarnings();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        try {
            jrs.insertRow();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        try {
            jrs.isAfterLast();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        try {
            jrs.isFirst();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        jrs.isReadOnly();
        try {
            jrs.moveToCurrentRow();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        try {
            jrs.moveToInsertRow();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        try {
            jrs.next();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
    }
View Full Code Here

            // expected, Invalid state
        }
    }

    public void testResult() throws Exception {
        JdbcRowSet jrs = newJdbcRowSet();
        assertTrue(jrs instanceof BaseRowSet);
        jrs.setCommand("select * from USER_INFO");
        jrs.setUrl(DERBY_URL);

        // before execute
        assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, jrs.getType());
        assertTrue(jrs.getEscapeProcessing());

        assertEquals(Connection.TRANSACTION_READ_COMMITTED, jrs
                .getTransactionIsolation());

        try {
            assertEquals(ResultSet.FETCH_FORWARD, jrs.getFetchDirection());
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }

        assertEquals(0, jrs.getFetchSize());

        assertEquals(0, jrs.getMaxFieldSize());
        assertEquals(0, jrs.getMaxRows());

        assertEquals(0, jrs.getQueryTimeout());
        assertFalse(jrs.getShowDeleted());

        assertEquals(DERBY_URL, jrs.getUrl());
        assertNull(jrs.getUsername());
        assertNull(jrs.getPassword());

        jrs.execute();

        // after execute
        assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, jrs.getType());
        assertTrue(jrs.getEscapeProcessing());

        assertEquals(Connection.TRANSACTION_READ_COMMITTED, jrs
                .getTransactionIsolation());

        assertEquals(ResultSet.FETCH_FORWARD, jrs.getFetchDirection());
        assertEquals(0, jrs.getFetchSize());

        assertEquals(0, jrs.getMaxFieldSize());
        assertEquals(0, jrs.getMaxRows());

        assertEquals(0, jrs.getQueryTimeout());
        assertFalse(jrs.getShowDeleted());

        assertEquals(DERBY_URL, jrs.getUrl());
        assertNull(jrs.getUsername());
        assertNull(jrs.getPassword());

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

        assertTrue(jrs.absolute(3));

        assertTrue(jrs.absolute(1));

        assertEquals(ResultSet.TYPE_FORWARD_ONLY, rs.getType());

        assertTrue(jrs instanceof BaseRowSet);

        jrs.close();
    }
View Full Code Here

        jrs.close();
    }

    public void testCursorMove() throws Exception {
        insertMoreData(6);
        JdbcRowSet jrs = newJdbcRowSet();
        jrs.setUrl(DERBY_URL);
        jrs.setCommand("SELECT * FROM USER_INFO");
        jrs.execute();

        jrs.beforeFirst();
        assertTrue(jrs.isBeforeFirst());
        assertTrue(jrs.next());
        assertTrue(jrs.first());
        assertFalse(jrs.previous());
        assertTrue(jrs.isBeforeFirst());
        assertTrue(jrs.absolute(1));
        assertTrue(jrs.first());
        assertEquals(1, jrs.getInt(1));

        assertTrue(jrs.relative(3));
        assertEquals(4, jrs.getInt(1));
        assertTrue(jrs.previous());
        assertEquals(3, jrs.getInt(1));
        assertTrue(jrs.relative(-2));
        assertTrue(jrs.first());

        assertTrue(jrs.absolute(10));
        assertEquals(10, jrs.getInt(1));
        assertTrue(jrs.last());
        assertFalse(jrs.next());
        assertTrue(jrs.isAfterLast());

        assertTrue(jrs.relative(-2));
        assertEquals(9, jrs.getInt(1));
        jrs.afterLast();
        assertTrue(jrs.isAfterLast());

        assertTrue(jrs.absolute(-3));
        assertEquals(8, jrs.getInt(1));

        jrs.close();
    }
View Full Code Here

        jrs.close();
    }

    public void testExecute() throws Exception {
        JdbcRowSet jrs = newJdbcRowSet();
        jrs.setUrl("bad url");

        try {
            jrs.execute();
            fail("Should SQLException");
        } catch (SQLException e) {
            // expected, No suitable driver
        }

        jrs = newJdbcRowSet();
        try {
            jrs.execute();
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
        jrs.setUrl(DERBY_URL);
        try {
            jrs.execute();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        /*
         * TODO It's really strange. setUrl(null) no affect here.
         */
        if (!"true".equals(System.getProperty("Testing Harmony"))) {
            jrs.setUrl(null);
            assertEquals(DERBY_URL, jrs.getUrl());
        }

        jrs.setCommand("SELECT * FROM USER_INFO");
        jrs.execute();
        assertTrue(jrs.last());
        assertEquals(4, jrs.getInt(1));
        jrs.close();

        /*
         * recall execute() after close()
         */
        assertEquals("SELECT * FROM USER_INFO", jrs.getCommand());
        assertEquals(DERBY_URL, jrs.getUrl());
        try {
            jrs.execute();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected, No current connection.
        }

        jrs.clearParameters();
        assertEquals("SELECT * FROM USER_INFO", jrs.getCommand());
        assertEquals(DERBY_URL, jrs.getUrl());
        try {
            jrs.execute();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }

        jrs = newJdbcRowSet();
        jrs.setUrl(DERBY_URL);
        jrs.setCommand("SELECT * FROM USER_INFO WHERE ID >= ?");
        jrs.setInt(1, 2);
        jrs.execute();
        assertTrue(jrs.first());
        assertEquals(2, jrs.getInt(1));

        // change the query condition
        jrs.setInt(1, 3);
        jrs.execute();
        assertTrue(jrs.first());
        assertEquals(3, jrs.getInt(1));

        // change the command
        jrs.setCommand("SELECT * FROM USER_INFO WHERE NAME = 'hermit'");
        jrs.execute();
        assertTrue(jrs.first());
        assertEquals(1, jrs.getInt(1));
        assertFalse(jrs.next());

        jrs.close();
    }
View Full Code Here

            // expected
        }
    }

    public void testAfterClose() throws Exception {
        JdbcRowSet jrs = newJdbcRowSet();
        jrs.setCommand("SELECT * FROM USER_INFO");
        jrs.setUrl(DERBY_URL);
        jrs.execute();
        jrs.close();

        try {
            jrs.absolute(1);
            fail("Should throw NullPointerException");
        } catch (SQLException e) {
            // expected
        }

        try {
            jrs.getString(1);
            fail("Should throw NullPointerException");
        } catch (SQLException e) {
            // expected
        }

        try {
            jrs.updateString(1, "hello");
            fail("Should throw NullPointerException");
        } catch (SQLException e) {
            // expected
        }

        assertEquals("SELECT * FROM USER_INFO", jrs.getCommand());

        try {
            jrs.getConcurrency();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected
        }

        try {
            jrs.getFetchDirection();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected
        }

View Full Code Here

    /**
     * @test javax.sql.rowset.JdbcRowTest.commit()
     */
    public void testCommit() throws Exception {
        JdbcRowSet jrs = newJdbcRowSet();
        jrs.setUrl(DERBY_URL);
        jrs.setCommand("SELECT * FROM USER_INFO");

        try {
            jrs.commit();
            fail("Shuld throw NullPointerException since jrs has not been executed.");
        } catch (NullPointerException e) {
            // Expected.
        }

        jrs.execute();
        assertTrue(jrs.absolute(4));
        assertEquals(4, jrs.getInt(1));

        // Inserts a new row.
        jrs.moveToInsertRow();
        jrs.updateInt(1, 5);
        jrs.updateString(2, "test5");
        jrs.insertRow();
        jrs.moveToCurrentRow();

        // Tests if jrs has the same behaviour with connection when commit in
        // auto-commit mode.
        boolean hasCommitException = true;

        try {
            conn.commit();
            hasCommitException = false;
        } catch (SQLException e) {
            // Nothing to do.
        }

        try {
            assertTrue(jrs.getAutoCommit());
            jrs.setAutoCommit(true);
            jrs.commit();
            // The behaviour of jrs should be same with the connection.

            if (hasCommitException) {
                fail("Should throw SQLException");
            }
        } catch (SQLException e) {
            // Expected.
        }

        assertTrue(jrs.absolute(5));
        assertEquals(5, jrs.getInt(1));

        // Set autoCommit to false.
        jrs.setAutoCommit(false);

        // Inserts a row.
        jrs.moveToInsertRow();
        jrs.updateInt(1, 6);
        jrs.updateString(2, "test6");
        jrs.insertRow();
        jrs.moveToCurrentRow();
        assertTrue(jrs.absolute(6));
        assertEquals(6, jrs.getInt(1));

        // Commits
        jrs.commit();
        assertTrue(jrs.absolute(6));
        assertEquals(6, jrs.getInt(1));
        jrs.commit();
        jrs.close();
    }
View Full Code Here

    /**
     * @test javax.sql.rowset.JdbcRowTest.rollback()
     */
    public void testRollback() throws Exception {
        JdbcRowSet jrs = newJdbcRowSet();
        jrs.setUrl(DERBY_URL);
        jrs.setCommand("SELECT * FROM USER_INFO");

        try {
            jrs.rollback();
            fail("Shuld throw NullPointerException since jrs has not been executed.");
        } catch (NullPointerException e) {
            // Expected.
        }

        jrs.execute();
        assertTrue(jrs.absolute(4));
        assertEquals(4, jrs.getInt(1));

        // Inserts a new row.
        jrs.moveToInsertRow();
        jrs.updateInt(1, 5);
        jrs.updateString(2, "test5");
        jrs.insertRow();
        jrs.moveToCurrentRow();

        assertTrue(jrs.absolute(5));
        assertEquals(5, jrs.getInt(1));

        // Set autoCommit to false.
        jrs.setAutoCommit(false);

        // Inserts a row.
        jrs.moveToInsertRow();
        jrs.updateInt(1, 6);
        jrs.updateString(2, "test6");
        jrs.insertRow();
        jrs.moveToCurrentRow();
        assertTrue(jrs.absolute(6));
        assertEquals(6, jrs.getInt(1));

        // Rollbacks
        jrs.rollback();
        try {
            jrs.first();
            fail("After rolling back, jrs can't do anything except close.");
        } catch (NullPointerException e) {
            // Expected.
        }

        jrs.close();

        // Reconnect
        jrs = newJdbcRowSet();
        jrs.setUrl(DERBY_URL);
        jrs.setCommand("SELECT * FROM USER_INFO");
        jrs.execute();
        assertTrue(jrs.last());
        assertEquals(
                "Since the insert action was roll back, so the last row is 5, not 6.",
                5, jrs.getInt(1));

        jrs.close();

    }
View Full Code Here

    /**
     * @test javax.sql.rowset.JdbcRowTest.rollback() When in auto-commit mode,
     *       the behaviour should be the same with the connection.
     */
    public void testRollbackException() throws Exception {
        JdbcRowSet jrs = newJdbcRowSet();
        jrs.setUrl(DERBY_URL);
        jrs.setCommand("SELECT * FROM USER_INFO");
        jrs.execute();

        // Tests if jrs has the same behaviour with connection when commit in
        // auto-commit mode.
        boolean hasRollbackException = true;

        try {
            conn.rollback();
            hasRollbackException = false;
        } catch (SQLException e) {
            // Nothing to do.
        }

        try {
            assertTrue(jrs.getAutoCommit());
            jrs.setAutoCommit(true);
            jrs.rollback();
            // The behaviour of jrs should be same with the connection.

            if (hasRollbackException) {
                fail("Should throw SQLException");
            }
        } catch (SQLException e) {
            // Expected.
        }

        jrs.close();
    }
View Full Code Here

    /**
     * @tests javax.sql.rowset.JdbcRowTest.rollback(SavePoint)
     */
    public void testRollback_LSavePoint_Exception() throws Exception {
        JdbcRowSet jrs = newJdbcRowSet();
        jrs.setUrl(DERBY_URL);
        jrs.setCommand("SELECT * FROM USER_INFO");

        try {
            jrs.rollback(null);
            fail("Shuld throw NullPointerException since jrs has not been executed.");
        } catch (NullPointerException e) {
            // Expected.
        }
        Savepoint savepoint = new MockSavepoint(1, "mock savepoint 1");
        try {
            jrs.rollback(savepoint);
            fail("Shuld throw NullPointerException since jrs has not been executed.");
        } catch (NullPointerException e) {
            // Expected.
        }

        jrs.execute();

        try {
            jrs.rollback(null);
            fail("Should throw SQLException since autoCommit is on");
        } catch (SQLException e) {
            // Expected
        }
        try {
            jrs.rollback(savepoint);
            fail("Should throw SQLException since autoCommit is on");
        } catch (SQLException e) {
            // Expected
        }

        jrs.setAutoCommit(false);
        try {
            jrs.rollback(savepoint);
            fail("Should throw ClassCastException "
                    + "since the savepoint is not the correct type.");
        } catch (ClassCastException e) {
            // Expected.
        }

        jrs.close();
    }
View Full Code Here

TOP

Related Classes of javax.sql.rowset.JdbcRowSet

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.