harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r648989 - 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 Thu, 17 Apr 2008 07:38:18 GMT
Author: tonywu
Date: Thu Apr 17 00:37:50 2008
New Revision: 648989

URL: http://svn.apache.org/viewvc?rev=648989&view=rev
Log:
Apply patch for HARMONY-5731 ([classlib][sql][rowset] - override several methods inherited from CachedRowSet in JoinRowSet to disable RowSetListener)

Added:
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetResultSetTest.java   (with props)
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetWebRowSetTest.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/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/JoinRowSetImpl.java
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/WebRowSetImpl.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/JdbcRowSetTest.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetCachedRowSetTest.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetJoinTest.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetOtherTest.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=648989&r1=648988&r2=648989&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 Thu Apr 17 00:37:50 2008
@@ -97,3 +97,4 @@
 rowset.34=Not set a match column
 rowset.35=Not a valid match olumn index
 rowset.36=Number of elements of two arrays don't equal
+rowset.37=The RowSet doesn't set the table name

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=648989&r1=648988&r2=648989&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 Thu Apr 17 00:37:50 2008
@@ -130,7 +130,7 @@
 
     private SyncProvider syncProvider;
 
-    private CachedRowSetImpl originalResultSet;
+    protected CachedRowSetImpl originalResultSet;
 
     private SQLWarning sqlwarn = new SQLWarning();
 
@@ -147,7 +147,7 @@
 
     private boolean isLastColNull;
 
-    private transient Connection conn;
+    protected transient Connection conn;
 
     private boolean isNotifyListener = true;
 
@@ -265,6 +265,11 @@
         }
 
         conn = con;
+
+        if (con == null) {
+            throw new SyncProviderException();
+        }
+
         try {
             conn.setAutoCommit(false);
             CachedRowSetWriter rowSetWriter = (CachedRowSetWriter) syncProvider
@@ -565,8 +570,7 @@
     }
 
     public ResultSet getOriginal() throws SQLException {
-        if (originalResultSet == null)
-        {
+        if (originalResultSet == null) {
             throw new NullPointerException();
         }
         return originalResultSet;
@@ -708,7 +712,8 @@
         }
     }
 
-    private void doPopulate(ResultSet rs, boolean isPaging) throws SQLException {
+    protected void doPopulate(ResultSet rs, boolean isPaging)
+            throws SQLException {
         isNotifyListener = false;
         meta = copyMetaData(rs.getMetaData());
 
@@ -1312,7 +1317,8 @@
      * @return whether the cursor is on result set
      * @throws SQLException
      */
-    private boolean doAbsolute(int row, boolean checkType) throws SQLException {
+    protected boolean doAbsolute(int row, boolean checkType)
+            throws SQLException {
         if (isCursorOnInsert) {
             // rowset.0=Not a valid position
             throw new SQLException(Messages.getString("rowset.0")); //$NON-NLS-1$
@@ -3009,6 +3015,7 @@
 
     private Connection retrieveConnection() throws SQLException {
         if (getUrl() != null) {
+            // TODO UserName and Password 
             return DriverManager.getConnection(getUrl());
         } else if (getDataSourceName() != null) {
             try {

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=648989&r1=648988&r2=648989&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 Thu Apr 17 00:37:50 2008
@@ -34,10 +34,6 @@
         super();
     }
 
-    public FilteredRowSetImpl(String providerID) throws SyncFactoryException {
-        super(providerID);
-    }
-
     public Predicate getFilter() {
         return predicate;
     }

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JoinRowSetImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JoinRowSetImpl.java?rev=648989&r1=648988&r2=648989&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JoinRowSetImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JoinRowSetImpl.java Thu Apr 17 00:37:50 2008
@@ -35,7 +35,9 @@
 import javax.sql.rowset.Joinable;
 import javax.sql.rowset.RowSetMetaDataImpl;
 import javax.sql.rowset.spi.SyncFactoryException;
+import javax.sql.rowset.spi.SyncProviderException;
 
+import org.apache.harmony.luni.util.NotImplementedException;
 import org.apache.harmony.sql.internal.nls.Messages;
 
 public class JoinRowSetImpl extends WebRowSetImpl implements JoinRowSet {
@@ -60,17 +62,24 @@
         initProperties();
     }
 
-    public JoinRowSetImpl(String providerID) throws SyncFactoryException {
-        super(providerID);
-        initProperties();
+    @Override
+    public void acceptChanges() throws SyncProviderException {
+        acceptChanges(conn);
+    }
+
+    @Override
+    protected boolean doAbsolute(int row, boolean checkType)
+            throws SQLException {
+        return super.doAbsolute(row, false);
     }
-    
 
     private void initProperties() {
         rsList = new ArrayList<RowSet>();
         matchColIndexs = new ArrayList<Integer>();
         matchColNames = new ArrayList<String>();
         joinType = INNER_JOIN;
+        setIsNotifyListener(false);
+        rows = new ArrayList<CachedRow>();
     }
 
     private void composeMetaData(ResultSetMetaData rsmd, int matchColumn)
@@ -343,63 +352,63 @@
                     throw new SQLException(Messages.getString("rowset.39")); //$NON-NLS-1$
                 }
 
-                matchIndex = matchColIndexs.get(0);
+                matchIndex = matchColIndexs.get(0).intValue();
                 if (i == 0) {
                     matchName = rowSet.getMetaData().getColumnName(matchIndex);
-                    whereClause += " " + tableName + "." + matchName + ",";
+                    whereClause += " " + tableName + "." + matchName + ","; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                 }
 
                 metaColumnCount = rowSet.getMetaData().getColumnCount();
                 for (int j = 1; j < matchIndex; j++) {
                     matchName = rowSet.getMetaData().getColumnName(j);
-                    whereClause += " " + tableName + "." + matchName;
+                    whereClause += " " + tableName + "." + matchName; //$NON-NLS-1$ //$NON-NLS-2$
 
                     if (j != metaColumnCount - 1 || i != size - 1) {
-                        whereClause += ",";
+                        whereClause += ","; //$NON-NLS-1$
                     } else {
-                        whereClause += " ";
+                        whereClause += " "; //$NON-NLS-1$
                     }
                 }
 
                 for (int j = matchIndex + 1; j <= metaColumnCount; j++) {
                     matchName = rowSet.getMetaData().getColumnName(j);
-                    whereClause += " " + tableName + "." + matchName;
+                    whereClause += " " + tableName + "." + matchName; //$NON-NLS-1$ //$NON-NLS-2$
 
                     if (j != metaColumnCount || i != size - 1) {
-                        whereClause += ",";
+                        whereClause += ","; //$NON-NLS-1$
                     } else {
-                        whereClause += " ";
+                        whereClause += " "; //$NON-NLS-1$
                     }
                 }
             }
-            whereClause += "from ";
+            whereClause += "from "; //$NON-NLS-1$
             for (int i = 0; i < size; i++) {
                 rowSet = (CachedRowSet) rsList.get(i);
                 tableName = rowSet.getTableName();
 
                 whereClause += tableName;
                 if (i != size - 1) {
-                    whereClause += ", ";
+                    whereClause += ", "; //$NON-NLS-1$
                 } else {
-                    whereClause += " ";
+                    whereClause += " "; //$NON-NLS-1$
                 }
             }
 
-            whereClause += "where ";
+            whereClause += "where "; //$NON-NLS-1$
             CachedRowSet firstRowSet = (CachedRowSet) rsList.get(0);
             String firstTableName = firstRowSet.getTableName();
             String firstMatchName = firstRowSet.getMetaData().getColumnName(
-                    matchColIndexs.get(0));
+                    matchColIndexs.get(0).intValue());
             for (int i = 1; i < size; i++) {
                 rowSet = (CachedRowSet) rsList.get(i);
                 tableName = rowSet.getTableName();
-                matchIndex = matchColIndexs.get(i);
+                matchIndex = matchColIndexs.get(i).intValue();
                 matchName = rowSet.getMetaData().getColumnName(matchIndex);
 
-                whereClause += firstTableName + "." + firstMatchName + " = ";
-                whereClause += tableName + "." + matchName;
+                whereClause += firstTableName + "." + firstMatchName + " = "; //$NON-NLS-1$ //$NON-NLS-2$
+                whereClause += tableName + "." + matchName; //$NON-NLS-1$
                 if (i != size - 1) {
-                    whereClause += " and ";
+                    whereClause += " and "; //$NON-NLS-1$
                 }
             }
         }
@@ -517,6 +526,33 @@
         }
     }
 
+    @Override
+    public boolean nextPage() throws SQLException {
+        boolean result = super.nextPage();
+        setIsNotifyListener(false);
+        return result;
+    }
+
+    @Override
+    public boolean previousPage() throws SQLException {
+        boolean result = super.previousPage();
+        setIsNotifyListener(false);
+        return result;
+    }
+
+    @Override
+    public void restoreOriginal() throws SQLException {
+        super.restoreOriginal();
+        setIsNotifyListener(false);
+    }
+
+    @Override
+    protected void doPopulate(ResultSet rs, boolean isPaging)
+            throws SQLException {
+        super.doPopulate(rs, isPaging);
+        setIsNotifyListener(false);
+    }
+
     /**
      * Join the data with another CachedRowSet. It updates rows,
      * currentRowIndex, currentRow and columnCount. It doesn't update its
@@ -542,8 +578,12 @@
 
             // Make clones for all the CachedRows in rowSetToAdd, regardless of
             // whether it is deleted.
+            CachedRow row;
             for (int i = 0; i < rowSetToAdd.rows.size(); i++) {
-                newRows.add(rowSetToAdd.rows.get(i).createClone());
+                row = rowSetToAdd.rows.get(i);
+                if (!row.isDelete() || rowSetToAdd.getShowDeleted()) {
+                    newRows.add(row.createClone());
+                }
             }
 
             // Sets the rows and columnCount.
@@ -556,6 +596,15 @@
             } else {
                 currentRow = null;
             }
+
+            // Inits other properties.
+            originalResultSet = rowSetToAdd.originalResultSet;
+            if (rowSetToAdd.conn != null) {
+                conn = rowSetToAdd.conn;
+            }
+            setTypeMap(rowSetToAdd.getTypeMap());
+            this.setTableName(rowSetToAdd.getTableName());
+            setShowDeleted(rowSetToAdd.getShowDeleted());
         } else {
             // Get the match index of itself and the rowSet to added.
             int matchIndex = matchColIndexs.get(0).intValue();
@@ -583,7 +632,7 @@
                         comparator);
             }
 
-            // Set the curosr of rowSetToAdd to the last.
+            // Set the cursor of rowSetToAdd to the last.
             rowSetToAdd.last();
 
             // Set the cursor of itself to beforeFirst.
@@ -807,9 +856,9 @@
      *            The column count of the result row.
      * @param originalColumnCount
      *            The column count of original row.
-     * @return
+     * @return The new created CachedRow.
      */
-    protected CachedRow constructNewRow(CachedRow row, CachedRow rowToAdd,
+    private CachedRow constructNewRow(CachedRow row, CachedRow rowToAdd,
             int matchColumnIndex, int matchColumnIndexOfToAdd,
             int resultColumnCount, int originalColumnCount) {
         Object[] rowData;
@@ -886,7 +935,6 @@
                 return 0;
             }
             return -1;
-
         }
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/WebRowSetImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/WebRowSetImpl.java?rev=648989&r1=648988&r2=648989&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/WebRowSetImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/WebRowSetImpl.java Thu Apr 17 00:37:50 2008
@@ -39,10 +39,6 @@
         super();
     }
 
-    public WebRowSetImpl(String providerID) throws SyncFactoryException {
-        super(providerID);
-    }
-
     public void readXml(Reader reader) throws SQLException {
         new XmlReaderImpl().readXML(this, reader);
     }

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=648989&r1=648988&r2=648989&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 Thu Apr 17 00:37:50 2008
@@ -1242,7 +1242,7 @@
         }
         assertNull(crset.getStatement());
 
