harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r652421 [5/6] - in /harmony/enhanced/classlib/branches/java6/modules: beans/src/main/java/java/beans/ beans/src/main/java/org/apache/harmony/beans/editors/ beans/src/test/java/org/apache/harmony/beans/tests/java/beans/ imageio/src/main/java...
Date Thu, 01 May 2008 03:14:38 GMT
Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java Wed Apr 30 20:14:31 2008
@@ -17,14 +17,12 @@
 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;
 import java.io.StringBufferInputStream;
 import java.io.StringReader;
 import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.sql.Array;
@@ -128,20 +126,20 @@
 
     private int[] keyCols;
 
-    private int columnCount;
+    protected int columnCount;
 
     private int deletedRowCount;
 
     private SyncProvider syncProvider;
 
-    private CachedRowSetImpl originalResultSet;
+    protected CachedRowSetImpl originalResultSet;
 
     private SQLWarning sqlwarn = new SQLWarning();
 
     // TODO deal with rowSetWarning
     private RowSetWarning rowSetWarning = new RowSetWarning();
 
-    private Class[] columnTypes;
+    protected Class[] columnTypes;
 
     private String[] matchColumnNames;
 
@@ -151,11 +149,11 @@
 
     private boolean isLastColNull;
 
-    private transient Connection conn;
+    protected transient Connection conn;
 
     private boolean isNotifyListener = true;
 
-    private static Map<Integer, Class<?>> TYPE_MAPPING = initialTypeMapping();
+    protected static Map<Integer, Class<?>> TYPE_MAPPING = initialTypeMapping();
 
     public static final String PROVIDER_ID = "Apache Harmony HYOptimisticProvider"; //$NON-NLS-1$
 
@@ -236,6 +234,7 @@
             currentConn = retrieveConnection();
             currentConn.setTypeMap(getTypeMap());
             acceptChanges(currentConn);
+            currentConn.commit();
         } catch (SQLException e) {
             try {
                 if (currentConn != null) {
@@ -251,7 +250,6 @@
             conn = preConn;
             if (currentConn != null) {
                 try {
-                    currentConn.commit();
                     currentConn.close();
                 } catch (SQLException ex) {
                     SyncProviderException spe = new SyncProviderException();
@@ -262,24 +260,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 (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);
@@ -341,6 +354,12 @@
             SyncProviderException ex = new SyncProviderException();
             ex.initCause(e);
             throw ex;
+        } finally {
+            try {
+                setShowDeleted(isShowDeleted);
+            } catch (SQLException e) {
+                // ignore
+            }
         }
     }
 
@@ -398,12 +417,11 @@
              */
             output = (CachedRowSetImpl) super.clone();
             // BaseRowSet.params
-            Field paramsField = output.getClass().getSuperclass()
-                    .getDeclaredField("params"); //$NON-NLS-1$
+            Field paramsField = BaseRowSet.class.getDeclaredField("params"); //$NON-NLS-1$
             paramsField.setAccessible(true);
             paramsField.set(output, paramsHashtable);
             // BaseRowSet.listeners
-            Field listenersField = output.getClass().getSuperclass()
+            Field listenersField = BaseRowSet.class
                     .getDeclaredField("listeners"); //$NON-NLS-1$
             listenersField.setAccessible(true);
             listenersField.set(output, listeners);
@@ -437,6 +455,7 @@
             // CachedRowSetImpl.originalResultSet
             CachedRowSetImpl copyOriginalRs = new CachedRowSetImpl();
             copyOriginalRs.populate(getOriginal());
+            getOriginal().beforeFirst();
             output.originalResultSet = copyOriginalRs;
 
             if (matchColumnIndexes != null) {
@@ -570,6 +589,9 @@
     }
 
     public ResultSet getOriginal() throws SQLException {
+        if (originalResultSet == null) {
+            throw new NullPointerException();
+        }
         return originalResultSet;
     }
 
@@ -634,10 +656,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;
@@ -654,10 +680,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;
@@ -709,7 +739,9 @@
         }
     }
 
-    private void doPopulate(ResultSet rs, boolean isPaging) throws SQLException {
+    protected void doPopulate(ResultSet rs, boolean isPaging)
+            throws SQLException {
+        boolean oldIsNotifyListener = isNotifyListener;
         isNotifyListener = false;
         meta = copyMetaData(rs.getMetaData());
 
@@ -736,32 +768,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();
         }
     }
@@ -848,10 +881,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);
 
@@ -898,7 +935,9 @@
 
     public void release() throws SQLException {
         rows = new ArrayList<CachedRow>();
-        notifyRowSetChanged();
+        if (isNotifyListener) {
+            notifyRowSetChanged();
+        }
     }
 
     public void restoreOriginal() throws SQLException {
@@ -906,6 +945,7 @@
             return;
         }
 
+        boolean oldIsNotifyListener = isNotifyListener;
         isNotifyListener = false;
         List<CachedRow> insertedRows = new ArrayList<CachedRow>();
         for (CachedRow row : rows) {
@@ -922,7 +962,9 @@
 
         first();
         isNotifyListener = true;
-        notifyRowSetChanged();
+        if (oldIsNotifyListener) {
+            notifyRowSetChanged();
+        }
     }
 
     public void rollback() throws SQLException {
@@ -950,7 +992,9 @@
             throw new SQLException(Messages.getString("rowset.22")); //$NON-NLS-1$
         }
         if (size() == 0 || size() % numRows == 0) {
-            notifyRowSetChanged();
+            if (isNotifyListener) {
+                notifyRowSetChanged();
+            }
         }
     }
 
