harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lvj...@apache.org
Subject svn commit: r638741 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/org/apache/harmony/sql/internal/nls/ main/java/org/apache/harmony/sql/internal/rowset/ test/java/org/apache/harmony/sql/tests/internal/rowset/
Date Wed, 19 Mar 2008 08:14:46 GMT
Author: lvjing
Date: Wed Mar 19 01:14:45 2008
New Revision: 638741

URL: http://svn.apache.org/viewvc?rev=638741&view=rev
Log:
Apply patch for HARMONY-5616,[classlib][sql] add event support in CachedRowSetImpl

Added:
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetListenerTest.java   (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/SyncResolverImpl.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/CachedRowSetPagingTest.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/CachedRowSetUpdateTest.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=638741&r1=638740&r2=638741&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties Wed Mar 19 01:14:45 2008
@@ -77,3 +77,8 @@
 rowset.14=Positioned updates not supported
 rowset.15=Columns being unset are not the same as set
 rowset.16=Not a valid command
+rowset.17=The Result Set is CONCUR_READ_ONLY
+rowset.18=None column is updated
+rowset.19=Populate data before calling
+rowset.20=Match columns should be greater than 0
+rowset.21=Not Updateable of the CurrentRow

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=638741&r1=638740&r2=638741&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java Wed Mar 19 01:14:45 2008
@@ -20,6 +20,8 @@
 import java.sql.SQLWarning;
 import java.util.BitSet;
 
+import org.apache.harmony.sql.internal.nls.Messages;
+
 public class CachedRow implements Cloneable {
     private Object[] columnData;
 
@@ -121,8 +123,8 @@
 
     public void updateObject(int columnIndex, Object x) throws SQLException {
         if (nonUpdateable) {
-            // TODO load message from resource file
-            throw new SQLException("Not Updateable of the CurrentRow");
+            // rowset.21=Not Updateable of the CurrentRow
+            throw new SQLException(Messages.getString("rowset.21")); //$NON-NLS-1$
         }
 
         columnData[columnIndex - 1] = x;

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=638741&r1=638740&r2=638741&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java Wed Mar 19 01:14:45 2008
@@ -143,7 +143,9 @@
 
     private Connection conn;
 
-    private static Map<Integer, Class> TYPE_MAPPING = initialTypeMapping();
+    private boolean isNotifyListener = true;
+
+    private static Map<Integer, Class<?>> TYPE_MAPPING = initialTypeMapping();
 
     public static final String PROVIDER_ID = "Apache Harmony HYOptimisticProvider"; //$NON-NLS-1$
 
@@ -152,8 +154,8 @@
         initialProperties();
     }
 
-    private static Map<Integer, Class> initialTypeMapping() {
-        HashMap<Integer, Class> map = new HashMap<Integer, Class>();
+    private static Map<Integer, Class<?>> initialTypeMapping() {
+        HashMap<Integer, Class<?>> map = new HashMap<Integer, Class<?>>();
         map.put(Integer.valueOf(Types.ARRAY), Array.class);
         map.put(Integer.valueOf(Types.BIGINT), Long.class);
         map.put(Integer.valueOf(Types.BINARY), byte[].class);
@@ -215,7 +217,7 @@
     public void acceptChanges() throws SyncProviderException {
         if (isCursorOnInsert) {
             // rowset.11=Illegal operation on an insert row
-            throw new SyncProviderException(Messages.getString("rowset.11"));
+            throw new SyncProviderException(Messages.getString("rowset.11")); //$NON-NLS-1$
         }
 
         Connection currentConn = null;
@@ -315,7 +317,9 @@
                 absolute(index);
             }
 
-            notifyRowSetChanged();
+            if (isNotifyListener) {
+                notifyRowSetChanged();
+            }
 
         } catch (SyncProviderException e) {
             throw e;
@@ -381,12 +385,12 @@
             output = (CachedRowSetImpl) super.clone();
             // BaseRowSet.params
             Field paramsField = output.getClass().getSuperclass()
-                    .getDeclaredField("params");
+                    .getDeclaredField("params"); //$NON-NLS-1$
             paramsField.setAccessible(true);
             paramsField.set(output, paramsHashtable);
             // BaseRowSet.listeners
             Field listenersField = output.getClass().getSuperclass()
-                    .getDeclaredField("listeners");
+                    .getDeclaredField("listeners"); //$NON-NLS-1$
             listenersField.setAccessible(true);
             listenersField.set(output, listeners);
             // BaseRowSet.map
@@ -438,14 +442,11 @@
 
             return output;
         } catch (CloneNotSupportedException e) {
-            // TODO add error message
-            throw new SQLException();
+            throw new SQLException(e.getMessage());
         } catch (NoSuchFieldException e) {
-            // TODO add error message
-            throw new SQLException();
+            throw new SQLException(e.getMessage());
         } catch (IllegalAccessException e) {
-            // TODO add error message
-            throw new SQLException();
+            throw new SQLException(e.getMessage());
         }
     }
 
@@ -479,22 +480,21 @@
         try {
             result = (RowSet) super.clone();
         } catch (CloneNotSupportedException e) {
-            // TODO add error message
-            throw new SQLException();
+            throw new SQLException(e.getMessage());
         }
 
         return result;
     }
 
-    public void execute(Connection conn) throws SQLException {
+    public void execute(Connection connection) throws SQLException {
         String localCommand = getCommand();
         if (localCommand == null || getParams() == null) {
             // rowset.16=Not a valid command
-            throw new SQLException(Messages.getString("rowset.16"));
+            throw new SQLException(Messages.getString("rowset.16")); //$NON-NLS-1$
         }
 
-        this.conn = conn;
-        PreparedStatement ps = conn.prepareStatement(localCommand);
+        conn = connection;
+        PreparedStatement ps = connection.prepareStatement(localCommand);
         Object[] params = getParams();
         for (int i = 0; i < params.length; i++)
             ps.setObject(i + 1, params[i]);
@@ -515,7 +515,15 @@
     }
 
     public int[] getKeyColumns() throws SQLException {
-        return keyCols == null ? null : keyCols.clone();
+        if (rows == null) {
+            // TODO add error messages
+            throw new SQLException();
+        }
+        if (keyCols == null) {
+            return new int[0];
+        }
+
+        return keyCols;
     }
 
     public ResultSet getOriginal() throws SQLException {
@@ -560,9 +568,8 @@
      */
     public boolean nextPage() throws SQLException {
         if (rows == null || nextPageRowIndex == -1 || getPageSize() == 0) {
-            // TODO load message from resource file
-            throw new SQLException(
-                    "Using execute() method populate data before calling");
+            // rowset.19=Populate data before calling
+            throw new SQLException(Messages.getString("rowset.19")); //$NON-NLS-1$
         }
 
         if (cachedResultSet == null) {
@@ -586,7 +593,10 @@
                     index++;
                 }
 
+                isNotifyListener = false;
                 doPopulate(rs, true);
+                notifyRowSetChanged();
+                isNotifyListener = true;
 
                 if (rows.size() == 0) {
                     return false;
@@ -602,7 +612,11 @@
 
         if (cachedResultSet.absolute(nextPageRowIndex)) {
             cachedResultSet.previous();
+
+            isNotifyListener = false;
             doPopulate(cachedResultSet, true);
+            notifyRowSetChanged();
+            isNotifyListener = true;
 
             if (rows.size() == 0) {
                 return false;
@@ -655,6 +669,7 @@
     }
 
     private void doPopulate(ResultSet rs, boolean isPaging) throws SQLException {
+        isNotifyListener = false;
         meta = copyMetaData(rs.getMetaData());
 
         columnCount = meta.getColumnCount();
@@ -698,6 +713,11 @@
 
         // recovery the states
         beforeFirst();
+
+        isNotifyListener = true;
+        if (isNotifyListener) {
+            notifyRowSetChanged();
+        }
     }
 
     // deep copy of ResultSetMetaData
@@ -744,9 +764,8 @@
 
     public boolean previousPage() throws SQLException {
         if (rows == null || previousPageRowIndex == -1 || getPageSize() == 0) {
-            // TODO load message from resource file
-            throw new SQLException(
-                    "Using execute() method populate data before calling");
+            // rowset.19=Populate data before calling
+            throw new SQLException(Messages.getString("rowset.19")); //$NON-NLS-1$
         }
 
         if (previousPageRowIndex == 0) {
@@ -788,7 +807,10 @@
                         && previousPageRowIndex - startIndex + 1 != prePageSize) {
                     setPageSize(previousPageRowIndex - startIndex + 1);
                 }
+                isNotifyListener = false;
                 doPopulate(rs, true);
+                notifyRowSetChanged();
+                isNotifyListener = true;
 
                 setPageSize(prePageSize);
 
@@ -834,8 +856,8 @@
     }
 
     public void release() throws SQLException {
-        // TODO send a rowSetChanged event to all listeners
         rows = new ArrayList<CachedRow>();
+        notifyRowSetChanged();
     }
 
     public void restoreOriginal() throws SQLException {
@@ -843,6 +865,7 @@
             return;
         }
 
+        isNotifyListener = false;
         List<CachedRow> insertedRows = new ArrayList<CachedRow>();
         for (CachedRow row : rows) {
             if (row.isInsert()) {
@@ -857,8 +880,8 @@
         deletedRowCount = 0;
 
         first();
-
-        // TODO fire rowSetChanged event
+        isNotifyListener = true;
+        notifyRowSetChanged();
     }
 
     public void rollback() throws SQLException {
@@ -881,7 +904,22 @@
     }
 
     public void setKeyColumns(int[] keys) throws SQLException {
-        keyCols = keys.clone();
+        if (keys == null) {
+            throw new NullPointerException();
+        }
+
+        if (rows == null) {
+            keyCols = keys.clone();
+        } else {
+            for (int key : keys) {
+                if (key <= 0 || key > columnCount) {
+                    // sql.27=Invalid column index :{0}
+                    throw new SQLException(Messages.getString("sql.27", key)); //$NON-NLS-1$
+                }
+            }
+
+            keyCols = keys.clone();
+        }
     }
 
     public void setMetaData(RowSetMetaData md) throws SQLException {
@@ -936,9 +974,9 @@
     public Collection<?> toCollection() throws SQLException {
         if (rows == null) {
             // sql.38=Object is invalid
-            throw new SQLException(Messages.getString("sql.38"));
+            throw new SQLException(Messages.getString("sql.38")); //$NON-NLS-1$
         }
-        List<Vector> list = new ArrayList<Vector>();
+        List<Vector<Object>> list = new ArrayList<Vector<Object>>();
         if (rows.size() > 0) {
             Vector<Object> vector = null;
             for (int i = 0; i < rows.size(); i++) {
@@ -956,12 +994,12 @@
     public Collection<?> toCollection(int column) throws SQLException {
         if (rows == null) {
             // sql.38=Object is invalid
-            throw new SQLException(Messages.getString("sql.38"));
+            throw new SQLException(Messages.getString("sql.38")); //$NON-NLS-1$
         }
 
         if (column <= 0 || column > columnCount) {
             // sql.42=Illegal Argument
-            throw new SQLException(Messages.getString("sql.42"));
+            throw new SQLException(Messages.getString("sql.42")); //$NON-NLS-1$
         }
 
         Vector<Object> vector = new Vector<Object>();
@@ -979,47 +1017,57 @@
 
     public void undoDelete() throws SQLException {
         if (isAfterLast() || isBeforeFirst()) {
-            // TODO add error messages
-            throw new SQLException();
+            // rowset.7=Not a valid cursor
+            throw new SQLException(Messages.getString("rowset.7")); //$NON-NLS-1$
         }
 
         if (currentRow != null && !currentRow.isDelete()) {
-            // TODO add error messages
-            throw new SQLException();
+            // rowset.0=Not a valid position
+            throw new SQLException(Messages.getString("rowset.0")); //$NON-NLS-1$
         }
 
         if (currentRow != null && currentRow.isDelete()) {
             currentRow.undoDelete();
             deletedRowCount--;
         }
+
+        if (isNotifyListener) {
+            notifyRowChanged();
+        }
     }
 
     public void undoInsert() throws SQLException {
-        // TODO notify listener
         checkValidRow();
         if (isCursorOnInsert) {
             // rowset.11=Illegal operation on an insert row
-            throw new SQLException(Messages.getString("rowset.11"));
+            throw new SQLException(Messages.getString("rowset.11")); //$NON-NLS-1$
         }
         if (!rowInserted()) {
             // rowset.4=Not an insert row
-            throw new SQLException(Messages.getString("rowset.4"));
+            throw new SQLException(Messages.getString("rowset.4")); //$NON-NLS-1$
         }
         rows.remove(currentRow);
         next();
+        if (isNotifyListener) {
+            notifyRowChanged();
+        }
     }
 
     public void undoUpdate() throws SQLException {
         checkValidRow();
         if (isCursorOnInsert && insertRow == null) {
             // rowset.11=Illegal operation on an insert row
-            throw new SQLException(Messages.getString("rowset.11"));
+            throw new SQLException(Messages.getString("rowset.11")); //$NON-NLS-1$
         }
         if (currentRow == insertRow) {
             currentRow = new CachedRow(new Object[columnCount]);
         } else if (rowUpdated()) {
             currentRow.restoreOriginal();
         }
+
+        if (isNotifyListener) {
+            notifyRowChanged();
+        }
     }
 
     public int[] getMatchColumnIndexes() throws SQLException {
@@ -1044,7 +1092,8 @@
     public void setMatchColumn(int columnIdx) throws SQLException {
         if (columnIdx < 0) {
             // TODO why is 0 valid? load message from resource files
-            throw new SQLException("Match columns should be greater than 0");
+            // rowset.20=Match columns should be greater than 0
+            throw new SQLException(Messages.getString("rowset.20")); //$NON-NLS-1$
         }
 
         if (matchColumnIndexes == null) {
@@ -1067,7 +1116,8 @@
         for (int i : columnIdxes) {
             if (i < 0) {
                 // TODO why is 0 valid? load message from resource files
-                throw new SQLException("Match columns should be greater than 0");
+                // rowset.20=Match columns should be greater than 0
+                throw new SQLException(Messages.getString("rowset.20")); //$NON-NLS-1$
             }
         }
 
@@ -1219,6 +1269,9 @@
             throw new SQLException(Messages.getString("rowset.0")); //$NON-NLS-1$
         }
         if (rows == null || rows.size() == 0) {
+            if (isNotifyListener) {
+                notifyCursorMoved();
+            }
             return false;
         }
 
@@ -1234,17 +1287,26 @@
         if (row <= 0) {
             currentRowIndex = 0;
             currentRow = null;
+            if (isNotifyListener) {
+                notifyCursorMoved();
+            }
             return false;
         }
 
         if (row > rows.size()) {
             currentRowIndex = rows.size() + 1;
             currentRow = null;
+            if (isNotifyListener) {
+                notifyCursorMoved();
+            }
             return false;
         }
 
         currentRowIndex = row;
         currentRow = rows.get(currentRowIndex - 1);
+        if (isNotifyListener) {
+            notifyCursorMoved();
+        }
         return true;
     }
 
@@ -1261,13 +1323,18 @@
     }
 
     public void cancelRowUpdates() 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 (rowUpdated()) {
             currentRow.restoreOriginal();
+            notifyRowChanged();
         }
     }
 
@@ -1295,12 +1362,15 @@
 
     public void deleteRow() throws SQLException {
         checkValidRow();
-        if (currentRow == insertRow) {
-            // TODO add error message
-            throw new SQLException();
+        if (isCursorOnInsert) {
+            // rowset.11=Illegal operation on an insert row
+            throw new SQLException(Messages.getString("rowset.11")); //$NON-NLS-1$
         }
         currentRow.setDelete();
         deletedRowCount++;
+        if (isNotifyListener) {
+            notifyRowChanged();
+        }
     }
 
     private void checkValidRow() throws SQLException {
@@ -1400,7 +1470,7 @@
             return (Array) obj;
         } catch (ClassCastException e) {
             // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10"));
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
     }
 
@@ -1454,7 +1524,7 @@
             return new BigDecimal(obj.toString());
         } catch (NumberFormatException e) {
             // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10"));
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
     }
 
@@ -1503,7 +1573,7 @@
             return (Blob) obj;
         } catch (ClassCastException e) {
             // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10"));
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
     }
 
@@ -1522,7 +1592,7 @@
             return Boolean.parseBoolean(obj.toString());
         } catch (Exception e) {
             // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10"));
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
     }
 
@@ -1541,7 +1611,7 @@
             return Byte.parseByte(obj.toString());
         } catch (NumberFormatException e) {
             // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10"));
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
     }
 
@@ -1560,7 +1630,7 @@
             return (byte[]) obj;
         } catch (ClassCastException e) {
             // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10"));
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
     }
 
@@ -1587,7 +1657,7 @@
             return new StringReader(new String((char[]) obj));
         }
         // rowset.10=Data Type Mismatch
-        throw new SQLException(Messages.getString("rowset.10"));
+        throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
     }
 
     public Reader getCharacterStream(String columnName) throws SQLException {
@@ -1605,7 +1675,7 @@
             return (Clob) obj;
         } catch (ClassCastException e) {
             // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10"));
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
     }
 
@@ -1619,7 +1689,7 @@
          */
         if (cursorName == null) {
             // rowset.14=Positioned updates not supported
-            throw new SQLException(Messages.getString("rowset.14"));
+            throw new SQLException(Messages.getString("rowset.14")); //$NON-NLS-1$
         }
         return cursorName;
     }
@@ -1638,10 +1708,10 @@
                 return new Date(((Timestamp) obj).getTime());
             }
             // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10"));
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         } catch (Exception e) {
             // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10"));
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
     }
 
@@ -1668,7 +1738,7 @@
             return Double.parseDouble(obj.toString());
         } catch (NumberFormatException e) {
             // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10"));
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
     }
 
@@ -1687,7 +1757,7 @@
             return Float.parseFloat(obj.toString());
         } catch (NumberFormatException e) {
             // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10"));
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
     }
 
