harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r598162 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java
Date Mon, 26 Nov 2007 08:29:48 GMT
Author: tonywu
Date: Mon Nov 26 00:29:42 2007
New Revision: 598162

URL: http://svn.apache.org/viewvc?rev=598162&view=rev
Log:
Apply patch HARMONY-5176 ([classlib][sql] deep copy originalRow when createCopy and createCopySchema)

Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java

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=598162&r1=598161&r2=598162&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
Mon Nov 26 00:29:42 2007
@@ -73,8 +73,6 @@
 
     private CachedRow currentRow;
 
-    private CachedRow originalRow;
-
     // start from : 1.
     private int currentRowIndex;
 
@@ -161,7 +159,10 @@
             RowSetWriter rowSetWriter = syncProvider.getRowSetWriter();
             CachedRowSetImpl input = (CachedRowSetImpl) createCopy();
             rowSetWriter.writeData(input);
-            // setOriginalRow();
+            /*
+             * FIXME: if no conflicts happen when writeData, then call
+             * setOriginalRow()
+             */
             notifyRowSetChanged();
         } catch (SQLException e) {
             // TODO deal with the exception
@@ -252,6 +253,10 @@
             if (getKeyColumns() != null) {
                 output.setKeyColumns(getKeyColumns().clone());
             }
+            // CachedRowSetImpl.originalResultSet
+            CachedRowSetImpl copyOriginalRs = new CachedRowSetImpl();
+            copyOriginalRs.populate(getOriginal());
+            output.originalResultSet = copyOriginalRs;
 
             /*
              * TODO uncomment after getMatchColumnIndexes and
@@ -288,35 +293,19 @@
     }
 
     public CachedRowSet createCopySchema() throws SQLException {
-        // For webRowSet: represent the table structure: Columns
-        CachedRowSetImpl result;
-        try {
-            // copy data from BaseRowSet
-            result = (CachedRowSetImpl) super.clone();
-            // deep copy meta data
-            result.meta = copyMetaData(meta);
-            result.columnCount = columnCount;
-            result.keyCols = keyCols == null ? null : keyCols.clone();
-            result.originalResultSet = new CachedRowSetImpl(syncProvider
-                    .getProviderID());
-            result.pageSize = pageSize;
-            result.setSyncProvider(syncProvider.getProviderID());
-            result.setTableName(getTableName());
-
-            // clean up rows data
-            result.currentColumn = null;
-            result.currentRowIndex = 0;
-            result.insertRow = null;
-            result.originalRow = null;
-            result.pageNumber = 1;
-            result.rememberedCursorPosition = 0;
-            result.rows = new ArrayList<CachedRow>();
-            result.sqlwarn = null;
-            return result;
-        } catch (CloneNotSupportedException e) {
-            // TODO add error message
-            throw new SQLException();
-        }
+        CachedRowSetImpl output = (CachedRowSetImpl) createCopy();
+
+        // clean up rows data
+        output.currentColumn = null;
+        output.currentRow = null;
+        output.currentRowIndex = 0;
+        output.insertRow = null;
+        output.pageNumber = 1;
+        output.rememberedCursorPosition = 0;
+        output.rows = new ArrayList<CachedRow>();
+        output.sqlwarn = null;
+
+        return output;
     }
 
     public RowSet createShared() throws SQLException {
@@ -364,11 +353,14 @@
             throw new SQLException();
         }
 
-        CachedRowSetImpl specialRset = new CachedRowSetImpl();
+        CachedRowSetImpl originalRowRset = new CachedRowSetImpl();
         ArrayList<CachedRow> data = new ArrayList<CachedRow>();
-        data.add(originalRow);
-        specialRset.setRows(data, columnCount);
-        return specialRset;
+        CachedRow originalCachedRow = rows.get(getRow() - 1).getOriginal();
+        data.add(originalCachedRow);
+        originalRowRset.setRows(data, columnCount);
+        originalRowRset.setType(ResultSet.TYPE_SCROLL_INSENSITIVE);
+        originalRowRset.setConcurrency(ResultSet.CONCUR_UPDATABLE);
+        return originalRowRset;
     }
 
     public int getPageSize() {
@@ -495,13 +487,12 @@
 
     public void setOriginalRow() throws SQLException {
 
+        // FIXME re-implements this method
         if (currentRow == null) {
             // TODO add error messages
             throw new SQLException();
         }
-        originalRow = currentRow;
         currentRow.setNonUpdateable();
-
     }
 
     public void setPageSize(int size) throws SQLException {
@@ -883,7 +874,12 @@
     }
 
     public int getRow() throws SQLException {
-        throw new NotImplementedException();
+        // FIXME need more tests
+        if (currentRow == null) {
+            return 0;
+        }
+
+        return currentRowIndex;
     }
 
     public short getShort(int columnIndex) throws SQLException {

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=598162&r1=598161&r2=598162&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
Mon Nov 26 00:29:42 2007
@@ -133,6 +133,35 @@
         }
     }
 
+    public void testGetOriginalRow() throws Exception {
+        try {
+            crset.getOriginalRow();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected: spec throw SQLException
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // RI throw ArrayIndexOutOfBoundsException
+        }
+
+        assertTrue(crset.absolute(3));
+        assertNotSame(crset.getOriginalRow(), crset.getOriginalRow());
+
+        crset.updateString(2, "update3");
+        ResultSet originalRow = crset.getOriginalRow();
+        assertTrue(originalRow.next());
+        assertEquals("test3", originalRow.getString(2));
+
+        // after call acceptChanges()
+        crset.updateRow();
+        crset.acceptChanges();
+        assertTrue(crset.absolute(3));
+        assertEquals("update3", crset.getString(2));
+        originalRow = crset.getOriginalRow();
+        assertTrue(originalRow.next());
+        // TODO uncomment it after implement Writer
+        // assertEquals("update3", originalRow.getString(2));
+    }
+
     public void testSetSyncProvider() throws Exception {
         if (System.getProperty("Testing Harmony") == "true") {
             String mySyncProvider = "org.apache.harmony.sql.internal.rowset.HYOptimisticProvider";
@@ -403,7 +432,6 @@
 
         CachedRowSet copy = crset.createCopyNoConstraints();
 
-        
         // default is ResultSet.CONCUR_UPDATABLE
         assertEquals(ResultSet.CONCUR_UPDATABLE, copy.getConcurrency());
         // default is ResultSet.TYPE_SCROLL_INSENSITIVE
@@ -655,7 +683,55 @@
         assertNull(listener.getTag());
     }
 
+    public void testCopySchema2() throws Exception {
+
+        // set value
+        crset.setCommand("testCommand");
+        crset.setConcurrency(ResultSet.CONCUR_READ_ONLY);
+        crset.setDataSourceName("testDataSourceName");
+        crset.setFetchDirection(ResultSet.FETCH_REVERSE);
+        crset.setMaxFieldSize(100);
+        crset.setMaxRows(10);
+        crset.setPageSize(10);
+        crset.setPassword("passwo");
+        crset.setQueryTimeout(100);
+        crset.setTableName("testTable");
+        crset.setTransactionIsolation(ResultSet.HOLD_CURSORS_OVER_COMMIT);
+        crset.setType(ResultSet.TYPE_SCROLL_SENSITIVE);
+        crset.setTypeMap(new HashMap<String, Class<?>>());
+        crset.setEscapeProcessing(false);
+        crset.setKeyColumns(new int[] { 1 });
+
+        // call createCopySchema()
+        CachedRowSet copy = crset.createCopySchema();
+        assertFalse(copy.next());
+        assertEquals(crset.getCommand(), copy.getCommand());
+        assertEquals(crset.getConcurrency(), copy.getConcurrency());
+        assertEquals(crset.getDataSourceName(), copy.getDataSourceName());
+        assertEquals(crset.getFetchDirection(), copy.getFetchDirection());
+        assertEquals(crset.getMaxFieldSize(), copy.getMaxFieldSize());
+        assertEquals(crset.getMaxRows(), copy.getMaxRows());
+        assertEquals(crset.getPageSize(), copy.getPageSize());
+        assertEquals(crset.getQueryTimeout(), copy.getQueryTimeout());
+        assertEquals(crset.getTableName(), copy.getTableName());
+        assertEquals(crset.getTransactionIsolation(), copy
+                .getTransactionIsolation());
+        assertEquals(crset.getType(), copy.getType());
+        assertEquals(crset.getUrl(), copy.getUrl());
+        assertEquals(crset.getEscapeProcessing(), copy.getEscapeProcessing());
+        assertTrue(Arrays.equals(crset.getKeyColumns(), copy.getKeyColumns()));
+
+        // compare the object reference
+        assertNotSame(crset.getKeyColumns(), copy.getKeyColumns());
+        assertNotSame(crset.getMetaData(), copy.getMetaData());
+        assertNotSame(crset.getOriginal(), copy.getOriginal());
+        assertNotSame(crset.getTypeMap(), copy.getTypeMap());
+    }
+
     public void testCreateCopy() throws Exception {
+
+        // TODO: lack of the test for CachedRowSet.getOriginal() and
+        // CachedRowSet.getOriginalRow()
 
         crset.absolute(3);
 



Mime
View raw message