@@ -1313,7 +1357,8 @@
      * @return whether the cursor is on result set
      * @throws SQLException
      */
-    private boolean doAbsolute(int row, boolean checkType) throws SQLException {
+    protected boolean doAbsolute(int row, boolean checkType)
+            throws SQLException {
         if (isCursorOnInsert) {
             // rowset.0=Not a valid position
             throw new SQLException(Messages.getString("rowset.0")); //$NON-NLS-1$
@@ -1384,7 +1429,9 @@
 
         if (rowUpdated()) {
             currentRow.restoreOriginal();
-            notifyRowChanged();
+            if (isNotifyListener) {
+                notifyRowChanged();
+            }
         }
     }
 
@@ -1441,6 +1488,10 @@
      * @return row index include delted rows
      */
     private int getIndexIncludeDeletedRows(int index) throws SQLException {
+        if (rows == null || rows.size() == 0) {
+            return -1;
+        }
+
         if (getShowDeleted()) {
             return index;
         }
@@ -1512,16 +1563,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 {
@@ -1531,11 +1579,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();
         }
@@ -1566,10 +1611,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) {
@@ -1599,11 +1645,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);
         }
@@ -1619,16 +1662,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 {
@@ -1638,16 +1678,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 {
@@ -1657,10 +1700,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) {
@@ -1676,16 +1720,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 {
@@ -1695,10 +1736,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);
         }
@@ -1721,16 +1760,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 {
@@ -1748,22 +1784,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 {
@@ -1790,10 +1819,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) {
@@ -1809,10 +1839,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) {
@@ -1828,10 +1859,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) {
@@ -1847,10 +1879,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) {
@@ -1904,16 +1937,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 {
@@ -1947,10 +1977,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) {
@@ -1971,16 +2002,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 {
@@ -1998,22 +2022,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 {
@@ -2040,16 +2057,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
@@ -2083,16 +2098,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 {
@@ -2103,12 +2115,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));
         }
@@ -2414,21 +2422,31 @@
             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();
             ex.initCause(e);
             throw ex;
         }
-        updateString(columnIndex, new String(out.toByteArray()));
+
+        updateString(columnIndex, new String(byteArray));
     }
 
     public void updateAsciiStream(String columnName, InputStream x, int length)
@@ -2462,15 +2480,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;
                 }
             }
 
@@ -2480,7 +2501,7 @@
             throw ex;
         }
 
-        updateBytes(columnIndex, out.toByteArray());
+        updateBytes(columnIndex, byteArray);
     }
 
     public void updateBinaryStream(String columnName, InputStream x, int length)
@@ -2533,6 +2554,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) {
@@ -2668,6 +2693,10 @@
     }
 
     public void updateRow() throws 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$