@@ -1706,7 +1776,7 @@
             return Integer.parseInt(obj.toString());
         } catch (NumberFormatException e) {
             // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10"));
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
     }
 
@@ -1725,7 +1795,7 @@
             return Long.parseLong(obj.toString());
         } catch (NumberFormatException e) {
             // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10"));
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
     }
 
@@ -1740,11 +1810,11 @@
     public Object getObject(int columnIndex) throws SQLException {
         if (meta == null || currentRow == null) {
             // rowset.7=Not a valid cursor
-            throw new SQLException(Messages.getString("rowset.7"));
+            throw new SQLException(Messages.getString("rowset.7")); //$NON-NLS-1$
         }
         if (columnIndex <= 0 || columnIndex > columnCount) {
             // sql.27=Invalid column index :{0}
-            throw new SQLException(Messages.getString("sql.27", columnIndex));
+            throw new SQLException(Messages.getString("sql.27", columnIndex)); //$NON-NLS-1$
         }
         Object obj = currentRow.getObject(columnIndex);
         if (obj == null) {
@@ -1780,7 +1850,7 @@
             return (Ref) obj;
         } catch (Exception e) {
             // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10"));
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
     }
 
@@ -1824,7 +1894,7 @@
             return Short.parseShort(obj.toString());
         } catch (NumberFormatException e) {
             // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10"));
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
     }
 
