harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lvj...@apache.org
Subject svn commit: r643694 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/org/apache/harmony/sql/internal/nls/ main/java/org/apache/harmony/sql/internal/rowset/ test/java/org/apache/harmony/sql/tests/internal/rowset/
Date Wed, 02 Apr 2008 02:57:55 GMT
Author: lvjing
Date: Tue Apr  1 19:57:53 2008
New Revision: 643694

URL: http://svn.apache.org/viewvc?rev=643694&view=rev
Log:
Apply patch for HARMONY-5680, [classlib][sql][rowset] - Implement getJoinType, setJoinType, supportsJoin, getRowSetNames methods in JoinRowSetImpl.java

Added:
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetTest.java   (with props)
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetTestCase.java   (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JoinRowSetImpl.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetTestCase.java

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties?rev=643694&r1=643693&r2=643694&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties Tue Apr  1 19:57:53 2008
@@ -92,3 +92,9 @@
 rowset.29=Insert failed
 rowset.30=Invalid state
 rowset.31=No current connection
+rowset.32=The given rowset is empty
+rowset.33=Not a rowset
+rowset.34=Not set a match column
+rowset.35=Not a valid match olumn index
+rowset.36=Number of elements of two arrays don't equal
+rowset.37=The RowSet doesn't set the table name

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java?rev=643694&r1=643693&r2=643694&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java Tue Apr  1 19:57:53 2008
@@ -83,16 +83,16 @@
 
     private static final long serialVersionUID = 1L;
 
-    private ArrayList<CachedRow> rows;
+    protected ArrayList<CachedRow> rows;
 
-    private RowSetMetaData meta;
+    protected RowSetMetaData meta;
 
-    private CachedRow currentRow;
+    protected CachedRow currentRow;
 
     /**
      * current row index include deleted rows, start from 1
      */
-    private int currentRowIndex;
+    protected int currentRowIndex;
 
     // the number of the rows in one "page"
     private int pageSize;
@@ -763,47 +763,44 @@
     }
 
     // deep copy of ResultSetMetaData
-    private RowSetMetaData copyMetaData(ResultSetMetaData metaData)
+    protected RowSetMetaData copyMetaData(ResultSetMetaData metaData)
             throws SQLException {
         RowSetMetaDataImpl rowSetMetaData = new RowSetMetaDataImpl();
         rowSetMetaData.setColumnCount(metaData.getColumnCount());
         for (int columnIndex = 1; columnIndex <= metaData.getColumnCount(); columnIndex++) {
             rowSetMetaData.setAutoIncrement(columnIndex, metaData
                     .isAutoIncrement(columnIndex));
-            rowSetMetaData.setCaseSensitive(columnIndex, metaData
-                    .isCaseSensitive(columnIndex));
-            rowSetMetaData.setCatalogName(columnIndex, metaData
-                    .getCatalogName(columnIndex));
-            rowSetMetaData.setColumnDisplaySize(columnIndex, metaData
-                    .getColumnDisplaySize(columnIndex));
-            rowSetMetaData.setColumnLabel(columnIndex, metaData
-                    .getColumnLabel(columnIndex));
-            rowSetMetaData.setColumnName(columnIndex, metaData
-                    .getColumnName(columnIndex));
-            rowSetMetaData.setColumnType(columnIndex, metaData
-                    .getColumnType(columnIndex));
-            rowSetMetaData.setColumnTypeName(columnIndex, metaData
-                    .getColumnTypeName(columnIndex));
-            rowSetMetaData.setCurrency(columnIndex, metaData
-                    .isCurrency(columnIndex));
-            rowSetMetaData.setNullable(columnIndex, metaData
-                    .isNullable(columnIndex));
-            rowSetMetaData.setPrecision(columnIndex, metaData
-                    .getPrecision(columnIndex));
-            rowSetMetaData
-                    .setScale(columnIndex, metaData.getScale(columnIndex));
-            rowSetMetaData.setSchemaName(columnIndex, metaData
-                    .getSchemaName(columnIndex));
-            rowSetMetaData.setSearchable(columnIndex, metaData
-                    .isSearchable(columnIndex));
-            rowSetMetaData.setSigned(columnIndex, metaData
-                    .isSigned(columnIndex));
-            rowSetMetaData.setTableName(columnIndex, metaData
-                    .getTableName(columnIndex));
+            doCopyMetaData(rowSetMetaData, columnIndex, metaData, columnIndex);
         }
         return rowSetMetaData;
     }
 