@@ -3001,7 +3030,8 @@
 
     private Connection retrieveConnection() throws SQLException {
         if (getUrl() != null) {
-            return DriverManager.getConnection(getUrl());
+            return DriverManager.getConnection(getUrl(), getUsername(),
+                    getPassword());
         } else if (getDataSourceName() != null) {
             try {
                 Context contex = new InitialContext();

Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java Wed Apr 30 20:14:31 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/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetWriter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetWriter.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetWriter.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetWriter.java Wed Apr 30 20:14:31 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/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/FilteredRowSetImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/FilteredRowSetImpl.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/FilteredRowSetImpl.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/FilteredRowSetImpl.java Wed Apr 30 20:14:31 2008
@@ -34,10 +34,6 @@
         super();
     }
 
-    public FilteredRowSetImpl(String providerID) throws SyncFactoryException {
-        super(providerID);
-    }
-
     public Predicate getFilter() {
         return predicate;
     }

Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JoinRowSetImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JoinRowSetImpl.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JoinRowSetImpl.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JoinRowSetImpl.java Wed Apr 30 20:14:31 2008
@@ -16,19 +16,26 @@
  */
 package org.apache.harmony.sql.internal.rowset;
 
+import java.sql.Connection;
+import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
+import java.sql.Types;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
 import javax.sql.RowSet;
 import javax.sql.RowSetMetaData;
 import javax.sql.rowset.CachedRowSet;
+import javax.sql.rowset.JdbcRowSet;
 import javax.sql.rowset.JoinRowSet;
 import javax.sql.rowset.Joinable;
 import javax.sql.rowset.RowSetMetaDataImpl;
 import javax.sql.rowset.spi.SyncFactoryException;
+import javax.sql.rowset.spi.SyncProviderException;
 
 import org.apache.harmony.luni.util.NotImplementedException;
 import org.apache.harmony.sql.internal.nls.Messages;
@@ -37,20 +44,33 @@
 
     private List<RowSet> rsList;
 
+    private CachedRowSet copyFirstRs;
+
     private List<Integer> matchColIndexs;
 
     private List<String> matchColNames;
 
     private int joinType;
 
+    private static String MERGED_COLUMN_NAME = "MergedCol"; //$NON-NLS-1$
+
+    // Whether the rows can be sorted using object in matched index.
+    private boolean isSortable;
+
     public JoinRowSetImpl() throws SyncFactoryException {
         super();
         initProperties();
     }
 
-    public JoinRowSetImpl(String providerID) throws SyncFactoryException {
-        super(providerID);
-        initProperties();
+    @Override
+    public void acceptChanges() throws SyncProviderException {
+        acceptChanges(conn);
+    }
+
+    @Override
+    protected boolean doAbsolute(int row, boolean checkType)
+            throws SQLException {
+        return super.doAbsolute(row, false);
     }
 
     private void initProperties() {
@@ -58,6 +78,8 @@
         matchColIndexs = new ArrayList<Integer>();
         matchColNames = new ArrayList<String>();
         joinType = INNER_JOIN;
+        setIsNotifyListener(false);
+        rows = new ArrayList<CachedRow>();
     }
 
     private void composeMetaData(ResultSetMetaData rsmd, int matchColumn)
@@ -76,7 +98,7 @@
             for (int i = 1; i <= getMetaData().getColumnCount(); i++) {
                 doCopyMetaData(rowSetMetaData, i, getMetaData(), i);
                 if (i == matchColIndexs.get(0).intValue()) {
-                    rowSetMetaData.setColumnName(i, "MergedCol"); //$NON-NLS-1$
+                    rowSetMetaData.setColumnName(i, MERGED_COLUMN_NAME);
                 }
             }
             int index = 0;
@@ -156,25 +178,60 @@
             throw new SQLException(Messages.getString("rowset.35")); //$NON-NLS-1$
         }
 
-        // TODO to be continue
-        rsList.add(rowset);
-        if (rsList.size() == 1) {
-            setMatchColumn(columnIdx);
-        }
-
+        int type = rowset.getMetaData().getColumnType(columnIdx);
         if (getMetaData() != null
-                && getMetaData().getColumnType(getMatchColumnIndexes()[0]) != rowset
-                        .getMetaData().getColumnType(columnIdx)) {
+                && getMetaData().getColumnType(getMatchColumnIndexes()[0]) != type) {
             setMetaData(null);
             rows = null;
+            // rowset.10=Data Type Mismatch
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
+        }
+
+        if (getMetaData() == null
+                && (type == Types.BINARY || type == Types.LONGVARBINARY
+                        || type == Types.VARBINARY || type == Types.BLOB
+                        || type == Types.CLOB || type == Types.ARRAY
+                        || type == Types.LONGVARCHAR
+                        || type == Types.JAVA_OBJECT || type == Types.OTHER || type == Types.NULL)) {
+            // rowset.10=Data Type Mismatch
             throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
         }
 
         composeMetaData(rowset.getMetaData(), columnIdx);
-        matchColIndexs.add(columnIdx);
 
-        // TODO join data
+        columnCount = getMetaData().getColumnCount();
+        // Reassign columnTypes.
+        columnTypes = new Class[columnCount];
+        for (int i = 1; i <= columnTypes.length; ++i) {
+            columnTypes[i - 1] = TYPE_MAPPING.get(Integer.valueOf(meta
+                    .getColumnType(i)));
+        }
+
+        matchColIndexs.add(Integer.valueOf(columnIdx));
+
+        if (rowset instanceof JdbcRowSet) {
+            CachedRowSet convertRowset = new CachedRowSetImpl();
+            convertRowset.populate(rowset);
+            rsList.add(convertRowset);
+        } else {
+            rsList.add(rowset);
+        }
+
+        if (rsList.size() == 1) {
+            initSortable();
+        }
+        try {
+            innerJoin();
+        } catch (CloneNotSupportedException e) {
+            SQLException sqlException = new SQLException();
+            sqlException.initCause(e);
+            throw sqlException;
+        }
 
+        if (rsList.size() == 1) {
+            copyFirstRs = ((CachedRowSet) rsList.get(0)).createCopy();
+            setMatchColumn(columnIdx);
+        }
     }
 
     public void addRowSet(RowSet rowset, String columnName) throws SQLException {
@@ -186,7 +243,12 @@
             throw new SQLException(Messages.getString("rowset.32")); //$NON-NLS-1$
         }
 
-        int columnIdx = rowset.findColumn(columnName);
+        int columnIdx = -1;
+        try {
+            columnIdx = rowset.findColumn(columnName);
+        } catch (SQLException e) {
+            throw e;
+        }
         addRowSet(rowset, columnIdx);
     }
 
@@ -245,18 +307,121 @@
     }
 
     public Collection<?> getRowSets() throws SQLException {
-        throw new NotImplementedException();
+        return rsList;
     }
 