@@ -1848,7 +1918,7 @@
             return obj.toString();
         } catch (Exception e) {
             // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10"));
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
     }
 
@@ -1878,10 +1948,10 @@
                 return new Time(((Timestamp) obj).getTime());
             }
             // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10"));
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         } catch (Exception e) {
             // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10"));
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
     }
 
@@ -1913,7 +1983,7 @@
             return Timestamp.valueOf(obj.toString());
         } catch (Exception e) {
             // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10"));
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
     }
 
@@ -1942,7 +2012,7 @@
             return (java.net.URL) obj;
         } catch (Exception e) {
             // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10"));
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
     }
 
@@ -1950,6 +2020,7 @@
         return getURL(getIndexByName(columnName));
     }
 
+    @SuppressWarnings("deprecation")
     public InputStream getUnicodeStream(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
@@ -2003,12 +2074,15 @@
             }
         }
         if (!isValueSet) {
-            // TODO add error message
-            throw new SQLException();
+            // rowset.18=None column is updated
+            throw new SQLException(Messages.getString("rowset.18")); //$NON-NLS-1$
         }
         insertRow.setInsert();
         rows.add(insertRow);
         insertRow = null;
+        if (isNotifyListener) {
+            notifyRowChanged();
+        }
     }
 
     public boolean isAfterLast() throws SQLException {
@@ -2141,8 +2215,9 @@
         checkValidRow();
         if (isCursorOnInsert) {
             // rowset.0=Not a valid position
-            throw new SQLException(Messages.getString("rowset.0"));
+            throw new SQLException(Messages.getString("rowset.0")); //$NON-NLS-1$
         }
+        currentRow.restoreOriginal();
     }
 
     public boolean relative(int moveRows) throws SQLException {
@@ -2228,7 +2303,7 @@
             currentRow = insertRow;
         }
 
-        Class type = columnTypes[columnIndex - 1];
+        Class<?> type = columnTypes[columnIndex - 1];
         if (type != null && !type.equals(String.class)
                 && !type.equals(byte[].class)) {
             // rowset.10=Data Type Mismatch
@@ -2280,7 +2355,7 @@
             currentRow = insertRow;
         }
 
-        Class type = columnTypes[columnIndex - 1];
+        Class<?> type = columnTypes[columnIndex - 1];
         if (type != null && !type.equals(byte[].class)) {
             // rowset.10=Data Type Mismatch
             throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
@@ -2353,7 +2428,7 @@
             currentRow = insertRow;
         }
 
