harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r537746 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/javax/sql/rowset/serial/SQLOutputImpl.java test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SQLOutputImplTest.java
Date Mon, 14 May 2007 08:19:05 GMT
Author: pyang
Date: Mon May 14 01:19:04 2007
New Revision: 537746

URL: http://svn.apache.org/viewvc?view=rev&rev=537746
Log:
Apply patch for HARMONY-3849([classlib][sql] 16 new methods in javax.sql.rowset.serial.SQLOutputImpl)

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

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SQLOutputImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SQLOutputImpl.java?view=diff&rev=537746&r1=537745&r2=537746
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SQLOutputImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SQLOutputImpl.java
Mon May 14 01:19:04 2007
@@ -17,7 +17,10 @@
 
 package javax.sql.rowset.serial;
 
+import java.io.BufferedReader;
+import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.Reader;
 import java.math.BigDecimal;
 import java.net.URL;
@@ -32,6 +35,7 @@
 import java.sql.Struct;
 import java.sql.Time;
 import java.sql.Timestamp;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Vector;
 
@@ -64,34 +68,80 @@
         this.map = map;
     }
 
-    public void writeArray(Array theArray) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeArray(Array))
+     */
+    @SuppressWarnings("unchecked")
+    public void writeArray(Array theArray) throws SQLException {
+        if (theArray != null) {
+            SerialArray serialArray = new SerialArray(theArray, map);
+            attributes.addElement(serialArray);
+        } else {
+            attributes.addElement(theArray);
+        }
     }
 
-    public void writeAsciiStream(InputStream theStream) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeAsciiStream(InputStream))
+     */
+    @SuppressWarnings("unchecked")
+    public void writeAsciiStream(InputStream theStream) throws SQLException {
+        BufferedReader br = new BufferedReader(new InputStreamReader(theStream));
+        StringBuffer stringBuffer = new StringBuffer();
+        String line;
+        try {
+            line = br.readLine();
+            while (line != null) {
+                stringBuffer.append(line);
+                line = br.readLine();
+            }
+            attributes.addElement(stringBuffer.toString());
+        } catch (IOException e) {
+            throw new SQLException();
+        } 
     }
 
-    public void writeBigDecimal(BigDecimal theBigDecimal) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeBigDecimal(BigDecimal))
+     */
+    @SuppressWarnings("unchecked")
+    public void writeBigDecimal(BigDecimal theBigDecimal) throws SQLException {
+        attributes.addElement(theBigDecimal);
     }
 
-    public void writeBinaryStream(InputStream theStream) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
+    /**
+     * {@inheritDoc}
+     * 
+     * FIXME So far NO difference has been detected between writeBinaryStream
+     * and writeAsciiStream in RI. Keep their implementation same temporarily
+     * until some bug is found.
+     * 
+     * @see java.sql.SQLOutput#writeBinaryStream(InputStream))
+     */
+    @SuppressWarnings("unchecked")
+    public void writeBinaryStream(InputStream theStream) throws SQLException {
+        writeAsciiStream(theStream);
     }
 
-    public void writeBlob(Blob theBlob) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeBlob(Blob))
+     */
+    @SuppressWarnings("unchecked")
+    public void writeBlob(Blob theBlob) throws SQLException {
+        if (theBlob != null) {
+            SerialBlob serialBlob = new SerialBlob (theBlob);
+            attributes.addElement(serialBlob);
+        } else {
+            attributes.addElement(theBlob);
+        }
     }
     
     /**
@@ -100,8 +150,7 @@
      * @see java.sql.SQLOutput#writeBoolean(boolean)
      */
     @SuppressWarnings({ "boxing", "unchecked" })
-    public void writeBoolean(boolean theFlag) throws SQLException,
-            NotImplementedException {
+    public void writeBoolean(boolean theFlag) throws SQLException {
         attributes.addElement(theFlag);
     }
 
@@ -125,22 +174,51 @@
         attributes.addElement(theBytes);
     }
 
-    public void writeCharacterStream(Reader theStream) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeCharacterStream(Reader))
+     */
+    @SuppressWarnings("unchecked")
+    public void writeCharacterStream(Reader theStream) throws SQLException {
+        BufferedReader br = new BufferedReader(theStream);
+        StringBuffer stringBuffer = new StringBuffer();
+        String line;
+        try {
+            line = br.readLine();
+            while (line != null) {
+                stringBuffer.append(line);
+                line = br.readLine();
+            }
+            attributes.addElement(stringBuffer.toString());
+        } catch (IOException e) {
+            throw new SQLException();
+        } 
     }
 
-    public void writeClob(Clob theClob) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeClob(Clob)
+     */
+    @SuppressWarnings("unchecked")
+    public void writeClob(Clob theClob) throws SQLException {
+        if (theClob != null) {
+            SerialClob serialClob = new SerialClob(theClob);
+            attributes.addElement(serialClob);
+        } else {
+            attributes.addElement(theClob);
+        }
     }
 