+    /**
+     * Gets a sql clause which specify the join action.
+     */
     public String getWhereClause() throws SQLException {
-        throw new NotImplementedException();
+        int size = rsList.size();
+
+        // If 0 rowSets in it, return "".
+        if (size == 0) {
+            return ""; //$NON-NLS-1$
+        }
+
+        String whereClause;
+        String tableName;
+        int metaColumnCount;
+        int matchIndex;
+        if (size == 1) {
+            tableName = ((CachedRowSet) rsList.get(0)).getTableName();
+            if (tableName == null) {
+                throw new SQLException(Messages.getString("rowset.39")); //$NON-NLS-1$
+            }
+            metaColumnCount = meta.getColumnCount();
+            whereClause = "Select"; //$NON-NLS-1$
+            for (int i = 1; i <= metaColumnCount; i++) {
+                whereClause += " " + tableName + "." + meta.getColumnName(i); //$NON-NLS-1$ //$NON-NLS-2$
+                if (i < metaColumnCount) {
+                    whereClause += ","; //$NON-NLS-1$
+                } else {
+                    whereClause += " from " + tableName; //$NON-NLS-1$
+                }
+            }
+        } else {
+            whereClause = "Select"; //$NON-NLS-1$
+            CachedRowSet rowSet;
+            String matchName;
+
+            for (int i = 0; i < size; i++) {
+                rowSet = (CachedRowSet) rsList.get(i);
+                tableName = rowSet.getTableName();
+                if (tableName == null) {
+                    throw new SQLException(Messages.getString("rowset.39")); //$NON-NLS-1$
+                }
+
+                matchIndex = matchColIndexs.get(0).intValue();
+                if (i == 0) {
+                    matchName = rowSet.getMetaData().getColumnName(matchIndex);
+                    whereClause += " " + tableName + "." + matchName + ","; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+                }
+
+                metaColumnCount = rowSet.getMetaData().getColumnCount();
+                for (int j = 1; j < matchIndex; j++) {
+                    matchName = rowSet.getMetaData().getColumnName(j);
+                    whereClause += " " + tableName + "." + matchName; //$NON-NLS-1$ //$NON-NLS-2$
+
+                    if (j != metaColumnCount - 1 || i != size - 1) {
+                        whereClause += ","; //$NON-NLS-1$
+                    } else {
+                        whereClause += " "; //$NON-NLS-1$
+                    }
+                }
+
+                for (int j = matchIndex + 1; j <= metaColumnCount; j++) {
+                    matchName = rowSet.getMetaData().getColumnName(j);
+                    whereClause += " " + tableName + "." + matchName; //$NON-NLS-1$ //$NON-NLS-2$
+
+                    if (j != metaColumnCount || i != size - 1) {
+                        whereClause += ","; //$NON-NLS-1$
+                    } else {
+                        whereClause += " "; //$NON-NLS-1$
+                    }
+                }
+            }
+            whereClause += "from "; //$NON-NLS-1$
+            for (int i = 0; i < size; i++) {
+                rowSet = (CachedRowSet) rsList.get(i);
+                tableName = rowSet.getTableName();
+
+                whereClause += tableName;
+                if (i != size - 1) {
+                    whereClause += ", "; //$NON-NLS-1$
+                } else {
+                    whereClause += " "; //$NON-NLS-1$
+                }
+            }
+
+            whereClause += "where "; //$NON-NLS-1$
+            CachedRowSet firstRowSet = (CachedRowSet) rsList.get(0);
+            String firstTableName = firstRowSet.getTableName();
+            String firstMatchName = firstRowSet.getMetaData().getColumnName(
+                    matchColIndexs.get(0).intValue());
+            for (int i = 1; i < size; i++) {
+                rowSet = (CachedRowSet) rsList.get(i);
+                tableName = rowSet.getTableName();
+                matchIndex = matchColIndexs.get(i).intValue();
+                matchName = rowSet.getMetaData().getColumnName(matchIndex);
+
+                whereClause += firstTableName + "." + firstMatchName + " = "; //$NON-NLS-1$ //$NON-NLS-2$
+                whereClause += tableName + "." + matchName; //$NON-NLS-1$
+                if (i != size - 1) {
+                    whereClause += " and "; //$NON-NLS-1$
+                }
+            }
+        }
+
+        return whereClause;
     }
 
     public void setJoinType(int joinType) throws SQLException {
         if (supportsJoinType(joinType)) {
             this.joinType = joinType;
         } else {
-            throw new SQLException("This type of join is not supported."); //$NON-NLS-1$
+            // rowset.38=This type of join is not supported
+            throw new SQLException(Messages.getString("rowset.38")); //$NON-NLS-1$
         }
     }
 
@@ -280,15 +445,469 @@
         return supportsJoinType(RIGHT_OUTER_JOIN);
     }
 