-        assertEquals(true, noInitialCrset.getEscapeProcessing());
+        assertTrue(noInitialCrset.getEscapeProcessing());
         assertEquals(Connection.TRANSACTION_READ_COMMITTED, noInitialCrset
                 .getTransactionIsolation());
 
@@ -1264,9 +1264,9 @@
         assertEquals(0, noInitialCrset.getMaxRows());
 
         assertEquals(0, noInitialCrset.getPageSize());
-        assertEquals(null, noInitialCrset.getPassword());
+        assertNull(noInitialCrset.getPassword());
         assertEquals(0, noInitialCrset.getQueryTimeout());
-        assertEquals(false, noInitialCrset.getShowDeleted());
+        assertFalse(noInitialCrset.getShowDeleted());
 
         assertNull(noInitialCrset.getTableName());
         assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, noInitialCrset

Modified: 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=648989&r1=648988&r2=648989&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JdbcRowSetTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JdbcRowSetTest.java Thu Apr 17 00:37:50 2008
@@ -252,7 +252,7 @@
         assertEquals(0, jrs.getMaxRows());
 
         assertEquals(0, jrs.getQueryTimeout());
-        assertEquals(false, jrs.getShowDeleted());
+        assertFalse(jrs.getShowDeleted());
 
         assertEquals(DERBY_URL, jrs.getUrl());
         assertNull(jrs.getUsername());
@@ -274,7 +274,7 @@
         assertEquals(0, jrs.getMaxRows());
 
         assertEquals(0, jrs.getQueryTimeout());
-        assertEquals(false, jrs.getShowDeleted());
+        assertFalse(jrs.getShowDeleted());
 
         assertEquals(DERBY_URL, jrs.getUrl());
         assertNull(jrs.getUsername());

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetCachedRowSetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetCachedRowSetTest.java?rev=648989&r1=648988&r2=648989&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetCachedRowSetTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetCachedRowSetTest.java Thu Apr 17 00:37:50 2008
@@ -17,8 +17,9 @@
 package org.apache.harmony.sql.tests.internal.rowset;
 
 import java.sql.SQLException;
