You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by lv...@apache.org on 2008/03/20 09:32:09 UTC

svn commit: r639200 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/javax/sql/rowset/spi/ main/java/org/apache/harmony/sql/internal/nls/ main/java/org/apache/harmony/sql/internal/rowset/ test/java/org/apache/harmony/sql/tests/internal/...

Author: lvjing
Date: Thu Mar 20 01:32:08 2008
New Revision: 639200

URL: http://svn.apache.org/viewvc?rev=639200&view=rev
Log:
Apply patch for HARMONY-5620,[classlib][sql][rowset] Implement HYOptimisticProvider and left methods in CachedRowSetImpl

Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/spi/SyncFactory.java
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/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/CachedRowSetReader.java
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetWriter.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/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetGetTest.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/CachedRowSetInsertTest.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetListenerTest.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetSQLWarningTest.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/CachedRowSetTestCase.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetTransactionTest.java

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/spi/SyncFactory.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/spi/SyncFactory.java?rev=639200&r1=639199&r2=639200&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/spi/SyncFactory.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/spi/SyncFactory.java Thu Mar 20 01:32:08 2008
@@ -56,7 +56,6 @@
 
     private static String resLocation;
 
-    // TODO: the default provider hasn't been implemented yet
     private static String defaultProviderName = "org.apache.harmony.sql.internal.rowset.HYOptimisticProvider"; //$NON-NLS-1$
 
     private static ProviderImpl defaultProvider = new ProviderImpl(

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=639200&r1=639199&r2=639200&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 Mar 20 01:32:08 2008
@@ -82,3 +82,8 @@
 rowset.19=Populate data before calling
 rowset.20=Match columns should be greater than 0
 rowset.21=Not Updateable of the CurrentRow
+rowset.22=Number of rows is less than fetch size
+rowset.23=Locking classification is not supported
+rowset.24=Unable to get connection
+rowset.25=(JNDI)Unable to get connection
+rowset.26=The object has not been initialized

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=639200&r1=639199&r2=639200&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 Thu Mar 20 01:32:08 2008
@@ -61,19 +61,7 @@
         mask.set(i);
     }
 
-    public void setUnavailable() {
-        // FIXME: What is this method used for?
-        setDelete();
-        setInsert();
-        mask.clear();
-        mask.flip(0, columnData.length);
-    }
-
     public void setNonUpdateable() {
-        // setDelete();
-        // setInsert();
-        // mask.clear();
-        // mask.flip(0,columnData.length);
         nonUpdateable = true;
     }
 

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=639200&r1=639199&r2=639200&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 Mar 20 01:32:08 2008
@@ -55,6 +55,9 @@
 import java.util.Map;
 import java.util.Vector;
 
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
 import javax.sql.RowSet;
 import javax.sql.RowSetEvent;
 import javax.sql.RowSetInternal;
@@ -69,7 +72,6 @@
 import javax.sql.rowset.spi.SyncProvider;
 import javax.sql.rowset.spi.SyncProviderException;
 
-import org.apache.harmony.luni.util.NotImplementedException;
 import org.apache.harmony.sql.internal.nls.Messages;
 
 public class CachedRowSetImpl extends BaseRowSet implements CachedRowSet,
@@ -116,7 +118,6 @@
 
     private boolean isCursorOnInsert;
 
-    // TODO remember to evalute it in CachedRowSetReader
     private int[] keyCols;
 
     private int columnCount;
@@ -221,12 +222,16 @@
         }
 
         Connection currentConn = null;