-    private boolean supportsJoinType(int joinType) {
-        if (joinType == INNER_JOIN) {
+    private boolean supportsJoinType(int type) {
+        if (type == INNER_JOIN) {
             return true;
         }
         return false;
     }
 
     public CachedRowSet toCachedRowSet() throws SQLException {
-        throw new NotImplementedException();
+        if (rsList.size() == 0) {
+            CachedRowSetImpl toCrset = new CachedRowSetImpl();
+            toCrset.setRows(new ArrayList<CachedRow>(), 0);
+            return toCrset;
+        } else if (rsList.size() == 1) {
+            CachedRowSet toCrset = ((CachedRowSet) rsList.get(0)).createCopy();
+            toCrset.setMetaData(meta);
+            return toCrset;
+        } else {
+            CachedRowSetImpl toCrset = new CachedRowSetImpl();
+            toCrset.setRows(rows, meta.getColumnCount());
+            toCrset.setMetaData(meta);
+            toCrset.columnTypes = columnTypes;
+            toCrset.setTypeMap(rsList.get(0).getTypeMap());
+            if (rsList.get(0).getUrl() != null) {
+                toCrset.setUrl(rsList.get(0).getUrl());
+                toCrset.setUsername(rsList.get(0).getUsername());
+                toCrset.setPassword(rsList.get(0).getPassword());
+            } else if (rsList.get(0).getDataSourceName() != null) {
+                toCrset.setDataSourceName(rsList.get(0).getDataSourceName());
+            }
+            return toCrset;
+        }
+    }
+
+    @Override
+    public void populate(ResultSet rs) throws SQLException {
+        // do nothing
+    }
+
+    @Override
+    public void populate(ResultSet rs, int startRow) throws SQLException {
+        // do nothing
+    }
+
+    @Override
+    public void execute() throws SQLException {
+        if (rsList.size() == 0) {
+            throw new SQLException();
+        } else if (rsList.size() == 1) {
+            try {
+                copyFirstRs.execute();
+                super.populate(copyFirstRs);
+            } catch (SQLException e) {
+                setRows(new ArrayList<CachedRow>(), getMetaData()
+                        .getColumnCount());
+                throw e;
+            }
+        } else {
+            setRows(new ArrayList<CachedRow>(), getMetaData().getColumnCount());
+            throw new SQLException();
+        }
     }
 
+    @Override
+    public void execute(Connection connection) throws SQLException {
+        if (rsList.size() == 0) {
+            throw new SQLException();
+        } else if (rsList.size() == 1) {
+            try {
+                copyFirstRs.execute(connection);
+                super.populate(copyFirstRs);
+            } catch (SQLException e) {
+                setRows(new ArrayList<CachedRow>(), getMetaData()
+                        .getColumnCount());
+                throw e;
+            }
+        } else {
+            setRows(new ArrayList<CachedRow>(), getMetaData().getColumnCount());
+            throw new SQLException();
+        }
+    }
+
+    /**
+     * Join the data with another CachedRowSet. It updates rows,
+     * currentRowIndex, currentRow and columnCount. It doesn't update its
+     * RowSetMetaData or any other status.
+     * 
+     * @throws SQLException
+     * @throws CloneNotSupportedException
+     */
+    private void innerJoin() throws SQLException, CloneNotSupportedException {
+        CachedRowSetImpl rowSetToAdd = (CachedRowSetImpl) rsList.get(rsList
+                .size() - 1);
+
+        // If it is the first RowSet added, then just copy the data of
+        // rowSetToAdd.
+        // Since here the RowSet has been added to rsList, so it is 2 to
+        // compared with, not 1.
+        if (rsList.size() < 2) {
+            // Create a new arrayList to store the copied data.
+            // Since the size will be the same with the rowSetToAdd, so
+            // initialing the list with this size will improve performance.
+            ArrayList<CachedRow> newRows = new ArrayList<CachedRow>(
+                    rowSetToAdd.rows.size());
+
+            // Make clones for all the CachedRows in rowSetToAdd, regardless of
+            // whether it is deleted.
+            CachedRow row;
+            for (int i = 0; i < rowSetToAdd.rows.size(); i++) {
+                row = rowSetToAdd.rows.get(i);
+                if (!row.isDelete() || rowSetToAdd.getShowDeleted()) {
+                    newRows.add(row.createClone());
+                }
+            }
+
+            // Sets the rows and columnCount.
+            setRows(newRows, rowSetToAdd.columnCount);
+
+            // Set the currentRow and currentRowIndex.
+            currentRowIndex = rowSetToAdd.currentRowIndex;
+            if (currentRowIndex > 0 && currentRowIndex <= rows.size()) {
+                currentRow = rows.get(currentRowIndex - 1);
+            } else {
+                currentRow = null;
+            }
+
+            // Inits other properties.
+            originalResultSet = rowSetToAdd.originalResultSet;
+            if (rowSetToAdd.conn != null) {
+                conn = rowSetToAdd.conn;
+            }
+            setTypeMap(rowSetToAdd.getTypeMap());
+            this.setTableName(rowSetToAdd.getTableName());
+            setShowDeleted(rowSetToAdd.getShowDeleted());
+        } else {
+            // Get the match index of itself and the rowSet to added.
+            int matchIndex = matchColIndexs.get(0).intValue();
+            // Here we can sure rsList.size() > 1
+            int matchIndexOfToAdd = matchColIndexs.get(rsList.size() - 1)
+                    .intValue();
+
+            // The comparator used to sort the rows of itself (When it can be
+            // sorted), and to compare
+            // the rows between these two rowSets.
+            CachedRowComparator comparator;
+
+            // If the rows can be sorted on the object of match index, call
+            // sortJoinRows.
+            // Otherwise call iterativeJoinRows.
+            if (isSortable()) {
+                comparator = new CachedRowComparator(matchIndex,
+                        matchIndexOfToAdd, true);
+                sortJoinRows(rowSetToAdd, matchIndex, matchIndexOfToAdd,
+                        comparator);
+            } else {
+                comparator = new CachedRowComparator(matchIndex,
+                        matchIndexOfToAdd, false);
+                iterativeJoinRows(rowSetToAdd, matchIndex, matchIndexOfToAdd,
+                        comparator);
+            }
+
+            // Set the cursor of rowSetToAdd to the last.
+            rowSetToAdd.last();
+
+            // Set the cursor of itself to beforeFirst.
+            beforeFirst();
+        }
+    }
+
+    private boolean isSortable() {
+        return isSortable;
+    }
+
+    private void initSortable() {
+        Class<?> clazz = columnTypes[matchColIndexs.get(0).intValue() - 1];
+        Class[] classes = clazz.getInterfaces();
+        isSortable = false;
+        for (Class<?> c : classes) {
+            if (c.equals(Comparable.class)) {
+                isSortable = true;
+                break;
+            }
+        }
+    }
+
+    private void iterativeJoinRows(CachedRowSetImpl rowSetToAdd,
+            int matchColumnIndex, int matchColumnIndexOfToAdd,
+            CachedRowComparator comparator) throws SQLException {
+        // The row from itself.
+        CachedRow row;
+        // The row from rowSet to add.
+        CachedRow rowToAdd;
+        // The row will be created to join the row and rowToAdd.
+        CachedRow newRow;
+
+        /*
+         * Create a new arrayList to store the copied data. Since the size will
+         * surely less then the min of the two rowSets, so initialing the list
+         * with half of the min will improve performance.
+         */
+        ArrayList<CachedRow> newRows = new ArrayList<CachedRow>(Math.min(rows
+                .size(), rowSetToAdd.rows.size()) / 2);
+
+        /*
+         * Computes the column count of rowSetToAdd, the result rowSet, the
+         * orignal rowSet.
+         */
+        int addedColumnCount = rowSetToAdd.getMetaData().getColumnCount();
+        int resultColumnCount = this.getMetaData().getColumnCount();
+
+        /*
+         * Since only one matched index is supported, and these two matched
+         * columns will merge to one column, so the original column count is
+         * just the minus of result comlumn count and added column count plus 1.
+         */
+        int originalColumnCount = resultColumnCount + 1 - addedColumnCount;
+
+        /*
+         * Iterates two rowsets, compare rowNum1 * rowNum2 times. If match,
+         * construct a new row, add it to the row list.
+         */
+        this.beforeFirst();
+        while (this.next()) {
+            row = this.getCurrentRow();
+            // If the value is null, just jump to next row.
+            // Since null won't match anything, even null.
+            if (row.getObject(matchColumnIndex) != null) {
+                rowSetToAdd.beforeFirst();
+                while (rowSetToAdd.next()) {
+                    rowToAdd = rowSetToAdd.getCurrentRow();
+                    if (comparator.compare(row, rowToAdd) == 0) {
+                        // It match, contruct a new row, add it to list.
+                        newRow = constructNewRow(row, rowToAdd,
+                                matchColumnIndex, matchColumnIndexOfToAdd,
+                                resultColumnCount, originalColumnCount);
+                        newRows.add(newRow);
+                    }
+                }
+            }
+        }
+
+        // Sets the rows and column count.
+        setRows(newRows, resultColumnCount);
+    }
+
+    private void sortJoinRows(CachedRowSetImpl rowSetToAdd,
+            int matchColumnIndex, int matchColumnIndexOfToAdd,
+            CachedRowComparator comparator) throws SQLException {
+        // The row from itself.
+        CachedRow row;
+        // The row from rowSet to add.
+        CachedRow rowToAdd;
+        // The row will be created to join the row and rowToAdd.
+        CachedRow newRow;
+
+        /*
+         * Create a new arrayList to store the copied data. Since the size will
+         * surely less then the min of the two rowSets, so initialing the list
+         * with half of the min will improve performance.
+         */
+        ArrayList<CachedRow> newRows = new ArrayList<CachedRow>(Math.min(rows
+                .size(), rowSetToAdd.rows.size()) / 2);
+
+        /*
+         * Computes the column count of rowSetToAdd, the result rowSet, the
+         * orignal rowSet.
+         */
+        int addedColumnCount = rowSetToAdd.getMetaData().getColumnCount();
+        int resultColumnCount = this.getMetaData().getColumnCount();
+
+        /*
+         * Since only one matched index is supported, and these two matched
+         * columns will merge to one column, so the original column count is
+         * just the minus of result comlumn count and added column count plus 1.
+         */
+        int originalColumnCount = resultColumnCount + 1 - addedColumnCount;
+
+        /*
+         * Sort the original rows. Set both the column to compared to the match
+         * index of original rows, since the comprasion will happened inside the
+         * orignal rows.
+         */
+        comparator.setFirstIndex(matchColumnIndex);
+        comparator.setSecondIndex(matchColumnIndex);
+        Collections.sort(rows, comparator);
+
+        /*
+         * Then comparator will be used to compare the object from two rowSets,
+         * so set firstIndex of comparator to match index of itself, and second
+         * index to match index of rowSet to add.
+         */
+        comparator.setFirstIndex(matchColumnIndex);
+        comparator.setSecondIndex(matchColumnIndexOfToAdd);
+
+        int position;
+        /*
+         * Iterates the rows of rowSetToAdd, find matched row in orignal rows
+         * using binary search.(It has been sorted).
+         */
+        rowSetToAdd.beforeFirst();
+        while (rowSetToAdd.next()) {
+            rowToAdd = rowSetToAdd.getCurrentRow();
+
+            /*
+             * If the value is null, just jump to next row. Since null won't
+             * match anything, even null.
+             */
+            if (rowToAdd.getObject(matchColumnIndexOfToAdd) == null) {
+                continue;
+            }
+
+            // Find the position of the matched row in original rows.
+            position = Collections.binarySearch(rows, rowToAdd, comparator);
+
+            // Not found, jump to next row.
+            if (position < 0) {
+                continue;
+            }
+
+            row = rows.get(position);
+            /*
+             * If row is deleted and showDeleted is false, it will not be
+             * joined.
+             */
+            if (getShowDeleted() || !row.isDelete()) {
+                // Contruct a new row, add it to list.
+                newRow = constructNewRow(row, rowToAdd, matchColumnIndex,
+                        matchColumnIndexOfToAdd, resultColumnCount,
+                        originalColumnCount);
+                newRows.add(newRow);
+
+                /*
+                 * Since there may be other rows also match, so we have to
+                 * examine the before positions and after positions until they
+                 * don't match. Remember, Collections.binarySearch does NOT
+                 * guarantee which row will be found if multiple element are
+                 * equal to the search value.
+                 */
+                for (int i = position - 1; i >= 0; i--) {
+                    row = rows.get(i);
+                    if (comparator.compare(row, rowToAdd) == 0) {
+                        newRow = constructNewRow(row, rowToAdd,
+                                matchColumnIndex, matchColumnIndexOfToAdd,
+                                resultColumnCount, originalColumnCount);
+                        newRows.add(newRow);
+                    } else {
+                        break;
+                    }
+                }
+
+                for (int i = position + 1; i < rows.size(); i++) {
+                    row = rows.get(i);
+                    if (comparator.compare(row, rowToAdd) == 0) {
+                        newRow = constructNewRow(row, rowToAdd,
+                                matchColumnIndex, matchColumnIndexOfToAdd,
+                                resultColumnCount, originalColumnCount);
+                        newRows.add(newRow);
+                    } else {
+                        break;
+                    }
+                }
+            }
+
+        }
+
+        // Sets the rows and column count.
+        setRows(newRows, resultColumnCount);
+    }
+
+    /**
+     * Construct a new CachedRow which will contain the data from both rows,
+     * excluding matched column, which will only appear once in the result row..
+     * 
+     * @param row
+     *            The first row to join.
+     * @param rowToAdd
+     *            The second row to join.
+     * @param matchColumnIndex
+     *            The match index of first row.
+     * @param matchColumnIndexOfToAdd
+     *            The match index of second row.
+     * @param resultColumnCount
+     *            The column count of the result row.
+     * @param originalColumnCount
+     *            The column count of original row.
+     * @return The new created CachedRow.
+     */
+    private CachedRow constructNewRow(CachedRow row, CachedRow rowToAdd,
+            int matchColumnIndex, int matchColumnIndexOfToAdd,
+            int resultColumnCount, int originalColumnCount) {
+        Object[] rowData;
+
+        rowData = new Object[resultColumnCount];
+
+        int i = 0;
+        for (; i < matchColumnIndex; i++) {
+            rowData[i] = row.getObject(i + 1);
+        }
+
+        for (; i < originalColumnCount; i++) {
+            rowData[i] = row.getObject(i + 1);
+        }
+
+        int j = 1;
+        for (; i < originalColumnCount + matchColumnIndexOfToAdd - 1; i++, j++) {
+            rowData[i] = rowToAdd.getObject(j);
+        }
+        for (; i < resultColumnCount; i++, j++) {
+            rowData[i] = rowToAdd.getObject(j + 1);
+        }
+        return new CachedRow(rowData);
+    }
+
+    private static class CachedRowComparator implements Comparator<CachedRow> {
+
+        private int firstIndex;
+
+        private int secondIndex;
+
+        private boolean isComparable;
+
+        public CachedRowComparator(int firstIndex, int secondIndex,
+                boolean isComparable) {
+            this.firstIndex = firstIndex;
+            this.secondIndex = secondIndex;
+            this.isComparable = isComparable;
+        }
+
+        public void setFirstIndex(int firstIndex) {
+            this.firstIndex = firstIndex;
+        }
+
+        public void setComparable(boolean isComparable) {
+            this.isComparable = isComparable;
+        }
+
+        public void setSecondIndex(int secondIndex) {
+            this.secondIndex = secondIndex;
+        }
+
+        public int compare(CachedRow object1, CachedRow object2) {
+            Object first = object1.getObject(firstIndex);
+            Object second = object2.getObject(secondIndex);
+
+            if (first == null && second == null) {
+                return 0;
+            }
+
+            if (first == null && second != null) {
+                return -1;
+            }
+
+            if (first != null && second == null) {
+                return 1;
+            }
+
+            if (isComparable) {
+                return ((Comparable<Object>) first).compareTo(second);
+            }
+
+            if (first.equals(second)) {
+                return 0;
+            }
+            return -1;
+        }
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/WebRowSetImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/WebRowSetImpl.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/WebRowSetImpl.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/WebRowSetImpl.java Wed Apr 30 20:14:31 2008
@@ -26,6 +26,8 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
+import javax.sql.rowset.BaseRowSet;
+import javax.sql.rowset.CachedRowSet;
 import javax.sql.rowset.WebRowSet;
 import javax.sql.rowset.spi.SyncFactoryException;
 
@@ -37,10 +39,6 @@
         super();
     }
 
-    public WebRowSetImpl(String providerID) throws SyncFactoryException {
-        super(providerID);
-    }
-
     public void readXml(Reader reader) throws SQLException {
         new XmlReaderImpl().readXML(this, reader);
     }
@@ -50,14 +48,14 @@
     }
 
     public void writeXml(ResultSet rs, Writer writer) throws SQLException {
-        populate(rs);
+        super.populate(rs);
         writeXml(writer);
         beforeFirst();
     }
 
     public void writeXml(ResultSet rs, OutputStream oStream)
             throws SQLException, IOException {
-        populate(rs);
+        super.populate(rs);
         writeXml(oStream);
         beforeFirst();
     }
@@ -70,4 +68,45 @@
         new XmlWriterImpl().writeXML(this, new OutputStreamWriter(oStream));
     }
 