-import java.util.Collection;
-import java.util.Iterator;
+
+import javax.sql.rowset.spi.SyncProviderException;
+
 
 public class JoinRowSetCachedRowSetTest extends JoinRowSetTestCase {
 
@@ -512,5 +513,376 @@
         // check data
         assertNotNull(jrs.getMetaData());
         assertFalse(jrs.first());
+    }
+
+    public void testCursorMoved() throws Exception {
+        Listener listener = new Listener();
+        jrs.addRowSetListener(listener);
+        assertNull(listener.getTag());
+
+        jrs.addRowSet(crset, 1);
+
+        assertTrue(jrs.absolute(1));
+        assertNull(listener.getTag());
+
+        assertTrue(jrs.next());
+        assertNull(listener.getTag());
+    }
+
+    public void testRowChanged() throws Exception {
+        Listener listener = new Listener();
+        jrs.addRowSetListener(listener);
+        assertNull(listener.getTag());
+        jrs.addRowSet(crset, 1);
+
+        assertTrue(jrs.absolute(1));
+        assertNull(listener.getTag());
+        jrs.setOriginalRow();
+        assertNull(listener.getTag());
+
+        /*
+         * updateRow() - rowChanged
+         */
+        assertTrue(jrs.absolute(3));
+        jrs.updateString(2, "abc");
+        assertNull(listener.getTag());
+        jrs.updateRow();
+        assertNull(listener.getTag());
+
+        /*
+         * deleteRow() - rowChanged
+         */
+        assertTrue(jrs.last());
+        jrs.deleteRow();
+        assertNull(listener.getTag());
+    }
+
+    public void testAcceptChanges_Exception() throws Exception {
+        try {
+            jrs.acceptChanges();
+            fail("Should throw SyncProviderException.");
+        } catch (SyncProviderException e) {
+            // Expected.
+        }
+
+        try {
+            jrs.acceptChanges(conn);
+            fail("Should throw NullPointerException.");
+        } catch (NullPointerException e) {
+            // Expected.
+        }
+
+        jrs.addRowSet(crset, 1);
+
+        jrs.acceptChanges();
+        jrs.acceptChanges(conn);
+
+        jrs.absolute(4);
+        jrs.updateString(2, "Updated");
+        jrs.updateRow();
+
+        jrs.acceptChanges();
+
+        jrs = newJoinRowSet();
+        jrs.addRowSet(crset, 1);
+        try {
+            jrs.acceptChanges();
+            fail("Should throw SyncProviderException.");
+        } catch (SyncProviderException e) {
+            // Expected.
+        }
+
+        jrs.acceptChanges(conn);
+        jrs.acceptChanges();
+    }
+
+    public void testAcceptChanges_Insert() throws Exception {
+        jrs.addRowSet(crset, 1);
+        jrs.absolute(4);
+        jrs.moveToInsertRow();
+        jrs.updateString(2, "Inserted");
+        jrs.updateInt(1, 5);
+        jrs.insertRow();
+        jrs.moveToCurrentRow();
+
+        try {
+            jrs.acceptChanges();
+            fail("Should throw SyncProviderException.");
+        } catch (SyncProviderException e) {
+            // Expected.
+        }
+        jrs.acceptChanges(conn);
+        rs = st.executeQuery("select * from USER_INFO");
+        crset = newNoInitialInstance();
+        crset.populate(rs);
+        int rowNum = 0;
+        crset.beforeFirst();
+        while (crset.next()) {
+            rowNum++;
+        }
+        assertEquals(5, rowNum);
+
+        assertTrue(jrs.absolute(5));
+        assertEquals("Inserted", jrs.getString(2));
+    }
+
+    public void testAcceptChanges_Update() throws Exception {
+        jrs.addRowSet(crset, 1);
+
+        jrs.absolute(4);
+        jrs.updateString(2, "Updated");
+        jrs.updateRow();
+        jrs.moveToCurrentRow();
+
+        try {
+            jrs.acceptChanges();
+            fail("Should throw SyncProviderException.");
+
+        } catch (SyncProviderException e) {
+            // Expected.
+        }
+        jrs.acceptChanges(conn);
+
+        rs = st.executeQuery("select * from USER_INFO");
+        crset = newNoInitialInstance();
+        crset.populate(rs);
+
+        crset.absolute(4);
+        assertEquals("Updated", crset.getString(2));
+
+        jrs.absolute(4);
+        assertEquals("Updated", jrs.getString(2));
+    }
+
+    public void testAcceptChanges_Delete() throws Exception {
+        jrs.addRowSet(crset, 1);
+
+        jrs.absolute(4);
+
+        jrs.deleteRow();
+        jrs.setShowDeleted(true);
+
+        int rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+
+        jrs.acceptChanges(conn);
+
+        rs = st.executeQuery("select * from USER_INFO");
+        crset = newNoInitialInstance();
+        crset.populate(rs);
+
+        rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        assertEquals(3, rowNum);
+
+        rowNum = 0;
+        crset.beforeFirst();
+        while (crset.next()) {
+            rowNum++;
+        }
+        // In RI, the deletion will not affect database.
+        // In harmony, The deletion will happen in database according to spec.
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertEquals(3, rowNum);
+        } else {
+            assertEquals(4, rowNum);
+        }
+    }
+
+    public void testAcceptChanges_TwoSameRowSets() throws Exception {
+        jrs.addRowSet(crset, 1);
+        crset.beforeFirst();
+        jrs.addRowSet(crset, 1);
+
+        jrs.absolute(4);
+        jrs.updateString(2, "Updated");
+        jrs.updateRow();
+
+        try {
+            jrs.acceptChanges(conn);
+            fail("Should throw SyncProviderException.");
+        } catch (SyncProviderException e) {
+            // Expected.
+        }
+    }
+
+    public void testAcceptChange_UpdateOrignailRowSet() throws Exception {
+        jrs.addRowSet(crset, 1);
+        crset.absolute(4);
+        crset.updateString(2, "Updated");
+        crset.updateRow();
+
+        jrs.acceptChanges(conn);
+
+        rs = st.executeQuery("select * from USER_INFO");
+        crset = newNoInitialInstance();
+        crset.populate(rs);
+        crset.absolute(4);
+        assertEquals("test4", crset.getString(2));
+    }
+
+    public void testUndoDeleted_Empty() throws Exception {
+        // No Exception.
+        jrs.undoDelete();
+    }
+
+    public void testUndoDeleted() throws Exception {
+        jrs.addRowSet(crset, 1);
+
+        /*
+         * 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
+            jrs.beforeFirst();
+            assertTrue(jrs.isBeforeFirst());
+            try {
+                jrs.undoDelete();
+                fail("Should throw SQLException");
+            } catch (SQLException e) {
+                // expected, invalid cursor
+            }
+
+            jrs.afterLast();
+            assertTrue(jrs.isAfterLast());
+            try {
+                jrs.undoDelete();
+                fail("Should throw SQLException");
+            } catch (SQLException e) {
+                // expected, invalid cursor
+            }
+
+            jrs.moveToInsertRow();
+            try {
+                jrs.undoDelete();
+                fail("Should throw SQLException");
+            } catch (SQLException e) {
+                // expected, invalid cursor
+            }
+
+            jrs.moveToCurrentRow();
+            assertTrue(jrs.absolute(1));
+            assertFalse(jrs.rowDeleted());
+            try {
+                jrs.undoDelete();
+                fail("Should throw SQLException");
+            } catch (SQLException e) {
+                // expected, invalid cursor
+            }
+
+        } else {
+            // when run on RI, it won't throw SQLException
+            jrs.beforeFirst();
+            assertTrue(jrs.isBeforeFirst());
+            jrs.undoDelete();
+
+            jrs.afterLast();
+            assertTrue(jrs.isAfterLast());
+            jrs.undoDelete();
+
+            jrs.moveToInsertRow();
+            jrs.undoDelete();
+
+            jrs.moveToCurrentRow();
+            assertTrue(jrs.absolute(1));
+            assertFalse(jrs.rowDeleted());
+            jrs.undoDelete();
+        }
+
+        // delete the fourth row
+        assertTrue(jrs.absolute(4));
+        assertEquals(4, jrs.getInt(1));
+        assertFalse(jrs.rowDeleted());
+        jrs.deleteRow();
+        assertTrue(jrs.rowDeleted());
+
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            jrs.undoDelete();
+            assertFalse(jrs.rowDeleted());
+            jrs.acceptChanges(conn);
+
+            // check DB
+            rs = st.executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE ID = 4");
+            assertTrue(rs.next());
+            assertEquals(1, rs.getInt(1));
+
+            // check CachedRowSet
+            jrs.beforeFirst();
+            int index = 0;
+            while (jrs.next()) {
+                index++;
+                assertEquals(index, jrs.getInt(1));
+            }
+            assertEquals(4, index);
+
+        } else {
+            // TODO undoDelete() still makes no difference in RI
+            jrs.undoDelete();
+            assertTrue(jrs.rowDeleted());
+            jrs.acceptChanges(conn);
+
+            // check DB
+            rs = st.executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE ID = 4");
+            assertTrue(rs.next());
+            assertEquals(1, rs.getInt(1));
+
+            // check CachedRowSet
+            jrs.beforeFirst();
+            int index = 0;
+            while (jrs.next()) {
+                index++;
+                assertEquals(index, jrs.getInt(1));
+            }
+            assertEquals(3, index);
+        }
+
+    }
+
+    public void testUndoInsert_Empty() throws Exception {
+        try {
+            jrs.undoInsert();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // Expected.
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // RI throws it.
+        }
+    }
+
+    public void testAcceptChanges_Complex() throws Exception {
+        crset.acceptChanges();
+
+        jrs.addRowSet(crset, 1);
+        try {
+            jrs.acceptChanges();
+            fail("Should throw SyncProviderException.");
+        } catch (SyncProviderException e) {
+            // Expected.
+        }
+        crset.acceptChanges();
+
+        jrs.acceptChanges(conn);
+        jrs.acceptChanges();
+
+        try {
+            jrs.acceptChanges(null);
+            fail("Should throw SyncProviderException.");
+        } catch (SyncProviderException e) {
+            // Expected.
+        }
+
+        try {
+            jrs.acceptChanges();
+            fail("Should throw SyncProviderException.");
+        } catch (SyncProviderException e) {
+            // Expected.
+        }
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetJoinTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetJoinTest.java?rev=648989&r1=648988&r2=648989&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetJoinTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetJoinTest.java Thu Apr 17 00:37:50 2008
@@ -20,6 +20,7 @@
 import java.sql.SQLException;
 
 import javax.sql.rowset.CachedRowSet;
+import javax.sql.rowset.spi.SyncProvider;
 
 public class JoinRowSetJoinTest extends JoinRowSetTestCase {
 
@@ -419,6 +420,341 @@
 
     }
 
+    public void testJoin_Delete() throws Exception {
+        rs = st.executeQuery("select * from BOOKS");
+        CachedRowSet crset2 = newNoInitialInstance();
+        crset2.populate(rs);
+
+        jrs.addRowSet(crset, 1);
+        jrs.first();
+        jrs.deleteRow();
+
+        int rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        assertEquals(3, rowNum);
+
+        jrs.addRowSet(crset2, 1);
+
+        rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        assertEquals(4, rowNum);
+    }
+
+    public void testJoin_Delete2() throws Exception {
+        rs = st.executeQuery("select * from BOOKS");
+        CachedRowSet crset2 = newNoInitialInstance();
+        crset2.populate(rs);
+
+       crset.absolute(3);
+        crset.deleteRow();
+        crset.setShowDeleted(true);
+
+        jrs.addRowSet(crset, 1);
+        jrs.first();
+        jrs.deleteRow();
+        
+        int rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        assertEquals(4, rowNum);
+
+        jrs.setShowDeleted(true);
+
+        rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        assertEquals(4, rowNum);
+
+        
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            if (jrs.getInt(1) == 3) {
+                assertTrue(jrs.rowDeleted());
+            }
+        }
+
+        crset2.absolute(6);
+        crset2.deleteRow();
+
+        crset2.beforeFirst();
+        while (crset2.next()) {
+            if (crset2.getInt(1) == 4) {
+                assertTrue(crset2.rowDeleted());
+            }
+        }
+
+        jrs.addRowSet(crset2, 1);
+
+        rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        assertEquals(5, rowNum);
+    }
+
+    public void testProperty_Empty() throws SQLException {
+        assertNull(jrs.getCommand());
+        assertEquals(ResultSet.CONCUR_UPDATABLE, jrs.getConcurrency());
+        try {
+            jrs.getCursorName();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // Expected.
+        }
+        assertNull(jrs.getDataSourceName());
+        assertTrue(jrs.getEscapeProcessing());
+        assertEquals(ResultSet.FETCH_FORWARD, jrs.getFetchDirection());
+        assertEquals(0, jrs.getFetchSize());
+        assertEquals(0, jrs.getMaxFieldSize());
+        assertEquals(0, jrs.getMaxRows());
+        assertNull(jrs.getMetaData());
+        assertEquals(0, jrs.getPageSize());
+        assertNull(jrs.getPassword());
+        assertEquals(0, jrs.getQueryTimeout());
+        assertFalse(jrs.getShowDeleted());
+        assertNull(jrs.getStatement());
+        assertNotNull(jrs.getSyncProvider());
+        assertNull(jrs.getTableName());
+        assertNull(jrs.getUrl());
+        assertNull(jrs.getUsername());
+        assertNull(jrs.getTypeMap());
+
+        try {
+            jrs.getOriginal();
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // RI throws it.
+        }
+
+        try {
+            jrs.getOriginalRow();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // Expected.
+        } catch (NullPointerException e) {
+            // RI throws it.
+        }
+    }
+
+    public void testProperty() throws Exception {
+        SyncProvider sp = jrs.getSyncProvider();
+
+        crset.setDataSourceName("testDataSource");
+        crset.setCommand("testCommand");
+        crset.setConcurrency(ResultSet.CONCUR_READ_ONLY);
+        crset.setEscapeProcessing(false);
+        crset.setFetchDirection(ResultSet.FETCH_REVERSE);
+        crset.setMaxRows(80);
+        // TODO How to set it.
+        // crset.setFetchSize(10);
+        crset.setPageSize(20);
+        crset.setPassword("testPassword");
+        crset.setQueryTimeout(5);
+        crset.setShowDeleted(true);
+        crset.setTableName("testTableName");
+        crset.setUrl("testUrl");
+        ;
+        crset.setUsername("testUserName");
+        crset.setMaxFieldSize(20);
+        jrs.addRowSet(crset, 1);
+
+        assertNull(jrs.getCommand());
+        assertEquals(ResultSet.CONCUR_UPDATABLE, jrs.getConcurrency());
+        assertNull(jrs.getDataSourceName());
+        assertTrue(jrs.getEscapeProcessing());
+        assertEquals(ResultSet.FETCH_FORWARD, jrs.getFetchDirection());
+        assertEquals(crset.getFetchSize(), jrs.getFetchSize());
+        assertEquals(0, jrs.getMaxFieldSize());
+        assertEquals(0, jrs.getMaxRows());
+        assertEquals(0, jrs.getPageSize());
+        assertNull(jrs.getPassword());
+        assertEquals(0, jrs.getQueryTimeout());
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertTrue(jrs.getShowDeleted());
+        }
+        else {
+            assertFalse(jrs.getShowDeleted());
+        }
+        assertNull(jrs.getStatement());
+        assertEquals(sp, jrs.getSyncProvider());
+        // TODO
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertEquals(crset.getTableName(), jrs.getTableName());
+        }
+        else {
+            assertNull(jrs.getTableName());
+        }
+        assertNull(jrs.getUrl());
+        assertNull(jrs.getUsername());
+        assertNotNull(jrs.getOriginal());
+        assertEquals(crset.getTypeMap(), jrs.getTypeMap());
+    }
+
+    public void testProperty_TwoRowSets() throws Exception {
+        jrs.addRowSet(crset, 1);
+        rs = st.executeQuery("select * from BOOKS");
+        CachedRowSet crset2 = newNoInitialInstance();
+        crset2.populate(rs);
+        crset2.setDataSourceName("testDataSourceName");
+        jrs.addRowSet(crset2, 1);
+
+        assertEquals(crset2.getTypeMap(), jrs.getTypeMap());
+        assertEquals(crset.getTypeMap(), crset2.getTypeMap());
+    }
+
+    public void testRowProperty_deleteRow() throws Exception {
+        crset.first();
+        crset.deleteRow();
+        int rowNum = 0;
+        crset.beforeFirst();
+        while (crset.next()) {
+            rowNum++;
+        }
+        assertEquals(3, rowNum);
+
+        jrs.addRowSet(crset, 1);
+
+        rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        assertEquals(3, rowNum);
+
+        jrs.setShowDeleted(true);
+        rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        assertEquals(3, rowNum);
+
+        CachedRowSet crset2 = newNoInitialInstance();
+        rs = st.executeQuery("select * from books");
+        crset2.populate(rs);
+
+        crset2.absolute(3);
+        crset2.deleteRow();
+
+        jrs.addRowSet(crset2, 1);
+
+        rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        assertEquals(3, rowNum);
+    }
+
+    public void testRowProperty_deleteRow2() throws Exception {
+        crset.first();
+        crset.deleteRow();
+        crset.setShowDeleted(true);
+        int rowNum = 0;
+        crset.beforeFirst();
+        while (crset.next()) {
+            rowNum++;
+        }
+        assertEquals(4, rowNum);
+
+        jrs.addRowSet(crset, 1);
+
+        rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+            if (jrs.getInt(1) == 1) {
+                assertTrue(jrs.rowDeleted());
+            } else {
+                assertFalse(jrs.rowDeleted());
+            }
+        }
+        if (System.getProperty("Testing Harmony") == "true") {
+            assertTrue(jrs.getShowDeleted());
+        }
+        else {
+        assertFalse(jrs.getShowDeleted());
+        }
+        assertEquals(4, rowNum);
+
+        CachedRowSet crset2 = newNoInitialInstance();
+        rs = st.executeQuery("select * from books");
+        crset2.populate(rs);
+
+        crset2.absolute(3);
+        crset2.deleteRow();
+        crset2.setShowDeleted(true);
+
+        jrs.addRowSet(crset2, 1);
+
+        rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+            assertFalse(jrs.rowDeleted());
+        }
+        assertEquals(6, rowNum);
+    }
+
+    public void testRowProperty_deleteRow3() throws Exception {
+        crset.first();
+        crset.deleteRow();
+        crset.setShowDeleted(true);
+        int rowNum = 0;
+        crset.beforeFirst();
+        while (crset.next()) {
+            rowNum++;
+        }
+        assertEquals(4, rowNum);
+
+        jrs.addRowSet(crset, 1);
+
+        jrs.setShowDeleted(true);
+
+        rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+            if (jrs.getInt(1) == 1) {
+                assertTrue(jrs.rowDeleted());
+            } else {
+                assertFalse(jrs.rowDeleted());
+            }
+        }
+        assertEquals(4, rowNum);
+        assertTrue(jrs.getShowDeleted());
+
+        CachedRowSet crset2 = newNoInitialInstance();
+        rs = st.executeQuery("select * from books");
+        crset2.populate(rs);
+
+        crset2.absolute(3);
+        crset2.deleteRow();
+        crset2.setShowDeleted(true);
+
+        jrs.addRowSet(crset2, 1);
+        jrs.setShowDeleted(false);
+
+        rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+            assertFalse(jrs.rowDeleted());
+        }
+        assertEquals(6, rowNum);
+    }
+
     protected int getVisibleSize(ResultSet rs) throws SQLException {
         rs.beforeFirst();
         int rowNum = 0;
@@ -426,6 +762,107 @@
             rowNum++;
         }
         return rowNum;
+    }
+    
+    public void testJoin_OrignalShowDeleted() throws SQLException {
+        jrs.addRowSet(crset, 1);
+        
+        jrs.first();
+        jrs.deleteRow();
+        
+        int rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        assertEquals(3, rowNum);
+        
+        crset.setShowDeleted(true);
+        assertEquals(3, rowNum);     
+    }
+    
+    public void testJoin_OrignalShowDeleted2() throws SQLException {
+        crset.setShowDeleted(true);
+        jrs.addRowSet(crset, 1);
+        
+        jrs.first();
+        jrs.deleteRow();
+        
+        int rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        assertEquals(4, rowNum);
+        assertTrue(jrs.absolute(4));
+        
+        if (System.getProperty("Testing Harmony") == "true") {
+            assertTrue(jrs.getShowDeleted());
+        }
+        else 
+        {
+        assertFalse(jrs.getShowDeleted());
+        }
+        crset.setShowDeleted(false);
+        rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        assertEquals(4, rowNum);
+        
+        crset.first();
+        jrs.beforeFirst();
+        assertTrue(crset.isFirst());
+        assertFalse(crset.isBeforeFirst());
+        assertTrue(jrs.isBeforeFirst());
+        
+        jrs.next();
+        assertTrue(crset.isFirst());
+        assertTrue(jrs.isFirst());
+        
+        jrs.next();
+        assertTrue(crset.isFirst());
+        assertFalse(jrs.isFirst());
+    }
+    
+    public void testJoin_OrignalShowDeleted3() throws Exception {
+        CachedRowSet crset2 = newNoInitialInstance();
+        rs = st.executeQuery("select * from books");
+        crset2.populate(rs);
+        
+        jrs.addRowSet(crset, 1);
+        jrs.first();
+        jrs.deleteRow();
+        
+        int rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        assertEquals(3, rowNum);
+        
+        crset2.setShowDeleted(true);
+        jrs.addRowSet(crset2, 1);
+        rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        assertEquals(4, rowNum);
+        
+        jrs.first();
+        jrs.deleteRow();
+        
+        rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        assertEquals(3, rowNum);
+        
+        
+        
     }
 
 }

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetOtherTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetOtherTest.java?rev=648989&r1=648988&r2=648989&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetOtherTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetOtherTest.java Thu Apr 17 00:37:50 2008
@@ -312,14 +312,15 @@
         Collection collection;
 
         CachedRowSet crs = newNoInitialInstance();
-        try {
-
-            jrs.addRowSet(crs, 1);
-            if ("true".equals(System.getProperty("Testing Harmony"))) {
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            try {
+                jrs.addRowSet(crs, 1);
                 fail("Should throw SQLException in harmony.");
+            } catch (SQLException e) {
+                // Expected.
             }
-        } catch (SQLException e) {
-            // Expected.
+        } else {
+            jrs.addRowSet(crs, 1);
         }
     }
 
@@ -509,7 +510,7 @@
     public void testGetWhereClause_MoreRowSets() throws Exception {
         crset.setTableName("Table1");
         jrs.addRowSet(crset, "ID");
-        
+
         // Creates another cached rowset.
         CachedRowSet crset2;
         crset2 = newNoInitialInstance();
@@ -518,14 +519,14 @@
         crset2.execute();
         crset2.setTableName("Table2");
         jrs.addRowSet(crset2, "AUTHORID");
-        
+
         crset2 = newNoInitialInstance();
         crset2.setCommand("SELECT * FROM BOOKS");
         crset2.setUrl(DERBY_URL);
         crset2.execute();
         crset2.setTableName("Table3");
         jrs.addRowSet(crset2, "AUTHORID");
-      
+
         String whereClause = jrs.getWhereClause();
         assertNotNull(whereClause);
     }

Added: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetResultSetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetResultSetTest.java?rev=648989&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetResultSetTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetResultSetTest.java Thu Apr 17 00:37:50 2008
@@ -0,0 +1,640 @@
+/*
+ *  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.CachedRowSet;
+
+import junit.framework.TestCase;
+
+public class JoinRowSetResultSetTest extends JoinRowSetTestCase {
+
+    public void testAbsolute_Empty() throws SQLException {
+        assertFalse(jrs.absolute(1));
+
+        // TODO non-bug different
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertFalse(jrs.absolute(0));
+        } else {
+            try {
+                assertTrue(jrs.absolute(0));
+                fail("Should throw SQLException");
+            } catch (SQLException e) {
+                // invalid cursor position
+            }
+        }
+    }
+
+    public void testAbsolute() throws Exception {
+        jrs.addRowSet(crset, 1);
+
+        // TODO non-bug different
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertFalse(jrs.absolute(0));
+        } else {
+            try {
+                assertTrue(jrs.absolute(0));
+                fail("Should throw SQLException");
+            } catch (SQLException e) {
+                // invalid cursor position
+            }
+        }
+
+        assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, jrs.getType());
+        assertTrue(jrs.absolute(1));
+        assertEquals(1, jrs.getInt(1));
+        assertTrue(jrs.absolute(4));
+        assertEquals(4, jrs.getInt(1));
+        assertTrue(jrs.absolute(3));
+        assertEquals(3, jrs.getInt(1));
+
+        // when position the cursor beyond the first/last row in the result set
+        assertFalse(jrs.absolute(10));
+        assertTrue(jrs.isAfterLast());
+        assertTrue(jrs.previous());
+        assertFalse(jrs.absolute(-10));
+        assertTrue(jrs.isBeforeFirst());
+        assertTrue(jrs.next());
+
+        /*
+         * TODO when the given row number is negative, spec says absolute(-1)
+         * equals last(). However, the return value of absolute(negative) is
+         * false when run on RI. The Harmony follows the spec.
+         */
+        if (System.getProperty("Testing Harmony") == "true") {
+            assertTrue(jrs.absolute(-1));
+            assertEquals(4, jrs.getInt(1));
+            assertTrue(jrs.absolute(-3));
+            assertEquals(2, jrs.getInt(1));
+            assertFalse(jrs.absolute(-5));
+        } else {
+            assertFalse(jrs.absolute(-1));
+            assertEquals(0, jrs.getRow());
+            assertTrue(jrs.isBeforeFirst());
+        }
+
+        jrs.moveToInsertRow();
+        try {
+            jrs.first();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        jrs.updateInt(1, 60);
+        jrs.updateString(2, "abc");
+        jrs.insertRow();
+        try {
+            jrs.absolute(3);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        jrs.moveToCurrentRow();
+        assertTrue(jrs.absolute(2));
+
+        jrs.setType(ResultSet.TYPE_FORWARD_ONLY);
+        assertEquals(jrs.getType(), ResultSet.TYPE_FORWARD_ONLY);
+
+        crset.setType(ResultSet.TYPE_FORWARD_ONLY);
+        assertEquals(crset.getType(), ResultSet.TYPE_FORWARD_ONLY);
+
+        // In CachedRowSet, it will throw SQLException, however, in JoinRowSet,
+        // it doesn't throw.
+        // TODO
+        assertTrue(jrs.absolute(1));
+        assertEquals(60, jrs.getInt(1));
+
+        if (System.getProperty("Testing Harmony") == "true") {
+            assertTrue(jrs.absolute(-1));
+            assertTrue(jrs.absolute(-3));
+            assertFalse(jrs.absolute(-5));
+        } else {
+            assertFalse(jrs.absolute(-1));
+            assertEquals(0, jrs.getRow());
+            assertTrue(jrs.isBeforeFirst());
+        }
+    }
+
+    public void testAbsolute_SetForwardOnly() throws Exception {
+        jrs.addRowSet(crset, 1);
+        jrs.setType(ResultSet.TYPE_FORWARD_ONLY);
+        assertEquals(ResultSet.TYPE_FORWARD_ONLY, jrs.getType());
+
+        jrs.first();
+        jrs.last();
+        jrs.beforeFirst();
+        jrs.afterLast();
+        jrs.previous();
+        jrs.relative(1);
+
+        jrs.absolute(2);
+        assertEquals(2, jrs.getInt(1));
+    }
+
+    public void testCachedRowSet_SetForwardOnly() throws Exception {
+        crset.setType(ResultSet.TYPE_FORWARD_ONLY);
+        assertEquals(ResultSet.TYPE_FORWARD_ONLY, crset.getType());
+
+        try {
+            crset.first();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // Expected.
+        }
+
+        try {
+            crset.absolute(2);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // Expected.
+        }
+    }
+
+    public void testAbsolute_AfterDeleteRow() throws Exception {
+        jrs.addRowSet(crset, 1);
+        jrs.first();
+        jrs.deleteRow();
+        int rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        assertEquals(3, rowNum);
+        jrs.beforeFirst();
+        assertFalse(jrs.absolute(4));
+        assertTrue(jrs.isAfterLast());
+
+        jrs.setShowDeleted(true);
+        assertTrue(jrs.getShowDeleted());
+
+        // In RI, set show deleted will not take effect.
+        // In harmony, it takes.
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertTrue(jrs.absolute(4));
+        } else {
+            assertFalse(jrs.absolute(4));
+        }
+        rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertEquals(4, rowNum);
+        } else {
+            assertEquals(3, rowNum);
+        }
+    }
+
+    public void testFirstAndLast_Empty() throws Exception {
+        assertFalse(jrs.isBeforeFirst());
+        // Different in RI and Harmony.
+        if (System.getProperty("Testing Harmony") == "true") {
+            assertFalse(jrs.isFirst());
+            assertFalse(jrs.isLast());
+        } else {
+            assertTrue(jrs.isFirst());
+            assertTrue(jrs.isLast());
+        }
+        assertFalse(jrs.isAfterLast());
+
+        jrs.beforeFirst();
+        assertFalse(jrs.first());
+        assertFalse(jrs.last());
+        jrs.afterLast();
+
+    }
+
+    public void testFirstAndLast() throws Exception {
+        jrs.addRowSet(crset, 1);
+        /*
+         * This method is used to test afterLast(), beforeFist(), first(),
+         * last()
+         */
+        assertFalse(jrs.isFirst());
+        assertTrue(jrs.isBeforeFirst());
+        assertTrue(jrs.first());
+        assertTrue(jrs.isFirst());
+        assertFalse(jrs.isBeforeFirst());
+        jrs.beforeFirst();
+        assertTrue(jrs.isBeforeFirst());
+        assertTrue(jrs.last());
+        assertTrue(jrs.isLast());
+
+        assertTrue(jrs.first());
+        assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, jrs.getType());
+    }
+
+    public void testAfterLast_Empty() throws Exception {
+        jrs.afterLast();
+        assertFalse(jrs.isAfterLast());
+    }
+
+    public void testAfterLast() throws Exception {
+        jrs.addRowSet(crset, 1);
+        jrs.afterLast();
+        jrs.previous();
+        assertEquals(4, jrs.getInt(1));
+    }
+
+    public void testRelative_Empty() throws Exception {
+        try {
+            jrs.relative(1);
+            fail("Should throw SQLException.");
+        } catch (SQLException e) {
+            // Expected.
+        }
+    }
+
+    public void testRelative() throws Exception {
+        jrs.addRowSet(crset, 1);
+        /*
+         * ri throw SQLException, but spec say relative(1) is identical to next
+         */
+        try {
+            jrs.relative(1);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+
+        assertTrue(jrs.next());
+        assertEquals("hermit", jrs.getString(2));
+
+        assertTrue(jrs.relative(2));
+        assertEquals("test3", jrs.getString(2));
+
+        assertTrue(jrs.relative(-1));
+        assertEquals("test", jrs.getString(2));
+
+        assertTrue(jrs.relative(0));
+        assertEquals("test", jrs.getString(2));
+
+        assertFalse(jrs.relative(-5));
+        assertEquals(0, jrs.getRow());
+
+        assertTrue(jrs.next());
+        assertEquals("hermit", jrs.getString(2));
+        assertTrue(jrs.relative(3));
+        assertEquals("test4", jrs.getString(2));
+
+        assertFalse(jrs.relative(3));
+        assertEquals(0, jrs.getRow());
+
+        assertTrue(jrs.isAfterLast());
+        assertTrue(jrs.previous());
+
+        // TODO RI's bug
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertEquals(DEFAULT_ROW_COUNT, jrs.getRow());
+            assertEquals("test4", jrs.getString(2));
+        } else {
+            assertEquals(-1, jrs.getRow());
+            assertEquals("test4", jrs.getString(2));
+
+            assertTrue(jrs.previous());
+            assertEquals(-2, jrs.getRow());
+            assertEquals("test3", jrs.getString(2));
+        }
+    }
+
+    public void testSetShowDeleted() throws Exception {
+        jrs.addRowSet(crset, 1);
+        jrs.first();
+        jrs.deleteRow();
+        int rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        assertEquals(3, rowNum);
+        jrs.first();
+        assertEquals(2, jrs.getInt(1));
+
+        rowNum = 0;
+        jrs.afterLast();
+        while (jrs.previous()) {
+            rowNum++;
+        }
+        assertEquals(3, rowNum);
+
+        jrs.setShowDeleted(true);
+        assertTrue(jrs.getShowDeleted());
+
+        rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        jrs.first();
+
+        // In RI, set show deleted will not take effect.
+        // In harmony, it takes.
+        if (System.getProperty("Testing Harmony") == "true") {
+            assertEquals(1, jrs.getInt(1));
+            assertEquals(4, rowNum);
+        } else {
+            assertEquals(2, jrs.getInt(1));
+            assertEquals(3, rowNum);
+        }
+
+        rowNum = 0;
+        jrs.afterLast();
+        while (jrs.previous()) {
+            rowNum++;
+        }
+        if (System.getProperty("Testing Harmony") == "true") {
+            assertEquals(4, rowNum);
+        } else {
+            assertEquals(3, rowNum);
+        }
+    }
+
+    public void testDeleteRow() throws Exception {
+        try {
+            jrs.deleteRow();
+            fail("Should throw SQLException.");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // RI throw ArrayIndexOutOfBoundsException.
+        } catch (SQLException e) {
+            // Expected.
+        }
+
+        jrs.addRowSet(crset, 1);
+        jrs.first();
+        jrs.deleteRow();
+
+        int rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        assertEquals(3, rowNum);
+
+        rowNum = 0;
+        crset.beforeFirst();
+        while (crset.next()) {
+            rowNum++;
+        }
+        assertEquals(4, rowNum);
+
+        crset.absolute(2);
+        crset.deleteRow();
+
+        rowNum = 0;
+        crset.beforeFirst();
+        while (crset.next()) {
+            rowNum++;
+        }
+        assertEquals(3, rowNum);
+
+        jrs.first();
+        assertEquals(2, jrs.getInt(1));
+    }
+
+    public void testDeleteRow_MultipleRowSets() throws Exception {
+        // Creates a new CachedRowSet from BOOKs
+        CachedRowSet crset2 = newNoInitialInstance();
+        rs = st.executeQuery("select * from BOOKS");
+        crset2.populate(rs);
+
+        jrs.addRowSet(crset, 1);
+        jrs.addRowSet(crset2, 1);
+
+        int rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+
+        assertEquals(6, rowNum);
+
+        jrs.first();
+        jrs.deleteRow();
+
+        rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+
+        assertEquals(5, rowNum);
+    }
+
+    public void testUpdateRow_Empty() throws Exception {
+        // TODO
+        // It's the problem of CachedRowSetImpl.
+        try {
+            jrs.updateRow();
+            fail("Should throw SQLException.");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // RI throw ArrayIndexOutOfBoundsException.
+        } catch (SQLException e) {
+            // Expected.
+        }
+    }
+
+    public void testUpdateRow() throws Exception {
+        jrs.addRowSet(crset, 1);
+        jrs.first();
+        jrs.updateString(2, "Updated");
+        jrs.updateRow();
+        assertEquals("Updated", jrs.getString(2));
+
+        crset.first();
+        assertEquals("hermit", crset.getString(2));
+
+        crset.next();
+        crset.updateString(2, "Updated2");
+        crset.updateRow();
+        assertEquals("Updated2", crset.getString(2));
+
+        jrs.first();
+        jrs.next();
+        assertEquals("test", jrs.getString(2));
+    }
+
+    public void testInsertRow_Empty() throws Exception {
+        try {
+            jrs.moveToInsertRow();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // Expected.
+        }
+    }
+
+    public void testInsertRow() throws Exception {
+        jrs.addRowSet(crset, 1);
+        jrs.moveToInsertRow();
+        jrs.updateInt(1, 10);
+        jrs.updateString(2, "Inserted");
+        jrs.insertRow();
+
+        jrs.moveToCurrentRow();
+        assertTrue(jrs.next());
+        assertEquals(10, jrs.getInt(1));
+        assertEquals("Inserted", jrs.getString(2));
+
+        int rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        assertEquals(5, rowNum);
+
+        rowNum = 0;
+        crset.beforeFirst();
+        while (crset.next()) {
+            rowNum++;
+        }
+        assertEquals(4, rowNum);
+
+        crset.moveToInsertRow();
+        crset.updateInt(1, 20);
+        crset.updateString(2, "Inserted2");
+        crset.insertRow();
+        crset.moveToCurrentRow();
+
+        rowNum = 0;
+        crset.beforeFirst();
+        while (crset.next()) {
+            rowNum++;
+        }
+        assertEquals(5, rowNum);
+
+        rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        assertEquals(5, rowNum);
+    }
+
+    public void testInsertRow_MultipleRowSets() throws Exception {
+        // Creates a new CachedRowSet from BOOKs
+        CachedRowSet crset2 = newNoInitialInstance();
+        rs = st.executeQuery("select * from BOOKS");
+        crset2.populate(rs);
+
+        jrs.addRowSet(crset2, 1);
+
+        int rowNum = 0;
+        jrs.beforeFirst();
+        while (jrs.next()) {
+            rowNum++;
+        }
+        assertEquals(7, rowNum);
+
+        jrs.moveToInsertRow();
+        jrs.updateInt(1, 20);
+        jrs.updateString(2, "Updated");
+        jrs.insertRow();
+        jrs.moveToCurrentRow();
+        assertEquals(20, jrs.getInt(1));
+        assertEquals("Updated", jrs.getString(2));
+    }
+
+    public void testGetInt() throws Exception {
+
+        try {
+            crset.getInt(1);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // Expected.
+        }
+
+        try {
+            jrs.getInt(1);
+            fail("Should throw SQLException.");
+        } catch (NullPointerException e) {
+            // RI throw NullPointerException.
+        } catch (SQLException e) {
+            // Expected.
+        }
+
+        jrs.addRowSet(crset, 1);
+        jrs.first();
+        assertEquals(1, jrs.getInt(1));
+
+        crset.first();
+        crset.updateInt(1, 60);
+        crset.updateRow();
+
+        crset.first();
+        assertEquals(60, crset.getInt(1));
+
+        jrs.first();
+        assertEquals(1, jrs.getInt(1));
+
+        jrs.absolute(2);
+        jrs.updateString(2, "Updated");
+        jrs.updateRow();
+
+        jrs.absolute(2);
+        assertEquals("Updated", jrs.getString(2));
+
+        crset.absolute(2);
+        assertEquals("test", crset.getString(2));
+    }
+
+    public void testRefreshRow_Empty() throws Exception {
+        try {
+            jrs.refreshRow();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // Expected.
+        } catch (IndexOutOfBoundsException e) {
+            // RI throw it.
+        }
+    }
+
+    public void testRefreshRow() throws Exception {
+        jrs.addRowSet(crset, 1);
+
+        /*
+         * Update the third row in database. Then call refreshRow().
+         */
+        int result = st
+                .executeUpdate("UPDATE USER_INFO SET NAME = 'update33' WHERE ID = 3");
+        assertEquals(1, result);
+
+        // still no effect.
+        jrs.absolute(3);
+        jrs.refreshRow();
+        assertEquals(3, jrs.getInt(1));
+        assertEquals("test3", jrs.getString(2));
+
+        jrs.updateString(2, "update33");
+        jrs.refreshRow();
+        assertEquals("test3", jrs.getString(2));
+
+    }
+
+    public void testCancelRowUpdates_Empty() throws Exception {
+        try {
+            jrs.cancelRowUpdates();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // Expected.
+        } catch (IndexOutOfBoundsException e) {
+            // RI throws it.
+        }
+    }
+}

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

