harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lvj...@apache.org
Subject svn commit: r639565 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/org/apache/harmony/sql/internal/rowset/ test/java/org/apache/harmony/sql/tests/internal/rowset/
Date Fri, 21 Mar 2008 08:20:11 GMT
Author: lvjing
Date: Fri Mar 21 01:20:04 2008
New Revision: 639565

URL: http://svn.apache.org/viewvc?rev=639565&view=rev
Log:
Apply patch for HARMONY-5628, [classlib][sql][rowset] Implement XmlWriter

Added:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/XmlWriterImpl.java   (with props)
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetObjTypeTest.java   (with props)
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/XmlWriterTest.java   (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/WebRowSetImpl.java

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java?rev=639565&r1=639564&r2=639565&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java Fri Mar 21 01:20:04 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 {
 
@@ -58,7 +68,23 @@
         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;
             }
 
             CachedRow currentRow = new CachedRow(columnData);

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/WebRowSetImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/WebRowSetImpl.java?rev=639565&r1=639564&r2=639565&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/WebRowSetImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/WebRowSetImpl.java Fri Mar 21 01:20:04 2008
@@ -19,6 +19,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.OutputStreamWriter;
 import java.io.Reader;
 import java.io.Writer;
 import java.sql.ResultSet;
@@ -31,6 +32,10 @@
 
 public class WebRowSetImpl extends CachedRowSetImpl implements WebRowSet {
 
+    public WebRowSetImpl() throws SyncFactoryException {
+        super();
+    }
+
     public WebRowSetImpl(String providerID) throws SyncFactoryException {
         super(providerID);
     }
@@ -44,20 +49,24 @@
     }
 
     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));
     }
 
 }