+    @Override
+    public CachedRowSet createCopy() throws SQLException {
+        WebRowSetImpl webRs = new WebRowSetImpl();
+        CachedRowSet copyCrset = super.createCopy();
+        copyCrset.beforeFirst();
+        webRs.populate(copyCrset);
+        webRs.setCommand(copyCrset.getCommand());
+        Object[] params = ((CachedRowSetImpl) copyCrset).getParams();
+        for (int i = 0; i < params.length; i++) {
+            if (params[i] instanceof Object[]) {
+                Object[] objs = (Object[]) params[i];
+                // character stream
+                if (objs.length == 2) {
+                    webRs.setCharacterStream(i + 1, (Reader) objs[0],
+                            ((Integer) objs[1]).intValue());
+                } else {
+                    int type = ((Integer) objs[2]).intValue();
+                    switch (type) {
+                    case BaseRowSet.ASCII_STREAM_PARAM:
+                        webRs.setAsciiStream(i + 1, (InputStream) objs[0],
+                                ((Integer) objs[1]).intValue());
+                        break;
+                    case BaseRowSet.BINARY_STREAM_PARAM:
+                        webRs.setBinaryStream(i + 1, (InputStream) objs[0],
+                                ((Integer) objs[1]).intValue());
+                        break;
+                    }
+                }
+            } else {
+                webRs.setObject(i + 1, params[i]);
+            }
+        }
+        if (copyCrset.getUrl() != null) {
+            webRs.setUrl(copyCrset.getUrl());
+            webRs.setUsername(copyCrset.getUsername());
+            webRs.setPassword(copyCrset.getPassword());
+        } else if (copyCrset.getDataSourceName() != null) {
+            webRs.setDataSourceName(copyCrset.getDataSourceName());
+        }
+        return webRs;
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetGetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetGetTest.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetGetTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetGetTest.java Wed Apr 30 20:14:31 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/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java Wed Apr 30 20:14:31 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
         }