+    protected void doCopyMetaData(RowSetMetaData targetRsmd, int targetIndex,
+            ResultSetMetaData srcRsmd, int srcIndex) throws SQLException {
+        targetRsmd.setAutoIncrement(targetIndex, srcRsmd
+                .isAutoIncrement(srcIndex));
+        targetRsmd.setCaseSensitive(targetIndex, srcRsmd
+                .isCaseSensitive(srcIndex));
+        targetRsmd
+                .setCatalogName(targetIndex, srcRsmd.getCatalogName(srcIndex));
+        targetRsmd.setColumnDisplaySize(targetIndex, srcRsmd
+                .getColumnDisplaySize(srcIndex));
+        targetRsmd
+                .setColumnLabel(targetIndex, srcRsmd.getColumnLabel(srcIndex));
+        targetRsmd.setColumnName(targetIndex, srcRsmd.getColumnName(srcIndex));
+        targetRsmd.setColumnType(targetIndex, srcRsmd.getColumnType(srcIndex));
+        targetRsmd.setColumnTypeName(targetIndex, srcRsmd
+                .getColumnTypeName(srcIndex));
+        targetRsmd.setCurrency(targetIndex, srcRsmd.isCurrency(srcIndex));
+        targetRsmd.setNullable(targetIndex, srcRsmd.isNullable(srcIndex));
+        targetRsmd.setPrecision(targetIndex, srcRsmd.getPrecision(srcIndex));
+        targetRsmd.setScale(targetIndex, srcRsmd.getScale(srcIndex));
+        targetRsmd.setSchemaName(targetIndex, srcRsmd.getSchemaName(srcIndex));
+        targetRsmd.setSearchable(targetIndex, srcRsmd.isSearchable(srcIndex));
+        targetRsmd.setSigned(targetIndex, srcRsmd.isSigned(srcIndex));
+        targetRsmd.setTableName(targetIndex, srcRsmd.getTableName(srcIndex));
+    }
+
     public boolean previousPage() throws SQLException {
         if (rows == null || previousPageRowIndex == -1 || getPageSize() == 0) {
             // rowset.19=Populate data before calling
@@ -2243,6 +2240,13 @@
      * @throws SQLException
      */
     private int findNextValidRow() throws SQLException {
+        if (isCursorOnInsert) {
+            // rowset.0=Not a valid position
+            throw new SQLException(Messages.getString("rowset.0")); //$NON-NLS-1$
+        }
+        if (rows == null || rows.size() == 0) {
+            return -1;
+        }
         int index = currentRowIndex + 1;
 
         if (getShowDeleted()) {
@@ -2275,6 +2279,13 @@
      * @throws SQLException
      */
     private int findPreviousValidRow() throws SQLException {
+        if (isCursorOnInsert) {
+            // rowset.0=Not a valid position
+            throw new SQLException(Messages.getString("rowset.0")); //$NON-NLS-1$
+        }
+        if (rows == null || rows.size() == 0) {
+            return -1;
+        }
         int index = currentRowIndex - 1;
 
         if (index <= 0) {

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JoinRowSetImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JoinRowSetImpl.java?rev=643694&r1=643693&r2=643694&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JoinRowSetImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/JoinRowSetImpl.java Tue Apr  1 19:57:53 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/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetTestCase.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetTestCase.java?rev=643694&r1=643693&r2=643694&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetTestCase.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetTestCase.java Tue Apr  1 19:57:53 2008
@@ -198,44 +198,54 @@
     protected void isMetaDataEquals(ResultSetMetaData expected,
             ResultSetMetaData actual) throws SQLException {
         assertEquals(expected.getColumnCount(), actual.getColumnCount());
+        isMetaDataEqualsInColCount(expected, 1, expected.getColumnCount(),
+                actual, 1);
+        assertEquals(expected.getTableName(1), actual.getTableName(1));
+    }
 
-        int columnCount = expected.getColumnCount();
-
-        for (int column = 1; column <= columnCount; column++) {
+    protected void isMetaDataEqualsInColCount(ResultSetMetaData expected,
+            int fromIndexInExpected, int toIndexInExpected,
+            ResultSetMetaData actual, int fromColInActual) throws SQLException {
+        for (int column = fromIndexInExpected; column <= toIndexInExpected; column++) {
             assertEquals(expected.isAutoIncrement(column), actual
-                    .isAutoIncrement(column));
+                    .isAutoIncrement(fromColInActual));
             assertEquals(expected.isCaseSensitive(column), actual
-                    .isCaseSensitive(column));
-            assertEquals(expected.isCurrency(column), actual.isCurrency(column));
+                    .isCaseSensitive(fromColInActual));
+            assertEquals(expected.isCurrency(column), actual
+                    .isCurrency(fromColInActual));
             assertEquals(expected.isDefinitelyWritable(column), actual
-                    .isDefinitelyWritable(column));
-            assertEquals(expected.isReadOnly(column), actual.isReadOnly(column));
+                    .isDefinitelyWritable(fromColInActual));
+            assertEquals(expected.isReadOnly(column), actual
+                    .isReadOnly(fromColInActual));
             assertEquals(expected.isSearchable(column), actual
-                    .isSearchable(column));
-            assertEquals(expected.isSigned(column), actual.isSigned(column));
-            assertEquals(expected.isWritable(column), actual.isWritable(column));
-            assertEquals(expected.isNullable(column), actual.isNullable(column));
+                    .isSearchable(fromColInActual));
+            assertEquals(expected.isSigned(column), actual
+                    .isSigned(fromColInActual));
+            assertEquals(expected.isWritable(column), actual
+                    .isWritable(fromColInActual));
+            assertEquals(expected.isNullable(column), actual
+                    .isNullable(fromColInActual));
             assertEquals(expected.getCatalogName(column), actual
-                    .getCatalogName(column));
+                    .getCatalogName(fromColInActual));
             assertEquals(expected.getColumnClassName(column), actual
-                    .getColumnClassName(column));
+                    .getColumnClassName(fromColInActual));
             assertEquals(expected.getColumnDisplaySize(column), actual
-                    .getColumnDisplaySize(column));
+                    .getColumnDisplaySize(fromColInActual));
             assertEquals(expected.getColumnLabel(column), actual
-                    .getColumnLabel(column));
+                    .getColumnLabel(fromColInActual));
             assertEquals(expected.getColumnName(column), actual
-                    .getColumnName(column));
+                    .getColumnName(fromColInActual));
             assertEquals(expected.getColumnType(column), actual
-                    .getColumnType(column));
+                    .getColumnType(fromColInActual));
             assertEquals(expected.getColumnTypeName(column), actual
-                    .getColumnTypeName(column));
+                    .getColumnTypeName(fromColInActual));
             assertEquals(expected.getPrecision(column), actual
-                    .getPrecision(column));
-            assertEquals(expected.getScale(column), actual.getScale(column));
+                    .getPrecision(fromColInActual));
+            assertEquals(expected.getScale(column), actual
+                    .getScale(fromColInActual));
             assertEquals(expected.getSchemaName(column), actual
-                    .getSchemaName(column));
-            assertEquals(expected.getTableName(column), actual
-                    .getTableName(column));
+                    .getSchemaName(fromColInActual));
+            fromColInActual++;
         }
     }
 

