harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r642114 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/javax/sql/rowset/ main/java/org/apache/harmony/sql/internal/nls/ main/java/org/apache/harmony/sql/internal/rowset/ test/java/org/apache/harmony/sql/tests/internal/rows...
Date Fri, 28 Mar 2008 07:40:02 GMT
Author: tonywu
Date: Fri Mar 28 00:39:55 2008
New Revision: 642114

URL: http://svn.apache.org/viewvc?rev=642114&view=rev
Log:
Apply patch for HARMONY-5661 ([classlib][sql][rowset] - Implement JdbcRowSet)

Added:
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JdbcRowSetTest.java   (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/BaseRowSet.java
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/AbstractRowSetImpl.java
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JdbcRowSetImpl.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/BaseRowSetTest.java

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/BaseRowSet.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/BaseRowSet.java?rev=642114&r1=642113&r2=642114&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/BaseRowSet.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/BaseRowSet.java Fri Mar 28 00:39:55 2008
@@ -169,6 +169,7 @@
             throw new SQLException();
         }
         this.command = cmd;
+        clearParameters();
     }
 
     public String getUrl() throws SQLException {
@@ -355,7 +356,7 @@
         if (rows < 0) {
             throw new SQLException();
         }
-        if (rows > maxRows) {
+        if (maxRows != 0 && rows > maxRows) {
             throw new SQLException();
         }
         this.fetchSize = rows;
@@ -725,7 +726,7 @@
         }
         return result;
     }
-    
+
     public BaseRowSet clone() throws CloneNotSupportedException{
         BaseRowSet result = (BaseRowSet) super.clone();        
         return result;

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties?rev=642114&r1=642113&r2=642114&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties Fri Mar 28 00:39:55 2008
@@ -90,3 +90,5 @@
 rowset.27=Illegal input string "{0}"
 rowset.28=The given value does not lie between the filter criterion
 rowset.29=Insert failed
+rowset.30=Invalid state
+rowset.31=No current connection

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/AbstractRowSetImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/AbstractRowSetImpl.java?rev=642114&r1=642113&r2=642114&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/AbstractRowSetImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/AbstractRowSetImpl.java Fri Mar 28 00:39:55 2008
@@ -22,8 +22,12 @@
 import java.sql.Array;
 import java.sql.Blob;
 import java.sql.Clob;
+import java.sql.Connection;
 import java.sql.Date;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
 import java.sql.Ref;
+import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.sql.SQLWarning;
@@ -33,548 +37,849 @@
 import java.util.Calendar;
 import java.util.Map;
 
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
 import javax.sql.RowSet;
 import javax.sql.rowset.BaseRowSet;
 
-import org.apache.harmony.luni.util.NotImplementedException;
+import org.apache.harmony.sql.internal.nls.Messages;
 
 public class AbstractRowSetImpl extends BaseRowSet implements RowSet {
 
+    protected ResultSet resultSet;
+
+    protected Connection connection;
+
+    protected PreparedStatement statement;
+
+    private boolean isClosed = false;
+
+    public AbstractRowSetImpl() {
+        initialProperties();
+        initParams();
+    }
+
     public void execute() throws SQLException {
-        throw new NotImplementedException();
+        if (isClosed) {
+            throw new SQLException(Messages.getString("rowset.31"));
+        }
+
+        if (connection != null) {
+            connection.close();
+        }
+
+        connection = retrieveConnection();
+        String localCommand = getCommand();
+        if (localCommand == null || getParams() == null) {
+            // rowset.16=Not a valid command
+            throw new SQLException(Messages.getString("rowset.16")); //$NON-NLS-1$
+        }
+
+        statement = connection.prepareStatement(localCommand,
+                ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
+        setParameter(statement);
+
+        resultSet = statement.executeQuery();
+    }
+
+    private Connection retrieveConnection() throws SQLException {
+        if (getUrl() == null && getDataSourceName() == null) {
+            throw new NullPointerException();
+        }
+
+        if (getUrl() != null) {
+            return DriverManager.getConnection(getUrl(), getUsername(), getPassword());
+        } else if (getDataSourceName() != null) {
+            try {
+                Context contex = new InitialContext();
+                DataSource ds = (DataSource) contex.lookup(getDataSourceName());
+                return ds.getConnection();
+            } catch (Exception e) {
+                // rowset.25=(JNDI)Unable to get connection
+                SQLException ex = new SQLException(Messages
+                        .getString("rowset.25")); //$NON-NLS-1$
+                throw ex;
+            }
+        }
+        // rowset.24=Unable to get connection
+        throw new SQLException(Messages.getString("rowset.24")); //$NON-NLS-1$
+    }
+
+    private void setParameter(PreparedStatement ps) throws SQLException {
+        Object[] params = getParams();
+        for (int i = 0; i < params.length; i++) {
+            if (params[i] instanceof Object[]) {
+                Object[] objs = (Object[]) params[i];
+                // character stream
+                if (objs.length == 2) {
+                    ps.setCharacterStream(i + 1, (Reader) objs[0],
+                            ((Integer) objs[1]).intValue());
+                } else {
+                    int type = ((Integer) objs[2]).intValue();
+                    switch (type) {
+                    case BaseRowSet.ASCII_STREAM_PARAM:
+                        ps.setAsciiStream(i + 1, (InputStream) objs[0],
+                                ((Integer) objs[1]).intValue());
+                        break;
+                    case BaseRowSet.BINARY_STREAM_PARAM:
+                        ps.setBinaryStream(i + 1, (InputStream) objs[0],
+                                ((Integer) objs[1]).intValue());
+                        break;
+                    case BaseRowSet.UNICODE_STREAM_PARAM:
+                        ps.setUnicodeStream(i + 1, (InputStream) objs[0],
+                                ((Integer) objs[1]).intValue());
+                        break;
+                    }
+                }
+            } else {
+                ps.setObject(i + 1, params[i]);
+            }
+        }
     }
 
     public boolean absolute(int row) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.absolute(row);
     }
 
     public void afterLast() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.afterLast();
     }
 
     public void beforeFirst() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.beforeFirst();
     }
 
     public void cancelRowUpdates() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.cancelRowUpdates();
     }
 
     public void clearWarnings() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.clearWarnings();
     }
 
     public void close() throws SQLException {
-        throw new NotImplementedException();
+        try {
+            if (resultSet != null) {
+                resultSet.close();
+            }
+
+            if (statement != null) {
+                statement.close();
+            }
+
+            if (connection != null) {
+                connection.close();
+            }
+
+        } finally {
+            isClosed = true;
+        }
     }
 
     public void deleteRow() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.deleteRow();
     }
 
     public int findColumn(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.findColumn(columnName);
     }
 
     public boolean first() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.first();
     }
 
     public Array getArray(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getArray(columnIndex);
     }
 
     public Array getArray(String colName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getArray(colName);
     }
 
     public InputStream getAsciiStream(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getAsciiStream(columnIndex);
     }
 
     public InputStream getAsciiStream(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getAsciiStream(columnName);
     }
 
     public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getBigDecimal(columnIndex);
     }
 