+        Connection preConn = conn;
         try {
-            currentConn = getConnection();
+            currentConn = retrieveConnection();
+            currentConn.setTypeMap(getTypeMap());
             acceptChanges(currentConn);
         } catch (SQLException e) {
             try {
-                currentConn.rollback();
+                if (currentConn != null) {
+                    currentConn.rollback();
+                }
             } catch (SQLException ex) {
                 // ignore
             }
@@ -234,7 +239,7 @@
             ex.initCause(e);
             throw ex;
         } finally {
-            conn = null;
+            conn = preConn;
             if (currentConn != null) {
                 try {
                     currentConn.commit();
@@ -425,16 +430,14 @@
             copyOriginalRs.populate(getOriginal());
             output.originalResultSet = copyOriginalRs;
 
-            /*
-             * TODO uncomment after getMatchColumnIndexes and
-             * getMatchColumnNames implemented
-             */
-            // if (getMatchColumnIndexes() != null) {
-            // output.setMatchColumn(getMatchColumnIndexes().clone());
-            // }
-            // if (getMatchColumnNames() != null) {
-            // output.setMatchColumn(getMatchColumnNames().clone());
-            // }
+            if (matchColumnIndexes != null) {
+                output.matchColumnIndexes = matchColumnIndexes.clone();
+            }
+
+            if (matchColumnNames != null) {
+                output.matchColumnNames = matchColumnNames.clone();
+            }
+
             output.setSyncProvider(getSyncProvider().getProviderID());
             if (insertRow != null) {
                 output.insertRow = insertRow.createClone();
@@ -516,8 +519,8 @@
 
     public int[] getKeyColumns() throws SQLException {
         if (rows == null) {
-            // TODO add error messages
-            throw new SQLException();
+            // rowset.26=The object has not been initialized
+            throw new SQLException(Messages.getString("rowset.26")); //$NON-NLS-1$
         }
         if (keyCols == null) {
             return new int[0];
@@ -532,8 +535,8 @@
 
     public ResultSet getOriginalRow() throws SQLException {
         if (currentRow == null) {
-            // TODO add error messages
-            throw new SQLException();
+            // rowset.7=Not a valid cursor
+            throw new SQLException(Messages.getString("rowset.7")); //$NON-NLS-1$
         }
 
         CachedRowSetImpl originalRowRset = new CachedRowSetImpl();
@@ -573,14 +576,13 @@
         }
 
         if (cachedResultSet == null) {
-            // TODO ensure the getConnection can works!
             String localCommand = getCommand();
             if (localCommand == null || getParams() == null) {
-                // TODO add error messages
-                throw new SQLException();
+                // rowset.16=Not a valid command
+                throw new SQLException(Messages.getString("rowset.16")); //$NON-NLS-1$
             }
 
-            PreparedStatement ps = getConnection().prepareStatement(
+            PreparedStatement ps = retrieveConnection().prepareStatement(
                     localCommand);
             Object[] params = getParams();
             for (int i = 0; i < params.length; i++) {
@@ -638,13 +640,13 @@
 
     public void populate(ResultSet rs, int startRow) throws SQLException {
         if (rs == null) {
-            // TODO add error messages
-            throw new SQLException();
+            // sql.42=Illegal Argument
+            throw new SQLException(Messages.getString("sql.42")); //$NON-NLS-1$
         }
 
         if (startRow == 1) {
             rs.beforeFirst();
-            // TODO use next move
+            // maybe use next to move is better
         } else if (startRow <= 0 || !rs.absolute(startRow - 1)) {
             // rowset.7=Not a valid cursor
             throw new SQLException(Messages.getString("rowset.7")); //$NON-NLS-1$
@@ -686,6 +688,11 @@
             // ignore
         }
 
+        if (rs.getStatement() != null
+                && rs.getStatement().getConnection() != null) {
+            setTypeMap(rs.getStatement().getConnection().getTypeMap());
+        }
+
         /*
          * this method not support paging, so before readData set pageSize and
          * maxRowsto 0 and restore previous values after readData
@@ -773,14 +780,13 @@
         }
 
         if (cachedResultSet == null) {
-            // TODO ensure the getConnection can works!
             String localCommand = getCommand();
             if (localCommand == null || getParams() == null) {
-                // TODO add error messages
-                throw new SQLException();
+                // rowset.16=Not a valid command
+                throw new SQLException(Messages.getString("rowset.16")); //$NON-NLS-1$
             }
 
-            PreparedStatement ps = getConnection().prepareStatement(
+            PreparedStatement ps = retrieveConnection().prepareStatement(
                     localCommand);
             Object[] params = getParams();
             for (int i = 0; i < params.length; i++)
@@ -900,7 +906,17 @@
 
     public void rowSetPopulated(RowSetEvent event, int numRows)
             throws SQLException {
-        throw new NotImplementedException();
+        if (numRows <= 0) {
+            // sql.42=Illegal Argument
+            throw new SQLException(Messages.getString("sql.42")); //$NON-NLS-1$
+        }
+        if (numRows < getFetchSize()) {
+            // rowset.22=Number of rows is less than fetch size
+            throw new SQLException(Messages.getString("rowset.22")); //$NON-NLS-1$
+        }
+        if (size() == 0 || size() % numRows == 0) {
+            notifyRowSetChanged();
+        }
     }
 
     public void setKeyColumns(int[] keys) throws SQLException {
@@ -928,8 +944,8 @@
 
     public void setOriginalRow() throws SQLException {
         if (currentRow == null) {
-            // TODO add error messages
-            throw new SQLException();
+            // rowset.7=Not a valid cursor
+            throw new SQLException(Messages.getString("rowset.7")); //$NON-NLS-1$
         }
 
         if (rowDeleted()) {
@@ -993,8 +1009,7 @@
 
     public Collection<?> toCollection(int column) throws SQLException {
         if (rows == null) {
-            // sql.38=Object is invalid
-            throw new SQLException(Messages.getString("sql.38")); //$NON-NLS-1$
+            return new Vector<Object>();
         }
 
         if (column <= 0 || column > columnCount) {
@@ -1091,7 +1106,7 @@
 
     public void setMatchColumn(int columnIdx) throws SQLException {
         if (columnIdx < 0) {
-            // TODO why is 0 valid? load message from resource files
+            // TODO why is 0 valid?
             // rowset.20=Match columns should be greater than 0
             throw new SQLException(Messages.getString("rowset.20")); //$NON-NLS-1$
         }
@@ -1115,7 +1130,7 @@
 
         for (int i : columnIdxes) {
             if (i < 0) {
-                // TODO why is 0 valid? load message from resource files
+                // TODO why is 0 valid?
                 // rowset.20=Match columns should be greater than 0
                 throw new SQLException(Messages.getString("rowset.20")); //$NON-NLS-1$
             }
@@ -1530,7 +1545,11 @@
 
     public BigDecimal getBigDecimal(int columnIndex, int scale)
             throws SQLException {
-        throw new NotImplementedException();
+        BigDecimal big = getBigDecimal(columnIndex);
+        if (big == null) {
+            return null;
+        }
+        return big.setScale(scale);
     }
 
     public BigDecimal getBigDecimal(String columnName) throws SQLException {
@@ -1684,9 +1703,6 @@
     }
 
     public String getCursorName() throws SQLException {
-        /*
-         * FIXME not sure how to implement it.
-         */
         if (cursorName == null) {
             // rowset.14=Positioned updates not supported
             throw new SQLException(Messages.getString("rowset.14")); //$NON-NLS-1$
@@ -1716,7 +1732,16 @@
     }
 
     public Date getDate(int columnIndex, Calendar cal) throws SQLException {
-        throw new NotImplementedException();
+        Date date = getDate(columnIndex);
+        if (date == null) {
+            return null;
+        }
+
+        Calendar tempCal = Calendar.getInstance(cal.getTimeZone());
+        tempCal.setTime(date);
+        cal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONTH),
+                tempCal.get(Calendar.DAY_OF_MONTH));
+        return new Date(cal.getTimeInMillis());
     }
 
     public Date getDate(String columnName) throws SQLException {
@@ -1827,7 +1852,8 @@
 
     public Object getObject(int columnIndex, Map<String, Class<?>> map)
             throws SQLException {
-        throw new NotImplementedException();
+        // FIXME the usage of map
+        return getObject(columnIndex);
     }
 
     public Object getObject(String columnName) throws SQLException {
@@ -1859,7 +1885,6 @@
     }
 
     public int getRow() throws SQLException {
-        // FIXME need more tests
         if (currentRow == null || rows == null || isCursorOnInsert) {
             return 0;
         }
@@ -1956,7 +1981,16 @@
     }
 
     public Time getTime(int columnIndex, Calendar cal) throws SQLException {
-        throw new NotImplementedException();
+        Time time = getTime(columnIndex);
+        if (time == null) {
+            return null;
+        }
+        Calendar tempCal = Calendar.getInstance(cal.getTimeZone());
+        tempCal.setTimeInMillis(time.getTime());
+        cal.set(Calendar.HOUR, tempCal.get(Calendar.HOUR));
+        cal.set(Calendar.MINUTE, tempCal.get(Calendar.MINUTE));
+        cal.set(Calendar.SECOND, tempCal.get(Calendar.SECOND));
+        return new Time(cal.getTimeInMillis());
     }
 
     public Time getTime(String columnName) throws SQLException {
@@ -1989,7 +2023,16 @@
 
     public Timestamp getTimestamp(int columnIndex, Calendar cal)
             throws SQLException {
-        throw new NotImplementedException();
+        Timestamp timestamp = getTimestamp(columnIndex);
+        if (timestamp == null) {
+            return null;
+        }
+        Calendar tempCal = Calendar.getInstance(cal.getTimeZone());
+        tempCal.setTimeInMillis(timestamp.getTime());
+        cal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONDAY),
+                tempCal.get(Calendar.DAY_OF_MONTH), tempCal.get(Calendar.HOUR),
+                tempCal.get(Calendar.MINUTE), tempCal.get(Calendar.SECOND));
+        return new Timestamp(cal.getTimeInMillis());
     }
 
     public Timestamp getTimestamp(String columnName) throws SQLException {
@@ -2078,7 +2121,7 @@
             throw new SQLException(Messages.getString("rowset.18")); //$NON-NLS-1$
         }
         insertRow.setInsert();
-        rows.add(insertRow);
+        rows.add(rememberedCursorPosition, insertRow);
         insertRow = null;
         if (isNotifyListener) {
             notifyRowChanged();
@@ -2132,14 +2175,16 @@
 
     public void moveToInsertRow() throws SQLException {
         if (meta == null) {
-            // TODO add error message
-            throw new SQLException();
+            // rowset.26=The object has not been initialized
+            throw new SQLException(Messages.getString("rowset.26")); //$NON-NLS-1$
         }
         insertRow = new CachedRow(new Object[columnCount]);
         currentRow = insertRow;
-        rememberedCursorPosition = currentRowIndex;
-        currentRowIndex = -1;
-        isCursorOnInsert = true;
+        if (!isCursorOnInsert) {
+            rememberedCursorPosition = currentRowIndex;
+            currentRowIndex = -1;
+            isCursorOnInsert = true;
+        }
     }
 
     public boolean next() throws SQLException {
@@ -2262,17 +2307,25 @@
     }
 
     public boolean rowInserted() throws SQLException {
-        if (currentRow == null || isCursorOnInsert) {
-            // TODO add error message
-            throw new SQLException();
+        if (currentRow == null) {
+            // rowset.7=Not a valid cursor
+            throw new SQLException(Messages.getString("rowset.7")); //$NON-NLS-1$
+        }
+        if (isCursorOnInsert) {
+            // rowset.11=Illegal operation on an insert row
+            throw new SQLException(Messages.getString("rowset.11")); //$NON-NLS-1$
         }
         return currentRow.isInsert();
     }
 
     public boolean rowUpdated() throws SQLException {
-        if (currentRow == null || currentRow == insertRow) {
-            // TODO add error message
-            throw new SQLException();
+        if (currentRow == null) {
+            // rowset.7=Not a valid cursor
+            throw new SQLException(Messages.getString("rowset.7")); //$NON-NLS-1$
+        }
+        if (isCursorOnInsert) {
+            // rowset.11=Illegal operation on an insert row
+            throw new SQLException(Messages.getString("rowset.11")); //$NON-NLS-1$
         }
 
         if (!currentRow.isUpdate()) {
@@ -2865,13 +2918,31 @@
     }
 
     public void execute() throws SQLException {
-        execute(getConnection());
-        conn = null;
+        Connection preConn = conn;
+        execute(retrieveConnection());
+        conn = preConn;
     }
 
     public Connection getConnection() throws SQLException {
-        // TODO consider user name, password and datasource
-        return DriverManager.getConnection(getUrl());
+        return conn;
+    }
+
+    private Connection retrieveConnection() throws SQLException {
+        if (getUrl() != null) {
+            return DriverManager.getConnection(getUrl());
+        } else if (getDataSourceName() != null) {
+            try {
+                Context contex = new InitialContext();
+                DataSource ds = (DataSource) contex.lookup(getDataSourceName());
+                return ds.getConnection();
+            } catch (Exception e) {
+                // rowset.25=(JNDI)Unable to get connection
+                SQLException ex = new SQLException("rowset.25"); //$NON-NLS-1$
+                throw ex;
+            }
+        }
+        // rowset.24=Unable to get connection
+        throw new SQLException("rowset.24"); //$NON-NLS-1$
     }
 
     CachedRow getCurrentRow() {

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java?rev=639200&r1=639199&r2=639200&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java Thu Mar 20 01:32:08 2008
@@ -30,7 +30,16 @@
 
     private ResultSetMetaData metadata;
 
+    public CachedRowSetReader() {
+        // do nothing, used by SyncProvider
+    }
+
     public CachedRowSetReader(ResultSet rs) throws SQLException {
+        this.rs = rs;
+        this.metadata = rs.getMetaData();
+    }
+
+    public void setResultSet(ResultSet rs) throws SQLException {
         this.rs = rs;
         this.metadata = rs.getMetaData();
     }

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetWriter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetWriter.java?rev=639200&r1=639199&r2=639200&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetWriter.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetWriter.java Thu Mar 20 01:32:08 2008
@@ -51,14 +51,11 @@
         return originalConnection;
     }
 
-    /**
-     * TODO add transaction
-     */
     public boolean writeData(RowSetInternal theRowSet) throws SQLException {
         initial(theRowSet);
         // analyse every row and do responsible task.
-        currentRowSet.beforeFirst();// currentRowSet.first();
-        originalRowSet.beforeFirst();// originalRowSet.first();
+        currentRowSet.beforeFirst();
+        originalRowSet.beforeFirst();
         resolver = null;
         while (currentRowSet.next()) {
             if (currentRowSet.rowInserted()) {
@@ -89,7 +86,6 @@
         if (resolver != null) {
             throw new SyncProviderException(resolver);
         }
-        // TODO release resource
         return true;
     }
 

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=639200&r1=639199&r2=639200&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 Thu Mar 20 01:32:08 2008
@@ -22,22 +22,19 @@
 import javax.sql.rowset.spi.SyncProvider;
 import javax.sql.rowset.spi.SyncProviderException;
 
-import org.apache.harmony.luni.util.NotImplementedException;
-
 public class HYOptimisticProvider extends SyncProvider {
 
-    private final static String providerID = "Apache Harmony";
+    private final static String providerID = "Apache Harmony"; //$NON-NLS-1$
 
-    private final static int providerGrade = SyncProvider.DATASOURCE_NO_LOCK;
+    private final static int providerGrade = SyncProvider.GRADE_CHECK_MODIFIED_AT_COMMIT;
 
-    private final static String vendor = "Apache Harmony";
+    private final static String vendor = "Apache Harmony"; //$NON-NLS-1$
 
-    private final static String version = "";
+    private final static String version = ""; //$NON-NLS-1$
 
     @Override
     public int getDataSourceLock() throws SyncProviderException {
-        // TODO Auto-generated method stub
-        return 0;
+        return DATASOURCE_NO_LOCK;
     }
 
     @Override
@@ -52,7 +49,7 @@
 
     @Override
     public RowSetReader getRowSetReader() {
-        throw new NotImplementedException();
+        return new CachedRowSetReader();
     }
 
     @Override
@@ -73,14 +70,15 @@
     @Override
     public void setDataSourceLock(int dataSourceLock)
             throws SyncProviderException {
-        // TODO Auto-generated method stub
-
+        if (dataSourceLock != DATASOURCE_NO_LOCK) {
+            // rowset.23=Locking classification is not supported
+            throw new SyncProviderException("rowset.23"); //$NON-NLS-1$
+        }
     }
 
     @Override
     public int supportsUpdatableView() {
-        // TODO Auto-generated method stub
-        return 0;
+        return NONUPDATABLE_VIEW_SYNC;
     }
 
 }

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetGetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetGetTest.java?rev=639200&r1=639199&r2=639200&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetGetTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetGetTest.java Thu Mar 20 01:32:08 2008
@@ -17,7 +17,10 @@
 
 package org.apache.harmony.sql.tests.internal.rowset;
 
+import java.sql.Date;
 import java.sql.SQLException;
+import java.sql.Time;
+import java.util.Calendar;
 
 public class CachedRowSetGetTest extends CachedRowSetTestCase {
 
@@ -209,7 +212,10 @@
             // expected
         }
 
-        crset.getDate(10);
+        Date date = crset.getDate(10);
+        Calendar cal = Calendar.getInstance();
+        date = crset.getDate(10, cal);
+        assertEquals(date.getTime(), cal.getTimeInMillis());
 
         try {
             crset.getDate(11);
@@ -218,7 +224,10 @@
             // expected
         }
 
-        crset.getDate(12);
+        date = crset.getDate(12);
+        assertEquals(52365412356663L, date.getTime());
+        date = crset.getDate(12, cal);
+        assertNotSame(52365412356663L, date.getTime());
     }
 
     public void testGetTime() throws Exception {
@@ -294,9 +303,14 @@
             // expected
         }
 
-        crset.getTime(11);
-
-        crset.getTime(12);
+        Time time = crset.getTime(11);
+        Calendar cal = Calendar.getInstance();
+        time = crset.getTime(11, cal);
+
+        time = crset.getTime(12);
+        assertEquals(52365412356663L, time.getTime());
+        cal = Calendar.getInstance();
+        time = crset.getTime(12, cal);
     }
 
     public void testGetTimestamp() throws Exception {
@@ -366,9 +380,27 @@
         }
 
         crset.getTimestamp(10);
+        Calendar cal = Calendar.getInstance();
+        crset.getTimestamp(10, cal);
 
         crset.getTimestamp(11);
+        cal = Calendar.getInstance();
+        crset.getTimestamp(11, cal);
 
         crset.getTimestamp(12);
+        cal = Calendar.getInstance();
+        crset.getTimestamp(12, cal);
+    }
+
+    public void testGetBigDecimal() throws Exception {
+        noInitialCrset = newNoInitialInstance();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        noInitialCrset.populate(rs);
+
+        assertTrue(noInitialCrset.absolute(3));
+        noInitialCrset.getBigDecimal(4);
+        noInitialCrset.getBigDecimal(4, 4);
+        noInitialCrset.getBigDecimal(5);
+        noInitialCrset.getBigDecimal(5, 4);
     }
 }

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=639200&r1=639199&r2=639200&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 Mar 20 01:32:08 2008
@@ -17,6 +17,7 @@
 
 package org.apache.harmony.sql.tests.internal.rowset;
 
+import java.io.PrintWriter;
 import java.math.BigDecimal;
 import java.sql.Connection;
 import java.sql.Date;
@@ -32,10 +33,14 @@
 import java.util.Iterator;
 import java.util.Vector;
 
+import javax.sql.DataSource;
 import javax.sql.RowSetEvent;
+import javax.sql.RowSetInternal;
 import javax.sql.RowSetListener;
 import javax.sql.RowSetMetaData;
 import javax.sql.rowset.CachedRowSet;
+import javax.sql.rowset.spi.SyncFactory;
+import javax.sql.rowset.spi.SyncProvider;
 import javax.sql.rowset.spi.SyncProviderException;
 import javax.sql.rowset.spi.SyncResolver;
 
@@ -76,8 +81,7 @@
         assertEquals("update3", crset.getString(2));
         originalRow = crset.getOriginalRow();
         assertTrue(originalRow.next());
-        // TODO uncomment it after implement Writer
-        // assertEquals("update3", originalRow.getString(2));
+        assertEquals("update3", originalRow.getString(2));
     }
 
     public void testSetOriginalRow() throws Exception {
@@ -206,7 +210,7 @@
 
     public void testAcceptChanges() throws SQLException {
         crset.setTableName("USER_INFO");
-        // FIXME: if the value of column is null, it would go wrong when
+        // NOTICE: if the value of column is null, it would go wrong when
         // call acceptChanges(). And if one method in TestCase throws
         // SQLException, the following method will be affected.
         rs.next();
@@ -482,7 +486,6 @@
         assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, crset
                 .getTransactionIsolation());
         assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, crset.getType());
-        assertNull(crset.getTypeMap());
         assertEquals(DERBY_URL, crset.getUrl());
         assertNull(crset.getUsername());
         assertTrue(crset.getEscapeProcessing());
@@ -602,7 +605,6 @@
 
         // check the attributes in the duplicate. These are supposed to be the
         // same as the original
-        // System.out.println("crsetCopySchema: " + crsetCopySchema.getInt(1));
         assertFalse(crsetCopySchema.next());
         assertEquals("testCommand", crsetCopySchema.getCommand());
         assertEquals(ResultSet.CONCUR_UPDATABLE, crsetCopySchema
@@ -619,9 +621,7 @@
         assertNull(listener.getTag());
         rs = st.executeQuery("select * from USER_INFO");
         crsetCopySchema.populate(rs);
-        // TODO: in the Harmony implementation, need to call notifyRowSetChanged
-        // at the suitable place
-        // assertEquals("rowSetChanged", listener.getTag());
+        assertEquals("rowSetChanged", listener.getTag());
         listener.clear();
         // the move of the original's cursor shouldn't affect the duplicate
         crset.next();
@@ -717,30 +717,28 @@
         assertEquals(crset.getCommand(), crsetCopy.getCommand());
         assertEquals(crset.getConcurrency(), crsetCopy.getConcurrency());
 
-        // uncomment after implemented
-        // try {
-        // assertEquals(crset.getCursorName(), crsetCopy.getCursorName());
-        // fail("Should throw SQLException");
-        // } catch (SQLException e) {
-        // // expected
-        // }
-        // try {
-        // assertEquals(crset.getMatchColumnIndexes(), crsetCopy
-        // .getMatchColumnIndexes());
-        // fail("Should throw SQLException");
-        // } catch (SQLException e) {
-        // // expected
-        // }
-        //
-        // try {
-        // assertEquals(crset.getMatchColumnNames(), crsetCopy
-        // .getMatchColumnNames());
-        // } catch (SQLException e) {
-        // // expected
-        // }
-        // assertEquals(crset.getRow(), crsetCopy.getRow());
-        // assertEquals(crset.getStatement(), crsetCopy.getStatement());
-        // assertNotSame(crset.getWarnings(), crsetCopy.getWarnings());
+        try {
+            assertEquals(crset.getCursorName(), crsetCopy.getCursorName());
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        try {
+            assertEquals(crset.getMatchColumnIndexes(), crsetCopy
+                    .getMatchColumnIndexes());
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+
+        try {
+            assertEquals(crset.getMatchColumnNames(), crsetCopy
+                    .getMatchColumnNames());
+        } catch (SQLException e) {
+            // expected
+        }
+        assertEquals(crset.getRow(), crsetCopy.getRow());
+        assertEquals(crset.getStatement(), crsetCopy.getStatement());
 
         assertEquals(crset.getEscapeProcessing(), crsetCopy
                 .getEscapeProcessing());
@@ -1165,26 +1163,25 @@
                 .getConcurrency());
         assertEquals(0, crset.getRow());
 
-        // TODO uncomment after impelemented
-        // try {
-        // crset.getCursorName();
-        // fail("Should throw SQLException");
-        // } catch (SQLException e) {
-        // // expected
-        // }
-        // try {
-        // crset.getMatchColumnIndexes();
-        // fail("Should throw SQLException");
-        // } catch (SQLException e) {
-        // // expected
-        // }
-        //
-        // try {
-        // crset.getMatchColumnNames();
-        // } catch (SQLException e) {
-        // // expected
-        // }
-        // assertNull(crset.getStatement());
+        try {
+            crset.getCursorName();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        try {
+            crset.getMatchColumnIndexes();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+
+        try {
+            crset.getMatchColumnNames();
+        } catch (SQLException e) {
+            // expected
+        }
+        assertNull(crset.getStatement());
 
         assertEquals(true, noInitialCrset.getEscapeProcessing());
         assertEquals(Connection.TRANSACTION_READ_COMMITTED, noInitialCrset
@@ -1484,31 +1481,26 @@
         assertTrue(rs.next());
         assertEquals(5, rs.getInt(1));
 
-        /*
-         * TODO Insert multiple rows one time, uncomment after implemented
-         */
-        // TODO uncomment it after insert methods are implemented
-        // noInitialCrset = newNoInitialInstance();
-        // rs = st.executeQuery("select * from USER_INFO");
-        // noInitialCrset.populate(rs);
-        // noInitialCrset.setReadOnly(false);
-        // noInitialCrset.moveToInsertRow();
-        // for (int i = 6; i <= 20; i++) {
-        // noInitialCrset.updateInt(1, i);
-        // noInitialCrset.updateString(2, "test" + i);
-        // noInitialCrset.insertRow();
-        // }
-        // noInitialCrset.moveToCurrentRow();
-        // noInitialCrset.acceptChanges(conn);
-        // // check the new rows in CachedRowSet
-        // assertEquals(20, noInitialCrset.size());
-        // // check the new rows in DB
-        // rs = st.executeQuery("select * from USER_INFO");
-        // int cursorIndex = 0;
-        // while (rs.next()) {
-        // cursorIndex++;
-        // }
-        // assertEquals(20, cursorIndex);
+        noInitialCrset = newNoInitialInstance();
+        rs = st.executeQuery("select * from USER_INFO");
+        noInitialCrset.populate(rs);
+        noInitialCrset.moveToInsertRow();
+        for (int i = 6; i <= 20; i++) {
+            noInitialCrset.updateInt(1, i);
+            noInitialCrset.updateString(2, "test" + i);
+            noInitialCrset.insertRow();
+        }
+        noInitialCrset.moveToCurrentRow();
+        noInitialCrset.acceptChanges(conn);
+        // check the new rows in CachedRowSet
+        assertEquals(20, noInitialCrset.size());
+        // check the new rows in DB
+        rs = st.executeQuery("select * from USER_INFO");
+        int cursorIndex = 0;
+        while (rs.next()) {
+            cursorIndex++;
+        }
+        assertEquals(20, cursorIndex);
     }
 
     public void testAcceptChanges_InsertException() throws Exception {
@@ -1540,15 +1532,7 @@
             }
 
             assertTrue(resolver.nextConflict());
-            /*
-             * TODO no-bug different, ri insert row after current row, Harmony
-             * insert row after last row
-             */
-            if ("true".equals(System.getProperty("Testing Harmony"))) {
-                assertEquals(5, resolver.getRow());
-            } else {
-                assertEquals(1, resolver.getRow());
-            }
+            assertEquals(1, resolver.getRow());
 
             assertEquals(SyncResolver.INSERT_ROW_CONFLICT, resolver.getStatus());
 
@@ -1589,16 +1573,7 @@
             }
 
             assertTrue(resolver.nextConflict());
-            /*
-             * TODO no-bug different, ri insert row after current row, Harmony
-             * insert row after last row
-             */
-            if ("true".equals(System.getProperty("Testing Harmony"))) {
-                assertEquals(5, resolver.getRow());
-            } else {
-                assertEquals(1, resolver.getRow());
-            }
-
+            assertEquals(1, resolver.getRow());
             assertEquals(SyncResolver.INSERT_ROW_CONFLICT, resolver.getStatus());
 
             for (int i = 1; i <= DEFAULT_COLUMN_COUNT; ++i) {
@@ -1675,15 +1650,7 @@
             }
 
             assertTrue(resolver.nextConflict());
-            /*
-             * TODO no-bug different, ri insert row after current row, Harmony
-             * insert row after last row
-             */
-            if ("true".equals(System.getProperty("Testing Harmony"))) {
-                assertEquals(5, resolver.getRow());
-            } else {
-                assertEquals(1, resolver.getRow());
-            }
+            assertEquals(1, resolver.getRow());
 
             assertEquals(SyncResolver.INSERT_ROW_CONFLICT, resolver.getStatus());
 
@@ -2122,11 +2089,6 @@
         assertEquals(7, crset.findColumn("FloaT_T"));
     }
 
-    /**
-     * TODO test event
-     * 
-     * @throws Exception
-     */
     public void testRestoreOriginal() throws Exception {
         // update
         assertTrue(crset.absolute(3));
@@ -2269,11 +2231,6 @@
         assertEquals("test3", crset.getString(2));
     }
 
-    /**
-     * TODO test event
-     * 
-     * @throws Exception
-     */
     public void testRestoreOriginal_MultiChanges() throws Exception {
         insertMoreData(5);
 
@@ -2416,24 +2373,25 @@
                     assertEquals(rs.getObject(i), vector.get(i - 1));
                 }
             }
+        } else {
+            rs = st.executeQuery("select * from USER_INFO");
+            noInitialCrset.populate(rs);
+
+            Collection<?> collection = noInitialCrset.toCollection();
+            assertEquals("class java.util.TreeMap$2", collection.getClass()
+                    .toString());
+            Iterator iter = collection.iterator();
+            assertTrue(iter.hasNext());
+            assertEquals("class com.sun.rowset.internal.Row", iter.next()
+                    .getClass().toString());
         }
     }
 
     public void testToCollectionInt() throws Exception {
         noInitialCrset = newNoInitialInstance();
-        if ("true".equals(System.getProperty("Testing Harmony"))) {
-            try {
-                noInitialCrset.toCollection(0);
-                fail("should throw SQLException");
-            } catch (SQLException e) {
-                // expected
-            }
-        } else {
-            assertEquals(0, noInitialCrset.toCollection(-1).size());
-            assertEquals(0, noInitialCrset.toCollection(0).size());
-            assertEquals(Vector.class, noInitialCrset.toCollection(1)
-                    .getClass());
-        }
+        assertEquals(0, noInitialCrset.toCollection(-1).size());
+        assertEquals(0, noInitialCrset.toCollection(0).size());
+        assertEquals(Vector.class, noInitialCrset.toCollection(1).getClass());
 
         rs = st.executeQuery("select * from USER_INFO");
         noInitialCrset.populate(rs);
@@ -2735,6 +2693,144 @@
         assertEquals(8, args[1]);
 
     }
+
+    public void testProvider() throws Exception {
+        SyncProvider provider = null;
+        if (System.getProperty("Testing Harmony") == "true") {
+            provider = SyncFactory
+                    .getInstance("Apache Harmony HYOptimisticProvider");
+        } else {
+            provider = SyncFactory
+                    .getInstance("com.sun.rowset.providers.RIOptimisticProvider");
+        }
+
+        assertEquals(SyncProvider.GRADE_CHECK_MODIFIED_AT_COMMIT, provider
+                .getProviderGrade());
+        assertEquals(SyncProvider.DATASOURCE_NO_LOCK, provider
+                .getDataSourceLock());
+        assertEquals(SyncProvider.NONUPDATABLE_VIEW_SYNC, provider
+                .supportsUpdatableView());
+
+        try {
+            provider.setDataSourceLock(SyncProvider.DATASOURCE_TABLE_LOCK);
+            fail("Should throw SyncProviderException");
+        } catch (SyncProviderException e) {
+            // expected
+        }
+
+        try {
+            provider.setDataSourceLock(SyncProvider.DATASOURCE_ROW_LOCK);
+            fail("Should throw SyncProviderException");
+        } catch (SyncProviderException e) {
+            // expected
+        }
+
+        try {
+            provider.setDataSourceLock(SyncProvider.DATASOURCE_DB_LOCK);
+            fail("Should throw SyncProviderException");
+        } catch (SyncProviderException e) {
+            // expected
+        }
+
+        provider.setDataSourceLock(SyncProvider.DATASOURCE_NO_LOCK);
+    }
+
+    public void testGetConnection() throws Exception {
+        RowSetInternal rowset = (RowSetInternal) noInitialCrset;
+        assertNull(rowset.getConnection());
+
+        noInitialCrset.setUsername("test");
+        noInitialCrset.setPassword("pwd");
+
+        assertNull(noInitialCrset.getUrl());
+        assertNull(noInitialCrset.getDataSourceName());
+        assertNull(rowset.getConnection());
+
+        noInitialCrset.setUrl(DERBY_URL);
+        assertNull(noInitialCrset.getDataSourceName());
+        assertNull(rowset.getConnection());
+
+        noInitialCrset.setUsername(null);
+        noInitialCrset.setPassword(null);
+        noInitialCrset.setUrl(DERBY_URL);
+        assertNull(noInitialCrset.getDataSourceName());
+        assertNull(rowset.getConnection());
+
+        // test acceptChange
+        crset = newNoInitialInstance();
+        rs = st.executeQuery("select * from USER_INFO");
+
+        crset.populate(rs);
+
+        rowset = (RowSetInternal) crset;
+
+        assertNull(crset.getUsername());
+        assertNull(crset.getPassword());
+        assertNull(crset.getUrl());
+        assertNull(crset.getDataSourceName());
+        assertNull(rowset.getConnection());
+
+        crset.setUrl(DERBY_URL);
+        assertNull(crset.getUsername());
+        assertNull(crset.getPassword());
+        assertEquals(DERBY_URL, crset.getUrl());
+        assertNull(rowset.getConnection());
+
+        crset.absolute(3);
+        crset.updateString(2, "update2");
+        assertEquals(DERBY_URL, crset.getUrl());
+        crset.acceptChanges();
+        assertNull(rowset.getConnection());
+
+        crset.acceptChanges(conn);
+
+        assertNotNull(rowset.getConnection());
+        assertSame(conn, rowset.getConnection());
+
+        crset.acceptChanges();
+        assertSame(conn, rowset.getConnection());
+
+        Connection connection = DriverManager.getConnection(DERBY_URL);
+        crset.acceptChanges(connection);
+        assertSame(connection, rowset.getConnection());
+
+    }
+
+    public void testRetrieveConnection() throws Exception {
+        crset = newNoInitialInstance();
+        rs = st.executeQuery("select * from USER_INFO");
+
+        crset.populate(rs);
+
+        assertNull(crset.getUrl());
+        assertNull(crset.getDataSourceName());
+        try {
+            crset.acceptChanges();
+            fail("Should throw SyncProviderException");
+        } catch (SyncProviderException e) {
+            // expected, Unable to get connection
+        }
+
+        // wrong user and password
+        crset.setUsername("testusername");
+        crset.setPassword("testpassword");
+        crset.setUrl(DERBY_URL);
+        crset.absolute(3);
+        crset.updateString(2, "update3");
+        crset.updateRow();
+
+        crset.acceptChanges();
+
+        crset.setDataSourceName("testDataSource");
+
+        try {
+            crset.acceptChanges();
+            fail("Should throw SyncProviderException");
+        } catch (SyncProviderException e) {
+            // expected, (JNDI)Unable to get connection
+        }
+    }
+
 }
 
 class Listener implements RowSetListener, Cloneable {
@@ -2743,14 +2839,13 @@
 
     private boolean isPrint = false;
 
-    private int count = 0;
+    private Object eventSource = null;
 
     public void cursorMoved(RowSetEvent theEvent) {
         if (isPrint) {
             System.out.println("cursorMoved");
         }
         tag = CachedRowSetListenerTest.EVENT_CURSOR_MOVED;
-        count++;
     }
 
     public void rowChanged(RowSetEvent theEvent) {
@@ -2758,7 +2853,6 @@
             System.out.println("rowChanged");
         }
         tag = CachedRowSetListenerTest.EVENT_ROW_CHANGED;
-        count++;
     }
 
     public void rowSetChanged(RowSetEvent theEvent) {
@@ -2766,23 +2860,24 @@
             System.out.println("rowSetChanged");
         }
         tag = CachedRowSetListenerTest.EVENT_ROWSET_CHANGED;
-        count++;
+        eventSource = theEvent.getSource();
     }
 
     public String getTag() {
         return tag;
     }
 
+    public Object getEventSource() {
+        return eventSource;
+    }
+
     public void clear() {
         tag = null;
+        eventSource = null;
     }
 
     public void setPrint(boolean isPrint) {
         this.isPrint = isPrint;
-    }
-
-    public int getCount() {
-        return count;
     }
 
     public Listener clone() throws CloneNotSupportedException {

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetInsertTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetInsertTest.java?rev=639200&r1=639199&r2=639200&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetInsertTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetInsertTest.java Thu Mar 20 01:32:08 2008
@@ -70,7 +70,7 @@
             // expected
         }
         noInitialCrset.insertRow();
-         try {
+        try {
             noInitialCrset.rowInserted();
             fail("should throw SQLException");
         } catch (SQLException e) {
@@ -112,9 +112,10 @@
         noInitialCrset.populate(rs);
         assertTrue(noInitialCrset.absolute(3));
         noInitialCrset.moveToInsertRow();
-        
+
+        // getRow() return 0 when the cursor is on the insert row
         assertEquals(0, noInitialCrset.getRow());
-        
+
         try {
             // call insertRow() without call any update method
             noInitialCrset.insertRow();
@@ -130,9 +131,16 @@
         assertEquals(0, noInitialCrset.getRow());
         noInitialCrset.insertRow();
         assertEquals(0, noInitialCrset.getRow());
-        
+
         noInitialCrset.moveToCurrentRow();
         assertEquals(3, noInitialCrset.getInt(1));
+
+        // the inserted row is after the current row immediately
+        assertTrue(noInitialCrset.next());
+        assertEquals("insert10", noInitialCrset.getString(2));
+
+        assertTrue(noInitialCrset.next());
+        assertEquals("test4", noInitialCrset.getString(2));
     }
 
     public void testInsertRow_Multi() throws Exception {
@@ -272,6 +280,43 @@
             index++;
             assertFalse(noInitialCrset.rowInserted());
         }
+        assertEquals(10, index);
+    }
+
+    public void testInsertRow_MultiTwo() throws Exception {
+        noInitialCrset = newNoInitialInstance();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        noInitialCrset.populate(rs);
+
+        assertTrue(noInitialCrset.first());
+        noInitialCrset.moveToInsertRow();
+        for (int i = 11; i <= 15; i++) {
+            noInitialCrset.updateInt(1, i);
+            noInitialCrset.updateString(2, "insert" + i);
+            noInitialCrset.insertRow();
+        }
+        noInitialCrset.moveToCurrentRow();
+        assertEquals(1, noInitialCrset.getInt(1));
+
+        int index = 1;
+        do {
+            if (index == 1) {
+                assertEquals(1, noInitialCrset.getInt(1));
+            } else if (index == 2) {
+                assertEquals(15, noInitialCrset.getInt(1));
+            } else if (index == 3) {
+                assertEquals(14, noInitialCrset.getInt(1));
+            } else if (index == 4) {
+                assertEquals(13, noInitialCrset.getInt(1));
+            } else if (index == 5) {
+                assertEquals(12, noInitialCrset.getInt(1));
+            } else if (index == 6) {
+                assertEquals(11, noInitialCrset.getInt(1));
+            } else if (index == 7) {
+                assertEquals(2, noInitialCrset.getInt(1));
+            }
+            index++;
+        } while (noInitialCrset.next());
         assertEquals(10, index);
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetListenerTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetListenerTest.java?rev=639200&r1=639199&r2=639200&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetListenerTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetListenerTest.java Thu Mar 20 01:32:08 2008
@@ -17,6 +17,10 @@
 
 package org.apache.harmony.sql.tests.internal.rowset;
 
+import java.sql.SQLException;
+
+import javax.sql.RowSetEvent;
+
 public class CachedRowSetListenerTest extends CachedRowSetTestCase {
 
     public static final String EVENT_CURSOR_MOVED = "cursorMoved";
@@ -198,11 +202,7 @@
         crset.updateString(2, "insert10");
         crset.insertRow();
         crset.moveToCurrentRow();
-        if ("true".equals(System.getProperty("Testing Harmony"))) {
-            assertTrue(crset.last());
-        } else {
-            assertTrue(crset.next());
-        }
+        assertTrue(crset.next());
         assertEquals("insert10", crset.getString(2));
         assertTrue(crset.rowInserted());
         listener.clear();
@@ -218,11 +218,7 @@
         crset.updateString(2, "insert11");
         crset.insertRow();
         crset.moveToCurrentRow();
-        if ("true".equals(System.getProperty("Testing Harmony"))) {
-            assertTrue(crset.last());
-        } else {
-            assertTrue(crset.next());
-        }
+        assertTrue(crset.next());
         assertTrue(crset.rowInserted());
         listener.clear();
         crset.undoInsert();
@@ -296,5 +292,111 @@
         noInitialCrset.release();
         assertEquals(EVENT_ROWSET_CHANGED, listener.getTag());
         listener.clear();
+    }
+
+    public void testRowSetPopulated_One() throws Exception {
+        /*
+         * There are 24 rows in database.
+         */
+        insertMoreData(20);
+        noInitialCrset = newNoInitialInstance();
+        Listener listener = new Listener();
+        noInitialCrset.addRowSetListener(listener);
+
+        assertEquals(0, noInitialCrset.getFetchSize());
+        noInitialCrset.setMaxRows(10);
+        noInitialCrset.setFetchSize(3);
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        noInitialCrset.populate(rs);
+        listener.clear();
+        noInitialCrset.rowSetPopulated(new RowSetEvent(noInitialCrset), 3);
+        assertEquals(EVENT_ROWSET_CHANGED, listener.getTag());
+
+        listener.clear();
+        noInitialCrset.rowSetPopulated(new RowSetEvent(noInitialCrset), 4);
+        assertEquals(EVENT_ROWSET_CHANGED, listener.getTag());
+
+        listener.clear();
+        noInitialCrset.rowSetPopulated(new RowSetEvent(noInitialCrset), 6);
+        assertEquals(EVENT_ROWSET_CHANGED, listener.getTag());
+
+        listener.clear();
+        noInitialCrset.rowSetPopulated(new RowSetEvent(noInitialCrset), 8);
+        assertEquals(EVENT_ROWSET_CHANGED, listener.getTag());
+
+        listener.clear();
+        noInitialCrset.rowSetPopulated(new RowSetEvent(noInitialCrset), 12);
+        assertEquals(EVENT_ROWSET_CHANGED, listener.getTag());
+
+        listener.clear();
+        noInitialCrset.rowSetPopulated(new RowSetEvent(noInitialCrset), 24);
+        assertEquals(EVENT_ROWSET_CHANGED, listener.getTag());
+    }
+
+    public void testRowSetPopulated_Two() throws Exception {
+        /*
+         * There are only 4 rows in database.
+         */
+        noInitialCrset = newNoInitialInstance();
+        Listener listener = new Listener();
+        noInitialCrset.addRowSetListener(listener);
+
+        listener.clear();
+        noInitialCrset.rowSetPopulated(new RowSetEvent(crset), 20);
+        assertEquals(EVENT_ROWSET_CHANGED, listener.getTag());
+        assertEquals(noInitialCrset, listener.getEventSource());
+
+        for (int i = 1; i <= 10; i++) {
+            listener.clear();
+            noInitialCrset.rowSetPopulated(new RowSetEvent(noInitialCrset), i);
+            assertEquals(EVENT_ROWSET_CHANGED, listener.getTag());
+        }
+
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        noInitialCrset.populate(rs);
+        noInitialCrset.setMaxRows(10);
+        noInitialCrset.setFetchSize(2);
+
+        listener.clear();
+        noInitialCrset.rowSetPopulated(new RowSetEvent(noInitialCrset), 2);
+        assertEquals(EVENT_ROWSET_CHANGED, listener.getTag());
+
+        listener.clear();
+        noInitialCrset.rowSetPopulated(new RowSetEvent(noInitialCrset), 3);
+        assertNull(listener.getTag());
+
+        listener.clear();
+        noInitialCrset.rowSetPopulated(new RowSetEvent(noInitialCrset), 4);
+        assertEquals(EVENT_ROWSET_CHANGED, listener.getTag());
+
+        listener.clear();
+        noInitialCrset.rowSetPopulated(new RowSetEvent(crset), 4);
+        assertEquals(EVENT_ROWSET_CHANGED, listener.getTag());
+        assertEquals(noInitialCrset, listener.getEventSource());
+    }
+
+    public void testRowSetPopulated_Three() throws Exception {
+        noInitialCrset = newNoInitialInstance();
+        Listener listener = new Listener();
+        noInitialCrset.addRowSetListener(listener);
+        noInitialCrset.setMaxRows(10);
+        noInitialCrset.setFetchSize(4);
+
+        try {
+            noInitialCrset.rowSetPopulated(new RowSetEvent(crset), 3);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+
+        listener.clear();
+        noInitialCrset.rowSetPopulated(new RowSetEvent(crset), 4);
+        assertEquals(EVENT_ROWSET_CHANGED, listener.getTag());
+
+        for (int i = 5; i <= 30; i++) {
+            listener.clear();
+            noInitialCrset.rowSetPopulated(new RowSetEvent(crset), i);
+            assertEquals(EVENT_ROWSET_CHANGED, listener.getTag());
+        }
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetSQLWarningTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetSQLWarningTest.java?rev=639200&r1=639199&r2=639200&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetSQLWarningTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetSQLWarningTest.java Thu Mar 20 01:32:08 2008
@@ -65,6 +65,13 @@
             noInitialCrset.getObject(1);
             assertNull(noInitialCrset.getWarnings());
         }
+
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        noInitialCrset.populate(rs);
+        assertNull(rs.getWarnings());
+        
+        assertTrue(noInitialCrset.first());
+        assertNull(rs.getWarnings());
     }
 
     public void testGetRowSetWarnings() throws Exception {

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=639200&r1=639199&r2=639200&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 Thu Mar 20 01:32:08 2008
@@ -32,9 +32,6 @@
 import javax.sql.rowset.CachedRowSet;
 
 public class CachedRowSetStreamTest extends CachedRowSetTestCase {
-    public static final String DERBY_URL_Create = "jdbc:derby:src/test/resources/STREAM;create=true";
-
-    public static final String DERBY_URL = "jdbc:derby:src/test/resources/STREAM";
 
     public final static int DEFAULT_COLUMN_COUNT = 3;
 

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetTestCase.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetTestCase.java?rev=639200&r1=639199&r2=639200&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetTestCase.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetTestCase.java Thu Mar 20 01:32:08 2008
@@ -137,8 +137,8 @@
         preStmt.setInt(1, 3);
         preStmt.setString(2, "test3");
         preStmt.setLong(3, 3333L);
-        preStmt.setBigDecimal(4, new BigDecimal(123));
-        preStmt.setBigDecimal(5, new BigDecimal(23));
+        preStmt.setBigDecimal(4, new BigDecimal("123.6521"));
+        preStmt.setBigDecimal(5, new BigDecimal("85.31"));
         preStmt.setInt(6, 13);
         preStmt.setFloat(7, 3.7F);
         preStmt.setFloat(8, 3.888F);

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetTransactionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetTransactionTest.java?rev=639200&r1=639199&r2=639200&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetTransactionTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetTransactionTest.java Thu Mar 20 01:32:08 2008
@@ -385,49 +385,23 @@
         crset.beforeFirst();
         index = 0;
 
-        if ("true".equals(System.getProperty("Testing Harmony"))) {
-            while (crset.next()) {
-                index++;
-                if (index == 4) {
-                    assertEquals("update4", crset.getString(2));
-                } else if (index == 5) {
-                    assertEquals("insert5", crset.getString(2));
-                } else if (index == 6) {
-                    assertEquals("insert66666666666", crset.getString(2));
-                }
-            }
-        } else {
-            while (crset.next()) {
-                index++;
-                if (index == 4) {
-                    assertEquals("update4", crset.getString(2));
-                } else if (index == 5) {
-                    assertEquals("insert66666666666", crset.getString(2));
-                } else if (index == 6) {
-                    assertEquals("insert5", crset.getString(2));
-                }
+        while (crset.next()) {
+            index++;
+            if (index == 4) {
+                assertEquals("update4", crset.getString(2));
+            } else if (index == 5) {
+                assertEquals("insert66666666666", crset.getString(2));
+            } else if (index == 6) {
+                assertEquals("insert5", crset.getString(2));
             }
         }
         assertEquals(6, index);
 
-        if ("true".equals(System.getProperty("Testing Harmony"))) {
-            try {
-                crset.acceptChanges();
-                fail("should throw exception");
-            } catch (SyncProviderException e) {
-                // expected
-            }
-
-            // check db
-            rs = st.executeQuery("SELECT * FROM USER_INFO");
-            index = 0;
-            while (rs.next()) {
-                index++;
-                if (index == 4) {
-                    assertEquals("test4", rs.getString(2));
-                }
-            }
-            assertEquals(4, index);
+        try {
+            crset.acceptChanges();
+            fail("should throw exception");
+        } catch (SyncProviderException e) {
+            // expected
         }
     }
 }