Added: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetTest.java?rev=643694&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetTest.java Tue Apr  1 19:57:53 2008
@@ -0,0 +1,757 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.sql.tests.internal.rowset;
+
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+
+import javax.sql.RowSet;
+import javax.sql.rowset.CachedRowSet;
+import javax.sql.rowset.FilteredRowSet;
+import javax.sql.rowset.JdbcRowSet;
+import javax.sql.rowset.Predicate;
+import javax.sql.rowset.WebRowSet;
+
+public class JoinRowSetTest extends JoinRowSetTestCase {
+
+    public void testAddJoinableRowSet_CachedRowSet_Exception() throws Exception {
+        try {
+            jrs.addRowSet(null);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+
+        try {
+            // CachedRowSet didn't set a match column
+            jrs.addRowSet(crset);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+
+        /*
+         * Test empty CachedRowSet. According to the spec, it should throw
+         * SQLException if the given rowset is empty. However, RI won't.
+         */
+        noInitialCrset.setMatchColumn(1);
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            try {
+                jrs.addRowSet(noInitialCrset);
+                fail("should throw SQLException");
+            } catch (SQLException e) {
+                // expected
+            }
+        } else {
+            assertNull(noInitialCrset.getMetaData());
+            jrs.addRowSet(noInitialCrset);
+        }
+        jrs.close();
+
+        /*
+         * Test CachedRowSet filled with data, but with an invalid column index.
+         * RI doesn't check the column index strictly.
+         */
+        jrs = newJoinRowSet();
+        crset.setMatchColumn(13);
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            try {
+                jrs.addRowSet(crset);
+                fail("should throw SQLException");
+            } catch (SQLException e) {
+                // expected
+            }
+        } else {
+            jrs.addRowSet(crset);
+        }
+        jrs.close();
+
+        /*
+         * Test CachedRowSet filled with data, but with an invalid column name
+         */
+        jrs = newJoinRowSet();
+        crset = newNoInitialInstance();
+        crset.populate(st.executeQuery("SELECT * FROM USER_INFO"));
+        crset.setMatchColumn("abc");
+        try {
+            jrs.addRowSet(crset);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        jrs.close();
+    }
+
+    public void testAddJoinableRowSet_CachedRowSet_MetaData() throws Exception {
+        assertNull(jrs.getMetaData());
+        crset.setMatchColumn(1);
+        jrs.addRowSet(crset);
+        assertSame(jrs.getMetaData(), crset.getMetaData());
+
+        noInitialCrset.setMatchColumn("AUTHORID");
+        noInitialCrset.populate(st.executeQuery("SELECT * FROM BOOKS"));
+        jrs.addRowSet(noInitialCrset);
+
+        /*
+         * The match column is named "MergedCol" in RI.
+         */
+        assertEquals("MergedCol", jrs.getMetaData().getColumnName(1));
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            isMetaDataEqualsInColCount(noInitialCrset.getMetaData(), 2,
+                    noInitialCrset.getMetaData().getColumnCount(), jrs
+                            .getMetaData(), 13);
+        }
+        isMetaDataEqualsInColCount(crset.getMetaData(), 2, crset.getMetaData()
+                .getColumnCount(), jrs.getMetaData(), 2);
+
+        /*
+         * Add another RowSet
+         */
+        insertDataToCustomerTable();
+        CachedRowSet thirdRs = newNoInitialInstance();
+        thirdRs.populate(st.executeQuery("SELECT * FROM CUSTOMER_INFO"));
+        jrs.addRowSet(thirdRs, "ID");
+
+        // check metadata
+        assertEquals(15, jrs.getMetaData().getColumnCount());
+        isMetaDataEqualsInColCount(crset.getMetaData(), 2, crset.getMetaData()
+                .getColumnCount(), jrs.getMetaData(), 2);
+        assertEquals("NAME", jrs.getMetaData().getColumnName(15));
+        jrs.close();
+    }
+
+    public void testAddJoinableRowSet_CachedRowSet_MetaData2() throws Exception {
+        /*
+         * Add the first CachedRowSet, populate with table BOOKS
+         */
+        noInitialCrset.populate(st.executeQuery("SELECT * FROM BOOKS"));
+        jrs.addRowSet(noInitialCrset, "NAME");
+        assertEquals(jrs.getMetaData(), noInitialCrset.getMetaData());
+
+        /*
+         * Add the second CachedRowSet, populate with table CUSTOMER_INFO
+         */
+        insertDataToCustomerTable();
+        CachedRowSet newCrset = newNoInitialInstance();
+        newCrset.populate(st.executeQuery("SELECT * FROM CUSTOMER_INFO"));
+        jrs.addRowSet(newCrset, "NAME");
+
+        /*
+         * TODO NOTICE The difference between RI and Harmony
+         */
+        ResultSetMetaData rsmd = jrs.getMetaData();
+        assertEquals(4, rsmd.getColumnCount());
+        assertEquals("AUTHORID", rsmd.getColumnName(1));
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertEquals("SN", rsmd.getColumnName(2));
+            assertEquals("MergedCol", rsmd.getColumnName(3));
+        } else {
+            assertEquals("MergedCol", rsmd.getColumnName(2));
+            assertEquals("NAME", rsmd.getColumnName(3));
+        }
+        assertEquals("ID", rsmd.getColumnName(4));
+
+        /*
+         * Add the third CachedRowSet, populate with table USER_INFO
+         */
+        jrs.addRowSet(crset, 2);
+        rsmd = jrs.getMetaData();
+        assertEquals(15, rsmd.getColumnCount());
+    }
+
+    public void testAddJoinableRowSet_CachedRowSet_Int_Exception()
+            throws Exception {
+        try {
+            jrs.addRowSet(null, 1);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        /*
+         * Test empty CachedRowSet
+         */
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            try {
+                // can't be empty
+                jrs.addRowSet(noInitialCrset, 1);
+                fail("should throw SQLException");
+            } catch (SQLException e) {
+                // expected
+            }
+        } else {
+            jrs.addRowSet(noInitialCrset, 1);
+        }
+        jrs.close();
+
+        /*
+         * Test non-empty CachedRowSet with invalid match column
+         */
+        try {
+            jrs.addRowSet(crset, -1);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+
+        try {
+            jrs.addRowSet(crset, 13);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+
+        try {
+            jrs.addRowSet(crset, "abc");
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        jrs.close();
+    }
+
+    public void testAddJoinableRowSet_CachedRowSet_IntArray_Exception()
+            throws Exception {
+        RowSet[] rowSets = new RowSet[2];
+        int[] matchCols = new int[1];
+        try {
+            jrs.addRowSet(rowSets, matchCols);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+
+        matchCols = new int[2];
+        try {
+            jrs.addRowSet(rowSets, matchCols);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        rowSets = new RowSet[] { crset, noInitialCrset };
+        matchCols = new int[] { 1, 1 };
+        try {
+            jrs.addRowSet(rowSets, matchCols);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+
+        noInitialCrset.populate(st.executeQuery("SELECT * FROM USER_INFO"));
+        rowSets = new RowSet[] { crset, noInitialCrset };
+        jrs.addRowSet(rowSets, matchCols);
+        jrs.close();
+    }
+
+    public void testAddJoinableRowSet_CachedRowSet_StringArray_Exception()
+            throws Exception {
+        RowSet[] rowSets = new RowSet[2];
+        String[] matchCols = new String[1];
+        try {
+            jrs.addRowSet(rowSets, matchCols);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+
+        matchCols = new String[2];
+        try {
+            jrs.addRowSet(rowSets, matchCols);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        rowSets = new RowSet[] { crset, noInitialCrset };
+        matchCols = new String[] { "ID", "AUTHORID" };
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            try {
+                jrs.addRowSet(rowSets, matchCols);
+                fail("should throw SQLException");
+            } catch (SQLException e) {
+                // expected
+            }
+        } else {
+            try {
+                jrs.addRowSet(rowSets, matchCols);
+                fail("should throw NullPointerException");
+            } catch (NullPointerException e) {
+                // expected
+            }
+        }
+
+        noInitialCrset.populate(st.executeQuery("SELECT * FROM USER_INFO"));
+        rowSets = new RowSet[] { crset, noInitialCrset };
+        try {
+            jrs.addRowSet(rowSets, matchCols);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        jrs.close();
+    }
+
+    public void testAddJoinableRowSet_WebRowSet_Exception() throws Exception {
+        /*
+         * Test empty WebRowSet
+         */
+        WebRowSet webRs = newWebRowSet();
+
+        /*
+         * Though WebRowSet implements Joinable, addRowSet(WebRowSet) would
+         * throw ClassCastException when run on RI.
+         */
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            try {
+                jrs.addRowSet(webRs);
+                fail("should throw SQLException");
+            } catch (SQLException e) {
+                // expected
+            }
+
+            webRs.setMatchColumn(1);
+            try {
+                jrs.addRowSet(webRs);
+                fail("should throw SQLException");
+            } catch (SQLException e) {
+                // expected
+            }
+        } else {
+            try {
+                jrs.addRowSet(webRs);
+                fail("should throw NullPointerException");
+            } catch (SQLException e) {
+                // Expected
+            }
+
+            webRs.setMatchColumn(1);
+            jrs.addRowSet(webRs);
+        }
+        jrs.close();
+
+        /*
+         * Test WebRowSet filled with data
+         */
+        // TODO uncomment it after implementing addRowSet(RowSet, int)
+        // jrs = newJoinRowSet();
+        // webRs = newWebRowSet();
+        // webRs.populate(st.executeQuery("SELECT * FROM USER_INFO"));
+        // webRs.setMatchColumn(1);
+        // jrs.addRowSet(webRs);
+        // assertTrue(jrs.next());
+        // assertEquals(1, jrs.getInt(1));
+        // jrs.close();
+    }
+
+    public void testAddJoinableRowSet_WebRowSet_Int_Exception()
+            throws Exception {
+        /*
+         * Test empty WebRowSet. RI would throw ClassCastException.
+         */
+        WebRowSet webRs = newWebRowSet();
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            try {
+                // can't be empty
+                jrs.addRowSet(webRs, 1);
+                fail("should throw SQLException");
+            } catch (SQLException e) {
+                // expected
+            }
+        } else {
+            jrs.addRowSet(webRs, 1);
+        }
+        jrs.close();
+
+        /*
+         * Test non-empty WebRowSet.
+         */
+        // TODO uncomment it after implementing addRowSet(RowSet, int)
+        // jrs = newJoinRowSet();
+        // webRs = newWebRowSet();
+        // webRs.populate(st.executeQuery("SELECT * FROM USER_INFO"));
+        // jrs.addRowSet(webRs, 1);
+        // assertTrue(jrs.next());
+        // assertEquals(1, jrs.getInt(1));
+        // jrs.close();
+    }
+
+    public void testAddJoinableRowSet_FilteredRowSet_Exception()
+            throws Exception {
+        /*
+         * Test empty FilteredRowSet
+         */
+        FilteredRowSet filteredRs = newFilterRowSet();
+        assertNull(filteredRs.getMetaData());
+        try {
+            // not set match column
+            jrs.addRowSet(filteredRs);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        filteredRs.setMatchColumn(1);
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            try {
+                // can't be empty
+                jrs.addRowSet(filteredRs);
+                fail("should throw SQLException");
+            } catch (SQLException e) {
+                // expected
+            }
+        } else {
+            jrs.addRowSet(filteredRs);
+        }
+        jrs.close();
+
+        /*
+         * Test FilteredRowSet filled with data, but without Filter
+         */
+        jrs = newJoinRowSet();
+        filteredRs = newFilterRowSet();
+        filteredRs.populate(st.executeQuery("SELECT * FROM USER_INFO"));
+        filteredRs.setMatchColumn(1);
+        jrs.addRowSet(filteredRs);
+        jrs.close();
+
+        /*
+         * Test FilteredRowSet filled with data and Filter
+         */
+        jrs = newJoinRowSet();
+        Predicate range = new RangeOne();
+        filteredRs.setFilter(range);
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            jrs.addRowSet(filteredRs);
+        } else {
+            try {
+                jrs.addRowSet(filteredRs);
+                fail("should throw SQLException");
+            } catch (SQLException e) {
+                // expected
+            }
+        }
+        jrs.close();
+    }
+
+    public void testAddJoinableRowSet_FilteredRowSet_Int_Exception()
+            throws Exception {
+        /*
+         * Test empty FilteredRowSet
+         */
+        FilteredRowSet filteredRs = newFilterRowSet();
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            try {
+                // can't be empty
+                jrs.addRowSet(filteredRs, 1);
+                fail("should throw SQLException");
+            } catch (SQLException e) {
+                // expected
+            }
+        } else {
+            jrs.addRowSet(filteredRs, 1);
+        }
+        jrs.close();
+
+        /*
+         * Test FilteredRowSet filled with data, but without Filter
+         */
+        jrs = newJoinRowSet();
+        filteredRs = newFilterRowSet();
+        filteredRs.populate(st.executeQuery("SELECT * FROM USER_INFO"));
+        jrs.addRowSet(filteredRs, 1);
+        jrs.close();
+
+        /*
+         * Test FilteredRowSet filled with data and Filter
+         */
+        jrs = newJoinRowSet();
+        filteredRs = newFilterRowSet();
+        filteredRs.populate(st.executeQuery("SELECT * FROM USER_INFO"));
+        Predicate range = new RangeOne();
+        filteredRs.setFilter(range);
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            jrs.addRowSet(filteredRs, 1);
+        } else {
+            try {
+                jrs.addRowSet(filteredRs, 1);
+                fail("should throw SQLException");
+            } catch (SQLException e) {
+                // expected
+            }
+        }
+        jrs.close();
+    }
+
+    public void testAddJoinableRowSet_JdbcRowSet_Exception() throws Exception {
+        /*
+         * Test empty JdbcRowSet
+         */
+        JdbcRowSet jdbcRs = newJdbcRowSet();
+        try {
+            jrs.addRowSet(jdbcRs);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        jdbcRs.setMatchColumn(1);
+        try {
+            jrs.addRowSet(jdbcRs);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        jrs.close();
+
+        /*
+         * Test JdbcRowSet filled with data
+         */
+        jrs = newJoinRowSet();
+        jdbcRs = newJdbcRowSet();
+        jdbcRs.setUrl(DERBY_URL);
+        jdbcRs.setCommand("SELECT * FROM USER_INFO");
+        jdbcRs.execute();
+        try {
+            jrs.addRowSet(jdbcRs);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        jdbcRs.setMatchColumn(2);
+        jrs.addRowSet(jdbcRs);
+        jrs.close();
+    }
+
+    public void testAddJoinableRowSet_JdbcRowSet_Int_Exception()
+            throws Exception {
+        /*
+         * Test empty JdbcRowSet
+         */
+        JdbcRowSet jdbcRs = newJdbcRowSet();
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            try {
+                jrs.addRowSet(jdbcRs, 1);
+                fail("should throw SQLException");
+            } catch (SQLException e) {
+                // expected
+            }
+        } else {
+            try {
+                jrs.addRowSet(jdbcRs, 1);
+                fail("should throw ClassCastException");
+            } catch (ClassCastException e) {
+                // expected
+            }
+        }
+        jrs.close();
+
+        /*
+         * Test JdbcRowSet filled with data
+         */
+        jrs = newJoinRowSet();
+        jdbcRs = newJdbcRowSet();
+        jdbcRs.setUrl(DERBY_URL);
+        jdbcRs.setCommand("SELECT * FROM USER_INFO");
+        jdbcRs.execute();
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            jrs.addRowSet(jdbcRs, 1);
+        } else {
+            try {
+                jrs.addRowSet(jdbcRs, 1);
+                fail("should throw ClassCastException");
+            } catch (ClassCastException e) {
+                // expected
+            }
+        }
+        jrs.close();
+    }
+
+    public void testTypeMatch() throws Exception {
+
+        for (int i = 1; i <= DEFAULT_COLUMN_COUNT; ++i) {
+            for (int j = 1; j <= DEFAULT_COLUMN_COUNT; ++j) {
+                if ((i == 7 && j == 9) || (i == 9 && j == 7)) {
+                    /*
+                     * TODO column 7 and column 9 map to same JDBC type, while
+                     * ri can't join neither
+                     */
+                    if ("true".equals(System.getProperty("Testing Harmony"))) {
+                        assertTrue(isTypeMatch(i, j));
+                    } else {
+                        assertFalse(isTypeMatch(i, j));
+                    }
+                    continue;
+                }
+
+                if (i == j) {
+                    assertTrue(isTypeMatch(i, j));
+                } else {
+                    assertFalse(isTypeMatch(i, j));
+                }
+            }
+        }
+    }
+
+    private boolean isTypeMatch(int first, int second) throws Exception {
+        jrs = newJoinRowSet();
+        CachedRowSet base = newNoInitialInstance();
+        rs = st.executeQuery("select * from USER_INFO");
+        rs.next();
+        rs.next();
+        rs.next();
+        base.populate(rs);
+
+        CachedRowSet join = newNoInitialInstance();
+        rs = st.executeQuery("select * from USER_INFO");
+        rs.next();
+        rs.next();
+        rs.next();
+        join.populate(rs);
+
+        base.setMatchColumn(first);
+
+        join.setMatchColumn(second);
+
+        jrs.addRowSet(base);
+
+        // TODO if type mismatch, harmony throw SQLException, ri is silent
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            try {
+                jrs.addRowSet(join);
+                return true;
+            } catch (SQLException e) {
+                return false;
+            }
+        } else {
+            jrs.addRowSet(join);
+            return jrs.getMetaData().getColumnName(first) != null;
+        }
+    }
+
+    public void testGetRowSetNames() throws Exception {
+        /*
+         * Add two CachedRowSet which don't set Table Name
+         */
+        assertEquals(0, jrs.getRowSetNames().length);
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertEquals("USER_INFO", crset.getTableName());
+            jrs.addRowSet(crset, 1);
+            assertEquals(1, jrs.getRowSetNames().length);
+            assertEquals("USER_INFO", jrs.getRowSetNames()[0]);
+        } else {
+            assertNull(crset.getTableName());
+            jrs.addRowSet(crset, 1);
+            assertEquals(0, jrs.getRowSetNames().length);
+            noInitialCrset.populate(st.executeQuery("SELECT * FROM BOOKS"));
+            noInitialCrset.setMatchColumn(1);
+            jrs.addRowSet(noInitialCrset);
+            if ("true".equals(System.getProperty("Testing Harmony"))) {
+                try {
+                    jrs.getRowSetNames();
+                    fail("should throw SQLException");
+                } catch (SQLException e) {
+                    // expected
+                }
+            } else {
+                try {
+                    jrs.getRowSetNames();
+                    fail("should throw NullPointerException");
+                } catch (NullPointerException e) {
+                    // expected
+                }
+            }
+        }
+
+        /*
+         * Add two CachedRowSet which both have set a table name
+         */
+        jrs = newJoinRowSet();
+        noInitialCrset = newNoInitialInstance();
+        noInitialCrset.populate(st.executeQuery("SELECT * FROM USER_INFO"));
+        noInitialCrset.setTableName("USER_INFO");
+        assertEquals("USER_INFO", noInitialCrset.getTableName());
+        noInitialCrset.setMatchColumn(1);
+        jrs.addRowSet(noInitialCrset);
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertEquals(1, jrs.getRowSetNames().length);
+            assertEquals("USER_INFO", jrs.getRowSetNames()[0]);
+        } else {
+            // RI still return 0
+            assertEquals(0, jrs.getRowSetNames().length);
+        }
+        // add the second CachedRowSet which also has set a table name
+        crset = newNoInitialInstance();
+        crset.populate(st.executeQuery("SELECT * FROM BOOKS"));
+        crset.setMatchColumn(1);
+        crset.setTableName("BOOKS");
+        assertEquals("BOOKS", crset.getTableName());
+        jrs.addRowSet(crset);
+        assertEquals(2, jrs.getRowSetNames().length);
+        assertEquals("USER_INFO", jrs.getRowSetNames()[0]);
+        assertEquals("BOOKS", jrs.getRowSetNames()[1]);
+        // add the third CachedRowSet which doesn't set a table name
+        CachedRowSet thirdCrset = newNoInitialInstance();
+        thirdCrset.populate(st.executeQuery("SELECT * FROM CUSTOMER_INFO"));
+        thirdCrset.setMatchColumn(1);
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            jrs.addRowSet(thirdCrset);
+            assertEquals(3, jrs.getRowSetNames().length);
+            assertEquals("CUSTOMER_INFO", jrs.getRowSetNames()[2]);
+        } else {
+            assertNull(thirdCrset.getTableName());
+            jrs.addRowSet(thirdCrset);
+            try {
+                jrs.getRowSetNames();
+                fail("should throw NullPointerException");
+            } catch (NullPointerException e) {
+                // expected
+            }
+        }
+
+        /*
+         * Add a JdbcRowSet which can't set Table Name
+         */
+        jrs = newJoinRowSet();
+        JdbcRowSet jdbcRs = newJdbcRowSet();
+        jdbcRs.setCommand("SELECT * FROM USER_INFO");
+        jdbcRs.setUrl(DERBY_URL);
+        jdbcRs.execute();
+        jdbcRs.setMatchColumn(1);
+        jrs.addRowSet(jdbcRs);
+        // add a CachedRowSet with table name
+        crset = newNoInitialInstance();
+        crset.populate(st.executeQuery("SELECT * FROM BOOKS"));
+        crset.setMatchColumn(1);
+        crset.setTableName("BOOKS");
+        jrs.addRowSet(crset);
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            try {
+                jrs.getRowSetNames();
+                fail("should throw SQLException");
+            } catch (SQLException e) {
+                // expected
+            }
+        } else {
+            try {
+                jrs.getRowSetNames();
+                fail("should throw NullPointerException");
+            } catch (NullPointerException e) {
+                // expected
+            }
+        }
+    }
+}

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

