harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r537756 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/javax/sql/rowset/serial/ test/java/org/apache/harmony/sql/tests/javax/sql/rowset/ test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/
Date Mon, 14 May 2007 09:03:30 GMT
Author: pyang
Date: Mon May 14 02:03:29 2007
New Revision: 537756

URL: http://svn.apache.org/viewvc?view=rev&rev=537756
Log:
Apply patch for HARMONY-3788([classlib][sql]complete 4 methods in j.s.r.s.SerialStruct)

Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialStruct.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockArray.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SQLOutputImplTest.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialStructTest.java

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialStruct.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialStruct.java?view=diff&rev=537756&r1=537755&r2=537756
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialStruct.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialStruct.java
Mon May 14 02:03:29 2007
@@ -20,11 +20,14 @@
 import java.io.Serializable;
 import java.sql.SQLData;
 import java.sql.SQLException;
+import java.sql.SQLOutput;
 import java.sql.Struct;
 import java.util.Map;
+import java.util.Vector;
 
-import org.apache.harmony.luni.util.NotImplementedException;
-
+/**
+ * A struct class for serialization.
+ */
 public class SerialStruct implements Struct, Serializable, Cloneable {
     // required by serialized form
     @SuppressWarnings("unused")
@@ -36,29 +39,74 @@
     // required by serialized form
     private Object[] attribs;
 
+    /**
+     * Constructs this serializable struct from an instance of SQLData. Use the
+     * mapping defined in the map for UDT.
+     * 
+     * @param in
+     *            an instance of SQLData.
+     * @param map
+     *            an user defined mapping for UDT.
+     * @throws SerialException
+     *             if there is something wrong.
+     */
     public SerialStruct(SQLData in, Map<String, Class<?>> map)
-            throws SerialException, NotImplementedException {
-        throw new NotImplementedException();
+            throws SerialException {
+        try {
+            SQLTypeName = in.getSQLTypeName();
+        } catch (SQLException e) {
+            throw new SerialException(e.getMessage());
+        }
+        Vector v = new Vector();
+        try {
+            SQLOutput out = new SQLOutputImpl(v, map);
+            in.writeSQL(out);
+        } catch (SQLException e) {
+            throw new SerialException(e.getMessage());
+        }
+        attribs = v.toArray();
     }
 
+    /**
+     * Constructs this serializable struct from an instance of Struct. Use the
+     * mapping defined in the map for UDT.
+     * 
+     * @param in
+     *            an instance of SQLData.
+     * @param map
+     *            an user defined mapping for UDT.
+     * @throws SerialException
+     *             if there is something wrong.
+     */
     public SerialStruct(Struct in, Map<String, Class<?>> map)
-            throws SerialException, NotImplementedException {
-        throw new NotImplementedException();
+            throws SerialException {
+        try {
+            SQLTypeName = in.getSQLTypeName();
+            attribs = in.getAttributes(map);
+        } catch (SQLException e) {
+            throw new SerialException(e.getMessage());
+        }
     }
 
-    public Object[] getAttributes() throws SerialException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
+    /**
+     * Returns all the attributes as an array of Object.
+     */
+    public Object[] getAttributes() throws SerialException {
+        return attribs;
     }
 
+    /**
+     * Returns all the attributes as an array of Object, with the mapping
+     * defined by user.
+     */
     public Object[] getAttributes(Map<String, Class<?>> map)
-            throws SerialException, NotImplementedException {
-        throw new NotImplementedException();
+            throws SerialException {
+        // TODO handle the map.
+        return attribs;
     }
 
-    public String getSQLTypeName() throws SerialException, NotImplementedException {
-        throw new NotImplementedException();
+    public String getSQLTypeName() throws SerialException {
+        return SQLTypeName;
     }
 
 }

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockArray.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockArray.java?view=diff&rev=537756&r1=537755&r2=537756
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockArray.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockArray.java
Mon May 14 02:03:29 2007
@@ -37,7 +37,7 @@
     }
 
     public Object getArray(Map<String, Class<?>> map) throws SQLException {
-        return null;
+        return new Object[0];
     }
 
     public int getBaseType() throws SQLException {

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SQLOutputImplTest.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/SQLOutputImplTest.java?view=diff&rev=537756&r1=537755&r2=537756
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SQLOutputImplTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SQLOutputImplTest.java
Mon May 14 02:03:29 2007
@@ -264,7 +264,27 @@
         impl.writeInt(Integer.MIN_VALUE);
         impl.writeLong(Long.MAX_VALUE);
         assertEquals(Long.MAX_VALUE, ((Long)attr.get(1)).longValue());
-    }    
+    }   
+    
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeObject(java.sql.SQLData)}
+     */
+    public void test_writeObjectLjava_sql_SQLData() throws SQLException {
+        MockSQLData sqlData = new MockSQLData();
+        sqlData.firstAttribute = "one";
+        sqlData.secondAttribute = Boolean.FALSE;
+        sqlData.thirdAttribute = "three";
+        sqlData.fourthAttribute = Integer.valueOf(4);
+        impl.writeObject(sqlData);
+        assertTrue(attr.get(0) instanceof SerialStruct);
+        SerialStruct struct = (SerialStruct) attr.get(0);
+        Object[] attributes = struct.getAttributes();
+        assertEquals(sqlData.firstAttribute, attributes[0]);
+        assertEquals(sqlData.secondAttribute, attributes[1]);
+        assertEquals(sqlData.thirdAttribute, attributes[2]);
+        assertEquals(sqlData.fourthAttribute, attributes[3]);
+        assertEquals("harmonytests.MockSQLData", struct.getSQLTypeName());
+    }
     
     /**
      * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeRef(Ref)}
@@ -294,6 +314,19 @@
         assertEquals("abc", ((String) attr.get(0)));
         impl.writeString("def");
         assertEquals("def", ((String) attr.get(1)));
+    }
+    
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeStruct(java.sql.Struct)}
+     */
+    public void test_writeStructLjava_sql_Struct() throws SQLException {
+        Struct struct = new MockStruct(new Object[] {}, "mockStruct1");
+        impl.writeStruct(struct);
+        assertEquals(1, attr.size());
+        assertTrue(attr.get(0) instanceof SerialStruct);
+        SerialStruct ss = (SerialStruct) attr.get(0);
+        assertEquals(0, ss.getAttributes().length);
+        assertEquals("mockStruct1", ss.getSQLTypeName());
     }
 
     /**

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialStructTest.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/SerialStructTest.java?view=diff&rev=537756&r1=537755&r2=537756
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialStructTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialStructTest.java
Mon May 14 02:03:29 2007
@@ -17,28 +17,153 @@
 
 package org.apache.harmony.sql.tests.javax.sql.rowset.serial;
 
+import java.sql.SQLData;
+import java.sql.SQLException;
+import java.sql.SQLInput;
+import java.sql.SQLOutput;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.sql.rowset.serial.SerialException;
+import javax.sql.rowset.serial.SerialStruct;
+
 import junit.framework.TestCase;
 
 public class SerialStructTest extends TestCase {
 
-    public void testSerialStructSQLDataMapOfStringClassOfQ() {
-        
+    Map<String, Class<?>> map = new HashMap<String, Class<?>>();
+
+    Map<String, Class<?>> emptyMap = new HashMap<String, Class<?>>();
+
+    public SerialStructTest() throws ClassNotFoundException {
+        map
+                .put(
+                        "name_t",
+                        Class
+                                .forName("org.apache.harmony.sql.tests.javax.sql.rowset.serial.Name"));
+        map
+                .put(
+                        "man_t",
+                        Class
+                                .forName("org.apache.harmony.sql.tests.javax.sql.rowset.serial.Man"));
+
+    }
+
+    public void testSerialStructSQLDataMapOfStringClassOfQ()
+            throws SQLException, ClassNotFoundException {
+        Man sdata = new Man(1, new Name("Tony", "Wu"));
+        try {
+            new SerialStruct((SerialStruct) null, emptyMap);
+            fail("should throw NullPointerException.");
+        } catch (NullPointerException e) {
+            // expected.
+        }
+        try {
+            new SerialStruct(sdata, null);
+            fail("should throw SerialException.");
+        } catch (SerialException e) {
+            // expected.
+        }
+        try {
+            new SerialStruct(sdata, null);
+            fail("should throw SerialException.");
+        } catch (SerialException e) {
+            // expected.
+        }
+        SerialStruct ss = new SerialStruct(sdata, emptyMap);
+        assertNotNull(ss);
+    }
+
+    public void testSerialStructStructMapOfStringClassOfQ()
+            throws SerialException {
+        Man sdata = new Man(1, new Name("Tony", "Wu"));
+        SerialStruct ss = new SerialStruct(sdata, emptyMap);
+        try {
+            new SerialStruct((SerialStruct) null, emptyMap);
+            fail("should throw NullPointerException.");
+        } catch (NullPointerException e) {
+            // expected.
+        }
+        new SerialStruct(ss, null);
+        SerialStruct ss2 = new SerialStruct(ss, emptyMap);
+        assertNotNull(ss2);
+    }
+
+    public void testGetAttributes() throws SerialException {
+        Man sdata = new Man(1, new Name("Tony", "Wu"));
+        SerialStruct ss = new SerialStruct(sdata, emptyMap);
+        Object[] o = ss.getAttributes();
+        assertSame(o, ss.getAttributes());
+    }
+
+    public void testGetAttributesMapOfStringClassOfQ() throws SerialException {
+        Man sdata = new Man(1, new Name("Tony", "Wu"));
+        SerialStruct ss = new SerialStruct(sdata, emptyMap);
+        Object[] o = ss.getAttributes(map);
+        assertSame(o, ss.getAttributes(map));
+    }
+
+    public void testGetSQLTypeName() throws SQLException {
+        Man sdata = new Man(1, new Name("Tony", "Wu"));
+        SerialStruct ss = new SerialStruct(sdata, emptyMap);
+        assertEquals(sdata.getSQLTypeName(), ss.getSQLTypeName());
+
     }
 
-    public void testSerialStructStructMapOfStringClassOfQ() {
-        
+}
+
+class Name implements SQLData {
+    public String first;
+
+    public String last;
+
+    private String sql_type = "name_t";
+
+    public Name(String first, String last) {
+        this.first = first;
+        this.last = last;
     }
 
-    public void testGetAttributes() {
-        
+    public String getSQLTypeName() {
+        return sql_type;
     }
 
-    public void testGetAttributesMapOfStringClassOfQ() {
-        
+    public void readSQL(SQLInput stream, String type) throws SQLException {
+        sql_type = type;
+        first = stream.readString();
+        last = stream.readString();
     }
 
-    public void testGetSQLTypeName() {
-        
+    public void writeSQL(SQLOutput stream) throws SQLException {
+        stream.writeString(first);
+        stream.writeString(last);
     }
+}
+
+class Man implements SQLData {
+    public int id;
+
+    public Name name;
+
+    private String sql_type = "man_t";
 
+    public Man(int i, Name string) {
+        id = i;
+        name = string;
+    }
+
+    public String getSQLTypeName() {
+        return sql_type;
+    }
+
+    public void readSQL(SQLInput stream, String type) throws SQLException {
+        sql_type = type;
+        id = stream.readInt();
+        name = (Name) stream.readObject();
+    }
+
+    public void writeSQL(SQLOutput stream) throws SQLException {
+        stream.writeInt(id);
+        stream.writeObject(name);
+    }
 }



Mime
View raw message