@@ -880,6 +879,62 @@
         assertFalse(crset.next());
     }
 
+    public void testCreateCopy4() throws Exception {
+        crset.setCommand("SELECT * FROM USER_INFO WHERE ID = ?");
+        crset.setInt(1, 3);
+        crset.execute();
+        // check data
+        assertTrue(crset.next());
+        assertEquals(3, crset.getInt(1));
+        assertFalse(crset.next());
+
+        // deep copy
+        CachedRowSet copyCrset = crset.createCopy();
+        copyCrset.beforeFirst();
+        assertTrue(copyCrset.next());
+        assertEquals(3, copyCrset.getInt(1));
+        assertFalse(copyCrset.next());
+        copyCrset.execute();
+        assertTrue(copyCrset.next());
+        assertEquals(3, copyCrset.getInt(1));
+        assertFalse(copyCrset.next());
+
+        crset.setInt(1, 4);
+        crset.execute();
+        crset.beforeFirst();
+        assertTrue(crset.next());
+        assertEquals(4, crset.getInt(1));
+        assertFalse(crset.next());
+
+        copyCrset.beforeFirst();
+        assertTrue(copyCrset.next());
+        assertEquals(3, copyCrset.getInt(1));
+        assertFalse(copyCrset.next());
+
+        copyCrset.execute();
+        copyCrset.beforeFirst();
+        assertTrue(copyCrset.next());
+        assertEquals(3, copyCrset.getInt(1));
+        assertFalse(copyCrset.next());
+
+        copyCrset.setInt(1, 1);
+        copyCrset.execute();
+        assertTrue(copyCrset.next());
+        assertEquals(1, copyCrset.getInt(1));
+        assertFalse(copyCrset.next());
+
+        crset.beforeFirst();
+        assertTrue(crset.next());
+        assertEquals(4, crset.getInt(1));
+        assertFalse(crset.next());
+
+        crset.execute();
+        crset.beforeFirst();
+        assertTrue(crset.next());
+        assertEquals(4, crset.getInt(1));
+        assertFalse(crset.next());
+    }
+
     public void testAfterLast() throws Exception {
         try {
             rs.afterLast();
@@ -1181,12 +1236,13 @@
 
         try {
             crset.getMatchColumnNames();
+            fail("Should throw SQLException");
         } catch (SQLException e) {
             // expected
         }
         assertNull(crset.getStatement());
 
-        assertEquals(true, noInitialCrset.getEscapeProcessing());
+        assertTrue(noInitialCrset.getEscapeProcessing());
         assertEquals(Connection.TRANSACTION_READ_COMMITTED, noInitialCrset
                 .getTransactionIsolation());
 
@@ -1208,9 +1264,9 @@
         assertEquals(0, noInitialCrset.getMaxRows());
 
         assertEquals(0, noInitialCrset.getPageSize());
-        assertEquals(null, noInitialCrset.getPassword());
+        assertNull(noInitialCrset.getPassword());
         assertEquals(0, noInitialCrset.getQueryTimeout());
-        assertEquals(false, noInitialCrset.getShowDeleted());
+        assertFalse(noInitialCrset.getShowDeleted());
 
         assertNull(noInitialCrset.getTableName());
         assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, noInitialCrset
@@ -1306,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));
@@ -2886,6 +2942,17 @@
             // expected
         }
     }
