harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r649421 - 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 Fri, 18 Apr 2008 09:17:53 GMT
Author: tonywu
Date: Fri Apr 18 02:17:50 2008
New Revision: 649421

URL: http://svn.apache.org/viewvc?rev=649421&view=rev
Log:
Apply patch for HARMONY-5762 ([classlib][sql][rowset] - Disable listener in JoinRowSetImpl and refactor the getXXX methods in CachedRowSetImpl)

Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/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/JoinRowSetImpl.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/CachedRowSetStreamTest.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JdbcRowSetTest.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetOtherTest.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetTest.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/XmlReaderTest.java

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties?rev=649421&r1=649420&r2=649421&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 Fri Apr 18 02:17:50 2008
@@ -98,3 +98,5 @@
 rowset.35=Not a valid match olumn index
 rowset.36=Number of elements of two arrays don't equal
 rowset.37=The RowSet doesn't set the table name
+rowset.38=This type of join is not supported
+rowset.39=The table name is null

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=649421&r1=649420&r2=649421&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 Fri Apr 18 02:17:50 2008
@@ -17,7 +17,6 @@
 package org.apache.harmony.sql.internal.rowset;
 
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Reader;
@@ -66,7 +65,6 @@
 import javax.sql.rowset.CachedRowSet;
 import javax.sql.rowset.RowSetMetaDataImpl;
 import javax.sql.rowset.RowSetWarning;
-import javax.sql.rowset.WebRowSet;
 import javax.sql.rowset.serial.SerialArray;
 import javax.sql.rowset.serial.SerialBlob;
 import javax.sql.rowset.serial.SerialClob;
@@ -232,6 +230,7 @@
             currentConn = retrieveConnection();
             currentConn.setTypeMap(getTypeMap());
             acceptChanges(currentConn);
