harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r646264 [11/13] - in /harmony/enhanced/classlib/branches/java6: depends/build/ depends/build/platform/ depends/files/ modules/accessibility/ modules/annotation/ modules/applet/ modules/archive/ modules/archive/src/main/java/java/util/jar/ m...
Date Wed, 09 Apr 2008 11:02:07 GMT
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=646264&r1=646263&r2=646264&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  9 04:01:14 2008
@@ -16,6 +16,11 @@
  */
 package org.apache.harmony.sql.internal.rowset;
 
+import java.net.URL;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Ref;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
@@ -23,6 +28,11 @@
 
 import javax.sql.RowSetInternal;
 import javax.sql.RowSetReader;
+import javax.sql.rowset.serial.SerialArray;
+import javax.sql.rowset.serial.SerialBlob;
+import javax.sql.rowset.serial.SerialClob;
+import javax.sql.rowset.serial.SerialDatalink;
+import javax.sql.rowset.serial.SerialRef;
 
 public class CachedRowSetReader implements RowSetReader {
 
@@ -30,11 +40,20 @@
 
     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
      */
@@ -49,10 +68,28 @@
         while (rs.next()) {
             Object[] columnData = new Object[columnCount];
             for (int i = 0; i < columnCount; i++) {
-                columnData[i] = rs.getObject(i + 1);
+                Object obj = rs.getObject(i + 1);
+                if (obj == null) {
+                    columnData[i] = null;
+                    continue;
+                }
+                if (obj instanceof Array) {
+                    obj = new SerialArray((Array) obj);
+                } else if (obj instanceof Blob) {
+                    obj = new SerialBlob((Blob) obj);
+                } else if (obj instanceof Clob) {
+                    obj = new SerialClob((Clob) obj);
+                } else if (obj instanceof Ref) {
+                    obj = new SerialRef((Ref) obj);
+                } else if (obj instanceof URL) {
+                    obj = new SerialDatalink((URL) obj);
+                }
+                columnData[i] = obj;
             }
 
-            data.add(new CachedRow(columnData));
+            CachedRow currentRow = new CachedRow(columnData);
+            currentRow.setSqlWarning(rs.getWarnings());
+            data.add(currentRow);
 
             if (maxRows > 0 && maxRows == data.size()) {
                 break;

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=646264&r1=646263&r2=646264&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  9 04:01:14 2008
@@ -25,6 +25,7 @@
 import javax.sql.RowSetWriter;
 import javax.sql.rowset.CachedRowSet;
 import javax.sql.rowset.spi.SyncProviderException;
+import javax.sql.rowset.spi.SyncResolver;
 
 public class CachedRowSetWriter implements RowSetWriter {
 
@@ -40,6 +41,8 @@
 
     private int columnCount;
 
+    private SyncResolverImpl resolver;
+
     public void setConnection(Connection conn) {
         originalConnection = conn;
     }
@@ -48,38 +51,53 @@
         return originalConnection;
     }
 
-    /**
-     * TODO add transaction
-     */
     public boolean writeData(RowSetInternal theRowSet) throws SQLException {
         initial(theRowSet);
         // analyse every row and do responsible task.
-        currentRowSet.beforeFirst();// currentRowSet.first();
-        originalRowSet.beforeFirst();// originalRowSet.first();
+        currentRowSet.beforeFirst();
+        originalRowSet.beforeFirst();
+        resolver = null;
         while (currentRowSet.next()) {
             if (currentRowSet.rowInserted()) {
-                insertCurrentRow();
+                try {
+                    insertCurrentRow();
+                } catch (SyncProviderException e) {
+                    addConflict(SyncResolver.INSERT_ROW_CONFLICT);
+                }
             } else if (currentRowSet.rowDeleted()) {
                 if (isConflictExistForCurrentRow()) {
-                    // TODO: conflict exists, should throw SyncProviderException
-                    throw new SyncProviderException();
+                    addConflict(SyncResolver.DELETE_ROW_CONFLICT);
                 }
 
                 deleteCurrentRow();
 
             } else if (currentRowSet.rowUpdated()) {
                 if (isConflictExistForCurrentRow()) {
-                    // TODO: conflict exists, should throw SyncProviderException
-                    throw new SyncProviderException();
+                    addConflict(SyncResolver.UPDATE_ROW_CONFLICT);
+                }
+                try {
+                    updateCurrentRow();
+                } catch (SyncProviderException e) {
+                    addConflict(SyncResolver.UPDATE_ROW_CONFLICT);
                 }
-                
-                updateCurrentRow();
             }
         }
-        // TODO release resource
+
+        if (resolver != null) {
+            throw new SyncProviderException(resolver);
+        }
         return true;
     }
 
+    private void addConflict(int status) throws SQLException {
+        if (resolver == null) {
+            resolver = new SyncResolverImpl(currentRowSet.getMetaData());
+        }
+
+        resolver.addConflictRow(new CachedRow(new Object[columnCount]),
+                currentRowSet.getRow(), status);
+    }
+
     /**
      * Insert the RowSet's current row to DB
      * 
@@ -120,13 +138,12 @@
          */
         PreparedStatement preSt = getConnection().prepareStatement(
                 insertSQL.toString());
-        for (int i = 0; i < updateCount; i++) {
-            preSt.setObject(i + 1, insertColValues[i]);
-        }
         try {
+            for (int i = 0; i < updateCount; i++) {
+                preSt.setObject(i + 1, insertColValues[i]);
+            }
             preSt.executeUpdate();
         } catch (SQLException e) {
-            // TODO generate SyncProviderException
             throw new SyncProviderException();
         } finally {
             preSt.close();
@@ -151,8 +168,12 @@
          */
         PreparedStatement preSt = getConnection().prepareStatement(
                 deleteSQL.toString());
-        fillParamInPreStatement(preSt, 1);
-        preSt.executeUpdate();
+        try {
+            fillParamInPreStatement(preSt, 1);
+            preSt.executeUpdate();
+        } finally {
+            preSt.close();
+        }
     }
 
     /**
@@ -193,21 +214,20 @@
          */
         PreparedStatement preSt = getConnection().prepareStatement(
                 updateSQL.toString());
-        // the SET part of SQL
-        for (int i = 0; i < updateCount; i++) {
-            if (updateColValues[i] == null) {
-                preSt.setNull(i + 1, currentRowSet.getMetaData().getColumnType(
-                        updateColIndexs[i]));
-            } else {
-                preSt.setObject(i + 1, updateColValues[i]);
-            }
-        }
-        // the WHERE part of SQL
-        fillParamInPreStatement(preSt, updateCount + 1);
         try {
+            // the SET part of SQL
+            for (int i = 0; i < updateCount; i++) {
+                if (updateColValues[i] == null) {
+                    preSt.setNull(i + 1, currentRowSet.getMetaData()
+                            .getColumnType(updateColIndexs[i]));
+                } else {
+                    preSt.setObject(i + 1, updateColValues[i]);
+                }
+            }
+            // the WHERE part of SQL
+            fillParamInPreStatement(preSt, updateCount + 1);
             preSt.executeUpdate();
         } catch (SQLException e) {
-            // TODO generate SyncProviderException
             throw new SyncProviderException();
         } finally {
             preSt.close();
@@ -244,15 +264,21 @@
 
         PreparedStatement preSt = getConnection().prepareStatement(
                 querySQL.toString());
-        fillParamInPreStatement(preSt, 1);
-        ResultSet queryRs = preSt.executeQuery();
-        if (queryRs.next()) {
-            if (queryRs.getInt(1) == 1) {
-                isExist = false;
+        ResultSet queryRs = null;
+        try {
+            fillParamInPreStatement(preSt, 1);
+            queryRs = preSt.executeQuery();
+            if (queryRs.next()) {
+                if (queryRs.getInt(1) == 1) {
+                    isExist = false;
+                }
             }
+        } finally {
+            if (queryRs != null) {
+                queryRs.close();
+            }
+            preSt.close();
         }
-        queryRs.close();
-        preSt.close();
 
         return isExist;
     }

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=646264&r1=646263&r2=646264&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  9 04:01:14 2008
@@ -22,21 +22,186 @@
 import javax.sql.rowset.Predicate;
 import javax.sql.rowset.spi.SyncFactoryException;
 
-import org.apache.harmony.luni.util.NotImplementedException;
+import org.apache.harmony.sql.internal.nls.Messages;
 
 public class FilteredRowSetImpl extends WebRowSetImpl implements FilteredRowSet {
 
+    private static final long serialVersionUID = -6532792430142890537L;
+
+    private Predicate predicate;
+
+    public FilteredRowSetImpl() throws SyncFactoryException {
+        super();
+    }
+
     public FilteredRowSetImpl(String providerID) throws SyncFactoryException {
         super(providerID);
-        // TODO Auto-generated constructor stub
     }
 
     public Predicate getFilter() {
-        throw new NotImplementedException();
+        return predicate;
     }
 
     public void setFilter(Predicate p) throws SQLException {
-        throw new NotImplementedException();
+        this.predicate = p;
     }
 
+    @Override
+    public boolean absolute(int row) throws SQLException {
+        if (predicate == null) {
+            return super.absolute(row);
+        }
+
+        beforeFirst();
+        if (row > 0) {
+            if (row > size()) {
+                afterLast();
+                return false;
+            }
+            int count = 0;
+            for (int i = 0; i < size(); i++) {
+                if (next()) {
+                    count++;
+                    if (count == row) {
+                        return true;
+                    }
+                }
+            }
+        } else if (row < 0) {
+            row = Math.abs(row);
+            if (row > size()) {
+                return false;
+            }
+            afterLast();
+            int count = 0;
+            for (int i = 0; i < size(); i++) {
+                if (previous()) {
+                    count++;
+                    if (count == row) {
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public boolean relative(int moveRows) throws SQLException {
+        if (predicate == null) {
+            return super.relative(moveRows);
+        }
+
+        if (moveRows > 0) {
+            int count = 0;
+            int maxCount = size() - getRow();
+            for (int i = 0; i < maxCount; i++) {
+                if (next()) {
+                    count++;
+                    if (count == moveRows) {
+                        return true;
+                    }
+                }
+            }
+        } else if (moveRows < 0) {
+            int count = 0;
+            int maxCount = getRow();
+            for (int i = 0; i < maxCount; i++) {
+                if (previous()) {
+                    count++;
+                    if (count == Math.abs(moveRows)) {
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public boolean next() throws SQLException {
+        if (predicate == null) {
+            return super.next();
+        }
+        while (super.next()) {
+            if (predicate.evaluate(this)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public boolean previous() throws SQLException {
+        if (predicate == null) {
+            return super.previous();
+        }
+        while (super.previous()) {
+            if (predicate.evaluate(this)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public boolean first() throws SQLException {
+        if (predicate == null) {
+            return super.first();
+        }
+        beforeFirst();
+        for (int i = 0; i < size(); i++) {
+            if (next()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public boolean last() throws SQLException {
+        if (predicate == null) {
+            return super.last();
+        }
+        afterLast();
+        for (int i = 0; i < size(); i++) {
+            if (previous()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public void insertRow() throws SQLException {
+        if (predicate != null) {
+            CachedRow insertRow = getInsertRow();
+            if (insertRow != null) {
+                for (int i = 0; i < getMetaData().getColumnCount(); i++) {
+                    if (insertRow.getUpdateMask(i)
+                            && !predicate.evaluate(insertRow.getObject(i + 1),
+                                    i + 1)) {
+                        // rowset.29=Insert failed
+                        throw new SQLException(Messages.getString("rowset.29"));
+                    }
+                }
+            }
+        }
+        super.insertRow();
+    }
+
+    @Override
+    protected void initInsertRow(int columnIndex, Object value)
+            throws SQLException {
+        super.initInsertRow(columnIndex, value);
+        if (predicate == null) {
+            return;
+        }
+        if (isCursorOnInsert() && !predicate.evaluate(value, columnIndex)) {
+            getInsertRow().updateObject(columnIndex, value);
+            // rowset.28=The given value does not lie between the filter
+            // criterion
+            throw new SQLException(Messages.getString("rowset.28"));
+        }
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/HYOptimisticProvider.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/HYOptimisticProvider.java?rev=646264&r1=646263&r2=646264&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/HYOptimisticProvider.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/HYOptimisticProvider.java
Wed Apr  9 04:01:14 2008
@@ -17,27 +17,28 @@
 
 package org.apache.harmony.sql.internal.rowset;
 
+import java.io.Serializable;
+
 import javax.sql.RowSetReader;
 import javax.sql.RowSetWriter;
 import javax.sql.rowset.spi.SyncProvider;
 import javax.sql.rowset.spi.SyncProviderException;
 
-import org.apache.harmony.luni.util.NotImplementedException;
+public class HYOptimisticProvider extends SyncProvider implements Serializable {
 
-public class HYOptimisticProvider extends SyncProvider {
+    private static final long serialVersionUID = -4275201032064821711L;
 
-    private final static String providerID = "Apache Harmony";
+    private final static String providerID = "Apache Harmony"; //$NON-NLS-1$
 
-    private final static int providerGrade = SyncProvider.DATASOURCE_NO_LOCK;
+    private final static int providerGrade = SyncProvider.GRADE_CHECK_MODIFIED_AT_COMMIT;
 
-    private final static String vendor = "Apache Harmony";
+    private final static String vendor = "Apache Harmony"; //$NON-NLS-1$
 
-    private final static String version = "";
+    private final static String version = ""; //$NON-NLS-1$
 
     @Override
     public int getDataSourceLock() throws SyncProviderException {
-        // TODO Auto-generated method stub
-        return 0;
+        return DATASOURCE_NO_LOCK;
     }
 
     @Override
@@ -52,7 +53,7 @@
 
     @Override
     public RowSetReader getRowSetReader() {
-        throw new NotImplementedException();
+        return new CachedRowSetReader();
     }
 
     @Override
@@ -73,14 +74,15 @@
     @Override
     public void setDataSourceLock(int dataSourceLock)
             throws SyncProviderException {
-        // TODO Auto-generated method stub
-
+        if (dataSourceLock != DATASOURCE_NO_LOCK) {
+            // rowset.23=Locking classification is not supported
+            throw new SyncProviderException("rowset.23"); //$NON-NLS-1$
+        }
     }
 
     @Override
     public int supportsUpdatableView() {
-        // TODO Auto-generated method stub
-        return 0;
+        return NONUPDATABLE_VIEW_SYNC;
     }
 
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JdbcRowSetImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JdbcRowSetImpl.java?rev=646264&r1=646263&r2=646264&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JdbcRowSetImpl.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JdbcRowSetImpl.java
Wed Apr  9 04:01:14 2008
@@ -18,76 +18,241 @@
 
 import java.sql.SQLException;
 import java.sql.Savepoint;
+import java.util.Arrays;
 
 import javax.sql.rowset.JdbcRowSet;
 import javax.sql.rowset.RowSetWarning;
 
-import org.apache.harmony.luni.util.NotImplementedException;
+import org.apache.harmony.sql.internal.nls.Messages;
 
 public class JdbcRowSetImpl extends AbstractRowSetImpl implements JdbcRowSet {
 
+    private String[] matchColumnNames;
+
+    private int[] matchColumnIndexes;
+
     public void commit() throws SQLException {
-        throw new NotImplementedException();
+        if (connection == null) {
+            throw new NullPointerException();
+        }
+        connection.commit();
     }
 
     public boolean getAutoCommit() throws SQLException {
-        throw new NotImplementedException();
+        if (connection == null) {
+            throw new NullPointerException();
+        }
+        return connection.getAutoCommit();
     }
 
     public RowSetWarning getRowSetWarnings() throws SQLException {
-        throw new NotImplementedException();
+        return null;
     }
 
     public void rollback() throws SQLException {
-        throw new NotImplementedException();
+        if (connection == null) {
+            throw new NullPointerException();
+        }
+
+        connection.rollback();
+        statement = null;
+        resultSet = null;
     }
 
     public void rollback(Savepoint s) throws SQLException {
-        throw new NotImplementedException();
+        if (connection == null) {
+            throw new NullPointerException();
+        }
+
+        connection.rollback(s);
+        statement = null;
+        resultSet = null;
     }
 
     public void setAutoCommit(boolean autoCommit) throws SQLException {
-        throw new NotImplementedException();
+        if (connection == null) {
+            throw new NullPointerException();
+        }
+
+        connection.setAutoCommit(autoCommit);
     }
 
     public int[] getMatchColumnIndexes() throws SQLException {
-        throw new NotImplementedException();
+        if (matchColumnIndexes == null || matchColumnIndexes.length == 0
+                || matchColumnIndexes[0] == -1) {
+            // rowset.13=Set Match columns before getting them
+            throw new SQLException(Messages.getString("rowset.13")); //$NON-NLS-1$
+        }
+
+        return matchColumnIndexes.clone();
     }
 
     public String[] getMatchColumnNames() throws SQLException {
-        throw new NotImplementedException();
+        if (matchColumnNames == null || matchColumnNames.length == 0
+                || matchColumnNames[0] == null) {
+            // rowset.13=Set Match columns before getting them
+            throw new SQLException(Messages.getString("rowset.13")); //$NON-NLS-1$
+        }
+        return matchColumnNames.clone();
     }
 
     public void setMatchColumn(int columnIdx) throws SQLException {
-        throw new NotImplementedException();
+        if (columnIdx < 0) {
+            // TODO why is 0 valid?
+            // rowset.20=Match columns should be greater than 0
+            throw new SQLException(Messages.getString("rowset.20")); //$NON-NLS-1$
+        }
+
+        if (matchColumnIndexes == null) {
+            /*
+             * FIXME initial match column, the default length of array is 10 in
+             * RI, we don't know why, just follow now
+             */
+            matchColumnIndexes = new int[10];
+            Arrays.fill(matchColumnIndexes, -1);
+        }
+
+        matchColumnIndexes[0] = columnIdx;
     }
 
     public void setMatchColumn(int[] columnIdxes) throws SQLException {
-        throw new NotImplementedException();
+        if (columnIdxes == null) {
+            throw new NullPointerException();
+        }
+
+        for (int i : columnIdxes) {
+            if (i < 0) {
+                // TODO why is 0 valid?
+                // rowset.20=Match columns should be greater than 0
+                throw new SQLException(Messages.getString("rowset.20")); //$NON-NLS-1$
+            }
+        }
+
+        if (matchColumnIndexes == null) {
+            /*
+             * FIXME initial match column, the default length of array is 10 in
+             * RI, we don't know why, just follow now
+             */
+            matchColumnIndexes = new int[10];
+            Arrays.fill(matchColumnIndexes, -1);
+        }
+
+        int[] newValue = new int[matchColumnIndexes.length + columnIdxes.length];
+        System.arraycopy(columnIdxes, 0, newValue, 0, columnIdxes.length);
+        System.arraycopy(matchColumnIndexes, 0, newValue, columnIdxes.length,
+                matchColumnIndexes.length);
+
+        matchColumnIndexes = newValue;
     }
 
     public void setMatchColumn(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        if (columnName == null || columnName.equals("")) { //$NON-NLS-1$
+            // rowset.12=Match columns should not be empty or null string
+            throw new SQLException(Messages.getString("rowset.12")); //$NON-NLS-1$
+        }
+
+        if (matchColumnNames == null) {
+            /*
+             * FIXME initial match column, the default length of array is 10 in
+             * RI, we don't know why, just follow now
+             */
+            matchColumnNames = new String[10];
+        }
+
+        matchColumnNames[0] = columnName;
     }
 
     public void setMatchColumn(String[] columnNames) throws SQLException {
-        throw new NotImplementedException();
+        if (columnNames == null) {
+            throw new NullPointerException();
+        }
+        for (String name : columnNames) {
+            if (name == null || name.equals("")) { //$NON-NLS-1$
+                // rowset.12=Match columns should not be empty or null string
+                throw new SQLException(Messages.getString("rowset.12")); //$NON-NLS-1$
+            }
+        }
+
+        if (matchColumnNames == null) {
+            /*
+             * FIXME initial match column, the default length of array is 10 in
+             * RI, we don't know why, just follow now
+             */
+            matchColumnNames = new String[10];
+        }
+
+        String[] newValue = new String[matchColumnNames.length
+                + columnNames.length];
+        System.arraycopy(columnNames, 0, newValue, 0, columnNames.length);
+        System.arraycopy(matchColumnNames, 0, newValue, columnNames.length,
+                matchColumnNames.length);
+
+        matchColumnNames = newValue;
     }
 
     public void unsetMatchColumn(int columnIdx) throws SQLException {
-        throw new NotImplementedException();
+
+        if (matchColumnIndexes == null || matchColumnIndexes.length == 0
+                || matchColumnIndexes[0] != columnIdx) {
+            throw new SQLException(Messages.getString("rowset.15")); //$NON-NLS-1$
+        }
+
+        matchColumnIndexes[0] = -1;
     }
 
     public void unsetMatchColumn(int[] columnIdxes) throws SQLException {
-        throw new NotImplementedException();
+        if (columnIdxes == null) {
+            throw new NullPointerException();
+        }
+
+        if (columnIdxes.length == 0) {
+            return;
+        }
+
+        if (matchColumnIndexes == null
+                || matchColumnIndexes.length < columnIdxes.length) {
+            throw new SQLException(Messages.getString("rowset.15")); //$NON-NLS-1$
+        }
+
+        for (int i = 0; i < columnIdxes.length; i++) {
+            if (matchColumnIndexes[i] != columnIdxes[i]) {
+                throw new SQLException(Messages.getString("rowset.15")); //$NON-NLS-1$  
 
+            }
+        }
+
+        Arrays.fill(matchColumnIndexes, 0, columnIdxes.length, -1);
     }
 
     public void unsetMatchColumn(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        if (matchColumnNames == null || matchColumnNames.length == 0
+                || !matchColumnNames[0].equals(columnName)) {
+            throw new SQLException(Messages.getString("rowset.15")); //$NON-NLS-1$
+        }
+
+        matchColumnNames[0] = null;
+
     }
 
     public void unsetMatchColumn(String[] columnName) throws SQLException {
-        throw new NotImplementedException();
-    }
+        if (columnName == null) {
+            throw new NullPointerException();
+        }
+
+        if (columnName.length == 0) {
+            return;
+        }
+
+        if (matchColumnNames == null
+                || matchColumnNames.length < columnName.length) {
+            throw new SQLException(Messages.getString("rowset.15")); //$NON-NLS-1$
+        }
+
+        for (int i = 0; i < columnName.length; i++) {
+            if (matchColumnNames[i] != columnName[i]) {
+                throw new SQLException(Messages.getString("rowset.15")); //$NON-NLS-1$  
 
+            }
+        }
 
+        Arrays.fill(matchColumnNames, 0, columnName.length, null);
+    }
 }

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=646264&r1=646263&r2=646264&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  9 04:01:14 2008
@@ -16,51 +16,232 @@
  */
 package org.apache.harmony.sql.internal.rowset;
 
+import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 
 import javax.sql.RowSet;
+import javax.sql.RowSetMetaData;
 import javax.sql.rowset.CachedRowSet;
 import javax.sql.rowset.JoinRowSet;
 import javax.sql.rowset.Joinable;
+import javax.sql.rowset.RowSetMetaDataImpl;
 import javax.sql.rowset.spi.SyncFactoryException;
 
 import org.apache.harmony.luni.util.NotImplementedException;
+import org.apache.harmony.sql.internal.nls.Messages;
 
 public class JoinRowSetImpl extends WebRowSetImpl implements JoinRowSet {
 
+    private List<RowSet> rsList;
+
+    private List<Integer> matchColIndexs;
+
+    private List<String> matchColNames;
+
+    private int joinType;
+
+    public JoinRowSetImpl() throws SyncFactoryException {
+        super();
+        initProperties();
+    }
+
     public JoinRowSetImpl(String providerID) throws SyncFactoryException {
         super(providerID);
-        // TODO Auto-generated constructor stub
+        initProperties();
+    }
+
+    private void initProperties() {
+        rsList = new ArrayList<RowSet>();
+        matchColIndexs = new ArrayList<Integer>();
+        matchColNames = new ArrayList<String>();
+        joinType = INNER_JOIN;
+    }
+
+    private void composeMetaData(ResultSetMetaData rsmd, int matchColumn)
+            throws SQLException {
+        if (getMetaData() == null) {
+            if (rsmd instanceof RowSetMetaData) {
+                setMetaData((RowSetMetaData) rsmd);
+            } else {
+                setMetaData(copyMetaData(rsmd));
+            }
+        } else {
+            int colCount = getMetaData().getColumnCount()
+                    + rsmd.getColumnCount() - 1;
+            RowSetMetaData rowSetMetaData = new RowSetMetaDataImpl();
+            rowSetMetaData.setColumnCount(colCount);
+            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$
+                }
+            }
+            int index = 0;
+            for (int j = 1; j <= rsmd.getColumnCount(); j++) {
+                if (j == matchColumn) {
+                    continue;
+                }
+                index++;
+                doCopyMetaData(rowSetMetaData, getMetaData().getColumnCount()
+                        + index, rsmd, j);
+            }
+            setMetaData(rowSetMetaData);
+        }
     }
 
     public void addRowSet(Joinable rowset) throws SQLException {
-        throw new NotImplementedException();
+        if (rowset == null || !(rowset instanceof RowSet)) {
+            // rowset.33=Not a rowset
+            throw new SQLException(Messages.getString("rowset.33")); //$NON-NLS-1$
+        }
+
+        RowSet currentRs = (RowSet) rowset;
+        if (currentRs.getMetaData() == null) {
+            // rowset.32=The given rowset is empty
+            throw new SQLException(Messages.getString("rowset.32")); //$NON-NLS-1$
+        }
+
+        int matchCol = -1;
+        try {
+            if (rowset.getMatchColumnIndexes() != null
+                    && rowset.getMatchColumnIndexes().length > 0) {
+                matchCol = rowset.getMatchColumnIndexes()[0];
+                if (matchCol <= 0
+                        || matchCol > currentRs.getMetaData().getColumnCount()) {
+                    matchCol = -2;
+                }
+            }
+        } catch (SQLException e) {
+            try {
+                if (rowset.getMatchColumnNames() != null
+                        && rowset.getMatchColumnNames().length > 0) {
+                    try {
+                        matchCol = currentRs.findColumn(rowset
+                                .getMatchColumnNames()[0]);
+                    } catch (SQLException e1) {
+                        matchCol = -3;
+                    }
+                }
+            } catch (SQLException e2) {
+                // ignore
+            }
+        } finally {
+            if (matchCol == -1) {
+                // rowset.34=Not set a match column
+                throw new SQLException(Messages.getString("rowset.34")); //$NON-NLS-1$
+            } else if (matchCol == -2) {
+                // rowset.35=Not a valid match olumn index
+                throw new SQLException(Messages.getString("rowset.35")); //$NON-NLS-1$
+            } else if (matchCol == -3) {
+                // rowset.1=Not a valid column name
+                throw new SQLException(Messages.getString("rowset.1")); //$NON-NLS-1$
+            }
+        }
+        addRowSet(currentRs, matchCol);
     }
 
     public void addRowSet(RowSet rowset, int columnIdx) throws SQLException {
-        throw new NotImplementedException();
+        if (rowset == null) {
+            throw new NullPointerException();
+        }
+        if (rowset.getMetaData() == null) {
+            // rowset.32=The given rowset is empty
+            throw new SQLException(Messages.getString("rowset.32")); //$NON-NLS-1$
+        }
+        if (columnIdx <= 0 || columnIdx > rowset.getMetaData().getColumnCount()) {
+            // rowset.35=Not a valid match olumn index
+            throw new SQLException(Messages.getString("rowset.35")); //$NON-NLS-1$
+        }
+
+        // TODO to be continue
+        rsList.add(rowset);
+        if (rsList.size() == 1) {
+            setMatchColumn(columnIdx);
+        }
+
+        if (getMetaData() != null
+                && getMetaData().getColumnType(getMatchColumnIndexes()[0]) != rowset
+                        .getMetaData().getColumnType(columnIdx)) {
+            setMetaData(null);
+            rows = null;
+            throw new SQLException(Messages.getString("rowset.10")); //$NON-NLS-1$
+        }
+
+        composeMetaData(rowset.getMetaData(), columnIdx);
+        matchColIndexs.add(columnIdx);
+
+        // TODO join data
+
     }
 
     public void addRowSet(RowSet rowset, String columnName) throws SQLException {
-        throw new NotImplementedException();
+        if (rowset == null) {
+            throw new NullPointerException();
+        }
+        if (rowset.getMetaData() == null) {
+            // rowset.32=The given rowset is empty
+            throw new SQLException(Messages.getString("rowset.32")); //$NON-NLS-1$
+        }
+
+        int columnIdx = rowset.findColumn(columnName);
+        addRowSet(rowset, columnIdx);
     }
 
     public void addRowSet(RowSet[] rowset, int[] columnIdx) throws SQLException {
-        throw new NotImplementedException();
+        if (rowset == null || columnIdx == null || rowset.length == 0
+                || columnIdx.length == 0) {
+            throw new NullPointerException();
+        }
+        if (rowset.length != columnIdx.length) {
+            // rowset.36=Number of elements of two arrays don't equal
+            throw new SQLException(Messages.getString("rowset.36")); //$NON-NLS-1$
+        }
+        for (int i = 0; i < rowset.length; i++) {
+            addRowSet(rowset[i], columnIdx[i]);
+        }
     }
 
     public void addRowSet(RowSet[] rowset, String[] columnName)
             throws SQLException {
-        throw new NotImplementedException();
+        if (rowset == null || columnName == null || rowset.length == 0
+                || columnName.length == 0) {
+            throw new NullPointerException();
+        }
+        if (rowset.length != columnName.length) {
+            // rowset.36=Number of elements of two arrays don't equal
+            throw new SQLException(Messages.getString("rowset.36")); //$NON-NLS-1$
+        }
+        for (int i = 0; i < rowset.length; i++) {
+            addRowSet(rowset[i], columnName[i]);
+        }
     }
 
     public int getJoinType() throws SQLException {
-        throw new NotImplementedException();
+        return joinType;
     }
 
     public String[] getRowSetNames() throws SQLException {
-        throw new NotImplementedException();
+        if (rsList == null || rsList.size() == 0) {
+            return new String[0];
+        }
+        String[] rowsetNames = new String[rsList.size()];
+        for (int i = 0; i < rsList.size(); i++) {
+            if (rsList.get(i) instanceof CachedRowSet) {
+                CachedRowSet cachedRs = (CachedRowSet) rsList.get(i);
+                if (cachedRs.getTableName() == null) {
+                    // rowset.37=The RowSet doesn't set the table name
+                    throw new SQLException(Messages.getString("rowset.37")); //$NON-NLS-1$
+                }
+                rowsetNames[i] = cachedRs.getTableName();
+            } else {
+                // rowset.37=The RowSet doesn't set the table name
+                throw new SQLException(Messages.getString("rowset.37")); //$NON-NLS-1$
+            }
+        }
+        return rowsetNames;
     }
 
     public Collection<?> getRowSets() throws SQLException {
@@ -72,27 +253,38 @@
     }
 
     public void setJoinType(int joinType) throws SQLException {
-        throw new NotImplementedException();
+        if (supportsJoinType(joinType)) {
+            this.joinType = joinType;
+        } else {
+            throw new SQLException("This type of join is not supported."); //$NON-NLS-1$
+        }
     }
 
     public boolean supportsCrossJoin() {
-        throw new NotImplementedException();
+        return supportsJoinType(CROSS_JOIN);
     }
 
     public boolean supportsFullJoin() {
-        throw new NotImplementedException();
+        return supportsJoinType(FULL_JOIN);
     }
 
     public boolean supportsInnerJoin() {
-        throw new NotImplementedException();
+        return supportsJoinType(INNER_JOIN);
     }
 
     public boolean supportsLeftOuterJoin() {
-        throw new NotImplementedException();
+        return supportsJoinType(LEFT_OUTER_JOIN);
     }
 
     public boolean supportsRightOuterJoin() {
-        throw new NotImplementedException();
+        return supportsJoinType(RIGHT_OUTER_JOIN);
+    }
+
+    private boolean supportsJoinType(int joinType) {
+        if (joinType == INNER_JOIN) {
+            return true;
+        }
+        return false;
     }
 
     public CachedRowSet toCachedRowSet() throws SQLException {

Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/SyncResolverImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/SyncResolverImpl.java?rev=646264&r1=646263&r2=646264&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/SyncResolverImpl.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/SyncResolverImpl.java
Wed Apr  9 04:01:14 2008
@@ -39,7 +39,6 @@
 import java.util.List;
 import java.util.Map;
 
-import javax.sql.RowSetMetaData;
 import javax.sql.rowset.BaseRowSet;
 import javax.sql.rowset.spi.SyncResolver;
 
@@ -61,7 +60,7 @@
 
     private int currentIndex;
 
-    private RowSetMetaData metadata;
+    private ResultSetMetaData metadata;
 
     private static class ConflictedRow {
         CachedRow row;
@@ -77,7 +76,7 @@
         }
     }
 
-    public SyncResolverImpl(RowSetMetaData metadata) {
+    public SyncResolverImpl(ResultSetMetaData metadata) {
         super();
         this.metadata = metadata;
         conflictRows = new ArrayList<ConflictedRow>();
@@ -166,7 +165,7 @@
             }
         }
         // rowset.1=Not a valid column name
-        throw new SQLException(Messages.getString("rowset.1"));
+        throw new SQLException(Messages.getString("rowset.1")); //$NON-NLS-1$
     }
 
     public void execute() throws SQLException {

Modified: harmony/enhanced/classlib/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=646264&r1=646263&r2=646264&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  9 04:01:14 2008
@@ -18,7 +18,9 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.io.OutputStreamWriter;
 import java.io.Reader;
 import java.io.Writer;
 import java.sql.ResultSet;
@@ -27,37 +29,45 @@
 import javax.sql.rowset.WebRowSet;
 import javax.sql.rowset.spi.SyncFactoryException;
 
-import org.apache.harmony.luni.util.NotImplementedException;
-
 public class WebRowSetImpl extends CachedRowSetImpl implements WebRowSet {
 
+    private static final long serialVersionUID = -1585509574069224797L;
+
+    public WebRowSetImpl() throws SyncFactoryException {
+        super();
+    }
+
     public WebRowSetImpl(String providerID) throws SyncFactoryException {
         super(providerID);
     }
 
     public void readXml(Reader reader) throws SQLException {
-        throw new NotImplementedException();
+        new XmlReaderImpl().readXML(this, reader);
     }
 
     public void readXml(InputStream iStream) throws SQLException, IOException {
-        throw new NotImplementedException();
+        new XmlReaderImpl().readXML(this, new InputStreamReader(iStream));
     }
 
     public void writeXml(ResultSet rs, Writer writer) throws SQLException {
-        throw new NotImplementedException();
+        populate(rs);
+        writeXml(writer);
+        beforeFirst();
     }
 
     public void writeXml(ResultSet rs, OutputStream oStream)
             throws SQLException, IOException {
-        throw new NotImplementedException();
+        populate(rs);
+        writeXml(oStream);
+        beforeFirst();
     }
 
     public void writeXml(Writer writer) throws SQLException {
-        throw new NotImplementedException();
+        new XmlWriterImpl().writeXML(this, writer);
     }
 
     public void writeXml(OutputStream oStream) throws SQLException, IOException {
-        throw new NotImplementedException();
+        new XmlWriterImpl().writeXML(this, new OutputStreamWriter(oStream));
     }
 
 }



Mime
View raw message