Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 4259 invoked from network); 26 Apr 2007 07:52:52 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 26 Apr 2007 07:52:52 -0000 Received: (qmail 53989 invoked by uid 500); 26 Apr 2007 07:52:59 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 53973 invoked by uid 500); 26 Apr 2007 07:52:59 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 53961 invoked by uid 99); 26 Apr 2007 07:52:58 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Apr 2007 00:52:58 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Apr 2007 00:52:51 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 21DD21A983A; Thu, 26 Apr 2007 00:52:31 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r532643 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/javax/sql/rowset/serial/SerialArray.java test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialArrayTest.java Date: Thu, 26 Apr 2007 07:52:30 -0000 To: commits@harmony.apache.org From: pyang@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070426075231.21DD21A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: pyang Date: Thu Apr 26 00:52:30 2007 New Revision: 532643 URL: http://svn.apache.org/viewvc?view=rev&rev=532643 Log: Apply patch for HARMONY-3750([classlib][sql]javax.sql.rowset.serial.SerialArray implementation) Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialArray.java harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialArrayTest.java Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialArray.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialArray.java?view=diff&rev=532643&r1=532642&r2=532643 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialArray.java (original) +++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialArray.java Thu Apr 26 00:52:30 2007 @@ -23,57 +23,226 @@ import java.sql.SQLException; import java.util.Map; -import org.apache.harmony.luni.util.NotImplementedException; - +/** + * + * A array that can be serialized + * + */ public class SerialArray implements Array, Serializable, Cloneable { - public Object getArray() throws SQLException, NotImplementedException { - throw new NotImplementedException(); - } - - public Object getArray(long index, int count) throws SQLException, - NotImplementedException { - throw new NotImplementedException(); - } + private static final long serialVersionUID = -8466174297270688520L; - public Object getArray(long index, int count, Map> map) - throws SQLException, NotImplementedException { - throw new NotImplementedException(); - } + Object[] elements; - public Object getArray(Map> map) throws SQLException, - NotImplementedException { - throw new NotImplementedException(); - } + int baseType; - public int getBaseType() throws SQLException, NotImplementedException { - throw new NotImplementedException(); - } - - public String getBaseTypeName() throws SQLException, - NotImplementedException { - throw new NotImplementedException(); - } - - public ResultSet getResultSet() throws SQLException, - NotImplementedException { - throw new NotImplementedException(); - } - - public ResultSet getResultSet(long index, int count) throws SQLException, - NotImplementedException { - throw new NotImplementedException(); - } + String baseTypeName; + int len; + + /** + * The constructor + * + * @param array + * array to be serializated + * @param map + * the UDT map + * @throws SerialException + * when any error occurs during serializing + * @throws SQLException + * if array is null + */ + public SerialArray(Array array, Map> map) + throws SerialException, SQLException { + // TODO add check for map + if (null == array || null == array.getArray()) { + throw new SQLException( + "Cannot instantiate a SerialArray object with a null Array object."); + } + baseType = array.getBaseType(); + baseTypeName = array.getBaseTypeName(); + elements = (Object[]) array.getArray(); + } + + /** + * The constructor + * + * @param array + * array to be serializated + * @throws SerialException + * when any error occurs during serializing + * @throws SQLException + * if array is null + */ + public SerialArray(Array array) throws SerialException, SQLException { + if (null == array || null == array.getArray()) { + throw new SQLException( + "Cannot instantiate a SerialArray object with a null Array object."); + } + baseType = array.getBaseType(); + baseTypeName = array.getBaseTypeName(); + elements = (Object[]) array.getArray(); + } + + /** + * Answers the array that copies the SerialArray object. + * + * @return the array that copies the SerialArray object. + * @throws SerialException + * if any error occurs when copy the array + */ + public Object getArray() throws SerialException { + Object[] ret = new Object[elements.length]; + System.arraycopy(elements, 0, ret, 0, elements.length); + return elements; + } + + /** + * Answers the array that copies the certain elements of the SerialArray + * object + * + * @param index + * the start offset + * @param count + * the length of element to be copied + * @return the array that copies the SerialArray object. + * @throws SerialException + * if any error occurs when copy the array + */ + public Object getArray(long index, int count) throws SerialException { + if (index < 0 || count >= index + elements.length) { + throw new SerialException("Illegal Argument"); + } + Object[] ret = new Object[count]; + // TODO check if casting long to int is legal + System.arraycopy(elements, (int) index, ret, 0, count); + return ret; + } + + /** + * Answers the array that copies the certain elements of the SerialArray + * object according to UDT map + * + * @param index + * the start offset + * @param count + * the length of element to be copied + * @param map + * the UDT map + * @return the array that copies the SerialArray object. + * @throws SerialException + * if any error occurs when copy the array + */ + public Object getArray(long index, int count, Map> map) + throws SerialException { + // TODO replace raw string to Msg.getString + if (index < 0 || count >= index + elements.length) { + throw new SerialException("Illegal Argument"); + } + Object[] ret = new Object[count]; + // TODO check if casting long to int is legal + System.arraycopy(elements, (int) index, ret, 0, count); + return ret; + } + + /** + * Answers the array that copies the SerialArray object according to UDT map + * + * @param map + * the UDT map + * @return the array that copies the SerialArray object. + * @throws SerialException + * if any error occurs when copy the array + */ + public Object getArray(Map> map) throws SerialException { + // TODO add check for map + Object[] ret = new Object[elements.length]; + System.arraycopy(elements, 0, ret, 0, elements.length); + return elements; + } + + /** + * Answers the base type of this array + * + * @return the base type of this array + * @throws SerialException + * if any errors occur + */ + public int getBaseType() throws SerialException { + return baseType; + } + + /** + * Answers the base type name of this array + * + * @return the base type name of this array + * @throws SerialException + * if any errors occur + */ + public String getBaseTypeName() throws SerialException { + return baseTypeName; + } + + /** + * Answers the base type of this array, but throw always + * UnsupportedOperationException here + * + * @return the base type of this array + * @throws SerialException + * if any errors occur + */ + public ResultSet getResultSet() throws SerialException { + throw new UnsupportedOperationException(); + } + + /** + * Answers the base type of this array, but throw always + * UnsupportedOperationException here + * + * @param index + * the start offset + * @param count + * the length of element to be copied + * @return the base type of this array + * @throws SerialException + * if any errors occur + */ + public ResultSet getResultSet(long index, int count) throws SerialException { + throw new UnsupportedOperationException(); + } + + /** + * Answers the base type of this array, but throw always + * UnsupportedOperationException here + * + * @param index + * the start offset + * @param count + * the length of element to be copied + * @param map + * the UDT map + * @return the base type of this array + * @throws SerialException + * if any errors occur + */ public ResultSet getResultSet(long index, int count, - Map> map) throws SQLException, - NotImplementedException { - throw new NotImplementedException(); + Map> map) throws SerialException { + throw new UnsupportedOperationException(); } + /** + * Answers the base type of this array, but throw always + * UnsupportedOperationException here + * + * @param map + * the UDT map + * @return the base type of this array + * @throws SerialException + * if any errors occur + */ public ResultSet getResultSet(Map> map) - throws SQLException, NotImplementedException { - throw new NotImplementedException(); + throws SerialException { + throw new UnsupportedOperationException(); } } Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialArrayTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialArrayTest.java?view=diff&rev=532643&r1=532642&r2=532643 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialArrayTest.java (original) +++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialArrayTest.java Thu Apr 26 00:52:30 2007 @@ -16,48 +16,272 @@ */ package org.apache.harmony.sql.tests.javax.sql.rowset.serial; +import java.sql.Array; +import java.sql.ResultSet; +import java.sql.SQLData; +import java.sql.SQLException; +import java.sql.SQLInput; +import java.sql.SQLOutput; +import java.sql.Types; +import java.util.HashMap; +import java.util.Map; + +import javax.sql.rowset.serial.SerialArray; +import javax.sql.rowset.serial.SerialException; + import junit.framework.TestCase; public class SerialArrayTest extends TestCase { - public void testGetArray() { - + private Array mock = new MockArray(); + + private SerialArray sa; + + String[] strs = new String[2]; + + Map> map = new HashMap>(); + + @Override + protected void setUp() throws Exception { + super.setUp(); + sa = new SerialArray(mock); + strs[0] = "test1"; + strs[1] = "test2"; + map.put("String", MockStringSQLData.class); + map.put("Object", MockObjectSQLData.class); } - public void testGetArrayLongInt() { - + public void testConstructor() throws SQLException { + // OK + sa = new SerialArray(mock); + // array.getArray should not return null + try { + sa = new SerialArray(new MockNullArray()); + fail("should throw SQLException"); + } catch (SQLException e) { + // expected + } + } + + public void testConstructor_map() throws SQLException { + try { + sa = new SerialArray(mock, null); + } catch (SQLException e) { + // expected + } + // array.getArray should not return null + try { + sa = new SerialArray(new MockNullArray(), null); + fail("should throw SQLException"); + } catch (SQLException e) { + // expected + } + } + + public void testGetArray() throws SerialException { + for (int i = 0; i < strs.length; i++) { + assertEquals(strs[i], ((Object[]) sa.getArray())[i]); + } + } + + public void testGetArrayLongInt() throws SerialException { + for (int i = 0; i < strs.length; i++) { + assertEquals(strs[i], ((Object[]) sa.getArray(i, 1))[0]); + } } public void testGetArrayLongIntMapOfStringClassOfQ() { - + } - public void testGetArrayMapOfStringClassOfQ() { - + public void testGetArrayMapOfStringClassOfQ() throws SerialException { + for (int i = 0; i < strs.length; i++) { + assertEquals(strs[i], ((Object[]) sa.getArray())[i]); + } } - public void testGetBaseType() { - + public void testGetBaseType() throws SerialException { + assertEquals(Types.ARRAY, sa.getBaseType()); } - public void testGetBaseTypeName() { - + public void testGetBaseTypeName() throws SQLException { + assertEquals("BaseName", sa.getBaseTypeName()); } - public void testGetResultSet() { - + public void testGetResultSet() throws SQLException { + try { + sa.getResultSet(); + fail("should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + // expected + } } - public void testGetResultSetLongInt() { - + public void testGetResultSetLongInt() throws SQLException { + try { + sa.getResultSet(0, 1); + fail("should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + // expected + } } - public void testGetResultSetLongIntMapOfStringClassOfQ() { - + public void testGetResultSetLongIntMapOfStringClassOfQ() + throws SQLException { + try { + sa.getResultSet(0, 1, null); + fail("should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + // expected + } } - public void testGetResultSetMapOfStringClassOfQ() { - + public void testGetResultSetMapOfStringClassOfQ() throws SerialException { + try { + sa.getResultSet(null); + fail("should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + // expected + } } + class MockArray implements Array { + + public Object getArray() throws SQLException { + return strs; + } + + public Object getArray(long index, int count) throws SQLException { + String[] ret = new String[count]; + for (int i = 0; i < ret.length; i++) { + ret[i] = strs[(int) index + i]; + } + return ret; + } + + public Object getArray(long index, int count, Map> map) + throws SQLException { + String[] ret = new String[count]; + for (int i = 0; i < ret.length; i++) { + ret[i] = strs[(int) index + i]; + } + return ret; + } + + public Object getArray(Map> map) throws SQLException { + return strs; + } + + public int getBaseType() throws SQLException { + return Types.ARRAY; + } + + public String getBaseTypeName() throws SQLException { + return "BaseName"; + } + + public ResultSet getResultSet() throws SQLException { + return null; + } + + public ResultSet getResultSet(long index, int count) + throws SQLException { + return null; + + } + + public ResultSet getResultSet(long index, int count, + Map> map) throws SQLException { + return null; + } + + public ResultSet getResultSet(Map> map) + throws SQLException { + return null; + } + } + + class MockNullArray implements Array { + + public Object getArray() throws SQLException { + return null; + } + + public Object getArray(long index, int count) throws SQLException { + return null; + } + + public Object getArray(long index, int count, Map> map) + throws SQLException { + return null; + } + + public Object getArray(Map> map) throws SQLException { + return strs; + } + + public int getBaseType() throws SQLException { + return Types.ARRAY; + } + + public String getBaseTypeName() throws SQLException { + return "BaseName"; + } + + public ResultSet getResultSet() throws SQLException { + return null; + } + + public ResultSet getResultSet(long index, int count) + throws SQLException { + return null; + + } + + public ResultSet getResultSet(long index, int count, + Map> map) throws SQLException { + return null; + } + + public ResultSet getResultSet(Map> map) + throws SQLException { + return null; + } + } + + class MockStringSQLData implements SQLData { + + private String name = "java.lang.String"; + + public String getSQLTypeName() throws SQLException { + return name; + } + + public void readSQL(SQLInput stream, String typeName) + throws SQLException { + return; + } + + public void writeSQL(SQLOutput stream) throws SQLException { + return; + } + } + + class MockObjectSQLData implements SQLData { + + private String name = "java.lang.Object"; + + public String getSQLTypeName() throws SQLException { + return name; + } + + public void readSQL(SQLInput stream, String typeName) + throws SQLException { + return; + } + + public void writeSQL(SQLOutput stream) throws SQLException { + return; + } + } }