Added: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/XmlWriterImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/XmlWriterImpl.java?rev=639565&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/XmlWriterImpl.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/XmlWriterImpl.java Fri Mar 21 01:20:04 2008
@@ -0,0 +1,353 @@
+/* 
+ * 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.internal.rowset;
+
+import java.io.Writer;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.Iterator;
+
+import javax.sql.rowset.WebRowSet;
+import javax.sql.rowset.spi.XmlWriter;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class XmlWriterImpl extends CachedRowSetWriter implements XmlWriter {
+
+    @SuppressWarnings("nls")
+    public void writeXML(WebRowSet caller, Writer writer) throws SQLException {
+        if (writer == null || caller == null || caller.getMetaData() == null) {
+            throw new NullPointerException();
+        }
+        caller.beforeFirst();
+        DocumentBuilder docBuidler = null;
+        Document doc = null;
+        try {
+            docBuidler = DocumentBuilderFactory.newInstance()
+                    .newDocumentBuilder();
+            doc = docBuidler.newDocument();
+        } catch (ParserConfigurationException e) {
+            throw new SQLException(e.getMessage());
+        }
+
+        /*
+         * root element: webRowSet
+         */
+        Element rootElement = doc.createElement("webRowSet");
+        rootElement.setAttribute("xmlns", "http://java.sun.com/xml/ns/jdbc");
+        rootElement.setAttribute("xmlns:xsi",
+                "http://www.w3.org/2001/XMLSchema-instance");
+        rootElement
+                .setAttribute("xsi:schemaLocation",
+                        "http://java.sun.com/xml/ns/jdbc http://java.sun.com/xml/ns/jdbc/webrowset.xsd");
+
+        /*
+         * Element: properties
+         */
+        Element prop = doc.createElement("properties");
+        rootElement.appendChild(prop);
+        writeProperties(doc, prop, caller);
+
+        /*
+         * Element: metadata
+         */
+        ResultSetMetaData rsmd = caller.getMetaData();
+        Element metadataEle = doc.createElement("metadata");
+        // column-count
+        int colCount = rsmd.getColumnCount();
+        Element colCountEle = doc.createElement("column-count");
+        colCountEle.setTextContent(Integer.toString(colCount));
+        metadataEle.appendChild(colCountEle);
+        // add each column definition
+        for (int i = 1; i <= colCount; i++) {
+            writeMetadataByCol(doc, metadataEle, rsmd, i);
+        }
+        rootElement.appendChild(metadataEle);
+
+        /*
+         * Element: data
+         */
+        Element data = doc.createElement("data");
+        rootElement.appendChild(data);
+
+        writeRowSetData(doc, data, caller);
+
+        /*
+         * add root element to Document
+         */
+        doc.appendChild(rootElement);
+
+        try {
+            Transformer transformer = TransformerFactory.newInstance()
+                    .newTransformer();
+            DOMSource domSrc = new DOMSource(doc);
+            StreamResult streamResult = new StreamResult(writer);
+            transformer.transform(domSrc, streamResult);
+        } catch (TransformerConfigurationException e) {
+            throw new SQLException(e.getMessage());
+        } catch (TransformerFactoryConfigurationError e) {
+            throw new SQLException(e.getMessage());
+        } catch (TransformerException e) {
+            throw new SQLException(e.getMessage());
+        }
+    }
+
+    private void writeRowSetData(Document doc, Element data, WebRowSet caller)
+            throws SQLException {
+        boolean preShowDelted = caller.getShowDeleted();
+        caller.setShowDeleted(true);
+
+        caller.beforeFirst();
+
+        while (caller.next()) {
+            wirteRow(doc, data, caller);
+        }
+
+        caller.setShowDeleted(preShowDelted);
+    }
+
+    private void wirteRow(Document doc, Element data, WebRowSet caller)
+            throws SQLException {
+        Element row = null;
+        if (caller.rowDeleted()) {
+            row = doc.createElement("deleteRow"); //$NON-NLS-1$
+        } else if (caller.rowInserted()) {
+            row = doc.createElement("insertRow"); //$NON-NLS-1$
+        } else if (caller.rowUpdated()) {
+            row = doc.createElement("modifyRow"); //$NON-NLS-1$
+        } else {
+            row = doc.createElement("currentRow"); //$NON-NLS-1$
+        }
+
+        data.appendChild(row);
+        for (int i = 1; i <= caller.getMetaData().getColumnCount(); ++i) {
+            if (caller.columnUpdated(i)) {
+                ResultSet result = caller.getOriginalRow();
+                result.next();
+                Object originalValue = result.getObject(i);
+                Object value = caller.getObject(i);
+                if (originalValue != null) {
+                    int columnType = caller.getMetaData().getColumnType(i);
+
+                    switch (columnType) {
+                    case Types.DATE:
+                        originalValue = Long.valueOf(result.getDate(i)
+                                .getTime());
+                        value = Long.valueOf(caller.getDate(i).getTime());
+                        break;
+                    case Types.TIME:
+                        originalValue = Long.valueOf(result.getTime(i)
+                                .getTime());
+                        value = Long.valueOf(caller.getTime(i).getTime());
+                        break;
+                    case Types.TIMESTAMP:
+                        originalValue = Long.valueOf(result.getTime(i)
+                                .getTime());
+                        value = Long.valueOf(caller.getTimestamp(i).getTime());
+                        break;
+                    }
+
+                    // leave to blank when it's binary or struct data type
+                    if (columnType == Types.ARRAY || columnType == Types.BINARY
+                            || columnType == Types.BLOB
+                            || columnType == Types.CLOB
+                            || columnType == Types.REF
+                            || columnType == Types.STRUCT
+                            || columnType == Types.DISTINCT) {
+                        originalValue = ""; //$NON-NLS-1$
+                        value = ""; //$NON-NLS-1$
+                    }
+
+                }
+
+                appendElement(row, doc, "columnValue", originalValue); //$NON-NLS-1$
+                appendElement(row, doc, "updateValue", value); //$NON-NLS-1$
+
+            } else {
+
+                Object value = caller.getObject(i);
+                if (value != null) {
+                    int columnType = caller.getMetaData().getColumnType(i);
+                    switch (columnType) {
+                    case Types.DATE:
+                        value = Long.valueOf(caller.getDate(i).getTime());
+                        break;
+                    case Types.TIME:
+                        value = Long.valueOf(caller.getTime(i).getTime());
+                        break;
+                    case Types.TIMESTAMP:
+                        value = Long.valueOf(caller.getTime(i).getTime());
+                        break;
+                    }
+                    // leave to blank when it's binary or struct data type
+                    if (columnType == Types.ARRAY || columnType == Types.BINARY
+                            || columnType == Types.BLOB
+                            || columnType == Types.CLOB
+                            || columnType == Types.REF
+                            || columnType == Types.STRUCT
+                            || columnType == Types.DISTINCT) {
+                        value = ""; //$NON-NLS-1$
+                    }
+                }
+
+                appendElement(row, doc, "columnValue", value); //$NON-NLS-1$
+            }
+        }
+    }
+
+    @SuppressWarnings( { "nls", "boxing" })
+    private void writeProperties(Document doc, Element prop, WebRowSet caller)
+            throws SQLException {
+
+        appendElement(prop, doc, "command", caller.getCommand());
+        appendElement(prop, doc, "concurrency", caller.getConcurrency());
+        appendElement(prop, doc, "datasource", caller.getDataSourceName());
+        appendElement(prop, doc, "escape-processing", caller
+                .getEscapeProcessing());
+        appendElement(prop, doc, "fetch-direction", caller.getFetchDirection());
+        appendElement(prop, doc, "fetch-size", caller.getFetchSize());
+        appendElement(prop, doc, "isolation-level", caller
+                .getTransactionIsolation());
+
+        // write key columns
+        Element keyColumns = doc.createElement("key-columns");
+        prop.appendChild(keyColumns);
+
+        int[] indexes = caller.getKeyColumns();
+        for (int i = 0; i < indexes.length; ++i) {
+            appendElement(keyColumns, doc, "column", indexes[i]);
+        }
+
+        // wirte type map
+        Element typeMap = doc.createElement("map");
+        prop.appendChild(typeMap);
+        if (caller.getTypeMap() != null) {
+            for (Iterator<String> iter = caller.getTypeMap().keySet()
+                    .iterator(); iter.hasNext();) {
+                String key = iter.next();
+                appendElement(typeMap, doc, "type", key);
+                appendElement(typeMap, doc, "class", caller.getTypeMap().get(
+                        key).getName());
+            }
+        }
+
+        appendElement(prop, doc, "max-field-size", caller.getMaxFieldSize());
+        appendElement(prop, doc, "max-rows", caller.getMaxRows());
+        appendElement(prop, doc, "query-timeout", caller.getQueryTimeout());
+        appendElement(prop, doc, "read-only", caller.isReadOnly());
+
+        String rowsetType = null;
+        switch (caller.getType()) {
+        case ResultSet.TYPE_FORWARD_ONLY:
+            rowsetType = "ResultSet.TYPE_FORWARD_ONLY";
+            break;
+        case ResultSet.TYPE_SCROLL_INSENSITIVE:
+            rowsetType = "ResultSet.TYPE_SCROLL_INSENSITIVE";
+            break;
+        case ResultSet.TYPE_SCROLL_SENSITIVE:
+            rowsetType = "ResultSet.TYPE_SCROLL_SENSITIVE";
+            break;
+
+        }
+
+        appendElement(prop, doc, "rowset-type", rowsetType);
+
+        appendElement(prop, doc, "show-deleted", caller.getShowDeleted());
+        appendElement(prop, doc, "table-name", caller.getTableName());
+        appendElement(prop, doc, "url", caller.getUrl());
+
+        Element provider = doc.createElement("sync-provider");
+        prop.appendChild(provider);
+
+        appendElement(provider, doc, "sync-provider-name", caller
+                .getSyncProvider().getProviderID());
+        appendElement(provider, doc, "sync-provider-vendor", caller
+                .getSyncProvider().getVendor());
+        appendElement(provider, doc, "sync-provider-version", caller
+                .getSyncProvider().getVersion());
+        appendElement(provider, doc, "sync-provider-grade", caller
+                .getSyncProvider().getProviderGrade());
+        appendElement(provider, doc, "data-source-lock", caller
+                .getSyncProvider().getDataSourceLock());
+
+    }
+
+    private Element createElement(Document doc, String name, Object value) {
+        Element element = doc.createElement(name);
+        if (value == null) {
+            element.appendChild(doc.createElement("null")); //$NON-NLS-1$
+        } else {
+            element.setTextContent(value.toString());
+        }
+
+        return element;
+    }
+
+    private void appendElement(Element root, Document doc, String name,
+            Object value) {
+        Element child = createElement(doc, name, value);
+        root.appendChild(child);
+    }
+
+    @SuppressWarnings( { "nls", "boxing" })
+    private void writeMetadataByCol(Document doc, Element ele,
+            ResultSetMetaData rsmd, int colIndex) throws SQLException {
+        Element colDefEle = doc.createElement("column-definition");
+        appendElement(colDefEle, doc, "column-index", colIndex);
+        appendElement(colDefEle, doc, "auto-increment", rsmd
+                .isAutoIncrement(colIndex));
+        appendElement(colDefEle, doc, "case-sensitive", rsmd
+                .isCaseSensitive(colIndex));
+        appendElement(colDefEle, doc, "currency", rsmd.isCurrency(colIndex));
+        appendElement(colDefEle, doc, "nullable", rsmd.isNullable(colIndex));
+        appendElement(colDefEle, doc, "signed", rsmd.isSigned(colIndex));
+        appendElement(colDefEle, doc, "searchable", rsmd.isSearchable(colIndex));
+        appendElement(colDefEle, doc, "column-display-size", rsmd
+                .getColumnDisplaySize(colIndex));
+        appendElement(colDefEle, doc, "column-label", rsmd
+                .getColumnLabel(colIndex));
+        appendElement(colDefEle, doc, "column-name", rsmd
+                .getColumnName(colIndex));
+        appendElement(colDefEle, doc, "schema-name", rsmd
+                .getSchemaName(colIndex));
+        appendElement(colDefEle, doc, "column-precision", rsmd
+                .getPrecision(colIndex));
+        appendElement(colDefEle, doc, "column-scale", rsmd.getScale(colIndex));
+        appendElement(colDefEle, doc, "table-name", rsmd.getTableName(colIndex));
+        appendElement(colDefEle, doc, "catalog-name", rsmd
+                .getCatalogName(colIndex));
+        appendElement(colDefEle, doc, "column-type", rsmd
+                .getColumnType(colIndex));
+        appendElement(colDefEle, doc, "column-type-name", rsmd
+                .getColumnTypeName(colIndex));
+        ele.appendChild(colDefEle);
+    }
+}

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