-    public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
-        throw new NotImplementedException();
+    public BigDecimal getBigDecimal(int columnIndex, int scale)
+            throws SQLException {
+        checkValid();
+        return resultSet.getBigDecimal(columnIndex, scale);
     }
 
     public BigDecimal getBigDecimal(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getBigDecimal(columnName);
     }
 
-    public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException {
-        throw new NotImplementedException();
+    public BigDecimal getBigDecimal(String columnName, int scale)
+            throws SQLException {
+        checkValid();
+        return resultSet.getBigDecimal(columnName, scale);
     }
 
     public InputStream getBinaryStream(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getBinaryStream(columnIndex);
     }
 
     public InputStream getBinaryStream(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getBinaryStream(columnName);
     }
 
     public Blob getBlob(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getBlob(columnIndex);
     }
 
     public Blob getBlob(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getBlob(columnName);
     }
 
     public boolean getBoolean(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getBoolean(columnIndex);
     }
 
     public boolean getBoolean(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getBoolean(columnName);
     }
 
     public byte getByte(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getByte(columnIndex);
     }
 
     public byte getByte(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getByte(columnName);
     }
 
     public byte[] getBytes(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getBytes(columnIndex);
     }
 
     public byte[] getBytes(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getBytes(columnName);
     }
 
     public Reader getCharacterStream(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getCharacterStream(columnIndex);
     }
 
     public Reader getCharacterStream(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getCharacterStream(columnName);
     }
 
     public Clob getClob(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getClob(columnIndex);
     }
 
     public Clob getClob(String colName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getClob(colName);
     }
 
     public String getCursorName() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getCursorName();
     }
 
     public Date getDate(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getDate(columnIndex);
     }
 
     public Date getDate(int columnIndex, Calendar cal) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getDate(columnIndex, cal);
     }
 
     public Date getDate(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getDate(columnName);
     }
 
     public Date getDate(String columnName, Calendar cal) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getDate(columnName, cal);
     }
 
     public double getDouble(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getDouble(columnIndex);
     }
 
     public double getDouble(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getDouble(columnName);
     }
 
     public float getFloat(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getFloat(columnIndex);
     }
 
     public float getFloat(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getFloat(columnName);
     }
 
     public int getInt(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getInt(columnIndex);
     }
 
     public int getInt(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getInt(columnName);
     }
 
     public long getLong(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getLong(columnIndex);
     }
 
     public long getLong(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getLong(columnName);
     }
 
     public ResultSetMetaData getMetaData() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getMetaData();
     }
 
     public Object getObject(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getObject(columnIndex);
     }
 
-    public Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLException {
-        throw new NotImplementedException();
+    public Object getObject(int columnIndex, Map<String, Class<?>> map)
+            throws SQLException {
+        checkValid();
+        return resultSet.getObject(columnIndex, map);
     }
 
     public Object getObject(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getObject(columnName);
     }
 
-    public Object getObject(String columnName, Map<String, Class<?>> map) throws SQLException {
-        throw new NotImplementedException();
+    public Object getObject(String columnName, Map<String, Class<?>> map)
+            throws SQLException {
+        checkValid();
+        return resultSet.getObject(columnName, map);
     }
 
     public Ref getRef(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getRef(columnIndex);
     }
 
     public Ref getRef(String colName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getRef(colName);
     }
 
     public int getRow() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getRow();
     }
 
     public short getShort(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getShort(columnIndex);
     }
 
     public short getShort(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getShort(columnName);
     }
 
     public Statement getStatement() throws SQLException {
-        throw new NotImplementedException();
+        if (statement != null && isClosed) {
+            throw new SQLException();
+        }
+        return statement;
     }
 
     public String getString(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getString(columnIndex);
     }
 
     public String getString(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getString(columnName);
     }
 
     public Time getTime(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getTime(columnIndex);
     }
 
     public Time getTime(int columnIndex, Calendar cal) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getTime(columnIndex, cal);
     }
 
     public Time getTime(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getTime(columnName);
     }
 
     public Time getTime(String columnName, Calendar cal) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getTime(columnName, cal);
     }
 
     public Timestamp getTimestamp(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getTimestamp(columnIndex);
     }
 