Added: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetWebRowSetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetWebRowSetTest.java?rev=648989&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetWebRowSetTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetWebRowSetTest.java Thu Apr 17 00:37:50 2008
@@ -0,0 +1,269 @@
+/*
+ *  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.io.StringReader;
+import java.io.StringWriter;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import javax.sql.rowset.CachedRowSet;
+import javax.sql.rowset.JoinRowSet;
+import javax.sql.rowset.WebRowSet;
+import javax.sql.rowset.spi.SyncProviderException;
+
+public class JoinRowSetWebRowSetTest extends JoinRowSetTestCase {
+
+    public void testWriteXml_Empty() throws Exception {
+        StringWriter writer = new StringWriter();
+        try {
+            jrs.writeXml(writer);
+            fail("Should throw NullPointerException.");
+        } catch (NullPointerException e) {
+            // Expected.
+        }
+    }
+
+    public void testReadXml_Empty() throws Exception {
+        jrs = newJoinRowSet();
+        jrs.addRowSet(crset, 1);
+        StringWriter writer = new StringWriter();
+        jrs.writeXml(writer);
+
+        JoinRowSet another = newJoinRowSet();
+        another.readXml(new StringReader(writer.getBuffer().toString()));
+
+        assertCachedRowSetEquals(jrs, another);
+    }
+
+    public void testWriteXml() throws Exception {
+        StringWriter writer = new StringWriter();
+
+        jrs.addRowSet(crset, 1);
+        jrs.writeXml(writer);
+
+        WebRowSet another = newWebRowSet();
+        another.readXml(new StringReader(writer.getBuffer().toString()));
+        assertCachedRowSetEquals(jrs, another);
+    }
+
+    public void testWriteAndRead_Insert() throws Exception {
+        jrs.addRowSet(crset, 1);
+        jrs.beforeFirst();
+        assertTrue(jrs.next());
+        jrs.moveToInsertRow();
+        jrs.updateInt(1, 5);
+        jrs.updateString(2, "insertrow");
+        jrs.insertRow();
+        jrs.moveToCurrentRow();
+        jrs.beforeFirst();
+
+        jrs.absolute(2);
+        assertTrue(jrs.rowInserted());
+
+        StringWriter writer = new StringWriter();
+        jrs.writeXml(writer);
+
+        JoinRowSet another = newJoinRowSet();
+        another.readXml(new StringReader(writer.getBuffer().toString()));
+
+        if (System.getProperty("Testing Harmony") == "true") {
+            assertCachedRowSetEquals(jrs, another);
+        } else {
+            // TODO why the output xml has no insert information.
+            another.absolute(2);
+            assertFalse(another.rowInserted());
+            jrs.absolute(2);
+            assertTrue(jrs.rowInserted());
+        }
+    }
+
+    public void testWriteAndRead_Update() throws Exception {
+        jrs.addRowSet(crset, 1);
+        jrs.beforeFirst();
+
+        assertTrue(jrs.absolute(3));
+        jrs.updateString(2, "updateRow");
+        jrs.updateRow();
+
+        assertTrue(jrs.next());
+        jrs.updateString(2, "anotherUpdateRow");
+        jrs.updateRow();
+
+        StringWriter writer = new StringWriter();
+
+        jrs.writeXml(writer);
+
+        JoinRowSet another = newJoinRowSet();
+        another.readXml(new StringReader(writer.getBuffer().toString()));
+
+
+        if (System.getProperty("Testing Harmony") == "true") {
+            assertCachedRowSetEquals(jrs, another);
+        } else {
+            another.absolute(3);
+            assertFalse(another.rowUpdated());
+            jrs.absolute(3);
+            assertTrue(jrs.rowUpdated());
+            
+            // TODO why the output xml has no update information.
+            another.absolute(4);
+            assertFalse(another.rowUpdated());
+            jrs.absolute(4);
+            assertTrue(jrs.rowUpdated());
+        }
+    }
+
+    public void testWriteAndRead_Delete() throws Exception {
+        jrs.addRowSet(crset, 1);
+        jrs.beforeFirst();
+
+        crset.setShowDeleted(true);
+        crset.absolute(3);
+        crset.deleteRow();
+        crset.absolute(3);
+        assertTrue(crset.rowDeleted());
+
+        jrs.setShowDeleted(true);
+        assertTrue(jrs.absolute(3));
+        jrs.deleteRow();
+
+        jrs.absolute(3);
+        assertTrue(jrs.rowDeleted());
+        
+        assertTrue(jrs.absolute(4));
+    }
+    
+    public void testWriteXmlLResultSet() throws Exception {
+        StringWriter writer = new StringWriter();
+        rs = st.executeQuery("select * from user_info");
+        jrs.writeXml(rs, writer);
+        
+        JoinRowSet jrs2 = newJoinRowSet();
+        jrs2.readXml(new StringReader(writer.getBuffer().toString()));
+        assertCachedRowSetEquals(crset, jrs2);
+    }
+
+    protected void assertCachedRowSetEquals(CachedRowSet expected,
+            CachedRowSet actual) throws Exception {
+        isMetaDataEquals(expected.getMetaData(), actual.getMetaData());
+        assertProperties(expected, actual);
+        assertData(expected, actual);
+    }
+
+    private void assertData(CachedRowSet expected, CachedRowSet actual)
+            throws SQLException {
+        assertEquals(expected.size(), actual.size());
+        expected.beforeFirst();
+        actual.beforeFirst();
+
+        int columnCount = expected.getMetaData().getColumnCount();
+        while (expected.next()) {
+            assertTrue(actual.next());
+            // TODO RI's bug: read deleted row from xml would become current row
+            if ("true".equals(System.getProperty("Testing Harmony"))) {
+                assertEquals(expected.rowDeleted(), actual.rowDeleted());
+            }
+            assertEquals(expected.rowInserted(), actual.rowInserted());
+            assertEquals(expected.rowUpdated(), actual.rowUpdated());
+            for (int i = 1; i <= columnCount; ++i) {
+                if (expected.getObject(i) == null) {
+                    assertNull(actual.getObject(i));
+                } else {
+                    assertEquals(expected.getObject(i).hashCode(), actual
+                            .getObject(i).hashCode());
+                }
+            }
+        }
+    }
+
+    private void assertProperties(CachedRowSet expected, CachedRowSet actual)
+            throws SQLException, SyncProviderException {
+        assertEquals(expected.getCommand(), actual.getCommand());
+        assertEquals(expected.getConcurrency(), actual.getConcurrency());
+
+        try {
+            assertEquals(expected.getCursorName(), actual.getCursorName());
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        try {
+            assertEquals(expected.getMatchColumnIndexes(), actual
+                    .getMatchColumnIndexes());
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+
+        try {
+            assertEquals(expected.getMatchColumnNames(), actual
+                    .getMatchColumnNames());
+        } catch (SQLException e) {
+            // expected
+        }
+
+        assertEquals(expected.getStatement(), actual.getStatement());
+
+        assertEquals(expected.getEscapeProcessing(), actual
+                .getEscapeProcessing());
+        assertEquals(expected.getFetchDirection(), actual.getFetchDirection());
+        assertEquals(expected.getFetchSize(), actual.getFetchSize());
+        if (expected.getKeyColumns() != null
+                && expected.getKeyColumns().length != 0) {
+            int[] keyColumns = expected.getKeyColumns();
+            int[] copyKeyColumns = actual.getKeyColumns();
+
+            assertEquals(keyColumns.length, copyKeyColumns.length);
+            for (int i = 0; i < keyColumns.length; i++) {
+                assertEquals(keyColumns[i], copyKeyColumns[i]);
+            }
+            assertEquals(expected.getKeyColumns(), actual.getKeyColumns());
+        }
+
+        assertEquals(expected.getMaxFieldSize(), actual.getMaxFieldSize());
+        assertEquals(expected.getMaxRows(), actual.getMaxRows());
+
+        assertEquals(expected.getPageSize(), actual.getPageSize());
+        assertEquals(expected.getPassword(), actual.getPassword());
+        assertEquals(expected.getQueryTimeout(), actual.getQueryTimeout());
+
+        // TODO RI doesn't set show deleted row correctly after writeXml
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertEquals(expected.getShowDeleted(), actual.getShowDeleted());
+        }
+
+        assertEquals(expected.getSyncProvider().getProviderID(), actual
+                .getSyncProvider().getProviderID());
+        assertEquals(expected.getSyncProvider().getProviderGrade(), actual
+                .getSyncProvider().getProviderGrade());
+        assertEquals(expected.getSyncProvider().getDataSourceLock(), actual
+                .getSyncProvider().getDataSourceLock());
+        assertEquals(expected.getSyncProvider().getVendor(), actual
+                .getSyncProvider().getVendor());
+        assertEquals(expected.getSyncProvider().getVersion(), actual
+                .getSyncProvider().getVersion());
+
+        assertEquals(expected.getTableName(), actual.getTableName());
+        assertEquals(expected.getTransactionIsolation(), actual
+                .getTransactionIsolation());
+        assertEquals(expected.getType(), actual.getType());
+
+        assertEquals(expected.getUsername(), actual.getUsername());
+    }
+}

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



Mime
View raw message