-        Class type = columnTypes[columnIndex - 1];
+        Class<?> type = columnTypes[columnIndex - 1];
         if (type != null && !type.equals(String.class)
                 && !type.equals(byte[].class)) {
             // rowset.10=Data Type Mismatch
@@ -2458,7 +2533,7 @@
             throws SQLException {
         checkValidRow();
         checkColumnValid(columnIndex);
-        Class type = columnTypes[columnIndex - 1];
+        Class<?> type = columnTypes[columnIndex - 1];
         // ava.sql.Types.DECIMA or java.sql.Types.NUMERIC types
         if (type.equals(BigDecimal.class)) {
             /*
@@ -2501,13 +2576,18 @@
     }
 
     public void updateRow() throws SQLException {
-        if ((currentRow == insertRow)
-                || (getConcurrency() == (ResultSet.CONCUR_READ_ONLY))) {
-            // TODO add error messages
-            throw new SQLException();
+        if (isCursorOnInsert) {
+            // rowset.11=Illegal operation on an insert row
+            throw new SQLException(Messages.getString("rowset.11")); //$NON-NLS-1$
+        }
+        if (getConcurrency() == (ResultSet.CONCUR_READ_ONLY)) {
+            // rowset.17=The Result Set is CONCUR_READ_ONLY
+            throw new SQLException(Messages.getString("rowset.17")); //$NON-NLS-1$
         }
         currentRow.setUpdate();
-        notifyRowChanged();
+        if (isNotifyListener) {
+            notifyRowChanged();
+        }
     }
 
     public void updateShort(int columnIndex, short x) throws SQLException {
@@ -2554,6 +2634,7 @@
      * @param value
      *            the new value to be updated
      */
+    @SuppressWarnings("boxing")
     private Object convertUpdateValue(int columnIndex, Object value)
             throws SQLException {
 
@@ -2561,7 +2642,7 @@
             return value;
         }
 
-        Class type = columnTypes[columnIndex - 1];
+        Class<?> type = columnTypes[columnIndex - 1];
 
         /*
          * TODO if type == null, the type mapping is not supported by Harmony
@@ -2714,6 +2795,43 @@
 
         if (type.equals(BigDecimal.class)) {
             return value;
+        }
+
+        if (type.equals(Date.class)) {
+            if (value instanceof Timestamp) {
+                Timestamp timestamp = (Timestamp) value;
+                return new Date(timestamp.getTime());
+            }
+
+            if (value instanceof String) {
+                return value;
+            }
+        }
+
+        if (type.equals(Time.class)) {
+            if (value instanceof Timestamp) {
+                Timestamp timestamp = (Timestamp) value;
+                return new Time(timestamp.getTime());
+            }
+
+            if (value instanceof String) {
+                return value;
+            }
+        }
+
+        if (type.equals(Timestamp.class)) {
+            if (value instanceof Date) {
+                Date date = (Date) value;
+                return new Timestamp(date.getTime());
+            }
+            if (value instanceof Time) {
+                Time time = (Time) value;
+                return new Timestamp(time.getTime());
+            }
+
+            if (value instanceof String) {
+                return value;
+            }
         }
 
         // rowset.10=Data Type Mismatch

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/SyncResolverImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/SyncResolverImpl.java?rev=638741&r1=638740&r2=638741&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/SyncResolverImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/SyncResolverImpl.java Wed Mar 19 01:14:45 2008
@@ -36,7 +36,6 @@
 import java.util.List;
 import java.util.Map;
 
-import javax.sql.RowSetMetaData;
 import javax.sql.rowset.BaseRowSet;
 import javax.sql.rowset.spi.SyncResolver;
 
@@ -163,7 +162,7 @@
             }
         }
         // rowset.1=Not a valid column name
-        throw new SQLException(Messages.getString("rowset.1"));
+        throw new SQLException(Messages.getString("rowset.1")); //$NON-NLS-1$
     }
 
     public void execute() 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=638741&r1=638740&r2=638741&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java Wed Mar 19 01:14:45 2008
@@ -181,6 +181,27 @@
         assertEquals(DEFAULT_ROW_COUNT, crset.size());
         // before populate should return 0
         assertEquals(0, noInitialCrset.size());
+
+        crset.absolute(3);
+        assertFalse(crset.getShowDeleted());
+        crset.deleteRow();
+        assertEquals(DEFAULT_ROW_COUNT, crset.size());
+
+        crset = newNoInitialInstance();
+        rs = st.executeQuery("select * from USER_INFO");
+
+        crset.populate(rs);
+        crset.setShowDeleted(true);
+        assertTrue(crset.getShowDeleted());
+        assertEquals(DEFAULT_ROW_COUNT, crset.size());
+
+        crset.absolute(3);
+        crset.deleteRow();
+        assertEquals(DEFAULT_ROW_COUNT, crset.size());
+
+        crset.acceptChanges(conn);
+
+        assertEquals(DEFAULT_ROW_COUNT - 1, crset.size());
     }
 
     public void testAcceptChanges() throws SQLException {
@@ -314,8 +335,9 @@
         Listener listener = new Listener(); // a class implements RowSetListener
         crset.addRowSetListener(listener);
         crset.absolute(3); // move to the third row for testing
-        // TODO: when the cursor moved, notifyCursorMoved() should be called
-        // assertEquals("cursorMoved", listener.getTag());
+        assertEquals(CachedRowSetListenerTest.EVENT_CURSOR_MOVED, listener
+                .getTag());
+        listener.clear();
 
         CachedRowSet crsetShared = (CachedRowSet) crset.createShared();
         assertEquals("testUsername", crsetShared.getUsername());
@@ -340,8 +362,10 @@
         assertEquals("modify3", crsetShared.getString(2));
         assertEquals("modify3", crset.getString(2));
         crsetShared.updateRow();
+        listener.clear();
         crsetShared.acceptChanges();
-        assertEquals("rowSetChanged", listener.getTag());
+        assertEquals(CachedRowSetListenerTest.EVENT_ROWSET_CHANGED, listener
+                .getTag());
 
         // when move the duplicate's cursor, the original shouldn't be affected
         crsetShared.absolute(1);
@@ -350,7 +374,6 @@
     }
 
     public void testcreateCopyNoConstraints() throws Exception {
-
         crset.setConcurrency(ResultSet.CONCUR_READ_ONLY);
         crset.setType(ResultSet.TYPE_SCROLL_SENSITIVE);
         crset.setEscapeProcessing(false);
@@ -365,6 +388,10 @@
         crset.setMaxFieldSize(10);
         crset.setFetchDirection(ResultSet.FETCH_UNKNOWN);
 
+        /*
+         * NOTICE: when run on RI, if add the listener first, then it will go
+         * wrong when call createCopySchema().It's said that clone failed.
+         */
         CachedRowSet copy = crset.createCopyNoConstraints();
 
         // default is ResultSet.CONCUR_UPDATABLE
@@ -391,9 +418,8 @@
         // default is null
         assertNull(copy.getTypeMap());
 
-        if (crset.getKeyColumns() == null) {
-            assertNull(copy.getKeyColumns());
-        } else {
+        if (crset.getKeyColumns() != null && crset.getKeyColumns().length != 0) {
+
             int[] keyColumns = crset.getKeyColumns();
             int[] copyKeyColumns = copy.getKeyColumns();
 
@@ -413,31 +439,6 @@
         assertEquals(crset.isLast(), copy.isLast());
         assertEquals(crset.getRow(), copy.getRow());
 
-        // TODO uncomment them after implemented
-        // assertNotSame(crset.getWarnings(), copy.getWarnings());
-        // assertEquals(crset.getStatement(), copy.getStatement());
-        // try {
-        // assertEquals(crset.getCursorName(), copy.getCursorName());
-        // fail("Should throw SQLException");
-        // } catch (SQLException e) {
-        // // expected
-        // }
-        //
-        // try {
-        // assertEquals(crset.getMatchColumnIndexes(), copy
-        // .getMatchColumnIndexes());
-        // fail("Should throw SQLException");
-        // } catch (SQLException e) {
-        // // expected
-        // }
-        //
-        // try {
-        // assertEquals(crset.getMatchColumnNames(), copy
-        // .getMatchColumnNames());
-        // } catch (SQLException e) {
-        // // expected
-        // }
-
         assertEquals(crset.isReadOnly(), copy.isReadOnly());
         assertEquals(crset.size(), copy.size());
 
@@ -485,7 +486,12 @@
         assertEquals(DERBY_URL, crset.getUrl());
         assertNull(crset.getUsername());
         assertTrue(crset.getEscapeProcessing());
-        assertNull(crset.getKeyColumns());
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertNotNull(crset.getKeyColumns());
+            assertEquals(0, crset.getKeyColumns().length);
+        } else {
+            assertNull(crset.getKeyColumns());
+        }
 
         // set value
         crset.setCommand("testCommand");
@@ -579,8 +585,6 @@
         // compare the meta data between the duplicate and the original
         assertNotSame(crset.getMetaData(), crsetCopySchema.getMetaData());
         assertNotSame(crset.getOriginal(), crsetCopySchema.getOriginal());
-        // assertNotSame(crset.getSyncProvider(), crsetCopySchema
-        // .getSyncProvider());
 
         assertEquals("USER_INFO", crset.getTableName());
         assertEquals("USER_INFO", rsmdCopySchema.getTableName(1));
@@ -589,7 +593,12 @@
         // check the primary key
         // TODO: RI doesn't evalute the keyColumns. The value of
         // crset.getKeyColumns() is null.
-        assertEquals(crset.getKeyColumns(), crsetCopySchema.getKeyColumns());
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertNotNull(crset.getKeyColumns());
+            assertEquals(0, crset.getKeyColumns().length);
+        } else {
+            assertNull(crset.getKeyColumns());
+        }
 
         // check the attributes in the duplicate. These are supposed to be the
         // same as the original
@@ -613,7 +622,7 @@
         // TODO: in the Harmony implementation, need to call notifyRowSetChanged
         // at the suitable place
         // assertEquals("rowSetChanged", listener.getTag());
-        listener.setTag(null);
+        listener.clear();
         // the move of the original's cursor shouldn't affect the duplicate
         crset.next();
         assertNull(listener.getTag());
@@ -737,9 +746,7 @@
                 .getEscapeProcessing());
         assertEquals(crset.getFetchDirection(), crsetCopy.getFetchDirection());
         assertEquals(crset.getFetchSize(), crsetCopy.getFetchSize());
-        if (crset.getKeyColumns() == null) {
-            assertNull(crsetCopy.getKeyColumns());
-        } else {
+        if (crset.getKeyColumns() != null && crset.getKeyColumns().length != 0) {
             int[] keyColumns = crset.getKeyColumns();
             int[] copyKeyColumns = crsetCopy.getKeyColumns();
 
@@ -853,7 +860,8 @@
 
         CachedRowSet crsetCopy = crset.createCopy();
         crsetCopy.execute();
-        assertEquals(DEFAULT_COLUMN_COUNT, crsetCopy.getMetaData().getColumnCount());
+        assertEquals(DEFAULT_COLUMN_COUNT, crsetCopy.getMetaData()
+                .getColumnCount());
         assertTrue(crsetCopy.next());
         assertEquals("test3", crsetCopy.getString(2));
         assertFalse(crsetCopy.next());
@@ -1185,7 +1193,16 @@
         assertEquals(ResultSet.FETCH_FORWARD, noInitialCrset
                 .getFetchDirection());
         assertEquals(0, noInitialCrset.getFetchSize());
-        assertNull(noInitialCrset.getKeyColumns());
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            try {
+                noInitialCrset.getKeyColumns();
+                fail("Should throw SQLException");
+            } catch (SQLException e) {
+                // expected
+            }
+        } else {
+            assertNull(noInitialCrset.getKeyColumns());
+        }
 
         assertEquals(0, noInitialCrset.getMaxFieldSize());
         assertEquals(0, noInitialCrset.getMaxRows());
@@ -2358,6 +2375,20 @@
         noInitialCrset.refreshRow();
         assertEquals(3, noInitialCrset.getInt(1));
         assertEquals("test3", noInitialCrset.getString(2));
+
+        noInitialCrset.updateString(2, "update33");
+        noInitialCrset.refreshRow();
+        assertEquals("test3", noInitialCrset.getString(2));
+
+        noInitialCrset.updateString(2, "update33");
+        noInitialCrset.updateRow();
+        noInitialCrset.beforeFirst();
+        assertTrue(noInitialCrset.absolute(3));
+        assertEquals("update33", noInitialCrset.getString(2));
+        assertTrue(noInitialCrset.rowUpdated());
+        noInitialCrset.refreshRow();
+        assertEquals("test3", noInitialCrset.getString(2));
+        assertFalse(noInitialCrset.rowUpdated());
     }
 
     public void testToCollection() throws Exception {
@@ -2567,34 +2598,195 @@
         }
     }
 
-    public class Listener implements RowSetListener, Cloneable {
+    public void testGetKeyColumns() throws Exception {
+        int[] columns = null;
+        /*
+         * TODO spec says SQLException should be thrown when CachedRowSet object
+         * is empty, while RI return null, Harmony follow spec
+         */
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            try {
+                columns = noInitialCrset.getKeyColumns();
+                fail("Should throw SQLException");
+            } catch (SQLException e) {
+                // expected
+            }
+
+        } else {
+            columns = noInitialCrset.getKeyColumns();
+            assertNull(columns);
+        }
+
+        columns = crset.getKeyColumns();
+
+        /*
+         * TODO spec says empty array should be return when on key columns is
+         * setted, while RI return null, Harmony follow spec
+         */
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertNotNull(columns);
+            assertEquals(0, columns.length);
+        } else {
+            assertNull(columns);
+        }
+
+    }
+
+    public void testSetKeyColumns() throws Exception {
+        try {
+            noInitialCrset.setKeyColumns(null);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        int[] columns = null;
+
+        noInitialCrset.setKeyColumns(new int[0]);
+        noInitialCrset.setKeyColumns(new int[] { 1, 100 });
 
-        private String tag = null;
+        rs = st.executeQuery("select * from user_info");
 
-        public void cursorMoved(RowSetEvent theEvent) {
-            tag = "cursorMoved";
+        noInitialCrset.populate(rs);
+
+        /*
+         * populate doesn't initial keyColumns, it's not reasonable, but we
+         * follow RI here
+         */
+        columns = noInitialCrset.getKeyColumns();
+        assertNotNull(columns);
+        assertEquals(2, columns.length);
+        assertEquals(1, columns[0]);
+        assertEquals(100, columns[1]);
+
+        try {
+            crset.setKeyColumns(null);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
         }
 
-        public void rowChanged(RowSetEvent theEvent) {
-            tag = "rowChanged";
+        crset.setKeyColumns(new int[0]);
+        columns = crset.getKeyColumns();
+        assertNotNull(columns);
+        assertEquals(0, columns.length);
+
+        try {
+            crset.setKeyColumns(new int[] { 1, 100 });
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Invalid column index 100
         }
 
-        public void rowSetChanged(RowSetEvent theEvent) {
-            tag = "rowSetChanged";
+        crset.setKeyColumns(new int[] { 1, 2 });
+        columns = crset.getKeyColumns();
+        assertNotNull(columns);
+        assertEquals(2, columns.length);
+        assertEquals(1, columns[0]);
+        assertEquals(2, columns[1]);
+
+        try {
+            crset.getMatchColumnIndexes();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+
+        crset.setMatchColumn(3);
+        int[] matchColumns = crset.getMatchColumnIndexes();
+        assertEquals(3, matchColumns[0]);
+        for (int i = 1; i < 10; ++i) {
+            assertEquals(-1, matchColumns[i]);
         }
 
-        public String getTag() {
-            return tag;
+        crset.setKeyColumns(new int[] { 4, 5 });
+        columns = crset.getKeyColumns();
+        assertNotNull(columns);
+        assertEquals(2, columns.length);
+        assertEquals(4, columns[0]);
+        assertEquals(5, columns[1]);
+
+        // setKeyColumns doesn't effect match columns
+        matchColumns = crset.getMatchColumnIndexes();
+        assertEquals(3, matchColumns[0]);
+        for (int i = 1; i < 10; ++i) {
+            assertEquals(-1, matchColumns[i]);
+        }
+
+        int[] args = new int[] { 6, 7 };
+        crset.setKeyColumns(args);
+        columns = crset.getKeyColumns();
+        assertNotNull(columns);
+        assertEquals(2, columns.length);
+        assertEquals(6, columns[0]);
+        assertEquals(7, columns[1]);
+
+        assertNotSame(args, columns);
+
+        // getKeyColumns doesn't do clone
+        assertSame(crset.getKeyColumns(), crset.getKeyColumns());
+        columns = crset.getKeyColumns();
+        assertEquals(6, columns[0]);
+        assertEquals(7, columns[1]);
+
+        columns[1] = 8;
+
+        args = crset.getKeyColumns();
+        assertEquals(8, args[1]);
+
+    }
+}
+
+class Listener implements RowSetListener, Cloneable {
+
+    private String tag = null;
+
+    private boolean isPrint = false;
+
+    private int count = 0;
+
+    public void cursorMoved(RowSetEvent theEvent) {
+        if (isPrint) {
+            System.out.println("cursorMoved");
         }
+        tag = CachedRowSetListenerTest.EVENT_CURSOR_MOVED;
+        count++;
+    }
 
-        public void setTag(String tag) {
-            this.tag = tag;
+    public void rowChanged(RowSetEvent theEvent) {
+        if (isPrint) {
+            System.out.println("rowChanged");
         }
+        tag = CachedRowSetListenerTest.EVENT_ROW_CHANGED;
+        count++;
+    }
 
-        public Listener clone() throws CloneNotSupportedException {
-            Listener listener = (Listener) super.clone();
-            listener.tag = tag;
-            return listener;
+    public void rowSetChanged(RowSetEvent theEvent) {
+        if (isPrint) {
+            System.out.println("rowSetChanged");
         }
+        tag = CachedRowSetListenerTest.EVENT_ROWSET_CHANGED;
+        count++;
+    }
+
+    public String getTag() {
+        return tag;
+    }
+
+    public void clear() {
+        tag = null;
+    }
+
+    public void setPrint(boolean isPrint) {
+        this.isPrint = isPrint;
+    }
+
+    public int getCount() {
+        return count;
+    }
+
+    public Listener clone() throws CloneNotSupportedException {
+        Listener listener = (Listener) super.clone();
+        return listener;
     }
 }

Added: 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=638741&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetListenerTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetListenerTest.java Wed Mar 19 01:14:45 2008
@@ -0,0 +1,300 @@
+/* 
+ * 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;
+
+public class CachedRowSetListenerTest extends CachedRowSetTestCase {
+
+    public static final String EVENT_CURSOR_MOVED = "cursorMoved";
+
+    public static final String EVENT_ROW_CHANGED = "rowChanged";
+
+    public static final String EVENT_ROWSET_CHANGED = "rowSetChanged";
+
+    public void testCursorMoved() throws Exception {
+        Listener listener = new Listener();
+        noInitialCrset = newNoInitialInstance();
+        noInitialCrset.addRowSetListener(listener);
+        assertNull(listener.getTag());
+
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        noInitialCrset.populate(rs);
+
+        /*
+         * absolute() - cursorMoved
+         */
+        assertTrue(noInitialCrset.absolute(1));
+        assertEquals(EVENT_CURSOR_MOVED, listener.getTag());
+        listener.clear();
+
+        assertTrue(noInitialCrset.absolute(1));
+        assertEquals(EVENT_CURSOR_MOVED, listener.getTag());
+        listener.clear();
+
+        /*
+         * relative() - cursorMoved
+         */
+        assertTrue(noInitialCrset.relative(1));
+        assertEquals(EVENT_CURSOR_MOVED, listener.getTag());
+        listener.clear();
+
+        assertTrue(noInitialCrset.relative(1));
+        assertEquals(EVENT_CURSOR_MOVED, listener.getTag());
+        listener.clear();
+
+        /*
+         * next() - cursorMoved
+         */
+        assertTrue(noInitialCrset.next());
+        assertEquals(EVENT_CURSOR_MOVED, listener.getTag());
+        listener.clear();
+
+        /*
+         * previous() - cursorMoved
+         */
+        assertTrue(noInitialCrset.previous());
+        assertEquals(EVENT_CURSOR_MOVED, listener.getTag());
+        listener.clear();
+
+        /*
+         * first() - cursorMoved
+         */
+        assertTrue(noInitialCrset.first());
+        assertEquals(EVENT_CURSOR_MOVED, listener.getTag());
+        listener.clear();
+
+        /*
+         * last() - cursorMoved
+         */
+        assertTrue(noInitialCrset.last());
+        assertEquals(EVENT_CURSOR_MOVED, listener.getTag());
+        listener.clear();
+
+        assertTrue(noInitialCrset.last());
+        assertEquals(EVENT_CURSOR_MOVED, listener.getTag());
+        listener.clear();
+
+        /*
+         * beforeFirst() - cursorMoved
+         */
+        noInitialCrset.beforeFirst();
+        assertEquals(EVENT_CURSOR_MOVED, listener.getTag());
+        listener.clear();
+
+        noInitialCrset.beforeFirst();
+        assertEquals(EVENT_CURSOR_MOVED, listener.getTag());
+        listener.clear();
+
+        /*
+         * afterLast() - cursorMoved
+         */
+        noInitialCrset.afterLast();
+        assertEquals(EVENT_CURSOR_MOVED, listener.getTag());
+        listener.clear();
+    }
+
+    public void testRowChanged() throws Exception {
+        Listener listener = new Listener();
+        noInitialCrset = newNoInitialInstance();
+        noInitialCrset.addRowSetListener(listener);
+        assertNull(listener.getTag());
+
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        noInitialCrset.populate(rs);
+
+        assertTrue(noInitialCrset.absolute(1));
+        listener.clear();
+        noInitialCrset.setOriginalRow();
+        assertNull(listener.getTag());
+
+        /*
+         * updateRow() - rowChanged
+         */
+        assertTrue(noInitialCrset.absolute(3));
+        listener.clear();
+        noInitialCrset.updateString(2, "abc");
+        assertNull(listener.getTag());
+        noInitialCrset.updateRow();
+        assertEquals(EVENT_ROW_CHANGED, listener.getTag());
+
+        assertTrue(noInitialCrset.next());
+        listener.clear();
+        noInitialCrset.updateRow();
+        assertEquals(EVENT_ROW_CHANGED, listener.getTag());
+        listener.clear();
+
+        noInitialCrset.setOriginalRow();
+        assertNull(listener.getTag());
+
+        /*
+         * deleteRow() - rowChanged
+         */
+        noInitialCrset.deleteRow();
+        assertEquals(EVENT_ROW_CHANGED, listener.getTag());
+
+        /*
+         * insertRow() - rowChanged
+         */
+        assertTrue(noInitialCrset.first());
+        listener.clear();
+        noInitialCrset.moveToInsertRow();
+        noInitialCrset.updateInt(1, 9);
+        noInitialCrset.updateString(2, "insert");
+        assertNull(listener.getTag());
+        noInitialCrset.insertRow();
+        assertEquals(EVENT_ROW_CHANGED, listener.getTag());
+        noInitialCrset.moveToCurrentRow();
+        listener.clear();
+
+        assertTrue(noInitialCrset.absolute(3));
+        listener.clear();
+        noInitialCrset.refreshRow();
+        noInitialCrset.updateString(2, "update3");
+        noInitialCrset.refreshRow();
+        assertNull(listener.getTag());
+        noInitialCrset.updateString(2, "update3");
+        noInitialCrset.updateRow();
+        listener.clear();
+        noInitialCrset.refreshRow();
+        assertNull(listener.getTag());
+
+        /*
+         * undoDelete() - rowChanged
+         */
+        crset.addRowSetListener(listener);
+        crset.setShowDeleted(true);
+        assertTrue(crset.absolute(3));
+        crset.deleteRow();
+        assertTrue(crset.rowDeleted());
+        assertTrue(crset.absolute(1));
+        assertTrue(crset.absolute(3));
+        assertEquals(3, crset.getInt(1));
+        assertTrue(crset.rowDeleted());
+        listener.clear();
+        crset.undoDelete();
+        assertEquals(EVENT_ROW_CHANGED, listener.getTag());
+        assertFalse(crset.rowDeleted());
+
+        /*
+         * undoUpdate() - rowChanged
+         */
+        assertTrue(crset.absolute(3));
+        crset.moveToInsertRow();
+        crset.updateInt(1, 10);
+        crset.updateString(2, "insert10");
+        crset.insertRow();
+        crset.moveToCurrentRow();
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertTrue(crset.last());
+        } else {
+            assertTrue(crset.next());
+        }
+        assertEquals("insert10", crset.getString(2));
+        assertTrue(crset.rowInserted());
+        listener.clear();
+        crset.undoUpdate();
+        assertEquals(EVENT_ROW_CHANGED, listener.getTag());
+
+        /*
+         * undoInsert() - rowChanged
+         */
+        assertTrue(crset.absolute(3));
+        crset.moveToInsertRow();
+        crset.updateInt(1, 11);
+        crset.updateString(2, "insert11");
+        crset.insertRow();
+        crset.moveToCurrentRow();
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertTrue(crset.last());
+        } else {
+            assertTrue(crset.next());
+        }
+        assertTrue(crset.rowInserted());
+        listener.clear();
+        crset.undoInsert();
+        assertEquals(EVENT_ROW_CHANGED, listener.getTag());
+    }
+
+    public void testRowSetChanged() throws Exception {
+        Listener listener = new Listener();
+        noInitialCrset = newNoInitialInstance();
+        noInitialCrset.addRowSetListener(listener);
+
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        assertNull(listener.getTag());
+        /*
+         * populate() - rowSetChanged
+         */
+        noInitialCrset.populate(rs);
+        assertEquals(EVENT_ROWSET_CHANGED, listener.getTag());
+        listener.clear();
+
+        /*
+         * acceptChanges(Connection) - rowSetChanged
+         */
+        noInitialCrset.acceptChanges(conn);
+        assertEquals(EVENT_ROWSET_CHANGED, listener.getTag());
+        listener.clear();
+
+        /*
+         * acceptChanges() - rowSetChanged
+         */
+        noInitialCrset.setUrl(DERBY_URL);
+        noInitialCrset.setCommand("SELECT * FROM USER_INFO");
+        noInitialCrset.acceptChanges();
+        assertEquals(EVENT_ROWSET_CHANGED, listener.getTag());
+        listener.clear();
+
+        /*
+         * execute() - rowSetChanged
+         */
+        noInitialCrset.execute();
+        assertEquals(EVENT_ROWSET_CHANGED, listener.getTag());
+        listener.clear();
+
+        /*
+         * execute(Connection) - rowSetChanged
+         */
+        noInitialCrset.execute(conn);
+        assertEquals(EVENT_ROWSET_CHANGED, listener.getTag());
+        listener.clear();
+
+        assertTrue(noInitialCrset.first());
+        listener.clear();
+        noInitialCrset.getOriginalRow();
+        assertNull(listener.getTag());
+
+        /*
+         * nextPage() and previousPage() - rowSetChanged. See
+         * CachedRowSetPagingTest.
+         */
+
+        /*
+         * restoreOriginal() - rowSetChanged
+         */
+        noInitialCrset.restoreOriginal();
+        assertEquals(EVENT_ROWSET_CHANGED, listener.getTag());
+        listener.clear();
+
+        /*
+         * release() - rowSetChanged
+         */
+        noInitialCrset.release();
+        assertEquals(EVENT_ROWSET_CHANGED, listener.getTag());
+        listener.clear();
+    }
+}

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

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetPagingTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetPagingTest.java?rev=638741&r1=638740&r2=638741&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetPagingTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetPagingTest.java Wed Mar 19 01:14:45 2008
@@ -31,6 +31,8 @@
     public void testPagingInMemory() throws Exception {
         insertMoreData(10);
         crset = newNoInitialInstance();
+        Listener listener = new Listener();
+        crset.addRowSetListener(listener);
 
         st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                 ResultSet.CONCUR_UPDATABLE);
@@ -52,7 +54,10 @@
             assertEquals(i, crset.getInt(1));
         }
 
+        listener.clear();
         assertTrue(crset.nextPage());
+        assertEquals(CachedRowSetListenerTest.EVENT_ROWSET_CHANGED, listener
+                .getTag());
 
         crset.beforeFirst();
 
@@ -71,6 +76,8 @@
         insertMoreData(4);
 
         crset = newNoInitialInstance();
+        Listener listener = new Listener();
+        crset.addRowSetListener(listener);
 
         st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                 ResultSet.CONCUR_UPDATABLE);
@@ -118,9 +125,14 @@
 
         assertFalse(crset.next());
         assertTrue(crset.isAfterLast());
+        listener.clear();
         assertFalse(crset.nextPage());
+        assertNull(listener.getTag());
 
+        listener.clear();
         assertTrue(crset.previousPage());
+        assertEquals(CachedRowSetListenerTest.EVENT_ROWSET_CHANGED, listener
+                .getTag());
 
         if (!"true".equals(System.getProperty("Testing Harmony"))) {
             // RI need previousPage one more time

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=638741&r1=638740&r2=638741&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 Wed Mar 19 01:14:45 2008
@@ -256,4 +256,7 @@
         crset.setUrl(DERBY_URL);
     }
 
+    public void testTestCase() throws Exception {
+        // do nothing
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetUpdateTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetUpdateTest.java?rev=638741&r1=638740&r2=638741&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetUpdateTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetUpdateTest.java Wed Mar 19 01:14:45 2008
@@ -169,6 +169,8 @@
 
     public void testCancelRowUpdates() throws Exception {
         noInitialCrset = newNoInitialInstance();
+        Listener listener = new Listener();
+        noInitialCrset.addRowSetListener(listener);
         try {
             noInitialCrset.cancelRowUpdates();
             fail("should throw exception");
@@ -214,7 +216,9 @@
         assertTrue(noInitialCrset.absolute(3));
         noInitialCrset.updateString(2, "update3");
         // call cancelRowUpdates() before updateRow(), no effect here
+        listener.clear();
         noInitialCrset.cancelRowUpdates();
+        assertNull(listener.getTag());
         assertEquals("update3", noInitialCrset.getString(2));
         noInitialCrset.updateRow();
         noInitialCrset.acceptChanges(conn);
@@ -226,7 +230,11 @@
         noInitialCrset.updateRow();
         assertEquals("update4", noInitialCrset.getString(2));
         // call cancelRowUpdates() after updateRow(), it works here
+
+        listener.clear();
         noInitialCrset.cancelRowUpdates();
+        assertEquals(CachedRowSetListenerTest.EVENT_ROW_CHANGED, listener
+                .getTag());
         assertEquals("test4", noInitialCrset.getString(2));
         noInitialCrset.acceptChanges(conn);
         assertEquals("test4", noInitialCrset.getString(2));
@@ -841,7 +849,24 @@
 
         crset.updateBigDecimal(2, new BigDecimal(12));
         assertEquals(new BigDecimal(12).toString(), crset.getObject(2));
-        
+
+        crset.updateLong(3, 444423L);
+        crset.updateBigDecimal(4, new BigDecimal(12));
+        crset.updateBigDecimal(5, new BigDecimal(23));
+        crset.updateLong(6, 33);
+        crset.updateFloat(7, 4.8F);
+        crset.updateFloat(8, 4.888F);
+        crset.updateDouble(9, 4.9999);
+        crset.updateDate(10, new Date(965324512));
+        crset.updateTime(11, new Time(452368512));
+        crset.updateTimestamp(12, new Timestamp(874532105));
+    }
+
+    public void testUpdateDate() throws Exception {
+        crset.moveToInsertRow();
+
+        crset.updateInt(1, 50);
+        crset.updateString(2, "test100");
         crset.updateLong(3, 444423L);
         crset.updateBigDecimal(4, new BigDecimal(12));
         crset.updateBigDecimal(5, new BigDecimal(23));
@@ -849,8 +874,155 @@
         crset.updateFloat(7, 4.8F);
         crset.updateFloat(8, 4.888F);
         crset.updateDouble(9, 4.9999);
+
         crset.updateDate(10, new Date(965324512));
+        try {
+            crset.updateInt(10, 12345);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Data Type Mismatch
+        }
+
+        try {
+            crset.updateLong(10, 123456789L);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Data Type Mismatch
+        }
+
+        try {
+            crset.updateDouble(10, 123456789.2398);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Data Type Mismatch
+        }
+
+        try {
+            crset.updateTime(10, new Time(452368512));
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Data Type Mismatch
+        }
+
+        crset.updateString(10, "test");
+        assertTrue(crset.getObject(10) instanceof String);
+        assertEquals("test", crset.getObject(10));
+
+        crset.updateTimestamp(10, new Timestamp(874532105));
+        assertTrue(crset.getObject(10) instanceof Date);
+        assertEquals(new Timestamp(874532105).getTime(), crset.getDate(10)
+                .getTime());
+
         crset.updateTime(11, new Time(452368512));
         crset.updateTimestamp(12, new Timestamp(874532105));
+    }
+
+    public void testUpdateTime() throws Exception {
+        crset.moveToInsertRow();
+
+        crset.updateInt(1, 50);
+        crset.updateString(2, "test100");
+        crset.updateLong(3, 444423L);
+        crset.updateBigDecimal(4, new BigDecimal(12));
+        crset.updateBigDecimal(5, new BigDecimal(23));
+        crset.updateLong(6, 33);
+        crset.updateFloat(7, 4.8F);
+        crset.updateFloat(8, 4.888F);
+        crset.updateDouble(9, 4.9999);
+        crset.updateDate(10, new Date(965324512));
+
+        crset.updateTime(11, new Time(452368512));
+
+        try {
+            crset.updateInt(11, 12345);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Data Type Mismatch
+        }
+
+        try {
+            crset.updateLong(11, 123456789L);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Data Type Mismatch
+        }
+
+        try {
+            crset.updateDouble(11, 123456789.2398);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Data Type Mismatch
+        }
+
+        try {
+            crset.updateDate(11, new Date(452368512));
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Data Type Mismatch
+        }
+
+        crset.updateString(11, "test");
+        assertTrue(crset.getObject(11) instanceof String);
+        assertEquals("test", crset.getObject(11));
+
+        crset.updateTimestamp(11, new Timestamp(874532105));
+        assertTrue(crset.getObject(11) instanceof Time);
+        assertEquals(new Timestamp(874532105).getTime(), crset.getTime(11)
+                .getTime());
+
+        crset.updateTimestamp(12, new Timestamp(874532105));
+    }
+
+    public void testUpdateTimestamp() throws Exception {
+        crset.moveToInsertRow();
+
+        crset.updateInt(1, 50);
+        crset.updateString(2, "test100");
+        crset.updateLong(3, 444423L);
+        crset.updateBigDecimal(4, new BigDecimal(12));
+        crset.updateBigDecimal(5, new BigDecimal(23));
+        crset.updateLong(6, 33);
+        crset.updateFloat(7, 4.8F);
+        crset.updateFloat(8, 4.888F);
+        crset.updateDouble(9, 4.9999);
+        crset.updateDate(10, new Date(965324512));
+        crset.updateTime(11, new Time(452368512));
+
+        crset.updateTimestamp(12, new Timestamp(874532105));
+
+        try {
+            crset.updateInt(12, 12345);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Data Type Mismatch
+        }
+
+        try {
+            crset.updateLong(12, 123456789L);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Data Type Mismatch
+        }
+
+        try {
+            crset.updateDouble(12, 123456789.2398);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Data Type Mismatch
+        }
+
+        crset.updateString(12, "test");
+        assertTrue(crset.getObject(12) instanceof String);
+        assertEquals("test", crset.getObject(12));
+
+        crset.updateDate(12, new Date(452368512));
+        assertTrue(crset.getObject(12) instanceof Timestamp);
+        assertEquals(new Date(452368512).getTime(), crset.getTimestamp(12)
+                .getTime());
+
+        crset.updateTime(12, new Time(874532105));
+        assertTrue(crset.getObject(12) instanceof Timestamp);
+        assertEquals(new Timestamp(874532105).getTime(), crset.getTimestamp(12)
+                .getTime());
     }
 }



Mime
View raw message