Added: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetTestCase.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetTestCase.java?rev=643694&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetTestCase.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/JoinRowSetTestCase.java Tue Apr  1 19:57:53 2008
@@ -0,0 +1,146 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.sql.tests.internal.rowset;
+
+import java.sql.SQLException;
+import javax.sql.RowSet;
+import javax.sql.rowset.FilteredRowSet;
+import javax.sql.rowset.JdbcRowSet;
+import javax.sql.rowset.JoinRowSet;
+import javax.sql.rowset.WebRowSet;
+
+public class JoinRowSetTestCase extends CachedRowSetTestCase {
+
+    protected JoinRowSet jrs;
+
+    public void setUp() throws Exception {
+        super.setUp();
+        createBookTable();
+        jrs = newJoinRowSet();
+    }
+
+    public void insertDataToCustomerTable() throws Exception {
+        st.executeUpdate("delete from CUSTOMER_INFO");
+        st
+                .executeUpdate("insert into CUSTOMER_INFO(ID,NAME) values (1111,'customer_one')");
+        st
+                .executeUpdate("insert into CUSTOMER_INFO(ID,NAME) values (5555,'customer_two')");
+        st
+                .executeUpdate("insert into CUSTOMER_INFO(ID,NAME) values (3,'test3')");
+        st
+                .executeUpdate("insert into CUSTOMER_INFO(ID,NAME) values (4,'test4')");
+    }
+
+    public void createBookTable() throws Exception {
+        st = conn.createStatement();
+        rs = conn.getMetaData().getTables(null, "APP", "BOOKS", null);
+        String createTableSQL = "create table BOOKS (AUTHORID INTEGER NOT NULL,SN VARCHAR(30) NOT NULL,NAME VARCHAR(30))";
+
+        if (rs.next()) {
+            st.execute("drop table BOOKS");
+        }
+        st.execute(createTableSQL);
+
+        st
+                .executeUpdate("insert into BOOKS(AUTHORID,SN,NAME) values (1,'sn1-1','test1')");
+        st
+                .executeUpdate("insert into BOOKS(AUTHORID,SN,NAME) values (1,'sn1-2','hermit')");
+        st
+                .executeUpdate("insert into BOOKS(AUTHORID,SN,NAME) values (2,'sn2-1','test')");
+        st
+                .executeUpdate("insert into BOOKS(AUTHORID,SN,NAME) values (3,'sn3-1','update3')");
+        st
+                .executeUpdate("insert into BOOKS(AUTHORID,SN,NAME) values (3,'sn3-1','test3')");
+        st
+                .executeUpdate("insert into BOOKS(AUTHORID,SN,NAME) values (4,'sn4-1','test4')");
+        st
+                .executeUpdate("insert into BOOKS(AUTHORID,SN,NAME) values (5,'sn5-1','test5')");
+    }
+
+    protected JoinRowSet newJoinRowSet() throws Exception {
+        JoinRowSet jrs = null;
+        try {
+            jrs = (JoinRowSet) Class.forName("com.sun.rowset.JoinRowSetImpl")
+                    .newInstance();
+        } catch (ClassNotFoundException e) {
+            jrs = (JoinRowSet) Class.forName(
+                    "org.apache.harmony.sql.internal.rowset.JoinRowSetImpl")
+                    .newInstance();
+        }
+        return jrs;
+    }
+
+    protected JdbcRowSet newJdbcRowSet() throws Exception {
+        try {
+            return (JdbcRowSet) Class.forName("com.sun.rowset.JdbcRowSetImpl")
+                    .newInstance();
+        } catch (ClassNotFoundException e) {
+            return (JdbcRowSet) Class.forName(
+                    "org.apache.harmony.sql.internal.rowset.JdbcRowSetImpl")
+                    .newInstance();
+        }
+    }
+
+    protected WebRowSet newWebRowSet() throws Exception {
+        try {
+            return (WebRowSet) Class.forName("com.sun.rowset.WebRowSetImpl")
+                    .newInstance();
+        } catch (ClassNotFoundException e) {
+            return (WebRowSet) Class.forName(
+                    "org.apache.harmony.sql.internal.rowset.WebRowSetImpl")
+                    .newInstance();
+        }
+    }
+
+    protected FilteredRowSet newFilterRowSet() throws Exception {
+        try {
+            return (FilteredRowSet) Class.forName(
+                    "com.sun.rowset.FilteredRowSetImpl").newInstance();
+        } catch (ClassNotFoundException e) {
+            return (FilteredRowSet) Class
+                    .forName(
+                            "org.apache.harmony.sql.internal.rowset.FilteredRowSetImpl")
+                    .newInstance();
+        }
+    }
+
+    /*
+     * Return the position of the first occurence of value in rowset on column,
+     * based from 1. return -1 if not found.
+     */
+    protected int findValue(Object value, RowSet rowset, int column)
+            throws SQLException {
+        int index = 1;
+
+        rowset.beforeFirst();
+
+        while (rowset.next()) {
+            if (value != null) {
+                if (value.equals(rowset.getObject(column))) {
+                    return index;
+                }
+            } else {
+                if (rowset.getObject(column) == null) {
+                    return index;
+                }
+            }
+            index++;
+        }
+        return -1;
+    }
+}

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



Mime
View raw message