+            currentConn.commit();
         } catch (SQLException e) {
             try {
                 if (currentConn != null) {
@@ -247,7 +246,6 @@
             conn = preConn;
             if (currentConn != null) {
                 try {
-                    currentConn.commit();
                     currentConn.close();
                 } catch (SQLException ex) {
                     SyncProviderException spe = new SyncProviderException();
@@ -258,29 +256,39 @@
         }
     }
 
-    public void acceptChanges(Connection con) throws SyncProviderException {
+    public void acceptChanges(Connection connection)
+            throws SyncProviderException {
         if (isCursorOnInsert) {
             // rowset.11=Illegal operation on an insert row
             throw new SyncProviderException(Messages.getString("rowset.11")); //$NON-NLS-1$
         }
 
-        conn = con;
+        // Follow RI to assign conn before checking whether conn is null
+        conn = connection;
 
-        if (con == null) {
+        if (conn == null) {
             throw new SyncProviderException();
         }
 
+        boolean isShowDeleted = false;
+        try {
+            isShowDeleted = getShowDeleted();
+        } catch (SQLException e) {
+            // ignore
+        }
+
         try {
             conn.setAutoCommit(false);
             CachedRowSetWriter rowSetWriter = (CachedRowSetWriter) syncProvider
                     .getRowSetWriter();
-            rowSetWriter.setConnection(con);
+            rowSetWriter.setConnection(conn);
             int beforeWriteIndex = currentRowIndex;
-            boolean isShowDeleted = getShowDeleted();
             // writer use next navigate rowset, so must make all rows visible
             setShowDeleted(true);
 
-            rowSetWriter.writeData(this);
+            if (!rowSetWriter.writeData(this)) {
+                throw rowSetWriter.getSyncException();
+            }
 
             // must reset curosr before reset showDeleted
             absolute(beforeWriteIndex);
@@ -342,6 +350,12 @@
             SyncProviderException ex = new SyncProviderException();
             ex.initCause(e);
             throw ex;
+        } finally {
+            try {
+                setShowDeleted(isShowDeleted);
+            } catch (SQLException e) {
+                // ignore
+            }
         }
     }
 
@@ -437,6 +451,7 @@
             // CachedRowSetImpl.originalResultSet
             CachedRowSetImpl copyOriginalRs = new CachedRowSetImpl();
             copyOriginalRs.populate(getOriginal());
+            getOriginal().beforeFirst();
             output.originalResultSet = copyOriginalRs;
 
             if (matchColumnIndexes != null) {
@@ -637,10 +652,14 @@
                     index++;
                 }
 
-                isNotifyListener = false;
-                doPopulate(rs, true);
-                notifyRowSetChanged();
-                isNotifyListener = true;
+                if (isNotifyListener) {
+                    isNotifyListener = false;
+                    doPopulate(rs, true);
+                    notifyRowSetChanged();
+                    isNotifyListener = true;
+                } else {
+                    doPopulate(rs, true);
+                }
 
                 if (rows.size() == 0) {
                     return false;
@@ -657,10 +676,14 @@
         if (cachedResultSet.absolute(nextPageRowIndex)) {
             cachedResultSet.previous();
 
-            isNotifyListener = false;
-            doPopulate(cachedResultSet, true);
-            notifyRowSetChanged();
-            isNotifyListener = true;
+            if (isNotifyListener) {
+                isNotifyListener = false;
+                doPopulate(cachedResultSet, true);
+                notifyRowSetChanged();
+                isNotifyListener = true;
+            } else {
+                doPopulate(cachedResultSet, true);
+            }
 
             if (rows.size() == 0) {
                 return false;
@@ -714,6 +737,7 @@
 
     protected void doPopulate(ResultSet rs, boolean isPaging)
             throws SQLException {
+        boolean oldIsNotifyListener = isNotifyListener;
         isNotifyListener = false;
         meta = copyMetaData(rs.getMetaData());
 
@@ -740,32 +764,33 @@
          * this method not support paging, so before readData set pageSize and
          * maxRowsto 0 and restore previous values after readData
          */
+        CachedRowSetReader crsReader = (CachedRowSetReader) syncProvider
+                .getRowSetReader();
+        crsReader.setResultSet(rs);
         if (!isPaging) {
             int prePageSize = getPageSize();
             setPageSize(0);
             int preMaxRows = getMaxRows();
             setMaxRows(0);
-            // FIXME use SyncProvider to get RowSetReader
-            new CachedRowSetReader(rs).readData(this);
+            crsReader.readData(this);
             setPageSize(prePageSize);
             setMaxRows(preMaxRows);
         } else {
-            // FIXME use SyncProvider to get RowSetReader
-            new CachedRowSetReader(rs).readData(this);
+            crsReader.readData(this);
         }
 
         setTableName(rs.getMetaData().getTableName(1));
 
         originalResultSet = new CachedRowSetImpl();
-        // FIXME use SyncProvider to get RowSetReader
-        new CachedRowSetReader(this).readData(originalResultSet);
+        crsReader.setResultSet(this);
+        crsReader.readData(originalResultSet);
         originalResultSet.setMetaData((RowSetMetaData) (getMetaData()));
 
         // recovery the states
         beforeFirst();
 
         isNotifyListener = true;
-        if (isNotifyListener) {
+        if (oldIsNotifyListener) {
             notifyRowSetChanged();
         }
     }
@@ -852,10 +877,14 @@
                         && previousPageRowIndex - startIndex + 1 != prePageSize) {
                     setPageSize(previousPageRowIndex - startIndex + 1);
                 }
-                isNotifyListener = false;
-                doPopulate(rs, true);
-                notifyRowSetChanged();
-                isNotifyListener = true;
+                if (isNotifyListener) {
+                    isNotifyListener = false;
+                    doPopulate(rs, true);
+                    notifyRowSetChanged();
+                    isNotifyListener = true;
+                } else {
+                    doPopulate(rs, true);
+                }
 
                 setPageSize(prePageSize);
 
@@ -902,7 +931,9 @@
 
     public void release() throws SQLException {
         rows = new ArrayList<CachedRow>();
-        notifyRowSetChanged();
+        if (isNotifyListener) {
+            notifyRowSetChanged();
+        }
     }
 
     public void restoreOriginal() throws SQLException {
@@ -910,6 +941,7 @@
             return;
         }
 
+        boolean oldIsNotifyListener = isNotifyListener;
         isNotifyListener = false;
         List<CachedRow> insertedRows = new ArrayList<CachedRow>();
         for (CachedRow row : rows) {
@@ -926,7 +958,9 @@
 
         first();
         isNotifyListener = true;
-        notifyRowSetChanged();
+        if (oldIsNotifyListener) {
+            notifyRowSetChanged();
+        }
     }
 
     public void rollback() throws SQLException {
@@ -954,7 +988,9 @@
             throw new SQLException(Messages.getString("rowset.22")); //$NON-NLS-1$
         }
         if (size() == 0 || size() % numRows == 0) {
-            notifyRowSetChanged();
+            if (isNotifyListener) {
+                notifyRowSetChanged();
+            }
         }
     }
 
@@ -1389,7 +1425,9 @@
 
         if (rowUpdated()) {
             currentRow.restoreOriginal();
-            notifyRowChanged();
+            if (isNotifyListener) {
+                notifyRowChanged();
+            }
         }
     }
 
@@ -1521,16 +1559,13 @@
     public Array getArray(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return null;
         }
-        isLastColNull = false;
-        try {
+        if (obj instanceof Array) {
             return (Array) obj;
-        } catch (ClassCastException e) {
-            // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
+        // rowset.10=Data Type Mismatch
+        throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
     }
 
     public Array getArray(String colName) throws SQLException {
@@ -1540,11 +1575,8 @@
     public InputStream getAsciiStream(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return null;
         }
-
-        isLastColNull = false;
         if (obj instanceof String) {
             obj = ((String) obj).toCharArray();
         }
@@ -1575,10 +1607,11 @@
     public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return null;
         }
-        isLastColNull = false;
+        if (obj instanceof BigDecimal) {
+            return (BigDecimal) obj;
+        }
         try {
             return new BigDecimal(obj.toString());
         } catch (NumberFormatException e) {
@@ -1608,11 +1641,8 @@
     public InputStream getBinaryStream(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return null;
         }
-
-        isLastColNull = false;
         if (obj instanceof byte[]) {
             return new ByteArrayInputStream((byte[]) obj);
         }
@@ -1628,16 +1658,13 @@
     public Blob getBlob(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return null;
         }
-        isLastColNull = false;
-        try {
+        if (obj instanceof Blob) {
             return (Blob) obj;
-        } catch (ClassCastException e) {
-            // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
+        // rowset.10=Data Type Mismatch
+        throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
     }
 
     public Blob getBlob(String columnName) throws SQLException {
@@ -1647,16 +1674,19 @@
     public boolean getBoolean(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return false;
         }
-        isLastColNull = false;
-        try {
-            return Boolean.parseBoolean(obj.toString());
-        } catch (Exception e) {
-            // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
+        if (obj instanceof Boolean) {
+            return (Boolean) obj;
         }
+        if (obj instanceof Number) {
+            if ("0".equals(obj.toString()) || "0.0".equals(obj.toString())) { //$NON-NLS-1$ //$NON-NLS-2$
+                return false;
+            }
+            return true;
+        }
+        // rowset.10=Data type mismatch
+        throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
     }
 
     public boolean getBoolean(String columnName) throws SQLException {
@@ -1666,10 +1696,11 @@
     public byte getByte(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return 0;
         }
-        isLastColNull = false;
+        if (obj instanceof Byte) {
+            return (Byte) obj;
+        }
         try {
             return Byte.parseByte(obj.toString());
         } catch (NumberFormatException e) {
@@ -1685,16 +1716,13 @@
     public byte[] getBytes(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return null;
         }
-        isLastColNull = false;
-        try {
+        if (obj instanceof byte[]) {
             return (byte[]) obj;
-        } catch (ClassCastException e) {
-            // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
+        // rowset.10=Data Type Mismatch
+        throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
     }
 
     public byte[] getBytes(String columnName) throws SQLException {
@@ -1704,10 +1732,8 @@
     public Reader getCharacterStream(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return null;
         }
-        isLastColNull = false;
         if (obj instanceof String) {
             return new StringReader((String) obj);
         }
@@ -1730,16 +1756,13 @@
     public Clob getClob(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return null;
         }
-        isLastColNull = false;
-        try {
+        if (obj instanceof Clob) {
             return (Clob) obj;
-        } catch (ClassCastException e) {
-            // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
+        // rowset.10=Data Type Mismatch
+        throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
     }
 
     public Clob getClob(String colName) throws SQLException {
@@ -1757,22 +1780,15 @@
     public Date getDate(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return null;
         }
-        isLastColNull = false;
-        try {
-            if (obj instanceof Date) {
-                return (Date) obj;
-            } else if (obj instanceof Timestamp) {
-                return new Date(((Timestamp) obj).getTime());
-            }
-            // rowset.10=Data Type Mismatch
-            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")); //$NON-NLS-1$
+        if (obj instanceof Date) {
+            return (Date) obj;
+        } else if (obj instanceof Timestamp) {
+            return new Date(((Timestamp) obj).getTime());
         }
+        // rowset.10=Data Type Mismatch
+        throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
     }
 
     public Date getDate(int columnIndex, Calendar cal) throws SQLException {
@@ -1799,10 +1815,11 @@
     public double getDouble(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return 0;
         }
-        isLastColNull = false;
+        if (obj instanceof Double) {
+            return (Double) obj;
+        }
         try {
             return Double.parseDouble(obj.toString());
         } catch (NumberFormatException e) {
@@ -1818,10 +1835,11 @@
     public float getFloat(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return 0;
         }
-        isLastColNull = false;
+        if (obj instanceof Float) {
+            return (Float) obj;
+        }
         try {
             return Float.parseFloat(obj.toString());
         } catch (NumberFormatException e) {
@@ -1837,10 +1855,11 @@
     public int getInt(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return 0;
         }
-        isLastColNull = false;
+        if (obj instanceof Integer) {
+            return (Integer) obj;
+        }
         try {
             return Integer.parseInt(obj.toString());
         } catch (NumberFormatException e) {
@@ -1856,10 +1875,11 @@
     public long getLong(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return 0;
         }
-        isLastColNull = false;
+        if (obj instanceof Long) {
+            return (Long) obj;
+        }
         try {
             return Long.parseLong(obj.toString());
         } catch (NumberFormatException e) {
@@ -1913,16 +1933,13 @@
     public Ref getRef(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return null;
         }
-        isLastColNull = false;
-        try {
+        if (obj instanceof Ref) {
             return (Ref) obj;
-        } catch (Exception e) {
-            // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
+        // rowset.10=Data Type Mismatch
+        throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
     }
 
     public Ref getRef(String colName) throws SQLException {
@@ -1956,10 +1973,11 @@
     public short getShort(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return 0;
         }
-        isLastColNull = false;
+        if (obj instanceof Short) {
+            return (Short) obj;
+        }
         try {
             return Short.parseShort(obj.toString());
         } catch (NumberFormatException e) {
@@ -1980,16 +1998,9 @@
     public String getString(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return null;
         }
-        isLastColNull = false;
-        try {
-            return obj.toString();
-        } catch (Exception e) {
-            // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
-        }
+        return obj.toString();
     }
 
     private void checkColumnValid(int columnIndex) throws SQLException {
@@ -2007,22 +2018,15 @@
     public Time getTime(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return null;
         }
-        isLastColNull = false;
-        try {
-            if (obj instanceof Time) {
-                return (Time) obj;
-            } else if (obj instanceof Timestamp) {
-                return new Time(((Timestamp) obj).getTime());
-            }
-            // rowset.10=Data Type Mismatch
-            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")); //$NON-NLS-1$
+        if (obj instanceof Time) {
+            return (Time) obj;
+        } else if (obj instanceof Timestamp) {
+            return new Time(((Timestamp) obj).getTime());
         }
+        // rowset.10=Data Type Mismatch
+        throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
     }
 
     public Time getTime(int columnIndex, Calendar cal) throws SQLException {
@@ -2049,16 +2053,14 @@
     public Timestamp getTimestamp(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return null;
         }
-        isLastColNull = false;
+        if (obj instanceof Date) {
+            return new Timestamp(((Date) obj).getTime());
+        } else if (obj instanceof Time) {
+            return new Timestamp(((Time) obj).getTime());
+        }
         try {
-            if (obj instanceof Date) {
-                return new Timestamp(((Date) obj).getTime());
-            } else if (obj instanceof Time) {
-                return new Timestamp(((Time) obj).getTime());
-            }
             return Timestamp.valueOf(obj.toString());
         } catch (Exception e) {
             // rowset.10=Data Type Mismatch
@@ -2092,16 +2094,13 @@
     public java.net.URL getURL(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return null;
         }
-        isLastColNull = false;
-        try {
+        if (obj instanceof java.net.URL) {
             return (java.net.URL) obj;
-        } catch (Exception e) {
-            // rowset.10=Data Type Mismatch
-            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
+        // rowset.10=Data Type Mismatch
+        throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
     }
 
     public java.net.URL getURL(String columnName) throws SQLException {
@@ -2112,12 +2111,8 @@
     public InputStream getUnicodeStream(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
-            isLastColNull = true;
             return null;
         }
-
-        isLastColNull = false;
-
         if (obj instanceof byte[]) {
             return new StringBufferInputStream(new String((byte[]) obj));
         }
@@ -2423,14 +2418,23 @@
             throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
 
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        if (length < 0) {
+            throw new NegativeArraySizeException();
+        }
+
+        byte[] byteArray = null;
         try {
+            if (length == 0 && in.read() == -1) {
+                throw new IndexOutOfBoundsException();
+            }
+
+            byteArray = new byte[length];
             for (int i = 0; i < length; ++i) {
                 int value = in.read();
                 if (value == -1) {
                     throw new IndexOutOfBoundsException();
                 }
-                out.write(value);
+                byteArray[i] = (byte) value;
             }
         } catch (IOException e) {
             SQLException ex = new SQLException();
@@ -2438,7 +2442,7 @@
             throw ex;
         }
 
-        updateString(columnIndex, new String(out.toByteArray()));
+        updateString(columnIndex, new String(byteArray));
     }
 
     public void updateAsciiStream(String columnName, InputStream x, int length)
@@ -2472,15 +2476,18 @@
             throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
 
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        if (length < 0) {
+            throw new NegativeArraySizeException();
+        }
+
+        byte[] byteArray = new byte[length];
         try {
-            int i = 0;
-            for (; i < length; ++i) {
+            for (int i = 0; i < length; ++i) {
                 int value = in.read();
                 if (value == -1) {
-                    out.write(0);
+                    byteArray[i] = 0;
                 } else {
-                    out.write(value);
+                    byteArray[i] = (byte) value;
                 }
             }
 
@@ -2490,7 +2497,7 @@
             throw ex;
         }
 
-        updateBytes(columnIndex, out.toByteArray());
+        updateBytes(columnIndex, byteArray);
     }
 
     public void updateBinaryStream(String columnName, InputStream x, int length)
@@ -2543,6 +2550,10 @@
             throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
 
+        if (length < 0) {
+            throw new NegativeArraySizeException();
+        }
+
         StringWriter out = new StringWriter();
         try {
             for (int i = 0; i < length; ++i) {
@@ -3015,8 +3026,8 @@
 
     private Connection retrieveConnection() throws SQLException {
         if (getUrl() != null) {
-            // TODO UserName and Password 
-            return DriverManager.getConnection(getUrl());
+            return DriverManager.getConnection(getUrl(), getUsername(),
+                    getPassword());
         } else if (getDataSourceName() != null) {
             try {
                 Context contex = new InitialContext();

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=649421&r1=649420&r2=649421&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 Fri Apr 18 02:17:50 2008
@@ -39,24 +39,12 @@
     private ResultSet rs;
 
     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();
     }
 
-    /**
-     * TODO disable all listeners
-     */
     public void readData(RowSetInternal theCaller) throws SQLException {
         CachedRowSetImpl cachedRowSet = (CachedRowSetImpl) theCaller;
         int pageSize = cachedRowSet.getPageSize();

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=649421&r1=649420&r2=649421&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 Fri Apr 18 02:17:50 2008
@@ -27,6 +27,8 @@
 import javax.sql.rowset.spi.SyncProviderException;
 import javax.sql.rowset.spi.SyncResolver;
 
+import org.apache.harmony.sql.internal.nls.Messages;
+
 public class CachedRowSetWriter implements RowSetWriter {
 
     private CachedRowSet originalRowSet;
@@ -43,6 +45,8 @@
 
     private SyncResolverImpl resolver;
 
+    private SyncProviderException syncException;
+
     public void setConnection(Connection conn) {
         originalConnection = conn;
     }
@@ -51,8 +55,12 @@
         return originalConnection;
     }
 
+    public SyncProviderException getSyncException() {
+        return syncException;
+    }
+
     public boolean writeData(RowSetInternal theRowSet) throws SQLException {
-        initial(theRowSet);
+        init(theRowSet);
         // analyse every row and do responsible task.
         currentRowSet.beforeFirst();
         originalRowSet.beforeFirst();
@@ -67,24 +75,25 @@
             } else if (currentRowSet.rowDeleted()) {
                 if (isConflictExistForCurrentRow()) {
                     addConflict(SyncResolver.DELETE_ROW_CONFLICT);
+                } else {
+                    deleteCurrentRow();
                 }
-
-                deleteCurrentRow();
-
             } else if (currentRowSet.rowUpdated()) {
                 if (isConflictExistForCurrentRow()) {
                     addConflict(SyncResolver.UPDATE_ROW_CONFLICT);
-                }
-                try {
-                    updateCurrentRow();
-                } catch (SyncProviderException e) {
-                    addConflict(SyncResolver.UPDATE_ROW_CONFLICT);
+                } else {
+                    try {
+                        updateCurrentRow();
+                    } catch (SyncProviderException e) {
+                        addConflict(SyncResolver.UPDATE_ROW_CONFLICT);
+                    }
                 }
             }
         }
 
         if (resolver != null) {
-            throw new SyncProviderException(resolver);
+            syncException = new SyncProviderException(resolver);
+            return false;
         }
         return true;
     }
@@ -103,23 +112,23 @@
      * 
      * @throws SQLException
      */
-    @SuppressWarnings("nls")
     private void insertCurrentRow() throws SQLException {
         /*
          * the first step: generate the insert SQL
          */
-        StringBuffer insertSQL = new StringBuffer("INSERT INTO " + tableName
-                + "(");
-        StringBuffer insertColNames = new StringBuffer();
-        StringBuffer insertPlaceholder = new StringBuffer();
+        StringBuilder insertSQL = new StringBuilder("INSERT INTO "); //$NON-NLS-1$
+        insertSQL.append(tableName);
+        insertSQL.append("("); //$NON-NLS-1$
+        StringBuilder insertColNames = new StringBuilder();
+        StringBuilder insertPlaceholder = new StringBuilder();
         Object[] insertColValues = new Object[columnCount];
 
         int updateCount = 0;
         for (int i = 1; i <= columnCount; i++) {
-            boolean isColUpdate = currentRowSet.columnUpdated(i);
-            if (isColUpdate) {
-                insertColNames.append(colNames[i - 1] + ",");
-                insertPlaceholder.append("?,");
+            if (currentRowSet.columnUpdated(i)) {
+                insertColNames.append(colNames[i - 1]);
+                insertColNames.append(","); //$NON-NLS-1$
+                insertPlaceholder.append("?,"); //$NON-NLS-1$
                 insertColValues[updateCount] = currentRowSet.getObject(i);
                 updateCount++;
             }
@@ -129,9 +138,9 @@
         }
 
         insertSQL.append(subStringN(insertColNames.toString(), 1));
-        insertSQL.append(") values (");
+        insertSQL.append(") values ("); //$NON-NLS-1$
         insertSQL.append(subStringN(insertPlaceholder.toString(), 1));
-        insertSQL.append(")");
+        insertSQL.append(")"); //$NON-NLS-1$
 
         /*
          * the second step: execute SQL
@@ -144,9 +153,14 @@
             }
             preSt.executeUpdate();
         } catch (SQLException e) {
-            throw new SyncProviderException();
+            // rowset.29=Insert failed
+            throw new SyncProviderException(Messages.getString("rowset.29"));//$NON-NLS-1$
         } finally {
-            preSt.close();
+            try {
+                preSt.close();
+            } catch (SQLException e) {
+                // ignore
+            }
         }
     }
 
@@ -159,8 +173,9 @@
         /*
          * the first step: generate the delete SQL
          */
-        StringBuffer deleteSQL = new StringBuffer("DELETE FROM " + tableName //$NON-NLS-1$
-                + " WHERE "); //$NON-NLS-1$
+        StringBuilder deleteSQL = new StringBuilder("DELETE FROM "); //$NON-NLS-1$
+        deleteSQL.append(tableName);
+        deleteSQL.append(" WHERE "); //$NON-NLS-1$
         deleteSQL.append(generateQueryCondition());
 
         /*
@@ -172,7 +187,11 @@
             fillParamInPreStatement(preSt, 1);
             preSt.executeUpdate();
         } finally {
-            preSt.close();
+            try {
+                preSt.close();
+            } catch (SQLException e) {
+                // ignore
+            }
         }
     }
 
@@ -181,22 +200,22 @@
      * 
      * @throws SQLException
      */
-    @SuppressWarnings("nls")
     private void updateCurrentRow() throws SQLException {
         /*
          * the first step: generate the delete SQL
          */
-        StringBuffer updateSQL = new StringBuffer("UPDATE " + tableName
-                + " SET ");
-        StringBuffer updateCols = new StringBuffer();
+        StringBuilder updateSQL = new StringBuilder("UPDATE "); //$NON-NLS-1$
+        updateSQL.append(tableName);
+        updateSQL.append(" SET "); //$NON-NLS-1$
+        StringBuilder updateCols = new StringBuilder();
         Object[] updateColValues = new Object[columnCount];
         int[] updateColIndexs = new int[columnCount];
 
         int updateCount = 0;
         for (int i = 1; i <= columnCount; i++) {
-            boolean isColUpdate = currentRowSet.columnUpdated(i);
-            if (isColUpdate) {
-                updateCols.append(colNames[i - 1] + " = ?, ");
+            if (currentRowSet.columnUpdated(i)) {
+                updateCols.append(colNames[i - 1]);
+                updateCols.append(" = ?, "); //$NON-NLS-1$
                 updateColValues[updateCount] = currentRowSet.getObject(i);
                 updateColIndexs[updateCount] = i;
                 updateCount++;
@@ -206,7 +225,7 @@
             return;
         }
         updateSQL.append(subStringN(updateCols.toString(), 2));
-        updateSQL.append(" WHERE ");
+        updateSQL.append(" WHERE "); //$NON-NLS-1$
         updateSQL.append(generateQueryCondition());
 
         /*
@@ -228,18 +247,27 @@
             fillParamInPreStatement(preSt, updateCount + 1);
             preSt.executeUpdate();
         } catch (SQLException e) {
-            throw new SyncProviderException();
+            // rowset.5=There are conflicts between rowset and data source
+            throw new SyncProviderException(Messages.getString("rowset.5"));//$NON-NLS-1$
         } finally {
-            preSt.close();
+            try {
+                preSt.close();
+            } catch (SQLException e) {
+                // ignore
+            }
         }
     }
 
-    private void initial(RowSetInternal theRowSet) throws SQLException {
+    private void init(RowSetInternal theRowSet) throws SQLException {
         currentRowSet = (CachedRowSetImpl) theRowSet;
         // initial environment
         originalRowSet = (CachedRowSet) currentRowSet.getOriginal();
-        // originalConnection = currentRowSet.getConnection();
-        tableName = currentRowSet.getTableName();
+        String schema = currentRowSet.getMetaData().getSchemaName(1);
+        if (schema == null || schema.length() == 0) {
+            tableName = currentRowSet.getTableName();
+        } else {
+            tableName = schema + "." + currentRowSet.getTableName(); //$NON-NLS-1$
+        }
         columnCount = currentRowSet.getMetaData().getColumnCount();
         colNames = new String[columnCount];
         for (int i = 1; i <= columnCount; i++) {
@@ -258,8 +286,9 @@
         boolean isExist = true;
         originalRowSet.absolute(currentRowSet.getRow()); // the original data
 
-        StringBuffer querySQL = new StringBuffer("SELECT COUNT(*) FROM " //$NON-NLS-1$
-                + tableName + " WHERE "); //$NON-NLS-1$
+        StringBuilder querySQL = new StringBuilder("SELECT COUNT(*) FROM "); //$NON-NLS-1$
+        querySQL.append(tableName);
+        querySQL.append(" WHERE "); //$NON-NLS-1$
         querySQL.append(generateQueryCondition());
 
         PreparedStatement preSt = getConnection().prepareStatement(
@@ -274,10 +303,14 @@
                 }
             }
         } finally {
-            if (queryRs != null) {
-                queryRs.close();
+            try {
+                if (queryRs != null) {
+                    queryRs.close();
+                }
+                preSt.close();
+            } catch (SQLException e) {
+                // ignore
             }
-            preSt.close();
         }
 
         return isExist;
@@ -289,17 +322,18 @@
      * 
      * @return the SQL query expression
      */
-    @SuppressWarnings("nls")
     private String generateQueryCondition() throws SQLException {
-        StringBuffer queryCondtion = new StringBuffer(" ");
+        StringBuilder queryCondtion = new StringBuilder();
         for (int i = 0; i < colNames.length; i++) {
             if (originalRowSet.getObject(i + 1) == null) {
-                queryCondtion.append(colNames[i] + " is null ");
+                queryCondtion.append(colNames[i]);
+                queryCondtion.append(" is null "); //$NON-NLS-1$
             } else {
-                queryCondtion.append(colNames[i] + " = ? ");
+                queryCondtion.append(colNames[i]);
+                queryCondtion.append(" = ? "); //$NON-NLS-1$
             }
             if (i != colNames.length - 1) {
-                queryCondtion.append(" and ");
+                queryCondtion.append(" and "); //$NON-NLS-1$
             }
         }
         return queryCondtion.toString();

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JoinRowSetImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JoinRowSetImpl.java?rev=649421&r1=649420&r2=649421&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JoinRowSetImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JoinRowSetImpl.java Fri Apr 18 02:17:50 2008
@@ -526,33 +526,6 @@
         }
     }
 
-    @Override
-    public boolean nextPage() throws SQLException {
-        boolean result = super.nextPage();
-        setIsNotifyListener(false);
-        return result;
-    }
-
-    @Override
-    public boolean previousPage() throws SQLException {
-        boolean result = super.previousPage();
-        setIsNotifyListener(false);
-        return result;
-    }
-
-    @Override
-    public void restoreOriginal() throws SQLException {
-        super.restoreOriginal();
-        setIsNotifyListener(false);
-    }
-
-    @Override
-    protected void doPopulate(ResultSet rs, boolean isPaging)
-            throws SQLException {
-        super.doPopulate(rs, isPaging);
-        setIsNotifyListener(false);
-    }
-
     /**
      * Join the data with another CachedRowSet. It updates rows,
      * currentRowIndex, currentRow and columnCount. It doesn't update its

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=649421&r1=649420&r2=649421&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 Fri Apr 18 02:17:50 2008
@@ -403,4 +403,73 @@
         noInitialCrset.getBigDecimal(5);
         noInitialCrset.getBigDecimal(5, 4);
     }
+
+    public void testGetBoolean() throws Exception {
+        crset.first();
+        assertTrue(crset.getBoolean(1));
+        crset.updateInt(1, 0);
+        assertFalse(crset.getBoolean(1));
+        crset.updateInt(1, -12);
+        assertTrue(crset.getBoolean(1));
+        crset.updateInt(1, 12);
+        assertTrue(crset.getBoolean(1));
+
+        try {
+            crset.getBoolean(2);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // Expected.
+        }
+
+        crset.updateString(2, "true");
+        try {
+            crset.getBoolean(2);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // Expected.
+        }
+
+        assertNull(crset.getObject(3));
+        assertFalse(crset.getBoolean(3));
+
+        crset.absolute(4);
+        assertEquals(444423L, crset.getLong(3));
+        assertTrue(crset.getBoolean(3));
+        crset.updateLong(3, 0);
+        assertFalse(crset.getBoolean(3));
+
+        assertTrue(crset.getBoolean(4));
+        assertTrue(crset.getBoolean(5));
+        assertTrue(crset.getBoolean(6));
+        assertTrue(crset.getBoolean(7));
+        crset.updateFloat(7, 0.0f);
+        assertFalse(crset.getBoolean(7));
+        crset.updateFloat(7, -23.1f);
+        assertTrue(crset.getBoolean(7));
+        assertTrue(crset.getBoolean(8));
+        assertTrue(crset.getBoolean(9));
+        crset.updateDouble(9, 0);
+        assertFalse(crset.getBoolean(9));
+
+        try {
+            crset.getBoolean(10);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // Expected.
+        }
+
+        try {
+            crset.getBoolean(11);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // Expected.
+        }
+
+        try {
+            crset.getBoolean(12);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // Expected.
+        }
+    }
 }

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=649421&r1=649420&r2=649421&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 Fri Apr 18 02:17:50 2008
@@ -21,7 +21,6 @@
 import java.io.ByteArrayOutputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import java.io.PrintWriter;
 import java.math.BigDecimal;
 import java.sql.Connection;
 import java.sql.Date;
@@ -37,7 +36,6 @@
 import java.util.Iterator;
 import java.util.Vector;
 
-import javax.sql.DataSource;
 import javax.sql.RowSetEvent;
 import javax.sql.RowSetInternal;
 import javax.sql.RowSetListener;
@@ -144,7 +142,7 @@
     }
 
     public void testSetSyncProvider() throws Exception {
-        if (System.getProperty("Testing Harmony") == "true") {
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
             String mySyncProvider = "org.apache.harmony.sql.internal.rowset.HYOptimisticProvider";
             crset.setSyncProvider(mySyncProvider);
             assertEquals(crset.getSyncProvider().getClass().getCanonicalName(),
@@ -737,6 +735,7 @@
         try {
             assertEquals(crset.getMatchColumnNames(), crsetCopy
                     .getMatchColumnNames());
+            fail("Should throw SQLException");
         } catch (SQLException e) {
             // expected
         }
@@ -1237,6 +1236,7 @@
 
         try {
             crset.getMatchColumnNames();
+            fail("Should throw SQLException");
         } catch (SQLException e) {
             // expected
         }
@@ -1362,7 +1362,7 @@
          * equals last(). However, the return value of absolute(negative) is
          * false when run on RI. The Harmony follows the spec.
          */
-        if (System.getProperty("Testing Harmony") == "true") {
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
             assertTrue(crset.absolute(-1));
             assertEquals(4, crset.getInt(1));
             assertTrue(crset.absolute(-3));
@@ -2948,8 +2948,7 @@
         try {
             crset.getOriginal();
             fail("Should throw NullPointerException.");
-        }
-        catch (NullPointerException e) {
+        } catch (NullPointerException e) {
             // Expected.
         }
     }

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=649421&r1=649420&r2=649421&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 Fri Apr 18 02:17:50 2008
@@ -734,6 +734,27 @@
             // expected
         }
 
+        try {
+            crset.updateAsciiStream(3, new ByteArrayInputStream(new byte[0]),
+                    -3);
+            fail("should throw NegativeArraySizeException");
+        } catch (NegativeArraySizeException e) {
+            // expected
+        }
+
+        try {
+            crset
+                    .updateAsciiStream(3,
+                            new ByteArrayInputStream(new byte[0]), 0);
+            fail("Should throw IndexOutOfBoundsException");
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+
+        crset.updateAsciiStream(3, new ByteArrayInputStream(new byte[] { 1, 2,
+                3, 4, 5 }), 0);
+        assertEquals(0, crset.getString(3).length());
+
         crset.updateAsciiStream(3, new ByteArrayInputStream(new byte[] { 1, 2,
                 3, 4, 5 }), 2);
 
@@ -756,6 +777,36 @@
         for (int i = 0; i < chars.length; i++) {
             assertEquals(i + 1, chars[i]);
         }
+
+        String value = new String("\u548c\u8c10");
+        in = new ByteArrayInputStream(value.getBytes());
+        crset.updateAsciiStream(2, in, in.available());
+
+        obj = crset.getObject(2);
+        assertTrue(obj instanceof String);
+        assertEquals(value, obj);
+
+        chars = ((String) obj).toCharArray();
+        char[] expected = value.toCharArray();
+        assertEquals(expected.length, chars.length);
+        for (int i = 0; i < chars.length; i++) {
+            assertEquals(expected[i], chars[i]);
+        }
+
+        value = new String("\u548d\u8c1a");
+        in = new ByteArrayInputStream(value.getBytes());
+        crset.updateAsciiStream(3, in, in.available());
+
+        obj = crset.getObject(3);
+        assertTrue(obj instanceof String);
+        assertEquals(value, obj);
+
+        chars = ((String) obj).toCharArray();
+        expected = value.toCharArray();
+        assertEquals(expected.length, chars.length);
+        for (int i = 0; i < chars.length; i++) {
+            assertEquals(expected[i], chars[i]);
+        }
     }
 
     public void testUpdateAsciiStream_Type_Mismatch() throws Exception {
@@ -842,6 +893,14 @@
     public void testUpdateBinaryStream() throws Exception {
         crset.next();
 
+        try {
+            crset.updateBinaryStream(3, new ByteArrayInputStream(
+                    new byte[] { 0 }), -3);
+            fail("should throw NegativeArraySizeException");
+        } catch (NegativeArraySizeException e) {
+            // expected
+        }
+
         crset.updateBinaryStream(3, new ByteArrayInputStream(new byte[] { 1 }),
                 10);
 
@@ -980,6 +1039,13 @@
             crset.updateCharacterStream(2, new StringReader("test"), 10);
             fail("Should throw IndexOutOfBoundsException");
         } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            crset.updateCharacterStream(2, new StringReader("test"), -3);
+            fail("should throw NegativeArraySizeException");
+        } catch (NegativeArraySizeException e) {
             // expected
         }
 

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JdbcRowSetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JdbcRowSetTest.java?rev=649421&r1=649420&r2=649421&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JdbcRowSetTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JdbcRowSetTest.java Fri Apr 18 02:17:50 2008
@@ -1018,6 +1018,18 @@
             // expected
         }
         jrs.getFetchSize();
+        try {
+            jrs.getMatchColumnIndexes();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        try {
+            jrs.getMatchColumnNames();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
         jrs.getMaxFieldSize();
         jrs.getMaxRows();
         try {

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetOtherTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetOtherTest.java?rev=649421&r1=649420&r2=649421&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetOtherTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetOtherTest.java Fri Apr 18 02:17:50 2008
@@ -16,11 +16,9 @@
  */
 package org.apache.harmony.sql.tests.internal.rowset;
 
-import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.util.Collection;
 
-import javax.sql.RowSetMetaData;
 import javax.sql.rowset.CachedRowSet;
 import javax.sql.rowset.JdbcRowSet;
 import javax.sql.rowset.JoinRowSet;
@@ -306,20 +304,24 @@
     /**
      * @throws Exception
      * @throws SQLException
-     * @tests java.sql.rowset.joinRowSet#getRowSets()
+     * @tests java.sql.rowset.joinRowSet#addRowSet()
      */
-    public void testGetRowSets_NoInitialCachedRowSet() throws Exception {
+    public void testAddRowSet_NoInitialCachedRowSet() throws Exception {
         Collection collection;
 
         CachedRowSet crs = newNoInitialInstance();
+        
         if ("true".equals(System.getProperty("Testing Harmony"))) {
             try {
                 jrs.addRowSet(crs, 1);
                 fail("Should throw SQLException in harmony.");
-            } catch (SQLException e) {
+            }
+            catch (SQLException e)
+            {
                 // Expected.
             }
-        } else {
+        }
+        else {
             jrs.addRowSet(crs, 1);
         }
     }

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetTest.java?rev=649421&r1=649420&r2=649421&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetTest.java Fri Apr 18 02:17:50 2008
@@ -334,18 +334,15 @@
         } else {
             try {
                 jrs.addRowSet(webRs);
-                fail("should throw ClassCastException");
-            } catch (ClassCastException e) {
+                fail("should throw NullPointerException");
+            } catch (NullPointerException e) {
                 // expected
+            } catch (SQLException e) {
+                // Expected
             }
 
             webRs.setMatchColumn(1);
-            try {
-                jrs.addRowSet(webRs);
-                fail("should throw ClassCastException");
-            } catch (ClassCastException e) {
-                // expected
-            }
+            jrs.addRowSet(webRs);
         }
         jrs.close();
 
@@ -356,17 +353,9 @@
         webRs = newWebRowSet();
         webRs.populate(st.executeQuery("SELECT * FROM USER_INFO"));
         webRs.setMatchColumn(1);
-        if ("true".equals(System.getProperty("Testing Harmony"))) {
-            jrs.addRowSet(webRs);
-        } else {
-            try {
-                // The same problem as the empty
-                jrs.addRowSet(webRs);
-                fail("should throw ClassCastException");
-            } catch (ClassCastException e) {
-                // expected
-            }
-        }
+        jrs.addRowSet(webRs);
+        assertTrue(jrs.next());
+        assertEquals(1, jrs.getInt(1));
         jrs.close();
     }
 
@@ -385,12 +374,7 @@
                 // expected
             }
         } else {
-            try {
-                jrs.addRowSet(webRs, 1);
-                fail("should throw ClassCastException");
-            } catch (ClassCastException e) {
-                // expected
-            }
+            jrs.addRowSet(webRs, 1);
         }
         jrs.close();
 
@@ -400,16 +384,9 @@
         jrs = newJoinRowSet();
         webRs = newWebRowSet();
         webRs.populate(st.executeQuery("SELECT * FROM USER_INFO"));
-        if ("true".equals(System.getProperty("Testing Harmony"))) {
-            jrs.addRowSet(webRs, 1);
-        } else {
-            try {
-                jrs.addRowSet(webRs, 1);
-                fail("should throw ClassCastException");
-            } catch (ClassCastException e) {
-                // expected
-            }
-        }
+        jrs.addRowSet(webRs, 1);
+        assertTrue(jrs.next());
+        assertEquals(1, jrs.getInt(1));
         jrs.close();
     }
 
@@ -860,5 +837,99 @@
             }
         }
         assertEquals(3, index);
+    }
+
+    public void testToCachedRowSet_acceptChanges() throws Exception {
+        /*
+         * The first CachedRowSet
+         */
+        jrs.addRowSet(crset, 1);
+        CachedRowSet toCrset = jrs.toCachedRowSet();
+        // call crset.acceptChanges()
+        assertTrue(crset.absolute(3));
+        assertEquals("test3", crset.getString(2));
+        crset.updateString(2, "update3");
+        crset.updateRow();
+        crset.acceptChanges();
+        assertTrue(crset.absolute(3));
+        assertEquals("update3", crset.getString(2));
+        // call toCrset.acceptChanges()
+        assertTrue(toCrset.absolute(3));
+        assertEquals("test3", toCrset.getString(2));
+        assertTrue(toCrset.last());
+        assertEquals("test4", toCrset.getString(2));
+        toCrset.updateString(2, "update4");
+        toCrset.updateRow();
+        toCrset.acceptChanges();
+        assertTrue(toCrset.absolute(4));
+        assertEquals("update4", toCrset.getString(2));
+
+        /*
+         * The second CachedRowSet
+         */
+        noInitialCrset.populate(st.executeQuery("SELECT * FROM BOOKS"));
+        jrs.addRowSet(noInitialCrset, 1);
+        toCrset = jrs.toCachedRowSet();
+        // call toCrset.acceptChanges()
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertTrue(toCrset.last());
+        } else {
+            assertTrue(toCrset.first());
+        }
+        assertEquals(4, toCrset.getInt(1));
+        toCrset.updateString(2, "modify4");
+        toCrset.updateRow();
+        try {
+            toCrset.acceptChanges();
+            fail("should throw exception");
+        } catch (Exception e) {
+            // expected
+        }
+    }
+
+    public void testCancelRowUpdates_Simple() throws Exception {
+        jrs.addRowSet(crset, 1);
+        Listener listener = new Listener();
+        jrs.addRowSetListener(listener);
+
+        jrs.absolute(4);
+        jrs.updateString(2, "Updated");
+        jrs.updateRow();
+        jrs.absolute(4);
+        assertEquals("Updated", jrs.getString(2));
+
+        jrs.cancelRowUpdates();
+        jrs.absolute(4);
+        assertEquals("test4", jrs.getString(2));
+        assertNull(listener.getTag());
+    }
+
+    public void testCancelRowUpdates() throws Exception {
+        jrs.addRowSet(crset, 1);
+        Listener listener = new Listener();
+        jrs.addRowSetListener(listener);
+
+        assertTrue(jrs.absolute(3));
+        jrs.updateString(2, "update3");
+        // call cancelRowUpdates() before updateRow(), no effect here
+        listener.clear();
+        jrs.cancelRowUpdates();
+        assertNull(listener.getTag());
+        assertEquals("update3", jrs.getString(2));
+        jrs.updateRow();
+        jrs.absolute(3);
+        assertEquals("update3", jrs.getString(2));
+
+        assertTrue(jrs.absolute(4));
+        jrs.updateString(2, "update4");
+        assertEquals("update4", jrs.getString(2));
+        jrs.updateRow();
+        assertEquals("update4", jrs.getString(2));
+        // call cancelRowUpdates() after updateRow(), it works here
+        listener.clear();
+        assertEquals("update4", jrs.getString(2));
+        jrs.cancelRowUpdates();
+        assertEquals("test4", jrs.getString(2));
+        assertNull(listener.getTag());
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/XmlReaderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/XmlReaderTest.java?rev=649421&r1=649420&r2=649421&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/XmlReaderTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/XmlReaderTest.java Fri Apr 18 02:17:50 2008
@@ -19,7 +19,6 @@
 
 import java.io.FileInputStream;
 import java.io.FileReader;
-import java.io.FileWriter;
 import java.io.Reader;
 import java.io.StringWriter;
 



Mime
View raw message