-    public void writeDate(Date theDate) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeDate(Date)
+     */
+    @SuppressWarnings("unchecked")
+    public void writeDate(Date theDate) throws SQLException {
+        attributes.addElement(theDate);
     }
     
     /**
@@ -183,16 +261,33 @@
         attributes.addElement(theLong);
     }
 
-    public void writeObject(SQLData theObject) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeObject(SQLData)
+     */
+    @SuppressWarnings("unchecked")
+    public void writeObject(SQLData theObject) throws SQLException {
+        if(theObject == null) {
+            attributes.addElement(null);
+        } else {
+            attributes.addElement(new SerialStruct(theObject, new HashMap(map)));
+        }
     }
 
-    public void writeRef(Ref theRef) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeRef(Ref)
+     */
+    @SuppressWarnings("unchecked")
+    public void writeRef(Ref theRef) throws SQLException {
+        if (theRef != null) {
+            SerialRef serialRef = new SerialRef(theRef);
+            attributes.addElement(serialRef);
+        } else {
+            attributes.addElement(theRef);
+        }
     }
 
     /**
@@ -205,34 +300,63 @@
         attributes.addElement(theShort);
     }
 
-    public void writeString(String theString) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeString(String)
+     */
+    @SuppressWarnings("unchecked")
+    public void writeString(String theString) throws SQLException {
+        attributes.addElement(theString);
     }
 
-    public void writeStruct(Struct theStruct) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeStruct(Struct)
+     */
+    @SuppressWarnings("unchecked")
+    public void writeStruct(Struct theStruct) throws SQLException {
+        if (theStruct != null) {
+            SerialStruct serialStruct = new SerialStruct(theStruct, map);
+            attributes.addElement(serialStruct);
+        } else {
+            attributes.addElement(theStruct);
+        }
     }
 
-    public void writeTime(Time theTime) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeTime(Time)
+     */
+    @SuppressWarnings("unchecked")
+    public void writeTime(Time theTime) throws SQLException {
+        attributes.addElement(theTime);
     }
 
-    public void writeTimestamp(Timestamp theTimestamp) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeTimestamp(Timestamp)
+     */
+    @SuppressWarnings("unchecked")
+    public void writeTimestamp(Timestamp theTimestamp) throws SQLException {
+        attributes.addElement(theTimestamp);
     }
 
-    public void writeURL(URL theURL) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeURL(URL)
+     */
+    @SuppressWarnings("unchecked")
+    public void writeURL(URL theURL) throws SQLException {
+        if (theURL != null) {
+            SerialDatalink serialDatalink = new SerialDatalink(theURL);
+            attributes.addElement(serialDatalink);
+        } else {
+            attributes.addElement(theURL);
+        }
     }
-
 }

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=537746&r1=537745&r2=537746
==============================================================================
--- 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 01:19:04 2007
@@ -17,12 +17,40 @@
 
 package org.apache.harmony.sql.tests.javax.sql.rowset.serial;
 
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.math.BigDecimal;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.Ref;
 import java.sql.SQLException;
+import java.sql.Struct;
+import java.sql.Time;
+import java.sql.Timestamp;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Vector;
 
 import javax.sql.rowset.serial.SQLOutputImpl;
+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;
+import javax.sql.rowset.serial.SerialStruct;
+
+import org.apache.harmony.sql.tests.javax.sql.rowset.MockArray;
+import org.apache.harmony.sql.tests.javax.sql.rowset.MockBlob;
+import org.apache.harmony.sql.tests.javax.sql.rowset.MockClob;
+import org.apache.harmony.sql.tests.javax.sql.rowset.MockRef;
+import org.apache.harmony.sql.tests.javax.sql.rowset.serial.SQLInputImplTest.MockSQLData;
+import org.apache.harmony.sql.tests.javax.sql.rowset.serial.SQLInputImplTest.MockStruct;
 
 import junit.framework.TestCase;
 
@@ -60,24 +88,69 @@
         }
     }
 
-    public void testWriteArray() {
-
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeArray(Array)}
+     */
+    public void test_writeArrayLjava_sql_Array() throws SQLException {
+        Array array = new MockArray();
+        impl.writeArray(array);
+        assertEquals(1, attr.size());
+        assertTrue(attr.get(0) instanceof SerialArray);
+        
+        impl.writeArray(null);
+        assertNull(attr.get(1));
     }
 