Added: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetObjTypeTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetObjTypeTest.java?rev=639565&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetObjTypeTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetObjTypeTest.java Fri Mar 21 01:20:04 2008
@@ -0,0 +1,106 @@
+/* 
+ * 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.Blob;
+import java.sql.Clob;
+import java.sql.PreparedStatement;
+
+import javax.sql.rowset.CachedRowSet;
+import javax.sql.rowset.serial.SerialBlob;
+import javax.sql.rowset.serial.SerialClob;
+
+public class CachedRowSetObjTypeTest extends CachedRowSetTestCase {
+
+    public final static int DEFAULT_COLUMN_COUNT = 3;
+
+    public final static int DEFAULT_ROW_COUNT = 1;
+
+    public void setUp() throws Exception {
+        super.setUp();
+        st = conn.createStatement();
+        rs = conn.getMetaData().getTables(null, "APP", "OBJ_TABLE", null);
+        String createTableSQL = "create table OBJ_TABLE (ID INTEGER NOT NULL, BLOB_T BLOB, CLOB_T CLOB)";
+        String alterTableSQL = "ALTER TABLE OBJ_TABLE  ADD CONSTRAINT OBJ_TABLE_PK Primary Key (ID)";
+
+        if (!rs.next()) {
+            st.execute(createTableSQL);
+            st.execute(alterTableSQL);
+        }
+
+        st.executeUpdate("delete from OBJ_TABLE");
+
+        String insertSQL = "INSERT INTO OBJ_TABLE(ID, BLOB_T, CLOB_T) VALUES(?, ?, ?)";
+        PreparedStatement preStmt = conn.prepareStatement(insertSQL);
+        preStmt.setInt(1, 1);
+        String sBlob = "It is a BLOB object. The sql type is BLOB.";
+        preStmt.setBytes(2, sBlob.getBytes());
+        preStmt.setString(3, "It is a CLOB object. The sql type is CLOB.");
+        assertEquals(1, preStmt.executeUpdate());
+
+        try {
+            crset = (CachedRowSet) Class.forName(
+                    "com.sun.rowset.CachedRowSetImpl").newInstance();
+            noInitialCrset = (CachedRowSet) Class.forName(
+                    "com.sun.rowset.CachedRowSetImpl").newInstance();
+        } catch (ClassNotFoundException e) {
+
+            crset = (CachedRowSet) Class.forName(
+                    "org.apache.harmony.sql.internal.rowset.CachedRowSetImpl")
+                    .newInstance();
+            noInitialCrset = (CachedRowSet) Class.forName(
+                    "org.apache.harmony.sql.internal.rowset.CachedRowSetImpl")
+                    .newInstance();
+
+            System.setProperty("Testing Harmony", "true");
+        }
+
+        rs = st.executeQuery("SELECT * FROM OBJ_TABLE");
+        crset.populate(rs);
+        crset.setUrl(DERBY_URL);
+        assertTrue(crset.next());
+    }
+
+    public void testGet() throws Exception {
+        Object objBlob = crset.getObject(2);
+        Object objClob = crset.getObject(3);
+        boolean isBlob = false;
+        boolean isClob = false;
+        if (objBlob instanceof SerialBlob) {
+            isBlob = true;
+        }
+        if (objClob instanceof SerialClob) {
+            isClob = true;
+        }
+        assertTrue(isBlob);
+        assertTrue(isClob);
+
+        isBlob = false;
+        isClob = false;
+        Blob blob = crset.getBlob(2);
+        Clob clob = crset.getClob(3);
+        if (blob instanceof SerialBlob) {
+            isBlob = true;
+        }
+        if (clob instanceof SerialClob) {
+            isClob = true;
+        }
+        assertTrue(isBlob);
+        assertTrue(isClob);
+    }
+}

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

Added: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/XmlWriterTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/XmlWriterTest.java?rev=639565&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/XmlWriterTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/XmlWriterTest.java Fri Mar 21 01:20:04 2008
@@ -0,0 +1,766 @@
+/* 
+ * 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.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.sql.Array;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.Types;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.sql.rowset.CachedRowSet;
+import javax.sql.rowset.WebRowSet;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+public class XmlWriterTest extends CachedRowSetTestCase {
+
+    private StringWriter strWriter = null;
+
+    public void setUp() throws Exception {
+        super.setUp();
+        strWriter = new StringWriter();
+    }
+
+    public void testWriteXML() throws Exception {
+        WebRowSet webRs = newWebRowSet();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        webRs.populate(rs);
+
+        Map<String, Class<?>> map = new HashMap<String, Class<?>>();
+        map.put("VARCHAR", String.class);
+        map.put("Array", Array.class);
+        webRs.setTypeMap(map);
+
+        webRs.setKeyColumns(new int[] { 2, 1 });
+
+        // update a row
+        assertTrue(webRs.absolute(4));
+        webRs.updateInt(1, 44);
+        webRs.updateString(2, "update44");
+        webRs.updateRow();
+
+        // update a row but not call updateRow()
+        assertTrue(webRs.absolute(2));
+        webRs.updateInt(1, 22);
+
+        // delete a row
+        assertTrue(webRs.absolute(3));
+        webRs.deleteRow();
+
+        // insert a row
+        webRs.moveToInsertRow();
+        webRs.updateInt(1, 77);
+        webRs.updateString(2, "insert77");
+        webRs.insertRow();
+        webRs.moveToCurrentRow();
+
+        webRs.writeXml(strWriter);
+
+        Document doc = getDocument(strWriter);
+        assertProperties(doc, webRs);
+        assertMetadata(doc, webRs);
+        assertData(doc, webRs);
+
+        webRs = newWebRowSet();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        webRs.populate(rs);
+
+        strWriter = new StringWriter();
+        webRs.writeXml(strWriter);
+
+        doc = getDocument(strWriter);
+        assertProperties(doc, webRs);
+        assertMetadata(doc, webRs);
+        assertData(doc, webRs);
+    }
+
+    public void testWriteXML_Update() throws Exception {
+        WebRowSet webRs = newWebRowSet();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        webRs.populate(rs);
+
+        webRs.absolute(3);
+        webRs.updateString(2, "update3");
+
+        webRs.writeXml(strWriter);
+
+        assertTrue(webRs.isAfterLast());
+
+        Document doc = getDocument(strWriter);
+
+        assertProperties(doc, webRs);
+        assertMetadata(doc, webRs);
+        assertData(doc, webRs);
+
+        webRs.updateRow();
+
+        strWriter = new StringWriter();
+        webRs.writeXml(strWriter);
+
+        assertTrue(webRs.isAfterLast());
+
+        doc = getDocument(strWriter);
+
+        assertProperties(doc, webRs);
+        assertMetadata(doc, webRs);
+        assertData(doc, webRs);
+    }
+
+    public void testWriteXML_Insert() throws Exception {
+        WebRowSet webRs = newWebRowSet();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        webRs.populate(rs);
+
+        webRs.moveToInsertRow();
+        webRs.updateString(2, "update3");
+        webRs.updateInt(4, 3);
+        webRs.moveToCurrentRow();
+
+        webRs.writeXml(strWriter);
+
+        assertTrue(webRs.isAfterLast());
+
+        Document doc = getDocument(strWriter);
+
+        assertProperties(doc, webRs);
+        assertMetadata(doc, webRs);
+        assertData(doc, webRs);
+
+        webRs = newWebRowSet();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        webRs.populate(rs);
+
+        assertTrue(webRs.absolute(3));
+        webRs.moveToInsertRow();
+        webRs.updateString(2, "insert5");
+        webRs.updateInt(1, 5);
+        webRs.insertRow();
+        webRs.moveToCurrentRow();
+        webRs.next();
+        webRs.updateString(2, "update5");
+        webRs.updateInt(1, 6);
+
+        strWriter = new StringWriter();
+        webRs.writeXml(strWriter);
+
+        assertTrue(webRs.isAfterLast());
+
+        doc = getDocument(strWriter);
+
+        assertProperties(doc, webRs);
+        assertMetadata(doc, webRs);
+        assertData(doc, webRs);
+    }
+
+    public void testWriteXML_Delete() throws Exception {
+        WebRowSet webRs = newWebRowSet();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        webRs.populate(rs);
+
+        webRs.absolute(3);
+        webRs.deleteRow();
+
+        assertEquals(0, webRs.getRow());
+
+        webRs.writeXml(strWriter);
+
+        assertTrue(webRs.isAfterLast());
+
+        Document doc = getDocument(strWriter);
+
+        assertProperties(doc, webRs);
+        assertMetadata(doc, webRs);
+        assertData(doc, webRs);
+    }
+
+    public void testWriteXML_Update_Delete() throws Exception {
+        WebRowSet webRs = newWebRowSet();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        webRs.populate(rs);
+
+        webRs.absolute(3);
+        webRs.updateString(2, "update3");
+
+        webRs.deleteRow();
+
+        webRs.writeXml(strWriter);
+
+        assertTrue(webRs.isAfterLast());
+
+        Document doc = getDocument(strWriter);
+
+        assertProperties(doc, webRs);
+        assertMetadata(doc, webRs);
+        assertData(doc, webRs);
+
+        webRs = newWebRowSet();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        webRs.populate(rs);
+
+        webRs.absolute(3);
+        webRs.updateString(2, "update3");
+        webRs.updateRow();
+
+        webRs.deleteRow();
+
+        strWriter = new StringWriter();
+        webRs.writeXml(strWriter);
+
+        assertTrue(webRs.isAfterLast());
+
+        doc = getDocument(strWriter);
+
+        assertProperties(doc, webRs);
+        assertMetadata(doc, webRs);
+        assertData(doc, webRs);
+    }
+
+    public void testWriteXML_NotInitial() throws Exception {
+        WebRowSet webRs = newWebRowSet();
+
+        try {
+            webRs.writeXml(strWriter);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        Writer writer = null;
+        try {
+            webRs.writeXml(writer);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+    }
+
+    public void testWriteXML_ResultSet() throws Exception {
+        WebRowSet webRs = newWebRowSet();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+
+        webRs.writeXml(rs, strWriter);
+
+        /*
+         * TODO spec says the cursor should move to previous position after
+         * writing. However, RI doesn't. Harmony follows spec
+         */
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertTrue(webRs.isBeforeFirst());
+        } else {
+            assertTrue(webRs.isAfterLast());
+        }
+
+        Document doc = getDocument(strWriter);
+
+        assertProperties(doc, webRs);
+        assertMetadata(doc, webRs);
+        assertData(doc, webRs);
+
+        webRs.absolute(2);
+
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        strWriter = new StringWriter();
+        webRs.writeXml(rs, strWriter);
+
+        /*
+         * TODO spec says the cursor should move to previous position after
+         * writing. However, RI doesn't. Harmony follows spec
+         */
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertTrue(webRs.isBeforeFirst());
+        } else {
+            assertTrue(webRs.isAfterLast());
+        }
+
+        doc = getDocument(strWriter);
+
+        assertProperties(doc, webRs);
+        assertMetadata(doc, webRs);
+        assertData(doc, webRs);
+    }
+
+    protected WebRowSet newWebRowSet() throws Exception {
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            return (WebRowSet) Class.forName(
+                    "org.apache.harmony.sql.internal.rowset.WebRowSetImpl")
+                    .newInstance();
+        }
+        return (WebRowSet) Class.forName("com.sun.rowset.WebRowSetImpl")
+                .newInstance();
+    }
+
+    public Document getDocument(StringWriter strWriter) throws Exception {
+        StringBuffer buffer = strWriter.getBuffer();
+        DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance()
+                .newDocumentBuilder();
+        return docBuilder.parse(new InputSource(new StringReader(buffer
+                .toString())));
+    }
+
+    public void assertProperties(Document doc, WebRowSet webRs)
+            throws Exception {
+        Element element = (Element) doc.getFirstChild();
+        Element prop = getElement(element, "properties");
+
+        element = getElement(prop, "command");
+        assertNotNull(element);
+        if (webRs.getCommand() != null) {
+            assertEquals(webRs.getCommand(), element.getTextContent());
+        } else {
+            assertEquals("null", element.getFirstChild().getNodeName());
+            assertEquals("", element.getFirstChild().getTextContent());
+        }
+
+        element = getElement(prop, "concurrency");
+        assertNotNull(element);
+        assertEquals(webRs.getConcurrency(), Integer.valueOf(
+                element.getTextContent()).intValue());
+
+        element = getElement(prop, "datasource");
+        assertNotNull(element);
+        if (webRs.getDataSourceName() != null) {
+            assertEquals(webRs.getDataSourceName(), element.getTextContent());
+        } else {
+            assertEquals("null", element.getFirstChild().getNodeName());
+            assertEquals("", element.getFirstChild().getTextContent());
+        }
+
+        element = getElement(prop, "escape-processing");
+        assertNotNull(element);
+        assertEquals(webRs.getEscapeProcessing(), Boolean.valueOf(
+                element.getTextContent()).booleanValue());
+
+        element = getElement(prop, "fetch-direction");
+        assertNotNull(element);
+
+        assertEquals(webRs.getFetchDirection(), Integer.valueOf(
+                element.getTextContent()).intValue());
+
+        element = getElement(prop, "fetch-size");
+        assertNotNull(element);
+        assertEquals(webRs.getFetchSize(), Integer.valueOf(
+                element.getTextContent()).intValue());
+
+        element = getElement(prop, "isolation-level");
+        assertNotNull(element);
+        assertEquals(webRs.getTransactionIsolation(), Integer.valueOf(
+                element.getTextContent()).intValue());
+
+        element = getElement(prop, "key-columns");
+        assertNotNull(element);
+        NodeList list = element.getChildNodes();
+
+        for (int i = 0, j = 0; i < list.getLength(); ++i) {
+            if (list.item(i) instanceof Element) {
+                assertEquals(webRs.getKeyColumns()[j], Integer.valueOf(
+                        list.item(i).getTextContent()).intValue());
+                ++j;
+            }
+        }
+
+        element = getElement(prop, "map");
+        assertNotNull(element);
+        list = element.getChildNodes();
+        int i = 0;
+        if (webRs.getTypeMap() != null) {
+            for (Iterator iter = webRs.getTypeMap().keySet().iterator(); iter
+                    .hasNext();) {
+                String key = (String) iter.next();
+                while (!(list.item(i) instanceof Element)) {
+                    i++;
+                }
+                assertEquals("type", list.item(i).getNodeName());
+                assertEquals(key, list.item(i).getTextContent());
+                ++i;
+
+                while (!(list.item(i) instanceof Element)) {
+                    i++;
+                }
+                assertEquals("class", list.item(i).getNodeName());
+                assertEquals(webRs.getTypeMap().get(key).getName(), list
+                        .item(i).getTextContent());
+                ++i;
+            }
+        }
+
+        element = getElement(prop, "max-field-size");
+        assertNotNull(element);
+        assertEquals(webRs.getMaxFieldSize(), Integer.valueOf(
+                element.getTextContent()).intValue());
+
+        element = getElement(prop, "max-rows");
+        assertNotNull(element);
+        assertEquals(webRs.getMaxRows(), Integer.valueOf(
+                element.getTextContent()).intValue());
+
+        element = getElement(prop, "query-timeout");
+        assertNotNull(element);
+        assertEquals(webRs.getQueryTimeout(), Integer.valueOf(
+                element.getTextContent()).intValue());
+
+        element = getElement(prop, "read-only");
+        assertNotNull(element);
+        assertEquals(webRs.isReadOnly(), Boolean.valueOf(
+                element.getTextContent()).booleanValue());
+
+        element = getElement(prop, "rowset-type");
+        assertNotNull(element);
+        switch (webRs.getType()) {
+        case ResultSet.TYPE_FORWARD_ONLY:
+            assertEquals("ResultSet.TYPE_FORWARD_ONLY", element
+                    .getTextContent());
+            break;
+
+        case ResultSet.TYPE_SCROLL_INSENSITIVE:
+            assertEquals("ResultSet.TYPE_SCROLL_INSENSITIVE", element
+                    .getTextContent());
+            break;
+
+        case ResultSet.TYPE_SCROLL_SENSITIVE:
+            assertEquals("ResultSet.TYPE_SCROLL_SENSITIVE", element
+                    .getTextContent());
+            break;
+        }
+
+        element = getElement(prop, "show-deleted");
+        assertNotNull(element);
+        /*
+         * TODO RI would change show deleted to true after writing data, but the
+         * value written to xml is right
+         */
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            assertEquals(webRs.getShowDeleted(), Boolean.valueOf(
+                    element.getTextContent()).booleanValue());
+        }
+
+        element = getElement(prop, "table-name");
+        assertNotNull(element);
+        if (webRs.getTableName() != null) {
+            assertEquals(webRs.getTableName(), element.getTextContent());
+        } else {
+            assertEquals("null", element.getFirstChild().getNodeName());
+            assertEquals("", element.getFirstChild().getTextContent());
+        }
+
+        element = getElement(prop, "url");
+        assertNotNull(element);
+        if (webRs.getUrl() != null) {
+            assertEquals(webRs.getUrl(), element.getTextContent());
+        } else {
+            assertEquals("null", element.getFirstChild().getNodeName());
+            assertEquals("", element.getFirstChild().getTextContent());
+        }
+
+        Element provider = getElement(prop, "sync-provider");
+
+        element = getElement(provider, "sync-provider-name");
+        assertNotNull(element);
+        assertEquals(webRs.getSyncProvider().getProviderID(), element
+                .getTextContent());
+
+        element = getElement(provider, "sync-provider-vendor");
+        assertNotNull(element);
+        assertEquals(webRs.getSyncProvider().getVendor(), element
+                .getTextContent());
+
+        element = getElement(provider, "sync-provider-version");
+        assertNotNull(element);
+        assertEquals(webRs.getSyncProvider().getVersion(), element
+                .getTextContent());
+
+        element = getElement(provider, "sync-provider-grade");
+        assertNotNull(element);
+        assertEquals(webRs.getSyncProvider().getProviderGrade(), Integer
+                .valueOf(element.getTextContent()).intValue());
+
+        element = getElement(provider, "data-source-lock");
+        assertNotNull(element);
+        assertEquals(webRs.getSyncProvider().getDataSourceLock(), Integer
+                .valueOf(element.getTextContent()).intValue());
+
+    }
+
+    private Element getElement(Element node, String name) {
+        NodeList list = node.getElementsByTagName(name);
+        assertEquals(1, list.getLength());
+        return (Element) list.item(0);
+    }
+
+    public void assertMetadata(Document doc, WebRowSet webRs) throws Exception {
+        boolean isArrived = false;
+        ResultSetMetaData meta = webRs.getMetaData();
+        NodeList nodeList = doc.getFirstChild().getChildNodes();
+        for (int i = 0; i < nodeList.getLength(); i++) {
+            Node node = nodeList.item(i);
+            if (node instanceof Element) {
+                Element ele = (Element) node;
+                if ("metadata".equals(ele.getTagName())) {
+                    isArrived = true;
+
+                    // column-count
+                    int colCount_Meta = webRs.getMetaData().getColumnCount();
+                    String colCount_Doc = ele.getElementsByTagName(
+                            "column-count").item(0).getTextContent();
+                    assertEquals(Integer.toString(colCount_Meta), colCount_Doc);
+
+                    // column-definition
+                    NodeList colDefList = ele
+                            .getElementsByTagName("column-definition");
+                    for (int j = 0; j < colDefList.getLength(); j++) {
+                        Element colDefEle = (Element) colDefList.item(j);
+                        NodeList children = colDefEle.getChildNodes();
+
+                        int columnIndex = 0;
+                        String autoIncrement = null;
+                        String caseSensitive = null;
+                        String currency = null;
+                        String nullable = null;
+                        String signed = null;
+                        String searchable = null;
+                        String columnDisplaySize = null;
+                        String columnLabel = null;
+                        String columnName = null;
+                        String schemaName = null;
+                        String columnPrecision = null;
+                        String columnScale = null;
+                        String tableName = null;
+                        String catalogName = null;
+                        String columnType = null;
+                        String columnTypeName = null;
+
+                        int index = 0;
+                        for (int k = 0; k < children.getLength(); k++) {
+                            if (children.item(k) instanceof Element) {
+                                index++;
+                                Element child = (Element) children.item(k);
+                                String childTag = child.getTagName();
+                                String childContent = child.getTextContent();
+                                if (index == 1) {
+                                    assertEquals("column-index", childTag);
+                                    columnIndex = Integer
+                                            .parseInt(childContent);
+                                } else if (index == 2) {
+                                    assertEquals("auto-increment", childTag);
+                                    autoIncrement = childContent;
+                                } else if (index == 3) {
+                                    assertEquals("case-sensitive", childTag);
+                                    caseSensitive = childContent;
+                                } else if (index == 4) {
+                                    assertEquals("currency", childTag);
+                                    currency = childContent;
+                                } else if (index == 5) {
+                                    assertEquals("nullable", childTag);
+                                    nullable = childContent;
+                                } else if (index == 6) {
+                                    assertEquals("signed", childTag);
+                                    signed = childContent;
+                                } else if (index == 7) {
+                                    assertEquals("searchable", childTag);
+                                    searchable = childContent;
+                                } else if (index == 8) {
+                                    assertEquals("column-display-size",
+                                            childTag);
+                                    columnDisplaySize = childContent;
+                                } else if (index == 9) {
+                                    assertEquals("column-label", childTag);
+                                    columnLabel = childContent;
+                                } else if (index == 10) {
+                                    assertEquals("column-name", childTag);
+                                    columnName = childContent;
+                                } else if (index == 11) {
+                                    assertEquals("schema-name", childTag);
+                                    schemaName = childContent;
+                                } else if (index == 12) {
+                                    assertEquals("column-precision", childTag);
+                                    columnPrecision = childContent;
+                                } else if (index == 13) {
+                                    assertEquals("column-scale", childTag);
+                                    columnScale = childContent;
+                                } else if (index == 14) {
+                                    assertEquals("table-name", childTag);
+                                    tableName = childContent;
+                                } else if (index == 15) {
+                                    assertEquals("catalog-name", childTag);
+                                    catalogName = childContent;
+                                } else if (index == 16) {
+                                    assertEquals("column-type", childTag);
+                                    columnType = childContent;
+                                } else if (index == 17) {
+                                    assertEquals("column-type-name", childTag);
+                                    columnTypeName = childContent;
+                                }
+                            }
+                        }
+                        assertEquals(17, index);
+
+                        assertEquals(autoIncrement, Boolean.toString(meta
+                                .isAutoIncrement(columnIndex)));
+                        assertEquals(caseSensitive, Boolean.toString(meta
+                                .isCaseSensitive(columnIndex)));
+                        assertEquals(currency, Boolean.toString(meta
+                                .isCurrency(columnIndex)));
+                        assertEquals(nullable, Integer.toString(meta
+                                .isNullable(columnIndex)));
+                        assertEquals(signed, Boolean.toString(meta
+                                .isSigned(columnIndex)));
+                        assertEquals(searchable, Boolean.toString(meta
+                                .isSearchable(columnIndex)));
+                        assertEquals(columnDisplaySize, Integer.toString(meta
+                                .getColumnDisplaySize(columnIndex)));
+                        assertEquals(columnLabel, meta
+                                .getColumnLabel(columnIndex));
+                        assertEquals(columnName, meta
+                                .getColumnName(columnIndex));
+                        assertEquals(schemaName, meta
+                                .getSchemaName(columnIndex));
+                        assertEquals(columnPrecision, Integer.toString(meta
+                                .getPrecision(columnIndex)));
+                        assertEquals(columnScale, Integer.toString(meta
+                                .getScale(columnIndex)));
+                        assertEquals(tableName, meta.getTableName(columnIndex));
+                        assertEquals(catalogName, meta
+                                .getCatalogName(columnIndex));
+                        assertEquals(columnType, Integer.toString(meta
+                                .getColumnType(columnIndex)));
+                        assertEquals(columnTypeName, meta
+                                .getColumnTypeName(columnIndex));
+                    }
+                }
+            }
+        }
+        assertTrue(isArrived);
+    }
+
+    public void assertData(Document doc, WebRowSet webRs) throws Exception {
+        webRs.setShowDeleted(true);
+        webRs.beforeFirst();
+
+        Element element = (Element) doc.getFirstChild();
+        Element dataEle = getElement(element, "data");
+        NodeList nodeList = dataEle.getChildNodes();
+        int rowIndex = 0;
+        for (int i = 0; i < nodeList.getLength(); i++) {
+            Node node = nodeList.item(i);
+            if (node instanceof Element) {
+                rowIndex++;
+                Element rowEle = (Element) node;
+                assertRow(rowEle, webRs, rowIndex);
+            }
+        }
+        assertEquals(webRs.size(), rowIndex);
+        webRs.setShowDeleted(false);
+    }
+
+    private void assertRow(Element ele, WebRowSet webRs, int rowIndex)
+            throws Exception {
+        assertTrue(webRs.absolute(rowIndex));
+        String rowTag = null;
+        if (webRs.rowDeleted()) {
+            rowTag = "deleteRow";
+        } else if (webRs.rowInserted()) {
+            rowTag = "insertRow";
+        } else if (webRs.rowUpdated()) {
+            /*
+             * TODO ri's bug. The tag should be "modifyRow" if a row is marked
+             * as update. However, RI still uses "currentRow". The tag should be
+             * "updateValue" if a column is updated. However, RI uses
+             * "updateRow".
+             */
+            if ("true".equals(System.getProperty("Testing Harmony"))) {
+                rowTag = "modifyRow";
+            } else {
+                rowTag = "currentRow";
+            }
+        } else {
+            rowTag = "currentRow";
+        }
+        assertEquals(rowTag, ele.getTagName());
+
+        // the original row
+        CachedRowSet originalRow = (CachedRowSet) webRs.getOriginalRow();
+        assertTrue(originalRow.next());
+
+        NodeList nodeList = ele.getChildNodes();
+        int colIndex = 0;
+        for (int i = 0; i < nodeList.getLength(); i++) {
+            Node node = nodeList.item(i);
+            if (node instanceof Element) {
+                Element element = (Element) node;
+                String tag = element.getTagName();
+                String content = element.getChildNodes().item(0).getNodeValue();
+                if ("columnValue".equals(tag)) {
+                    colIndex++;
+                    if (content == null) {
+                        assertNull(originalRow.getObject(colIndex));
+                    } else {
+                        String columnValue = null;
+                        int columnType = webRs.getMetaData().getColumnType(
+                                colIndex);
+                        if (Types.DATE == columnType) {
+                            columnValue = Long.toString(originalRow.getDate(
+                                    colIndex).getTime());
+                        } else if (Types.TIME == columnType) {
+                            columnValue = Long.toString(originalRow.getTime(
+                                    colIndex).getTime());
+                        } else if (Types.TIMESTAMP == columnType) {
+                            columnValue = Long.toString(originalRow
+                                    .getTimestamp(colIndex).getTime());
+                        } else {
+                            columnValue = originalRow.getString(colIndex);
+                        }
+                        assertEquals(content, columnValue);
+                    }
+                } else {
+                    if (content == null) {
+                        assertNull(webRs.getObject(colIndex));
+                    } else {
+                        String columnValue = null;
+                        int columnType = webRs.getMetaData().getColumnType(
+                                colIndex);
+                        if (Types.DATE == columnType) {
+                            columnValue = Long.toString(webRs.getDate(colIndex)
+                                    .getTime());
+                        } else if (Types.TIME == columnType) {
+                            columnValue = Long.toString(webRs.getTime(colIndex)
+                                    .getTime());
+                        } else if (Types.TIMESTAMP == columnType) {
+                            columnValue = Long.toString(webRs.getTimestamp(
+                                    colIndex).getTime());
+                        } else {
+                            columnValue = webRs.getString(colIndex);
+                        }
+                        assertEquals(content, columnValue);
+                    }
+                }
+            }
+        }
+        assertEquals(DEFAULT_COLUMN_COUNT, colIndex);
+    }
+}

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



Mime
View raw message