-    public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
-        throw new NotImplementedException();
+    public Timestamp getTimestamp(int columnIndex, Calendar cal)
+            throws SQLException {
+        checkValid();
+        return resultSet.getTimestamp(columnIndex, cal);
     }
 
     public Timestamp getTimestamp(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getTimestamp(columnName);
     }
 
-    public Timestamp getTimestamp(String columnName, Calendar cal) throws SQLException {
-        throw new NotImplementedException();
+    public Timestamp getTimestamp(String columnName, Calendar cal)
+            throws SQLException {
+        checkValid();
+        return resultSet.getTimestamp(columnName, cal);
     }
 
     public java.net.URL getURL(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getURL(columnIndex);
     }
 
     public java.net.URL getURL(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getURL(columnName);
     }
 
     public InputStream getUnicodeStream(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getUnicodeStream(columnIndex);
     }
 
     public InputStream getUnicodeStream(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getUnicodeStream(columnName);
     }
 
     public SQLWarning getWarnings() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.getWarnings();
     }
 
     public void insertRow() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.insertRow();
     }
 
     public boolean isAfterLast() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.isAfterLast();
     }
 
     public boolean isBeforeFirst() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.isBeforeFirst();
     }
 
     public boolean isFirst() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.isFirst();
     }
 
     public boolean isLast() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.isLast();
     }
 
     public boolean last() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.last();
     }
 
     public void moveToCurrentRow() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.moveToCurrentRow();
     }
 
     public void moveToInsertRow() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.moveToInsertRow();
     }
 
     public boolean next() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.next();
     }
 
     public boolean previous() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.previous();
     }
 
     public void refreshRow() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.refreshRow();
     }
 
     public boolean relative(int rows) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.relative(rows);
     }
 
     public boolean rowDeleted() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.rowDeleted();
     }
 
     public boolean rowInserted() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.rowInserted();
     }
 
     public boolean rowUpdated() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.rowUpdated();
     }
 
     public void updateArray(int columnIndex, Array x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateArray(columnIndex, x);
     }
 
     public void updateArray(String columnName, Array x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateArray(columnName, x);
     }
 
