harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lvj...@apache.org
Subject svn commit: r641234 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/org/apache/harmony/sql/internal/nls/ main/java/org/apache/harmony/sql/internal/rowset/ test/java/org/apache/harmony/sql/tests/internal/rowset/
Date Wed, 26 Mar 2008 10:22:56 GMT
Author: lvjing
Date: Wed Mar 26 03:22:46 2008
New Revision: 641234

URL: http://svn.apache.org/viewvc?rev=641234&view=rev
Log:
Apply patch for HARMONY-5653, [classlib][sql][rowset]Implement FilteredRowSet and refine CachedRowSet

Added:
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/FilteredRowSetTest.java   (with props)
Modified:
    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/CachedRow.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/FilteredRowSetImpl.java
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/HYOptimisticProvider.java
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/XmlReaderImpl.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetDeleteTest.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetStreamTest.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/WebRowSetTest.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/XmlReaderTest.java

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=641234&r1=641233&r2=641234&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 Wed Mar 26 03:22:46 2008
@@ -88,3 +88,5 @@
 rowset.25=(JNDI)Unable to get connection
 rowset.26=The object has not been initialized
 rowset.27=Illegal input string "{0}"
+rowset.28=The given value does not lie between the filter criterion
+rowset.29=Insert failed

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java?rev=641234&r1=641233&r2=641234&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java Wed Mar 26 03:22:46 2008
@@ -16,13 +16,17 @@
  */
 package org.apache.harmony.sql.internal.rowset;
 
+import java.io.Serializable;
 import java.sql.SQLException;
 import java.sql.SQLWarning;
 import java.util.BitSet;
 
 import org.apache.harmony.sql.internal.nls.Messages;
 
-public class CachedRow implements Cloneable {
+public class CachedRow implements Cloneable, Serializable {
+
+    private static final long serialVersionUID = 5131958045838461662L;
+
     private Object[] columnData;
 
     private Object[] originalColumnData;

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=641234&r1=641233&r2=641234&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 Wed Mar 26 03:22:46 2008
@@ -67,6 +67,10 @@
 import javax.sql.rowset.CachedRowSet;
 import javax.sql.rowset.RowSetMetaDataImpl;
 import javax.sql.rowset.RowSetWarning;
+import javax.sql.rowset.serial.SerialArray;
+import javax.sql.rowset.serial.SerialBlob;
+import javax.sql.rowset.serial.SerialClob;
+import javax.sql.rowset.serial.SerialRef;
 import javax.sql.rowset.spi.SyncFactory;
 import javax.sql.rowset.spi.SyncFactoryException;
 import javax.sql.rowset.spi.SyncProvider;
@@ -142,7 +146,7 @@
 
     private boolean isLastColNull;
 
-    private Connection conn;
+    private transient Connection conn;
 
     private boolean isNotifyListener = true;
 
@@ -498,22 +502,53 @@
 
         conn = connection;
         PreparedStatement ps = connection.prepareStatement(localCommand);
-        Object[] params = getParams();
-        for (int i = 0; i < params.length; i++)
-            ps.setObject(i + 1, params[i]);
+        setParameter(ps);
 
         if (ps.execute()) {
             doPopulate(ps.getResultSet(), true);
+
+            if (getPageSize() != 0) {
+                nextPageRowIndex = rows.size() + 1;
+                previousPageRowIndex = 0;
+                cachedResultSet = null;
+            } else {
+                previousPageRowIndex = -1;
+                nextPageRowIndex = -1;
+                cachedResultSet = null;
+            }
         }
 
-        if (getPageSize() != 0) {
-            nextPageRowIndex = rows.size() + 1;
-            previousPageRowIndex = 0;
-            cachedResultSet = null;
-        } else {
-            previousPageRowIndex = -1;
-            nextPageRowIndex = -1;
-            cachedResultSet = null;
+    }
+
+    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]);
+            }
         }
     }
 
@@ -584,10 +619,9 @@
 
             PreparedStatement ps = retrieveConnection().prepareStatement(
                     localCommand);