-    public void testWriteAsciiStream() {
-
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeAsciiStream(InputStream)}
+     */
+    public void test_writeAsciiStreamLjava_io_InputStream() throws SQLException {
+        InputStream stream = new ByteArrayInputStream("abc".getBytes());
+        impl.writeAsciiStream(stream);
+        assertEquals(1, attr.size());
+        assertEquals("abc", attr.get(0));
+        
+        try {
+            impl.writeAsciiStream(null);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
     }
 
-    public void testWriteBigDecimal() {
-
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeBigDecimal(java.math.BigDecimal)}
+     */
+    public void test_writeBigDecimalLjava_math_BigDecimal() throws SQLException {
+        impl.writeBigDecimal(BigDecimal.ONE);
+        impl.writeBigDecimal(BigDecimal.ONE);
+        assertSame(attr.get(0), attr.get(1));
+        
+        impl.writeBigDecimal(null);
+        assertNull(attr.get(2));
     }
 
-    public void testWriteBinaryStream() {
-
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeBinaryStream(InputStream)}
+     */
+    public void test_writeBinaryStreamLjava_io_InputStream() throws SQLException {
+        InputStream stream = new ByteArrayInputStream("abc".getBytes());
+        impl.writeBinaryStream(stream);
+        assertEquals(1, attr.size());
+        assertEquals("abc", attr.get(0));
     }
 
-    public void testWriteBlob() {
-
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeBlob(Blob)}
+     */
+    public void test_writeBlobLjava_sql_Blob() throws SQLException {
+        Blob blob = new MockBlob();
+        impl.writeBlob(blob);
+        assertEquals(1, attr.size());
+        assertTrue(attr.get(0) instanceof SerialBlob);
+        
+        impl.writeBlob(null);
+        assertNull(attr.get(1));
     }
 
     /**
@@ -121,16 +194,34 @@
         assertEquals((byte)0, attrBytes[2]);
     }
 
-    public void testWriteCharacterStream() {
-
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeCharacterStream(Reader))}
+     */
+    public void test_writeCharacterStreamLjava_io_Reader() throws SQLException {
+        Reader stream = new StringReader("abc");
+        impl.writeCharacterStream(stream);
+        assertEquals(1, attr.size());
+        assertEquals("abc", attr.get(0));        
     }
 
-    public void testWriteClob() {
-
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeClob(Clob)}
+     */
+    public void test_writeClobLjava_sql_Clob() throws SQLException {
+        Clob clob = new MockClob();
+        impl.writeClob(clob);
+        assertEquals(1, attr.size());
+        assertTrue(attr.get(0) instanceof SerialClob);
     }
 
-    public void testWriteDate() {
-
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeDate(Date)}
+     */
+    public void test_writeDateLjava_sql_Date() throws SQLException {
+        Date date = new Date(200);
+        impl.writeDate(date);
+        assertEquals(1, attr.size());
+        assertEquals(attr.get(0), date);
     }
 
     /**
@@ -173,14 +264,16 @@
         impl.writeInt(Integer.MIN_VALUE);
         impl.writeLong(Long.MAX_VALUE);
         assertEquals(Long.MAX_VALUE, ((Long)attr.get(1)).longValue());
-    }
-
-    public void testWriteObject() {
-
-    }
-
-    public void testWriteRef() {
-
+    }    
+    
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeRef(Ref)}
+     */
+    public void test_writeRefLjava_sql_Ref() throws SQLException {
+        Ref ref = new MockRef();
+        impl.writeRef(ref);
+        assertEquals(1, attr.size());
+        assertTrue(attr.get(0) instanceof SerialRef);
     }
 
     /**
@@ -193,24 +286,49 @@
         assertEquals((short) -32768, ((Short) attr.get(1)).shortValue());
     }
 
-    public void testWriteString() {
-
-    }
-
-    public void testWriteStruct() {
-
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeString(String)}
+     */
+    public void test_writeStringLjava_lang_String() throws SQLException {
+        impl.writeString("abc");
+        assertEquals("abc", ((String) attr.get(0)));
+        impl.writeString("def");
+        assertEquals("def", ((String) attr.get(1)));
     }
 
-    public void testWriteTime() {
-
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeTime(Time)}
+     */
+    public void test_writeTimeLjava_sql_Time() throws SQLException {
+        Time time = new Time(200);
+        impl.writeTime(time);
+        assertEquals(1, attr.size());
+        assertEquals(attr.get(0), time);  
     }
 
-    public void testWriteTimestamp() {
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeTimestamp(Timestamp)}
+     */
+    public void test_writeTimestampLjava_sql_Timestamp() throws SQLException {
+        Timestamp time = new Timestamp(200);
+        impl.writeTimestamp(time);
+        assertEquals(1, attr.size());
+        assertEquals(attr.get(0), time);  
 
     }
 
-    public void testWriteURL() {
-
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeURL(URL)}
+     */
+    public void test_writeURLLjava_net_URL() throws MalformedURLException, SQLException {
+        URL url = new URL("http://www.apache.org");
+        impl.writeURL(url);
+        assertEquals(1, attr.size());
+        assertTrue(attr.get(0) instanceof SerialDatalink);  
+        assertEquals(url, ((SerialDatalink)attr.get(0)).getDatalink());
+        
+        impl.writeURL(null);
+        assertNull(attr.get(1));
     }
 
     @Override



Mime
View raw message