+
+    public void testGetOriginal() throws Exception {
+        crset = newNoInitialInstance();
+        try {
+            crset.getOriginal();
+            fail("Should throw NullPointerException.");
+        } catch (NullPointerException e) {
+            // Expected.
+        }
+    }
+
 }
 
 class Listener implements RowSetListener, Cloneable {

Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetStreamTest.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetStreamTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetStreamTest.java Wed Apr 30 20:14:31 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(new String(value.getBytes()), obj);
+
+        byte[] bytes = ((String) obj).getBytes();
+        byte[] expected = value.getBytes();
+        assertEquals(expected.length, bytes.length);
+        for (int i = 0; i < bytes.length; i++) {
+            assertEquals(expected[i], bytes[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(new String(value.getBytes()), obj);
+
+        bytes = ((String) obj).getBytes();
+        expected = value.getBytes();
+        assertEquals(expected.length, bytes.length);
+        for (int i = 0; i < bytes.length; i++) {
+            assertEquals(expected[i], bytes[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);
 
@@ -983,6 +1042,13 @@
             // expected
         }
 
+        try {
+            crset.updateCharacterStream(2, new StringReader("test"), -3);
+            fail("should throw NegativeArraySizeException");
+        } catch (NegativeArraySizeException e) {
+            // expected
+        }
+
         crset.updateCharacterStream(2, new StringReader("test"), 1);
 
         Object obj = crset.getObject(2);
@@ -1126,7 +1192,8 @@
                 // FOR BIT DATA' from a data value of type
                 // 'java.io.InputStream(ASCII)'.
                 /*
-                 * TODO It seems RI invoke wrong method when it's setBinaryStream
+                 * TODO It seems RI invoke wrong method when it's
+                 * setBinaryStream
                  */
             }
         }



Mime
View raw message