-            Object[] params = getParams();
-            for (int i = 0; i < params.length; i++) {
-                ps.setObject(i + 1, params[i]);
-            }
+
+            setParameter(ps);
+
             if (ps.execute()) {
                 ResultSet rs = ps.getResultSet();
                 int index = 1;
@@ -788,9 +822,8 @@
 
             PreparedStatement ps = retrieveConnection().prepareStatement(
                     localCommand);
-            Object[] params = getParams();
-            for (int i = 0; i < params.length; i++)
-                ps.setObject(i + 1, params[i]);
+
+            setParameter(ps);
 
             if (ps.execute()) {
                 ResultSet rs = ps.getResultSet();
@@ -1841,6 +1874,7 @@
             // sql.27=Invalid column index :{0}
             throw new SQLException(Messages.getString("sql.27", columnIndex)); //$NON-NLS-1$
         }
+
         Object obj = currentRow.getObject(columnIndex);
         if (obj == null) {
             isLastColNull = true;
@@ -2110,7 +2144,7 @@
             throw new SQLException(Messages.getString("rowset.4")); //$NON-NLS-1$
         }
         boolean isValueSet = false;
-        for (int i = 1; i <= columnCount; i++) {
+        for (int i = 0; i < columnCount; i++) {
             if (currentRow.getUpdateMask(i)) {
                 isValueSet = true;
                 break;
@@ -2121,7 +2155,11 @@
             throw new SQLException(Messages.getString("rowset.18")); //$NON-NLS-1$
         }
         insertRow.setInsert();
-        rows.add(rememberedCursorPosition, insertRow);
+        if (rememberedCursorPosition > rows.size()) {
+            rows.add(insertRow);
+        } else {
+            rows.add(rememberedCursorPosition, insertRow);
+        }
         insertRow = null;
         if (isNotifyListener) {
             notifyRowChanged();
@@ -2351,10 +2389,7 @@
             throws SQLException {
         checkValidRow();
         checkColumnValid(columnIndex);
-        if (isCursorOnInsert && insertRow == null) {
-            insertRow = new CachedRow(new Object[columnCount]);
-            currentRow = insertRow;
-        }
+        initInsertRow(columnIndex, in);
 
         Class<?> type = columnTypes[columnIndex - 1];
         if (type != null && !type.equals(String.class)
@@ -2403,10 +2438,7 @@
             throws SQLException {
         checkValidRow();
         checkColumnValid(columnIndex);
-        if (isCursorOnInsert && insertRow == null) {
-            insertRow = new CachedRow(new Object[columnCount]);
-            currentRow = insertRow;
-        }
+        initInsertRow(columnIndex, in);
 
         Class<?> type = columnTypes[columnIndex - 1];
         if (type != null && !type.equals(byte[].class)) {
@@ -2476,10 +2508,7 @@
             throws SQLException {
         checkValidRow();
         checkColumnValid(columnIndex);
-        if (isCursorOnInsert && insertRow == null) {
-            insertRow = new CachedRow(new Object[columnCount]);
-            currentRow = insertRow;
-        }
+        initInsertRow(columnIndex, in);
 
         Class<?> type = columnTypes[columnIndex - 1];
         if (type != null && !type.equals(String.class)
@@ -2575,10 +2604,7 @@
     public void updateObject(int columnIndex, Object x) throws SQLException {
         checkValidRow();
         checkColumnValid(columnIndex);
-        if (isCursorOnInsert && insertRow == null) {
-            insertRow = new CachedRow(new Object[columnCount]);
-            currentRow = insertRow;
-        }
+        initInsertRow(columnIndex, x);
         currentRow.updateObject(columnIndex, x);
     }
 
@@ -2604,10 +2630,7 @@
             // x = ((BigDecimal) x).setScale(scale);
             // }
         }
-        if (isCursorOnInsert && insertRow == null) {
-            insertRow = new CachedRow(new Object[columnCount]);
-            currentRow = insertRow;
-        }
+        initInsertRow(columnIndex, x);
         currentRow.updateObject(columnIndex, x);
     }
 
@@ -2666,12 +2689,24 @@
             throws SQLException {
         checkValidRow();
         checkColumnValid(columnIndex);
+        initInsertRow(columnIndex, value);
+        currentRow.updateObject(columnIndex, convertUpdateValue(columnIndex,
+                value));
+    }
+
+    /**
+     * The implementation of FilteredRowSet would override this method. The
+     * parameters also are used for override.
+     * 
+     * @param columnIndex
+     * @param value
+     */
+    protected void initInsertRow(int columnIndex, Object value)
+            throws SQLException {
         if (isCursorOnInsert && insertRow == null) {
             insertRow = new CachedRow(new Object[columnCount]);
             currentRow = insertRow;
         }
-        currentRow.updateObject(columnIndex, convertUpdateValue(columnIndex,
-                value));
     }
 
     /**
@@ -2702,7 +2737,28 @@
          * now, leave this type check to JDBC driver
          */
 
-        if (type == null || type.isInstance(value)) {
+        if (type == null) {
+            return value;
+        }
+
+        // convert to serializable object
+        if (type.isInstance(value)) {
+            if (type.equals(Array.class) && !(value instanceof SerialArray)) {
+                return new SerialArray((Array) value);
+            }
+
+            if (type.equals(Blob.class) && !(value instanceof SerialBlob)) {
+                return new SerialBlob((Blob) value);
+            }
+
+            if (type.equals(Clob.class) && !(value instanceof SerialClob)) {
+                return new SerialClob((Clob) value);
+            }
+
+            if (type.equals(Ref.class) && !(value instanceof SerialRef)) {
+                return new SerialRef((Ref) value);
+            }
+
             return value;
         }
 
@@ -2937,12 +2993,13 @@
                 return ds.getConnection();
             } catch (Exception e) {
                 // rowset.25=(JNDI)Unable to get connection
-                SQLException ex = new SQLException("rowset.25"); //$NON-NLS-1$
+                SQLException ex = new SQLException(Messages
+                        .getString("rowset.25")); //$NON-NLS-1$
                 throw ex;
             }
         }
         // rowset.24=Unable to get connection
-        throw new SQLException("rowset.24"); //$NON-NLS-1$
+        throw new SQLException(Messages.getString("rowset.24")); //$NON-NLS-1$
     }
 
     CachedRow getCurrentRow() {
@@ -2955,4 +3012,19 @@
         super.setCommand(cmd);
     }
 
+    protected boolean isCursorOnInsert() {
+        return isCursorOnInsert;
+    }
+
+    protected boolean isNotifyListener() {
+        return isNotifyListener;
+    }
+
+    protected void setIsNotifyListener(boolean isNotifyListener) {
+        this.isNotifyListener = isNotifyListener;
+    }
+
+    protected CachedRow getInsertRow() {
+        return insertRow;
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/FilteredRowSetImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/FilteredRowSetImpl.java?rev=641234&r1=641233&r2=641234&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/FilteredRowSetImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/FilteredRowSetImpl.java Wed Mar 26 03:22:46 2008
@@ -22,21 +22,186 @@
 import javax.sql.rowset.Predicate;
 import javax.sql.rowset.spi.SyncFactoryException;
 
-import org.apache.harmony.luni.util.NotImplementedException;
+import org.apache.harmony.sql.internal.nls.Messages;
 
 public class FilteredRowSetImpl extends WebRowSetImpl implements FilteredRowSet {
 
+    private static final long serialVersionUID = -6532792430142890537L;
+
+    private Predicate predicate;
+
+    public FilteredRowSetImpl() throws SyncFactoryException {
+        super();
+    }
+
     public FilteredRowSetImpl(String providerID) throws SyncFactoryException {
         super(providerID);
-        // TODO Auto-generated constructor stub
     }
 
     public Predicate getFilter() {
-        throw new NotImplementedException();
+        return predicate;
     }
 
     public void setFilter(Predicate p) throws SQLException {
-        throw new NotImplementedException();
+        this.predicate = p;
     }
 
+    @Override
+    public boolean absolute(int row) throws SQLException {
+        if (predicate == null) {
+            return super.absolute(row);
+        }
+
+        beforeFirst();
+        if (row > 0) {
+            if (row > size()) {
+                afterLast();
+                return false;
+            }
+            int count = 0;
+            for (int i = 0; i < size(); i++) {
+                if (next()) {
+                    count++;
+                    if (count == row) {
+                        return true;
+                    }
+                }
+            }
+        } else if (row < 0) {
+            row = Math.abs(row);
+            if (row > size()) {
+                return false;
+            }
+            afterLast();
+            int count = 0;
+            for (int i = 0; i < size(); i++) {
+                if (previous()) {
+                    count++;
+                    if (count == row) {
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public boolean relative(int moveRows) throws SQLException {
+        if (predicate == null) {
+            return super.relative(moveRows);
+        }
+
+        if (moveRows > 0) {
+            int count = 0;
+            int maxCount = size() - getRow();
+            for (int i = 0; i < maxCount; i++) {
+                if (next()) {
+                    count++;
+                    if (count == moveRows) {
+                        return true;
+                    }
+                }
+            }
+        } else if (moveRows < 0) {
+            int count = 0;
+            int maxCount = getRow();
+            for (int i = 0; i < maxCount; i++) {
+                if (previous()) {
+                    count++;
+                    if (count == Math.abs(moveRows)) {
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public boolean next() throws SQLException {
+        if (predicate == null) {
+            return super.next();
+        }
+        while (super.next()) {
+            if (predicate.evaluate(this)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public boolean previous() throws SQLException {
+        if (predicate == null) {
+            return super.previous();
+        }
+        while (super.previous()) {
+            if (predicate.evaluate(this)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public boolean first() throws SQLException {
+        if (predicate == null) {
+            return super.first();
+        }
+        beforeFirst();
+        for (int i = 0; i < size(); i++) {
+            if (next()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public boolean last() throws SQLException {
+        if (predicate == null) {
+            return super.last();
+        }
+        afterLast();
+        for (int i = 0; i < size(); i++) {
+            if (previous()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public void insertRow() throws SQLException {
+        if (predicate != null) {
+            CachedRow insertRow = getInsertRow();
+            if (insertRow != null) {
+                for (int i = 0; i < getMetaData().getColumnCount(); i++) {
+                    if (insertRow.getUpdateMask(i)
+                            && !predicate.evaluate(insertRow.getObject(i + 1),
+                                    i + 1)) {
+                        // rowset.29=Insert failed
+                        throw new SQLException(Messages.getString("rowset.29"));
+                    }
+                }
+            }
+        }
+        super.insertRow();
+    }
+
+    @Override
+    protected void initInsertRow(int columnIndex, Object value)
+            throws SQLException {
+        super.initInsertRow(columnIndex, value);
+        if (predicate == null) {
+            return;
+        }
+        if (isCursorOnInsert() && !predicate.evaluate(value, columnIndex)) {
+            getInsertRow().updateObject(columnIndex, value);
+            // rowset.28=The given value does not lie between the filter
+            // criterion
+            throw new SQLException(Messages.getString("rowset.28"));
+        }
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/HYOptimisticProvider.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/HYOptimisticProvider.java?rev=641234&r1=641233&r2=641234&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/HYOptimisticProvider.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/HYOptimisticProvider.java Wed Mar 26 03:22:46 2008
@@ -17,12 +17,16 @@
 
 package org.apache.harmony.sql.internal.rowset;
 
+import java.io.Serializable;
+
 import javax.sql.RowSetReader;
 import javax.sql.RowSetWriter;
 import javax.sql.rowset.spi.SyncProvider;
 import javax.sql.rowset.spi.SyncProviderException;
 
-public class HYOptimisticProvider extends SyncProvider {
+public class HYOptimisticProvider extends SyncProvider implements Serializable {
+
+    private static final long serialVersionUID = -4275201032064821711L;
 
     private final static String providerID = "Apache Harmony"; //$NON-NLS-1$
 

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/XmlReaderImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/XmlReaderImpl.java?rev=641234&r1=641233&r2=641234&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/XmlReaderImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/XmlReaderImpl.java Wed Mar 26 03:22:46 2008
@@ -206,10 +206,6 @@
             currentValue = new String(ch, start, length);
         }
 
-        private void readHeader() {
-            // TODO
-        }
-
         private void readProperties() throws SQLException {
             if ("command".equals(currentTagName)) { //$NON-NLS-1$
                 webRs.setCommand(currentValue);

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetDeleteTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetDeleteTest.java?rev=641234&r1=641233&r2=641234&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetDeleteTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetDeleteTest.java Wed Mar 26 03:22:46 2008
@@ -340,14 +340,8 @@
         noInitialCrset.populate(rs);
 
         /*
-         * Test exception. According to spec, it would throw SQLException when
-         * calling undoDelete() in such conditions:
-         * 
-         * 1) the current row has not been deleted.
-         * 
-         * 2) the cursor is on the insert row.
-         * 
-         * 3) the curosr is before the first row, or after the last row.
+         * Test exception. It would throw SQLException when calling undoDelete()
+         * in such conditions.
          */
         if ("true".equals(System.getProperty("Testing Harmony"))) {
             // TODO RI doesn't follow the spec, we follow spec
@@ -475,11 +469,6 @@
         // NOTICE: The cursor is on the second row, not the third row
         assertEquals(2, noInitialCrset.getInt(1));
 
-        // assertTrue(noInitialCrset.absolute(1));
-        // System.out.println("first: ");
-        // for (int i = 1; i <= DEFAULT_COLUMN_COUNT; i++) {
-        // System.out.print(noInitialCrset.getObject(i) + " ");
-        // }
         // retrieve the data in CachedRowSet after calling deleteRow()
         noInitialCrset.beforeFirst();
         int index = 0;
@@ -537,7 +526,7 @@
 
     public void testRelative() throws Exception {
         insertMoreData(10);
-        
+
         rs = st.executeQuery("SELECT * FROM USER_INFO");
         crset = newNoInitialInstance();
         crset.populate(rs);

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java?rev=641234&r1=641233&r2=641234&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java Wed Mar 26 03:22:46 2008
@@ -17,6 +17,10 @@
 
 package org.apache.harmony.sql.tests.internal.rowset;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.io.PrintWriter;
 import java.math.BigDecimal;
 import java.sql.Connection;
@@ -86,9 +90,8 @@
 
     public void testSetOriginalRow() throws Exception {
         /*
-         * According to the spec, this method is called internally after the any
-         * modified values in the current row have been synchronized with the
-         * data source.
+         * This method is called internally after the current row have been
+         * synchronized with the data source.
          */
         crset.beforeFirst();
         assertTrue(crset.absolute(3));
@@ -2831,6 +2834,58 @@
         }
     }
 
+    public void testSerializable() throws Exception {
+
+        crset.absolute(3);
+        crset.updateString(2, "update3");
+
+        assertEquals(3, crset.getRow());
+
+        ByteArrayOutputStream bout = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream(bout);
+        out.writeObject(crset);
+
+        out.close();
+
+        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(
+                bout.toByteArray()));
+
+        CachedRowSet another = (CachedRowSet) in.readObject();
+        in.close();
+
+        isMetaDataEquals(crset.getMetaData(), another.getMetaData());
+
+        assertEquals(crset.getRow(), another.getRow());
+        assertEquals(crset.getString(2), another.getString(2));
+
+        crset = newNoInitialInstance();
+        crset.setCommand("SELECT * FROM USER_INFO");
+        crset.setUrl(DERBY_URL);
+        crset.execute();
+
+        crset.absolute(3);
+
+        bout = new ByteArrayOutputStream();
+        out = new ObjectOutputStream(bout);
+        out.writeObject(crset);
+
+        out.close();
+
+        in = new ObjectInputStream(new ByteArrayInputStream(bout.toByteArray()));
+
+        another = (CachedRowSet) in.readObject();
+
+        isMetaDataEquals(crset.getMetaData(), another.getMetaData());
+
+        assertEquals(crset.getRow(), another.getRow());
+
+        try {
+            another.commit();
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+    }
 }
 
 class Listener implements RowSetListener, Cloneable {

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetStreamTest.java?rev=641234&r1=641233&r2=641234&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetStreamTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetStreamTest.java Wed Mar 26 03:22:46 2008
@@ -1095,4 +1095,94 @@
         }
     }
 
+    public void testSetBinaryStream() throws Exception {
+
+        insertRow(3, "test3", new byte[] { 1, 2, 3 });
+        crset = newNoInitialInstance();
+
+        crset.setCommand("select * from STREAM where VARCHAR_FOR_BIT_T= ?");
+
+        crset.setBinaryStream(1, new ByteArrayInputStream(
+                new byte[] { 1, 2, 3 }), 3);
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+
+            crset.execute(conn);
+
+            assertTrue(crset.next());
+
+            assertEquals(3, crset.getInt(1));
+
+            byte[] bs = crset.getBytes(3);
+            assertEquals(1, bs[0]);
+            assertEquals(2, bs[1]);
+            assertEquals(3, bs[2]);
+        } else {
+            try {
+                crset.execute(conn);
+                fail("Should throw SQLException");
+            } catch (SQLException e) {
+                // error message: An attempt was made to get a data value of
+                // type 'VARCHAR ()
+                // FOR BIT DATA' from a data value of type
+                // 'java.io.InputStream(ASCII)'.
+                /*
+                 * TODO It seems RI invoke wrong method when it's setBinaryStream
+                 */
+            }
+        }
+
+    }
+
+    public void testSetAsciiStream() throws Exception {
+
+        crset = newNoInitialInstance();
+
+        crset.setCommand("update STREAM set LONGVARCHAR_T=? where ID= ?");
+
+        String value = "It's    is a very very very long long long story";
+        crset.setAsciiStream(1, new ByteArrayInputStream(value.getBytes()),
+                value.getBytes().length);
+        crset.setInt(2, 1);
+
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+
+            crset.execute(conn);
+            rs = st.executeQuery("select * from STREAM where ID = 1");
+
+            assertTrue(rs.next());
+            assertEquals(1, rs.getInt(1));
+            assertEquals(value, rs.getString(2));
+        } else {
+            try {
+                crset.execute(conn);
+                fail("Should throw SQLException");
+            } catch (SQLException e) {
+                // Unable to deduce param type
+                /*
+                 * TODO It seems RI doesn't support stream
+                 */
+            }
+        }
+    }
+
+    public void testSetCharacterStream() throws Exception {
+
+        crset = newNoInitialInstance();
+
+        String value = new String("\u548c\u8c10");
+        crset.setCommand("update STREAM set LONGVARCHAR_T=? where ID= ?");
+
+        crset.setCharacterStream(1, new StringReader(value), value
+                .toCharArray().length);
+        crset.setInt(2, 1);
+
+        crset.execute(conn);
+
+        rs = st.executeQuery("select * from STREAM where ID = 1");
+
+        assertTrue(rs.next());
+        assertEquals(1, rs.getInt(1));
+        assertEquals(value, rs.getString(2));
+
+    }
 }

Added: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/FilteredRowSetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/FilteredRowSetTest.java?rev=641234&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/FilteredRowSetTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/FilteredRowSetTest.java Wed Mar 26 03:22:46 2008
@@ -0,0 +1,903 @@
+/* 
+ * 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.ResultSet;
+import java.sql.SQLException;
+
+import javax.sql.RowSet;
+import javax.sql.rowset.FilteredRowSet;
+import javax.sql.rowset.Predicate;
+
+public class FilteredRowSetTest extends CachedRowSetTestCase {
+
+    public final static int EVALUATE_DEFAULT = 0;
+
+    public final static int EVALUATE_ROWSET = 1;
+
+    public final static int EVALUATE_INSERT = 2;
+
+    public void testCreateShared() throws Exception {
+        FilteredRowSet filteredRowSet = newFilterRowSet();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        filteredRowSet.populate(rs);
+
+        Predicate range = new RangeOne();
+        filteredRowSet.setFilter(range);
+
+        FilteredRowSet copyFilteredRs = (FilteredRowSet) filteredRowSet
+                .createShared();
+        assertSame(range, copyFilteredRs.getFilter());
+    }
+
+    public void testCreateCopy() throws Exception {
+        FilteredRowSet filteredRowSet = newFilterRowSet();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        filteredRowSet.populate(rs);
+
+        Predicate range = new RangeOne();
+        filteredRowSet.setFilter(range);
+
+        try {
+            filteredRowSet.createCopy();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    public void testSetFilter() throws Exception {
+        FilteredRowSet filteredRowSet = newFilterRowSet();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        filteredRowSet.populate(rs);
+
+        /*
+         * Set Filter: RangeOne
+         */
+        Predicate range = new RangeOne();
+        filteredRowSet.setFilter(range);
+        filteredRowSet.beforeFirst();
+        int index = 0;
+        while (filteredRowSet.next()) {
+            index++;
+            assertTrue(filteredRowSet.getString(2).indexOf("test") != -1);
+        }
+        assertEquals(3, index);
+        assertSame(range, filteredRowSet.getFilter());
+
+        /*
+         * Set another Filter: RangeTwo
+         */
+        range = new RangeTwo();
+        filteredRowSet.setFilter(range);
+        filteredRowSet.beforeFirst();
+        index = 0;
+        boolean isSecondRowFiltered = true;
+        while (filteredRowSet.next()) {
+            index++;
+            if ("test2".equals(filteredRowSet.getString(2))) {
+                isSecondRowFiltered = false;
+            }
+        }
+        assertEquals(3, index);
+        assertTrue(isSecondRowFiltered);
+        assertSame(range, filteredRowSet.getFilter());
+
+        /*
+         * Remove Filter
+         */
+        filteredRowSet.setFilter(null);
+        filteredRowSet.beforeFirst();
+        index = 0;
+        while (filteredRowSet.next()) {
+            index++;
+            assertEquals(index, filteredRowSet.getInt(1));
+        }
+        assertEquals(4, index);
+        assertNull(filteredRowSet.getFilter());
+    }
+
+    public void testSetFilterOnFilteredRow() throws Exception {
+        FilteredRowSet filteredRowSet = newFilterRowSet();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        filteredRowSet.populate(rs);
+
+        filteredRowSet.next();
+        assertEquals(1, filteredRowSet.getRow());
+        Predicate range = new RangeOne();
+        filteredRowSet.setFilter(range);
+
+        // not filtered
+        assertEquals(1, filteredRowSet.getRow());
+        assertEquals("hermit", filteredRowSet.getString(2));
+
+        filteredRowSet.updateString(2, "update");
+        assertEquals("update", filteredRowSet.getString(2));
+
+        filteredRowSet.next();
+        assertEquals(2, filteredRowSet.getRow());
+        assertEquals("test", filteredRowSet.getString(2));
+
+        filteredRowSet.previous();
+        assertTrue(filteredRowSet.isBeforeFirst());
+
+        try {
+            filteredRowSet.getString(2);
+            fail("should should SQLException");
+        } catch (SQLException e) {
+            // expected, Not a valid cursor
+        }
+
+        filteredRowSet.setFilter(null);
+
+        assertTrue(filteredRowSet.isBeforeFirst());
+
+        assertTrue(filteredRowSet.next());
+        assertEquals("update", filteredRowSet.getString(2));
+
+        filteredRowSet.setFilter(range);
+        assertEquals("update", filteredRowSet.getString(2));
+        filteredRowSet.updateString(2, "testUpdate");
+
+        filteredRowSet.next();
+        assertEquals(2, filteredRowSet.getRow());
+        assertEquals("test", filteredRowSet.getString(2));
+
+        filteredRowSet.previous();
+        assertEquals(1, filteredRowSet.getRow());
+        assertEquals("testUpdate", filteredRowSet.getString(2));
+
+    }
+
+    public void testPopulate() throws Exception {
+        /*
+         * Set Filter before populate()
+         */
+        RangeOne range = new RangeOne();
+        FilteredRowSet filteredRowSet = newFilterRowSet();
+        filteredRowSet.setFilter(range);
+        assertSame(range, filteredRowSet.getFilter());
+
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        filteredRowSet.populate(rs);
+
+        assertTrue(filteredRowSet.first());
+        assertEquals(2, filteredRowSet.getInt(1));
+
+        filteredRowSet.setFilter(null);
+        assertTrue(filteredRowSet.first());
+        assertEquals(1, filteredRowSet.getInt(1));
+    }
+
+    public void testAbsolute() throws Exception {
+        FilteredRowSet filteredRowSet = newFilterRowSet();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        filteredRowSet.populate(rs);
+        /*
+         * When running on RI, filteredRowSet.absolute(1) is false here.
+         * However, the cursor moves to the first row already.
+         */
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertTrue(filteredRowSet.absolute(1));
+        } else {
+            assertFalse(filteredRowSet.absolute(1));
+        }
+        assertEquals("hermit", filteredRowSet.getString(2));
+
+        RangeOne range = new RangeOne();
+        filteredRowSet.setFilter(range);
+
+        /*
+         * When running on RI, filteredRowSet.absolute(1) is false.
+         */
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertTrue(filteredRowSet.absolute(1));
+        } else {
+            assertFalse(filteredRowSet.absolute(1));
+        }
+        assertEquals("test", filteredRowSet.getString(2));
+        range.clear();
+        assertTrue(filteredRowSet.absolute(2));
+        assertEquals(3, filteredRowSet.getRow());
+        assertEquals(3, filteredRowSet.getInt(1));
+        assertEquals(EVALUATE_ROWSET, range.getTag());
+        assertEquals(3, range.getCount());
+
+        range.clear();
+        assertTrue(filteredRowSet.absolute(2));
+        assertEquals(3, filteredRowSet.getInt(1));
+        assertEquals(EVALUATE_ROWSET, range.getTag());
+        assertEquals(3, range.getCount());
+
+        range.clear();
+        assertTrue(filteredRowSet.absolute(3));
+        assertEquals(4, filteredRowSet.getInt(1));
+        assertEquals(EVALUATE_ROWSET, range.getTag());
+        assertEquals(4, range.getCount());
+
+        assertFalse(filteredRowSet.absolute(4));
+
+        assertTrue(filteredRowSet.absolute(-2));
+        assertEquals(3, filteredRowSet.getInt(1));
+
+        assertTrue(filteredRowSet.absolute(-3));
+        assertEquals(2, filteredRowSet.getInt(1));
+
+        assertFalse(filteredRowSet.absolute(-4));
+        assertTrue(filteredRowSet.isBeforeFirst());
+    }
+
+    public void testRelative() throws Exception {
+        FilteredRowSet filteredRowSet = newFilterRowSet();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        filteredRowSet.populate(rs);
+
+        assertTrue(filteredRowSet.absolute(3));
+        assertEquals(3, filteredRowSet.getInt(1));
+        assertFalse(filteredRowSet.relative(2));
+
+        assertTrue(filteredRowSet.absolute(3));
+        assertEquals(3, filteredRowSet.getInt(1));
+        assertTrue(filteredRowSet.relative(1));
+        assertEquals(4, filteredRowSet.getInt(1));
+
+        assertTrue(filteredRowSet.absolute(3));
+        assertEquals(3, filteredRowSet.getInt(1));
+        assertTrue(filteredRowSet.relative(-1));
+        assertEquals(2, filteredRowSet.getInt(1));
+        assertFalse(filteredRowSet.relative(-2));
+
+        RangeOne range = new RangeOne();
+        filteredRowSet.setFilter(range);
+
+        filteredRowSet.beforeFirst();
+        assertTrue(filteredRowSet.relative(2));
+        assertEquals(3, filteredRowSet.getInt(1));
+        assertEquals(3, filteredRowSet.getRow());
+        assertFalse(filteredRowSet.relative(-2));
+        assertTrue(filteredRowSet.isBeforeFirst());
+    }
+
+    public void testCursorMove() throws Exception {
+        insertMoreData(30);
+        FilteredRowSet filteredRowSet = newFilterRowSet();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        filteredRowSet.populate(rs);
+        RangeThree range = new RangeThree();
+        filteredRowSet.setFilter(range);
+
+        assertTrue(filteredRowSet.first());
+        assertEquals("hermit", filteredRowSet.getString(2));
+        /*
+         * TODO It's really strange. When running on RI, filteredRowSet.first()
+         * is true. The cursor stays on the first row. However,
+         * filteredRowSet.absolute(1) is false. But the cursor still stays on
+         * the first row.
+         */
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertTrue(filteredRowSet.absolute(1));
+        } else {
+            assertFalse(filteredRowSet.absolute(1));
+        }
+        assertEquals("hermit", filteredRowSet.getString(2));
+        assertTrue(filteredRowSet.relative(1));
+        assertEquals("test4", filteredRowSet.getString(2));
+        /*
+         * First call absolute(2), then call relative(-1), the cursor returns
+         * the first row.
+         */
+        assertTrue(filteredRowSet.absolute(2));
+        assertEquals("test4", filteredRowSet.getString(2));
+        assertTrue(filteredRowSet.relative(-1));
+        assertEquals("hermit", filteredRowSet.getString(2));
+
+        assertTrue(filteredRowSet.last());
+        assertEquals("test34", filteredRowSet.getString(2));
+
+        assertTrue(filteredRowSet.previous());
+        assertEquals("test32", filteredRowSet.getString(2));
+
+        assertTrue(filteredRowSet.relative(-1));
+        assertEquals("test30", filteredRowSet.getString(2));
+
+        assertTrue(filteredRowSet.absolute(5));
+        assertEquals("test10", filteredRowSet.getString(2));
+
+        assertTrue(filteredRowSet.relative(3));
+        assertEquals("test16", filteredRowSet.getString(2));
+
+        assertTrue(filteredRowSet.relative(-3));
+        assertEquals("test10", filteredRowSet.getString(2));
+
+        assertTrue(filteredRowSet.relative(4));
+        assertEquals("test18", filteredRowSet.getString(2));
+
+        assertTrue(filteredRowSet.relative(13));
+        assertEquals("test34", filteredRowSet.getString(2));
+
+        assertFalse(filteredRowSet.next());
+        assertTrue(filteredRowSet.isAfterLast());
+
+        assertTrue(filteredRowSet.absolute(22));
+        assertEquals("test34", filteredRowSet.getString(2));
+
+        assertTrue(filteredRowSet.relative(-21));
+        assertEquals("hermit", filteredRowSet.getString(2));
+
+        assertFalse(filteredRowSet.relative(-1));
+        assertTrue(filteredRowSet.isBeforeFirst());
+    }
+
+    public void testNextAndPrevious() throws Exception {
+        FilteredRowSet filteredRowSet = newFilterRowSet();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        filteredRowSet.populate(rs);
+
+        RangeOne range = new RangeOne();
+        filteredRowSet.setFilter(range);
+
+        assertTrue(filteredRowSet.next());
+        assertEquals(2, filteredRowSet.getInt(1));
+        assertEquals(EVALUATE_ROWSET, range.getTag());
+        assertEquals(2, range.getCount());
+        range.clear();
+        assertTrue(filteredRowSet.next());
+        assertEquals(3, filteredRowSet.getInt(1));
+        assertEquals(EVALUATE_ROWSET, range.getTag());
+        assertEquals(1, range.getCount());
+
+        range.clear();
+        assertTrue(filteredRowSet.previous());
+        assertEquals(2, filteredRowSet.getInt(1));
+        assertEquals(1, range.getCount());
+        range.clear();
+        assertFalse(filteredRowSet.previous());
+        assertEquals(EVALUATE_ROWSET, range.getTag());
+    }
+
+    public void testNoFilter_Insert() throws Exception {
+        FilteredRowSet filteredRowSet = newFilterRowSet();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        filteredRowSet.populate(rs);
+
+        /*
+         * TODO Call updateXXX() would throw NullPointerException on insert row
+         * when running on RI.
+         */
+        filteredRowSet.moveToInsertRow();
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            filteredRowSet.updateInt(1, 10);
+            filteredRowSet.updateString(2, "insert10");
+            filteredRowSet.insertRow();
+        } else {
+            try {
+                filteredRowSet.updateInt(1, 10);
+                fail("should throw NullPointerException");
+            } catch (NullPointerException e) {
+                // expected
+            }
+            try {
+                filteredRowSet.updateString(2, "insert10");
+                fail("should throw NullPointerException");
+            } catch (NullPointerException e) {
+                // expected
+            }
+            try {
+                filteredRowSet.insertRow();
+                fail("should throw SQLException");
+            } catch (SQLException e) {
+                // expected
+            }
+        }
+        filteredRowSet.moveToCurrentRow();
+    }
+
+    public void testFilter_Insert() throws Exception {
+        FilteredRowSet filteredRowSet = newFilterRowSet();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        filteredRowSet.populate(rs);
+
+        Predicate range = new RangeOne();
+        filteredRowSet.setFilter(range);
+
+        /*
+         * Insert a row. when call updateXXX(), evaluate(Object value, int
+         * column) is called to check first.
+         */
+        filteredRowSet.afterLast();
+        filteredRowSet.moveToInsertRow();
+        filteredRowSet.updateInt(1, 200);
+        try {
+            filteredRowSet.updateString("NAME", "test200");
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            filteredRowSet.updateString("NAME", "insert200");
+        }
+        filteredRowSet.insertRow();
+        filteredRowSet.moveToCurrentRow();
+
+        /*
+         * Although the new row is inserted, it is invalid through
+         * evaluate(RowSet rs). Therefore, the inserted row is not visible.
+         */
+        filteredRowSet.beforeFirst();
+        int index = 0;
+        while (filteredRowSet.next()) {
+            index++;
+            assertEquals(index + 1, filteredRowSet.getInt(1));
+        }
+        assertEquals(3, index);
+
+        /*
+         * Remove filter. See the inserted row. Then set again, and commit to
+         * database.
+         */
+        filteredRowSet.setFilter(null);
+        assertTrue(filteredRowSet.last());
+        assertEquals(200, filteredRowSet.getInt(1));
+        assertTrue(filteredRowSet.rowInserted());
+        filteredRowSet.setFilter(range);
+        filteredRowSet.acceptChanges(conn);
+        // check database: the inserted row isn't commited to database
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        index = 0;
+        while (rs.next()) {
+            index++;
+            assertEquals(index, rs.getInt(1));
+        }
+        assertEquals(4, index);
+
+        /*
+         * Remove filter
+         */
+        filteredRowSet.setFilter(null);
+        filteredRowSet.beforeFirst();
+        index = 0;
+        while (filteredRowSet.next()) {
+            index++;
+            if (index == 5) {
+                /*
+                 * Though the new row isn't inserted into database, the inserted
+                 * row lost it's status after acceptChanges().
+                 */
+                assertEquals(200, filteredRowSet.getInt(1));
+                assertFalse(filteredRowSet.rowInserted());
+            } else {
+                assertEquals(index, filteredRowSet.getInt(1));
+            }
+        }
+        assertEquals(5, index);
+    }
+
+    public void testFilter_Update() throws Exception {
+        FilteredRowSet filteredRowSet = newFilterRowSet();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        filteredRowSet.populate(rs);
+
+        Predicate range = new RangeOne();
+        filteredRowSet.setFilter(range);
+
+        /*
+         * Update the third row. Filter has no effect here.
+         */
+        assertTrue(filteredRowSet.last());
+        assertEquals("test4", filteredRowSet.getString(2));
+        filteredRowSet.updateString(2, "update4");
+        filteredRowSet.updateRow();
+        assertEquals("update4", filteredRowSet.getString(2));
+        // the updated row becomes not visible through filter
+        assertTrue(filteredRowSet.last());
+        assertEquals("test3", filteredRowSet.getString(2));
+
+        // commit to database
+        filteredRowSet.acceptChanges(conn);
+        rs = st
+                .executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE NAME = 'update4'");
+        assertTrue(rs.next());
+        assertEquals(0, rs.getInt(1));
+
+        /*
+         * Remove filter
+         */
+        filteredRowSet.setFilter(null);
+        assertTrue(filteredRowSet.last());
+        assertEquals("update4", filteredRowSet.getString(2));
+        /*
+         * The forth row isn't updated to database, and it lost it's status
+         * after acceptChanges().
+         */
+        assertFalse(filteredRowSet.rowUpdated());
+    }
+
+    public void testFilter_Delete() throws Exception {
+        FilteredRowSet filteredRowSet = newFilterRowSet();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        filteredRowSet.populate(rs);
+
+        /*
+         * Mark the first row as delete.
+         */
+        assertTrue(filteredRowSet.first());
+        assertEquals(1, filteredRowSet.getInt(1));
+        filteredRowSet.deleteRow();
+
+        Predicate range = new RangeOne();
+        filteredRowSet.setFilter(range);
+
+        assertTrue(filteredRowSet.first());
+        assertEquals(2, filteredRowSet.getInt(1));
+
+        filteredRowSet.acceptChanges(conn);
+        rs = st.executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE ID = 1");
+        assertTrue(rs.next());
+        assertEquals(1, rs.getInt(1));
+
+        /*
+         * Remove filter
+         */
+        filteredRowSet.setFilter(null);
+        filteredRowSet.acceptChanges(conn);
+        rs = st.executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE ID = 1");
+        assertTrue(rs.next());
+        assertEquals(1, rs.getInt(1));
+        /*
+         * The first row has been deleted from FilteredRowSet. However, it isn't
+         * deleted from database.
+         */
+        filteredRowSet.setShowDeleted(true);
+        assertTrue(filteredRowSet.first());
+        assertEquals(2, filteredRowSet.getInt(1));
+    }
+
+    public void testPaging() throws Exception {
+        insertMoreData(4);
+
+        FilteredRowSet filteredRowSet = newFilterRowSet();
+
+        filteredRowSet.setCommand("select * from USER_INFO");
+        filteredRowSet.setUrl(DERBY_URL);
+
+        filteredRowSet.setPageSize(3);
+        filteredRowSet.execute();
+
+        Predicate filter = new OddRowFilter();
+
+        filteredRowSet.setFilter(filter);
+
+        assertEquals("select * from USER_INFO", filteredRowSet.getCommand());
+
+        assertFalse(filteredRowSet.previousPage());
+
+        assertTrue(filteredRowSet.next());
+        assertEquals(1, filteredRowSet.getInt(1));
+
+        assertTrue(filteredRowSet.next());
+        assertEquals(3, filteredRowSet.getInt(1));
+
+        assertFalse(filteredRowSet.next());
+        assertTrue(filteredRowSet.isAfterLast());
+
+        if (!"true".equals(System.getProperty("Testing Harmony"))) {
+            // RI need nextPage one more time
+            assertTrue(filteredRowSet.nextPage());
+        }
+
+        int index = 5;
+        while (filteredRowSet.nextPage()) {
+            while (filteredRowSet.next()) {
+                assertEquals(index, filteredRowSet.getInt(1));
+                index += 2;
+            }
+        }
+
+        assertEquals(9, index);
+
+        filteredRowSet = newFilterRowSet();
+        filteredRowSet.setCommand("select * from USER_INFO");
+        filteredRowSet.setUrl(DERBY_URL);
+
+        filteredRowSet.setPageSize(3);
+        filteredRowSet.execute();
+
+        filteredRowSet.setFilter(filter);
+
+        assertTrue(filteredRowSet.next());
+        assertEquals(1, filteredRowSet.getInt(1));
+
+        assertTrue(filteredRowSet.nextPage());
+        if (!"true".equals(System.getProperty("Testing Harmony"))) {
+            // RI need nextPage one more time
+            assertTrue(filteredRowSet.nextPage());
+        }
+
+        assertTrue(filteredRowSet.next());
+
+        assertEquals(5, filteredRowSet.getInt(1));
+
+        assertTrue(filteredRowSet.nextPage());
+
+        assertTrue(filteredRowSet.next());
+        assertEquals(7, filteredRowSet.getInt(1));
+
+        assertFalse(filteredRowSet.nextPage());
+
+    }
+
+    public void testPagingInMemory() throws Exception {
+        insertMoreData(10);
+        FilteredRowSet filteredRowSet = newFilterRowSet();
+
+        st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
+                ResultSet.CONCUR_UPDATABLE);
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+
+        // the max rows load into memory
+        filteredRowSet.setMaxRows(5);
+        filteredRowSet.setPageSize(3);
+
+        filteredRowSet.populate(rs, 1);
+
+        OddRowFilter filter = new OddRowFilter();
+        filteredRowSet.setFilter(filter);
+
+        if (!"true".equals(System.getProperty("Testing Harmony"))) {
+            // RI need nextPage one more time
+            assertTrue(filteredRowSet.nextPage());
+        }
+
+        assertTrue(filteredRowSet.next());
+        assertEquals(1, filteredRowSet.getInt(1));
+
+        assertTrue(filteredRowSet.next());
+        assertEquals(3, filteredRowSet.getInt(1));
+
+        assertFalse(filteredRowSet.next());
+        assertTrue(filteredRowSet.isAfterLast());
+
+        assertTrue(filteredRowSet.nextPage());
+
+        filteredRowSet.beforeFirst();
+
+        assertTrue(filteredRowSet.next());
+        assertEquals(5, filteredRowSet.getInt(1));
+
+        assertFalse(filteredRowSet.next());
+        assertTrue(filteredRowSet.isAfterLast());
+
+        assertFalse(filteredRowSet.nextPage());
+
+        st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
+                ResultSet.CONCUR_UPDATABLE);
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+
+        filteredRowSet = newFilterRowSet();
+        filteredRowSet.setFilter(filter);
+        filteredRowSet.setPageSize(3);
+
+        filteredRowSet.populate(rs, 1);
+
+        if (!"true".equals(System.getProperty("Testing Harmony"))) {
+            // RI need nextPage one more time
+            assertTrue(filteredRowSet.nextPage());
+        }
+
+        assertTrue(filteredRowSet.next());
+        assertEquals(1, filteredRowSet.getInt(1));
+
+        assertTrue(filteredRowSet.next());
+        assertEquals(3, filteredRowSet.getInt(1));
+
+        assertFalse(filteredRowSet.next());
+        assertTrue(filteredRowSet.isAfterLast());
+
+        filteredRowSet.setPageSize(2);
+        assertTrue(filteredRowSet.nextPage());
+
+        assertTrue(filteredRowSet.isBeforeFirst());
+
+        assertTrue(filteredRowSet.next());
+        assertEquals(5, filteredRowSet.getInt(1));
+
+        assertFalse(filteredRowSet.next());
+        assertTrue(filteredRowSet.isAfterLast());
+
+        filteredRowSet.setPageSize(5);
+        assertTrue(filteredRowSet.nextPage());
+
+        assertTrue(filteredRowSet.isBeforeFirst());
+
+        assertTrue(filteredRowSet.next());
+        assertEquals(7, filteredRowSet.getInt(1));
+
+        assertTrue(filteredRowSet.next());
+        assertEquals(9, filteredRowSet.getInt(1));
+
+        assertFalse(filteredRowSet.next());
+        assertTrue(filteredRowSet.isAfterLast());
+
+        assertTrue(filteredRowSet.previousPage());
+
+        assertTrue(filteredRowSet.isBeforeFirst());
+
+        assertTrue(filteredRowSet.next());
+        assertEquals(1, filteredRowSet.getInt(1));
+
+        assertTrue(filteredRowSet.next());
+        assertEquals(3, filteredRowSet.getInt(1));
+
+        assertTrue(filteredRowSet.next());
+        assertEquals(5, filteredRowSet.getInt(1));
+
+        assertFalse(filteredRowSet.next());
+        assertTrue(filteredRowSet.isAfterLast());
+
+        assertFalse(filteredRowSet.previousPage());
+    }
+
+    protected FilteredRowSet newFilterRowSet() throws Exception {
+        try {
+            return (FilteredRowSet) Class.forName(
+                    "com.sun.rowset.FilteredRowSetImpl").newInstance();
+        } catch (ClassNotFoundException e) {
+            return (FilteredRowSet) Class
+                    .forName(
+                            "org.apache.harmony.sql.internal.rowset.FilteredRowSetImpl")
+                    .newInstance();
+        }
+    }
+}
+
+class RangeOne implements Predicate, Cloneable {
+
+    private boolean isPrint;
+
+    private int tag;
+
+    private int count;
+
+    public void setPrint(boolean isPrint) {
+        this.isPrint = isPrint;
+    }
+
+    public int getTag() {
+        return tag;
+    }
+
+    public int getCount() {
+        return count;
+    }
+
+    public void clear() {
+        tag = FilteredRowSetTest.EVALUATE_DEFAULT;
+        count = 0;
+    }
+
+    public boolean evaluate(RowSet rs) {
+        tag = FilteredRowSetTest.EVALUATE_ROWSET;
+        count++;
+        if (isPrint) {
+            System.out.println("RangeOne.evaluate(RowSet rs)");
+        }
+        try {
+            if (rs.getString(2).indexOf("test") != -1) {
+                return true;
+            }
+        } catch (SQLException e) {
+            // e.printStackTrace();
+        }
+        return false;
+    }
+
+    public boolean evaluate(Object value, int column) throws SQLException {
+        /*
+         * This method is internally called by FilteredRowSet while inserting
+         * new rows.
+         */
+        tag = FilteredRowSetTest.EVALUATE_INSERT;
+        count++;
+        if (column == 2) {
+            return value.toString().indexOf("insert") != -1;
+        }
+        return true;
+    }
+
+    public boolean evaluate(Object value, String columnName)
+            throws SQLException {
+        /*
+         * This method is internally called by FilteredRowSet while inserting
+         * new rows. However, even the second parameter is columnName,
+         * FilteredRowSet still calls evaluate(Object value, int column).
+         */
+        tag = FilteredRowSetTest.EVALUATE_INSERT;
+        count++;
+        return false;
+    }
+
+    public RangeOne clone() throws CloneNotSupportedException {
+        return (RangeOne) super.clone();
+    }
+}
+
+class RangeTwo implements Predicate {
+    public boolean evaluate(RowSet rs) {
+        try {
+            if (rs.getInt(1) > 2 || "hermit".equals(rs.getString(2))) {
+                return true;
+            }
+        } catch (SQLException e) {
+            // e.printStackTrace();
+        }
+        return false;
+    }
+
+    public boolean evaluate(Object value, int column) throws SQLException {
+        return false;
+    }
+
+    public boolean evaluate(Object value, String columnName)
+            throws SQLException {
+        return false;
+    }
+}
+
+class RangeThree implements Predicate {
+
+    public boolean evaluate(RowSet rs) {
+        try {
+            String name = rs.getString(2);
+            if ("hermit".equals(name) || name.indexOf("2") != -1
+                    || name.indexOf("4") != -1 || name.indexOf("6") != -1
+                    || name.indexOf("8") != -1 || name.indexOf("0") != -1) {
+                return true;
+            }
+        } catch (SQLException e) {
+            // do nothing
+        }
+        return false;
+    }
+
+    public boolean evaluate(Object value, int column) throws SQLException {
+        return false;
+    }
+
+    public boolean evaluate(Object value, String columnName)
+            throws SQLException {
+        return false;
+    }
+
+}
+
+class OddRowFilter implements Predicate {
+    public boolean evaluate(RowSet rs) {
+        try {
+            return rs.getInt(1) % 2 == 1;
+        } catch (SQLException e) {
+            // do nothing
+        }
+        return false;
+    }
+
+    public boolean evaluate(Object value, int column) throws SQLException {
+        return false;
+    }
+
+    public boolean evaluate(Object value, String columnName)
+            throws SQLException {
+        return false;
+    }
+}

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

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/WebRowSetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/WebRowSetTest.java?rev=641234&r1=641233&r2=641234&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/WebRowSetTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/WebRowSetTest.java Wed Mar 26 03:22:46 2008
@@ -14,10 +14,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.harmony.sql.tests.internal.rowset;
 
-import java.io.FileWriter;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.sql.SQLException;
@@ -75,11 +73,11 @@
         assertTrue(webRs.absolute(3));
         webRs.updateString(2, "updateRow");
         webRs.updateRow();
-        
+
         assertTrue(webRs.next());
         webRs.updateString(2, "anotherUpdateRow");
         webRs.updateRow();
-        
+
         StringWriter writer = new StringWriter();
 
         webRs.writeXml(writer);
@@ -90,7 +88,7 @@
         assertCachedRowSetEquals(webRs, another);
 
     }
-    
+
     public void testWriteAndRead_Delete() throws Exception {
         rs = st.executeQuery("SELECT * FROM USER_INFO");
         webRs = newWebRowSet();

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/XmlReaderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/XmlReaderTest.java?rev=641234&r1=641233&r2=641234&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/XmlReaderTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/XmlReaderTest.java Wed Mar 26 03:22:46 2008
@@ -17,7 +17,9 @@
 
 package org.apache.harmony.sql.tests.internal.rowset;
 
+import java.io.FileInputStream;
 import java.io.FileReader;
+import java.io.FileWriter;
 import java.io.Reader;
 import java.io.StringWriter;
 
@@ -81,7 +83,25 @@
     }
 
     public void testReaderXml_InputStream() throws Exception {
-        // TODO
+        WebRowSet webRs = newWebRowSet();
+        webRs.readXml(new FileInputStream(currentUrl));
+
+        /*
+         * TODO A row is marked as delete in XML. The row isn't marked as delete
+         * any more after populating to WebRowSet.
+         */
+        if (!"true".equals(System.getProperty("Testing Harmony"))) {
+            assertTrue(webRs.absolute(3));
+            assertEquals(3, webRs.getInt(1));
+            assertFalse(webRs.rowDeleted());
+            webRs.deleteRow();
+        }
+
+        Document srcDoc = DocumentBuilderFactory.newInstance()
+                .newDocumentBuilder().parse(currentUrl);
+        XmlWriterTest.assertProperties(srcDoc, webRs);
+        XmlWriterTest.assertMetadata(srcDoc, webRs);
+        XmlWriterTest.assertData(srcDoc, webRs);
     }
 
     public void setUp() throws Exception {



Mime
View raw message