-    public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException {
-        throw new NotImplementedException();
+    public void updateAsciiStream(int columnIndex, InputStream x, int length)
+            throws SQLException {
+        checkValid();
+        resultSet.updateAsciiStream(columnIndex, x, length);
     }
 
-    public void updateAsciiStream(String columnName, InputStream x, int length) throws SQLException {
-        throw new NotImplementedException();
+    public void updateAsciiStream(String columnName, InputStream x, int length)
+            throws SQLException {
+        checkValid();
+        resultSet.updateAsciiStream(columnName, x, length);
     }
 
-    public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException {
-        throw new NotImplementedException();
+    public void updateBigDecimal(int columnIndex, BigDecimal x)
+            throws SQLException {
+        checkValid();
+        resultSet.updateBigDecimal(columnIndex, x);
     }
 
-    public void updateBigDecimal(String columnName, BigDecimal x) throws SQLException {
-        throw new NotImplementedException();
+    public void updateBigDecimal(String columnName, BigDecimal x)
+            throws SQLException {
+        checkValid();
+        resultSet.updateBigDecimal(columnName, x);
     }
 
-    public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException {
-        throw new NotImplementedException();
+    public void updateBinaryStream(int columnIndex, InputStream x, int length)
+            throws SQLException {
+        checkValid();
+        resultSet.updateBinaryStream(columnIndex, x, length);
     }
 
-    public void updateBinaryStream(String columnName, InputStream x, int length) throws SQLException {
-        throw new NotImplementedException();
+    public void updateBinaryStream(String columnName, InputStream x, int length)
+            throws SQLException {
+        checkValid();
+        resultSet.updateBinaryStream(columnName, x, length);
     }
 
     public void updateBlob(int columnIndex, Blob x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateBlob(columnIndex, x);
     }
 
     public void updateBlob(String columnName, Blob x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateBlob(columnName, x);
     }
 
     public void updateBoolean(int columnIndex, boolean x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateBoolean(columnIndex, x);
     }
 
     public void updateBoolean(String columnName, boolean x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateBoolean(columnName, x);
     }
 
     public void updateByte(int columnIndex, byte x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateByte(columnIndex, x);
     }
 
     public void updateByte(String columnName, byte x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateByte(columnName, x);
     }
 
     public void updateBytes(int columnIndex, byte[] x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateBytes(columnIndex, x);
     }
 
     public void updateBytes(String columnName, byte[] x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateBytes(columnName, x);
     }
 
-    public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException {
-        throw new NotImplementedException();
+    public void updateCharacterStream(int columnIndex, Reader x, int length)
+            throws SQLException {
+        checkValid();
+        resultSet.updateCharacterStream(columnIndex, x, length);
     }
 
-    public void updateCharacterStream(String columnName, Reader reader, int length) throws SQLException {
-        throw new NotImplementedException();
+    public void updateCharacterStream(String columnName, Reader reader,
+            int length) throws SQLException {
+        checkValid();
+        resultSet.updateCharacterStream(columnName, reader, length);
     }
 
     public void updateClob(int columnIndex, Clob x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateClob(columnIndex, x);
     }
 
     public void updateClob(String columnName, Clob x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateClob(columnName, x);
     }
 
     public void updateDate(int columnIndex, Date x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateDate(columnIndex, x);
     }
 
     public void updateDate(String columnName, Date x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateDate(columnName, x);
     }
 
     public void updateDouble(int columnIndex, double x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateDouble(columnIndex, x);
     }
 
     public void updateDouble(String columnName, double x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateDouble(columnName, x);
     }
 
     public void updateFloat(int columnIndex, float x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateFloat(columnIndex, x);
     }
 
     public void updateFloat(String columnName, float x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateFloat(columnName, x);
     }
 
     public void updateInt(int columnIndex, int x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateInt(columnIndex, x);
     }
 
     public void updateInt(String columnName, int x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateInt(columnName, x);
     }
 
     public void updateLong(int columnIndex, long x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateLong(columnIndex, x);
     }
 
     public void updateLong(String columnName, long x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateLong(columnName, x);
     }
 
     public void updateNull(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateNull(columnIndex);
     }
 
     public void updateNull(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateNull(columnName);
     }
 
     public void updateObject(int columnIndex, Object x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateObject(columnIndex, x);
     }
 
-    public void updateObject(int columnIndex, Object x, int scale) throws SQLException {
-        throw new NotImplementedException();
+    public void updateObject(int columnIndex, Object x, int scale)
+            throws SQLException {
+        checkValid();
+        resultSet.updateObject(columnIndex, x, scale);
     }
 
     public void updateObject(String columnName, Object x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateObject(columnName, x);
     }
 
-    public void updateObject(String columnName, Object x, int scale) throws SQLException {
-        throw new NotImplementedException();
+    public void updateObject(String columnName, Object x, int scale)
+            throws SQLException {
+        checkValid();
+        resultSet.updateObject(columnName, x, scale);
     }
 
     public void updateRef(int columnIndex, Ref x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateRef(columnIndex, x);
     }
 
     public void updateRef(String columnName, Ref x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateRef(columnName, x);
     }
 
     public void updateRow() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateRow();
     }
 
     public void updateShort(int columnIndex, short x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateShort(columnIndex, x);
     }
 
     public void updateShort(String columnName, short x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateShort(columnName, x);
     }
 
     public void updateString(int columnIndex, String x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateString(columnIndex, x);
     }
 
     public void updateString(String columnName, String x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateString(columnName, x);
     }
 
     public void updateTime(int columnIndex, Time x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateTime(columnIndex, x);
     }
 
     public void updateTime(String columnName, Time x) throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        resultSet.updateTime(columnName, x);
     }
 
-    public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException {
-        throw new NotImplementedException();
+    public void updateTimestamp(int columnIndex, Timestamp x)
+            throws SQLException {
+        checkValid();
+        resultSet.updateTimestamp(columnIndex, x);
     }
 
-    public void updateTimestamp(String columnName, Timestamp x) throws SQLException {
-        throw new NotImplementedException();
+    public void updateTimestamp(String columnName, Timestamp x)
+            throws SQLException {
+        checkValid();
+        resultSet.updateTimestamp(columnName, x);
     }
 
     public boolean wasNull() throws SQLException {
-        throw new NotImplementedException();
+        checkValid();
+        return resultSet.wasNull();
     }
 
+    public int getConcurrency() throws SQLException {
+        if (resultSet == null) {
+            throw new NullPointerException();
+        }
+
+        return resultSet.getConcurrency();
+    }
+
+    public int getFetchDirection() throws SQLException {
+        if (resultSet == null) {
+            throw new NullPointerException();
+        }
+
+        return resultSet.getFetchDirection();
+    }
+
+    private void checkValid() throws SQLException {
+        if (resultSet == null && connection == null) {
+            throw new SQLException(Messages.getString("rowset.30")); //$NON-NLS-1$
+        }
+
+        if (resultSet == null && connection != null) {
+            throw new NullPointerException();
+        }
+    }
+
+    private void initialProperties() {
+        try {
+            setEscapeProcessing(true);
+            setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+            setConcurrency(ResultSet.CONCUR_UPDATABLE);
+            setType(ResultSet.TYPE_SCROLL_INSENSITIVE);
+            setMaxRows(0);
+            setQueryTimeout(0);
+            setShowDeleted(false);
+            setUsername(null);
+            setPassword(null);
+            setMaxFieldSize(0);
+            setTypeMap(null);
+            setFetchSize(0);
+        } catch (SQLException e) {
+            // ignore, never reached
+        }
 
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java?rev=642114&r1=642113&r2=642114&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java Fri Mar 28 00:39:55 2008
@@ -134,6 +134,7 @@
 
     private SQLWarning sqlwarn = new SQLWarning();
 
+    // TODO deal with rowSetWarning
     private RowSetWarning rowSetWarning = new RowSetWarning();
 
     private Class[] columnTypes;

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JdbcRowSetImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JdbcRowSetImpl.java?rev=642114&r1=642113&r2=642114&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JdbcRowSetImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JdbcRowSetImpl.java Fri Mar 28 00:39:55 2008
@@ -27,27 +27,49 @@
 public class JdbcRowSetImpl extends AbstractRowSetImpl implements JdbcRowSet {
 
     public void commit() throws SQLException {
-        throw new NotImplementedException();
+        if (connection == null) {
+            throw new NullPointerException();
+        }
+        connection.commit();
     }
 
     public boolean getAutoCommit() throws SQLException {
-        throw new NotImplementedException();
+        if (connection == null) {
+            throw new NullPointerException();
+        }
+        return connection.getAutoCommit();
     }
 
     public RowSetWarning getRowSetWarnings() throws SQLException {
-        throw new NotImplementedException();
+        return null;
     }
 
     public void rollback() throws SQLException {
-        throw new NotImplementedException();
+        if (connection == null) {
+            throw new NullPointerException();
+        }
+
+        connection.rollback();
+        statement = null;
+        resultSet = null;
     }
 
     public void rollback(Savepoint s) throws SQLException {
-        throw new NotImplementedException();
+        if (connection == null) {
+            throw new NullPointerException();
+        }
+
+        connection.rollback(s);
+        statement = null;
+        resultSet = null;
     }
 
     public void setAutoCommit(boolean autoCommit) throws SQLException {
-        throw new NotImplementedException();
+        if (connection == null) {
+            throw new NullPointerException();
+        }
+
+        connection.setAutoCommit(autoCommit);
     }
 
     public int[] getMatchColumnIndexes() throws SQLException {

Added: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JdbcRowSetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JdbcRowSetTest.java?rev=642114&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JdbcRowSetTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JdbcRowSetTest.java Fri Mar 28 00:39:55 2008
@@ -0,0 +1,1428 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.harmony.sql.tests.internal.rowset;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Savepoint;
+import java.sql.Statement;
+
+import javax.sql.RowSet;
+import javax.sql.rowset.BaseRowSet;
+import javax.sql.rowset.JdbcRowSet;
+import javax.sql.rowset.RowSetWarning;
+
+public class JdbcRowSetTest extends CachedRowSetTestCase {
+
+    private JdbcRowSet newJdbcRowSet() throws Exception {
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            return (JdbcRowSet) Class.forName(
+                    "org.apache.harmony.sql.internal.rowset.JdbcRowSetImpl")
+                    .newInstance();
+        }
+        return (JdbcRowSet) Class.forName("com.sun.rowset.JdbcRowSetImpl")
+                .newInstance();
+    }
+
+    public void testBeforeInitial() throws Exception {
+        JdbcRowSet jrs = newJdbcRowSet();
+
+        // move cursor
+        try {
+            jrs.absolute(1);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Invalid state
+        }
+
+        try {
+            jrs.beforeFirst();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Invalid state
+        }
+
+        try {
+            jrs.afterLast();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Invalid state
+        }
+        try {
+            jrs.last();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Invalid state
+        }
+        try {
+            jrs.first();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Invalid state
+        }
+        try {
+            jrs.isAfterLast();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Invalid state
+        }
+        try {
+            jrs.isBeforeFirst();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Invalid state
+        }
+        try {
+            jrs.isFirst();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Invalid state
+        }
+        try {
+            jrs.isLast();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Invalid state
+        }
+
+        try {
+            jrs.getRow();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Invalid state
+        }
+
+        try {
+            jrs.getString(1);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Invalid state
+        }
+
+        // get properties
+
+        try {
+            jrs.getConcurrency();
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            jrs.getFetchDirection();
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        assertEquals(0, jrs.getFetchSize());
+        assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, jrs.getType());
+        assertNull(jrs.getTypeMap());
+        assertTrue(jrs.getEscapeProcessing());
+
+        // set properties
+        jrs.setConcurrency(RowSet.CONCUR_UPDATABLE);
+        jrs.setType(ResultSet.TYPE_FORWARD_ONLY);
+        jrs.setEscapeProcessing(false);
+        assertFalse(jrs.getEscapeProcessing());
+
+        // JdbcRowSet methods
+        try {
+            jrs.getAutoCommit();
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            jrs.commit();
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            jrs.setAutoCommit(false);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            jrs.rollback();
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        assertNull(jrs.getRowSetWarnings());
+
+        // update methods
+        try {
+            jrs.updateString(1, "test");
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Invalid state
+        }
+
+        try {
+            jrs.insertRow();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Invalid state
+        }
+
+        jrs.close();
+
+        try {
+            jrs.clearWarnings();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Invalid state
+        }
+
+        try {
+            jrs.findColumn("ID");
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Invalid state
+        }
+
+        try {
+            jrs.wasNull();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Invalid state
+        }
+
+        try {
+            jrs.getMetaData();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Invalid state
+        }
+
+        try {
+            jrs.getWarnings();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // 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());
+        assertEquals(false, 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());
+        assertEquals(false, 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();
+    }
+
+    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();
+    }
+
+    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();
+    }
+
+    public void testExecute_SelectCmd() throws Exception {
+        JdbcRowSet jrs = newJdbcRowSet();
+        jrs.setCommand("SELECT * FROM USER_INFO WHERE ID > ?");
+        jrs.setUrl(DERBY_URL);
+        jrs.setInt(1, 1);
+        jrs.execute();
+
+        assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, jrs.getType());
+        assertEquals(ResultSet.CONCUR_UPDATABLE, jrs.getConcurrency());
+        assertTrue(jrs.getAutoCommit());
+        assertTrue(jrs.first());
+        assertEquals(2, jrs.getInt(1));
+        assertTrue(jrs.absolute(2));
+        assertEquals(3, jrs.getInt(1));
+        assertTrue(jrs.last());
+        assertEquals(4, jrs.getInt(1));
+        assertTrue(jrs.previous());
+        assertEquals(3, jrs.getInt(1));
+        assertTrue(jrs.relative(-1));
+        assertEquals(2, jrs.getInt(1));
+        jrs.close();
+    }
+
+    public void testExecute_UpdateCmd() throws Exception {
+        JdbcRowSet jrs = newJdbcRowSet();
+        jrs.setCommand("Update User_INFO set Name= ? Where ID= ? ");
+        jrs.setUrl(DERBY_URL);
+        jrs.setString(1, "update");
+        jrs.setInt(2, 3);
+        try {
+            jrs.execute();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        jrs.close();
+    }
+
+    public void testExecute_DeleteCmd() throws Exception {
+        JdbcRowSet jrs = newJdbcRowSet();
+        jrs.setCommand("DELETE FROM USER_INFO");
+        jrs.setUrl(DERBY_URL);
+        try {
+            jrs.execute();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        jrs.close();
+    }
+
+    public void testExecute_InsertCmd() throws Exception {
+        JdbcRowSet jrs = newJdbcRowSet();
+        jrs.setCommand("insert into USER_INFO(ID,NAME) values (6,'insert6')");
+        jrs.setUrl(DERBY_URL);
+        try {
+            jrs.execute();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        jrs.close();
+    }
+
+    public void testUpdateRow_Normal() throws Exception {
+        JdbcRowSet jrs = newJdbcRowSet();
+        jrs.setCommand("SELECT * FROM USER_INFO");
+        jrs.setUrl(DERBY_URL);
+        jrs.execute();
+
+        assertTrue(jrs.absolute(3));
+        assertEquals(3, jrs.getInt(1));
+        assertEquals("test3", jrs.getString(2));
+        jrs.updateString(2, "update3");
+        assertFalse(jrs.rowUpdated());
+        jrs.updateRow();
+        assertTrue(jrs.rowUpdated());
+        assertEquals("update3", jrs.getString(2));
+
+        jrs.close();
+
+        // check db
+        rs = st
+                .executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE NAME = 'update3'");
+        assertTrue(rs.next());
+        assertEquals(1, rs.getInt(1));
+    }
+
+    public void testUpdateRow_Exception() throws Exception {
+        JdbcRowSet jrs = newJdbcRowSet();
+        jrs.setCommand("SELECT * FROM USER_INFO");
+        jrs.setUrl(DERBY_URL);
+        jrs.execute();
+
+        assertTrue(jrs.absolute(-2));
+        assertEquals("test3", jrs.getString(2));
+        jrs.updateRow();
+        assertFalse(jrs.rowUpdated());
+
+        jrs.updateString(2, "too looooooooooooooooooooong");
+        try {
+            jrs.updateRow();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        try {
+            assertFalse(jrs.rowUpdated());
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+
+        try {
+            assertTrue(jrs.absolute(1));
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+
+        jrs.close();
+    }
+
+    public void testDeleteRow() throws Exception {
+        insertMoreData(6);
+        JdbcRowSet jrs = newJdbcRowSet();
+        jrs.setCommand("SELECT * FROM USER_INFO");
+        jrs.setUrl(DERBY_URL);
+        jrs.execute();
+
+        assertTrue(jrs.first());
+        jrs.deleteRow();
+
+        try {
+            jrs.getInt(1);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+
+        jrs.close();
+
+        /*
+         * Check database
+         */
+        rs = st.executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE ID = 1");
+        assertTrue(rs.next());
+        assertEquals(0, rs.getInt(1));
+    }
+
+    public void testResultSet_InsertRow() throws Exception {
+        Statement stmt = conn.createStatement(
+                ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
+        ResultSet rset = stmt.executeQuery("SELECT * FROM USER_INFO");
+        assertTrue(rset.first());
+        assertEquals(1, rset.getInt(1));
+        rset.moveToInsertRow();
+        rset.updateInt(1, 5);
+        rset.updateString(2, "insert5");
+        rset.insertRow();
+        rset.moveToCurrentRow();
+        assertEquals(1, rset.getInt(1));
+        assertTrue(rset.last());
+        assertEquals(5, rset.getInt(1));
+
+        /*
+         * Because the above called rset.last(), the inserted row which ID is 6
+         * becomes invisible to JdbcRowSet.
+         */
+        rset.moveToInsertRow();
+        rset.updateInt(1, 6);
+        rset.updateString(2, "insert6");
+        rset.insertRow();
+        rset.moveToCurrentRow();
+
+        int index = 0;
+        rset.beforeFirst();
+        while (rset.next()) {
+            index++;
+            assertEquals(index, rset.getInt(1));
+        }
+        assertEquals(5, index);
+
+        rset.close();
+        stmt.close();
+
+        /*
+         * Check database
+         */
+        rs = st
+                .executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE NAME = 'insert5' OR NAME = 'insert6'");
+        assertTrue(rs.next());
+        assertEquals(2, rs.getInt(1));
+    }
+
+    public void testInsertRow_Single() throws Exception {
+        /*
+         * In JdbcRowSet, the inserted row is the last row. The behavior is the
+         * same as ResultSet.
+         */
+        JdbcRowSet jrs = newJdbcRowSet();
+        jrs.setCommand("SELECT * FROM USER_INFO");
+        jrs.setUrl(DERBY_URL);
+        jrs.execute();
+
+        jrs.moveToInsertRow();
+        jrs.updateInt(1, 5);
+        jrs.updateString(2, "insert5");
+        jrs.insertRow();
+        jrs.moveToCurrentRow();
+
+        // check the inserted row
+        assertTrue(jrs.absolute(5));
+        /*
+         * If uncommenting the following line, then the inserted row which ID is
+         * 6 would be invisible to JdbcRowSet.
+         */
+        // assertTrue(jrs.isLast());
+        assertEquals(5, jrs.getInt(1));
+
+        jrs.moveToInsertRow();
+        jrs.updateInt(1, 6);
+        jrs.updateString(2, "insert6");
+        jrs.insertRow();
+        jrs.moveToCurrentRow();
+
+        assertTrue(jrs.last());
+        assertEquals(6, jrs.getInt(1));
+        assertTrue(jrs.previous());
+        assertEquals(5, jrs.getInt(1));
+
+        jrs.close();
+
+        // check db
+        rs = st
+                .executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE NAME = 'insert5' OR NAME = 'insert6'");
+        assertTrue(rs.next());
+        assertEquals(2, rs.getInt(1));
+    }
+
+    public void testInsertRow_Multi() throws Exception {
+        JdbcRowSet jrs = newJdbcRowSet();
+        jrs.setCommand("SELECT * FROM USER_INFO");
+        jrs.setUrl(DERBY_URL);
+        jrs.execute();
+
+        jrs.moveToInsertRow();
+        jrs.updateInt(1, 5);
+        jrs.updateString(2, "insert5");
+        jrs.insertRow();
+        jrs.updateInt(1, 6);
+        jrs.updateString(2, "insert6");
+        jrs.insertRow();
+        jrs.updateInt(1, 7);
+        jrs.updateString(2, "insert7");
+        jrs.insertRow();
+        jrs.moveToCurrentRow();
+
+        int index = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            index++;
+            assertEquals(index, jrs.getInt(1));
+        }
+        assertEquals(7, index);
+
+        jrs.close();
+
+        /*
+         * Check database
+         */
+        rs = st
+                .executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE NAME LIKE 'insert%'");
+        assertTrue(rs.next());
+        assertEquals(3, rs.getInt(1));
+
+        /*
+         * Change another way to insert multiple rows
+         */
+        jrs = newJdbcRowSet();
+        jrs.setCommand("SELECT * FROM USER_INFO");
+        jrs.setUrl(DERBY_URL);
+        jrs.execute();
+
+        assertTrue(jrs.absolute(7));
+        jrs.moveToInsertRow();
+        jrs.updateInt(1, 8);
+        jrs.updateString(2, "insert8");
+        jrs.insertRow();
+        jrs.moveToInsertRow();
+        jrs.updateInt(1, 9);
+        jrs.updateString(2, "insert9");
+        jrs.insertRow();
+        jrs.moveToInsertRow();
+        jrs.updateInt(1, 10);
+        jrs.updateString(2, "insert10");
+        jrs.insertRow();
+        jrs.moveToCurrentRow();
+
+        /*
+         * Check JdbcRowSet
+         */
+        assertEquals(7, jrs.getInt(1));
+        index = 7;
+        while (jrs.next()) {
+            index++;
+            assertEquals(index, jrs.getInt(1));
+        }
+        assertEquals(10, index);
+
+        jrs.close();
+
+        /*
+         * Check database
+         */
+        rs = st.executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE ID > 7");
+        assertTrue(rs.next());
+        assertEquals(3, rs.getInt(1));
+    }
+
+    public void testCancelRowUpdates() throws Exception {
+        JdbcRowSet jrs = newJdbcRowSet();
+        jrs.setCommand("SELECT * FROM USER_INFO");
+        jrs.setUrl(DERBY_URL);
+        jrs.execute();
+
+        jrs.moveToInsertRow();
+        try {
+            jrs.cancelRowUpdates();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        jrs.moveToCurrentRow();
+
+        assertTrue(jrs.absolute(3));
+        jrs.updateString(2, "update3");
+        jrs.updateRow();
+        assertTrue(jrs.rowUpdated());
+        assertEquals("update3", jrs.getString(2));
+        jrs.cancelRowUpdates();
+        assertEquals("update3", jrs.getString(2));
+
+        assertTrue(jrs.next());
+        assertEquals(4, jrs.getInt(1));
+        jrs.updateString(2, "update4");
+        assertFalse(jrs.rowUpdated());
+        assertEquals("update4", jrs.getString(2));
+        jrs.cancelRowUpdates();
+        assertEquals("test4", jrs.getString(2));
+
+        jrs.close();
+
+        /*
+         * Check database
+         */
+        rs = st.executeQuery("SELECT * FROM USER_INFO WHERE ID = 3");
+        assertTrue(rs.next());
+        assertEquals("update3", rs.getString(2));
+    }
+
+    public void testFindColumn() throws Exception {
+        JdbcRowSet jrs = newJdbcRowSet();
+        try {
+            jrs.findColumn("abc");
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        jrs.setCommand("SELECT * FROM USER_INFO");
+        jrs.setUrl(DERBY_URL);
+        jrs.execute();
+
+        assertEquals(1, jrs.findColumn("ID"));
+        try {
+            jrs.findColumn("abc");
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+
+        jrs.close();
+    }
+
+    public void testGetStatement() throws Exception {
+        JdbcRowSet jrs = newJdbcRowSet();
+        assertNull(jrs.getStatement());
+        jrs.setCommand("SELECT * FROM USER_INFO");
+        jrs.setUrl(DERBY_URL);
+        jrs.execute();
+        assertTrue(jrs.getStatement() instanceof PreparedStatement);
+
+        jrs.close();
+
+        try {
+            assertNull(jrs.getStatement());
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    public void testAutoCommit_True() throws Exception {
+        JdbcRowSet jrs = newJdbcRowSet();
+        jrs.setCommand("SELECT * FROM USER_INFO");
+        jrs.setUrl(DERBY_URL);
+        jrs.execute();
+
+        assertTrue(jrs.getAutoCommit());
+        assertTrue(jrs.absolute(3));
+        jrs.updateString(2, "update3");
+        jrs.updateRow();
+        jrs.rollback();
+
+        // after rollback, resultset is closed
+        assertNull(jrs.getStatement());
+        try {
+            jrs.getString(2);
+            fail("should throw exception");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            jrs.absolute(1);
+            fail("should throw exception");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        jrs.close();
+
+        /*
+         * TODO Check database. The database is supposed to has been updated.
+         * However, it's not.
+         */
+        rs = st
+                .executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE NAME = 'update3'");
+        assertTrue(rs.next());
+        assertEquals(0, rs.getInt(1));
+    }
+
+    public void testAutoCommit_False() throws Exception {
+        JdbcRowSet jrs = newJdbcRowSet();
+        jrs.setCommand("SELECT * FROM USER_INFO");
+        jrs.setUrl(DERBY_URL);
+        jrs.execute();
+
+        jrs.setAutoCommit(false);
+        assertFalse(jrs.getAutoCommit());
+        assertTrue(jrs.absolute(3));
+        jrs.updateString(2, "update3");
+        jrs.updateRow();
+        jrs.commit();
+        jrs.rollback();
+
+        /*
+         * TODO why throw NullPointerException after call rollback()?
+         */
+        try {
+            jrs.absolute(1);
+            fail("should throw exception");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        jrs.close();
+
+        /*
+         * Check database
+         */
+        rs = st
+                .executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE NAME = 'update3'");
+        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());
+    }
+
+    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();
+        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
+        }
+    }
+
+    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
+        }
+
+    }
+
+    /**
+     * @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();
+    }
+
+    /**
+     * @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();
+
+    }
+
+    /**
+     * @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();
+    }
+
+    /**
+     * @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();
+    }
+
+    /**
+     * @tests javax.sql.rowset.JdbcRowTest.setShowDeleted() and
+     *        javax.sql.rowset.JdbcRowTest.getShowDeleted().
+     */
+    public void testShowDeleted() throws Exception {
+        JdbcRowSet jrs = newJdbcRowSet();
+
+        boolean showDeleted = jrs.getShowDeleted();
+        assertFalse("The default value is false.", showDeleted);
+
+        jrs.setUrl(DERBY_URL);
+        jrs.setCommand("SELECT * FROM USER_INFO");
+        jrs.execute();
+
+        // Deletes the 4th row.
+        jrs.absolute(4);
+        jrs.deleteRow();
+        try {
+            jrs.getInt(1);
+            fail("Should throw SQLException " + "since no current row.");
+        } catch (SQLException e) {
+            // Expected.
+        }
+
+        jrs.first();
+        int index = 0;
+        while (jrs.next()) {
+            index++;
+        }
+
+        assertEquals(3, index);
+
+        jrs.setShowDeleted(true);
+        assertTrue(jrs.getShowDeleted());
+
+        jrs.absolute(3);
+        jrs.deleteRow();
+        jrs.first();
+        index = 0;
+        while (jrs.next()) {
+            index++;
+        }
+
+        assertEquals("The deleted row should still be showed", 3, index);
+
+        jrs.close();
+    }
+
+    public class MockSavepoint implements Savepoint {
+        private int id;
+
+        private String name;
+
+        public MockSavepoint(int id, String name) {
+            this.id = id;
+            this.name = name;
+        }
+
+        public int getSavepointId() throws SQLException {
+            return id;
+        }
+
+        public String getSavepointName() throws SQLException {
+            return name;
+        }
+
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JdbcRowSetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/BaseRowSetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/BaseRowSetTest.java?rev=642114&r1=642113&r2=642114&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/BaseRowSetTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/BaseRowSetTest.java Fri Mar 28 00:39:55 2008
@@ -267,6 +267,37 @@
                 params[0] instanceof SerialRef);
     }
 
+    // Parameters should be cleared when setCommand()
+    public void testSetCommand() throws SQLException {
+        BaseRowSetImpl baseRowSet = new BaseRowSetImpl();
+        baseRowSet.initParams();
+        baseRowSet.setCommand("Test command ? and ?");
+        baseRowSet.setString(1, "FirstParameter");
+        baseRowSet.setString(2, "SecondParameter");
+        Object[] params1 = baseRowSet.getParams();
+
+        assertEquals("The number of parameters should be 2 after setting.", 2,
+                params1.length);
+
+        baseRowSet.setCommand("Test command 2 without parameter");
+        Object[] params2 = baseRowSet.getParams();
+
+        assertEquals(
+                "The number of parameters should be 0 since command has been reset",
+                0, params2.length);
+
+    }
+
+    // Since the maxSize is set to 0 by default and 0 represents no limit, we
+    // can't just throw exception when we want to set size greater to 0,
+    public void testSetFetchSize() throws SQLException {
+        BaseRowSetImpl baseRowSet = new BaseRowSetImpl();
+        baseRowSet.initParams();
+        assertEquals(0, baseRowSet.getMaxRows());
+        baseRowSet.setFetchSize(3);
+        assertEquals("The fetch size should be set to 3.", 3, baseRowSet.getFetchSize());
+    }
+    
     private static final class BaseRowSetImpl extends BaseRowSet {
         private static final long serialVersionUID = 1L;
 



Mime
View raw message