harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r500234 - in /harmony/enhanced/classlib/trunk/modules/sql: META-INF/ src/main/java/javax/sql/rowset/serial/ src/main/java/org/apache/harmony/sql/internal/nls/ src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/
Date Fri, 26 Jan 2007 13:18:42 GMT
Author: ayza
Date: Fri Jan 26 05:18:41 2007
New Revision: 500234

URL: http://svn.apache.org/viewvc?view=rev&rev=500234
Log:
Applying patch from HARMONY-3017 ([classlib][sql] Implementation for SerialClob constructors,getCharacterStream(),
and length() methods.).

Modified:
    harmony/enhanced/classlib/trunk/modules/sql/META-INF/MANIFEST.MF
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialClob.java
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialBlobTest.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialClobTest.java

Modified: harmony/enhanced/classlib/trunk/modules/sql/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/META-INF/MANIFEST.MF?view=diff&rev=500234&r1=500233&r2=500234
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/META-INF/MANIFEST.MF (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/META-INF/MANIFEST.MF Fri Jan 26 05:18:41 2007
@@ -16,6 +16,7 @@
  java.lang.reflect,
  java.math,
  java.net,
+ java.nio;resolution:=optional,
  java.rmi,
  java.security,
  java.text,
@@ -33,3 +34,4 @@
  javax.sql.rowset.spi,
  javax.transaction,
  javax.transaction.xa
+

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialClob.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialClob.java?view=diff&rev=500234&r1=500233&r2=500234
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialClob.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialClob.java
Fri Jan 26 05:18:41 2007
@@ -17,6 +17,8 @@
 
 package javax.sql.rowset.serial;
 
+import java.io.CharArrayReader;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.Reader;
@@ -26,6 +28,7 @@
 import java.sql.SQLException;
 
 import org.apache.harmony.luni.util.NotImplementedException;
+import org.apache.harmony.sql.internal.nls.Messages;
 
 public class SerialClob implements Clob, Serializable, Cloneable {
 
@@ -49,18 +52,44 @@
     @SuppressWarnings("unused")
     private long origLen;
 
-    public SerialClob(char[] ch) throws SerialException, SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
+    public SerialClob(char[] ch) throws SerialException, SQLException {
+        buf = new char[ch.length];
+        origLen = ch.length;
+        len = origLen;
+        System.arraycopy(ch, 0, buf, 0, (int) len);
     }
 
-    public SerialClob(Clob clob) throws SerialException, SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
+    public SerialClob(Clob clob) throws SerialException, SQLException {
+        Reader characterStream;
+        InputStream asciiStream;
+
+        if (clob == null) {
+            throw new SQLException(Messages.getString("sql.19"));//$NON-NLS-1$
+        }
+
+        characterStream = clob.getCharacterStream();
+        asciiStream = clob.getAsciiStream();
+        if (characterStream == null || asciiStream == null) {
+            throw new SQLException(Messages.getString("sql.20"));//$NON-NLS-1$
+        }
+
+        this.clob = clob;
+        origLen = clob.length();
+        len = origLen;
+        buf = new char[(int) len];
+        try {
+            characterStream.read(buf);
+        } catch (IOException e) {
+            SerialException se = new SerialException(
+                    "SerialClob: " + e.getMessage());
+
+            se.initCause(e);
+            throw se;
+        }
     }
 
-    public long length() throws SerialException, NotImplementedException {
-        throw new NotImplementedException();
+    public long length() throws SerialException {
+        return len;
     }
 
     public InputStream getAsciiStream() throws SerialException,
@@ -70,7 +99,7 @@
 
     public Reader getCharacterStream() throws SerialException,
             NotImplementedException {
-        throw new NotImplementedException();
+        return new CharArrayReader(buf);
     }
 
     public String getSubString(long pos, int length) throws SerialException,

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties?view=diff&rev=500234&r1=500233&r2=500234
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
Fri Jan 26 05:18:41 2007
@@ -32,4 +32,6 @@
 sql.15=Invalid position in BLOB object set
 sql.16=Invalid offset in byte array set
 sql.17=javax.sql.rowset.serial.SerialException: Length more than what can be truncated
-sql.18=Unsupported operation. SerialBlob cannot return a writable binary stream, unless instantiated
with a Blob object that provides a setBinaryStream() implementation
\ No newline at end of file
+sql.18=Unsupported operation. SerialBlob cannot return a writable binary stream, unless instantiated
with a Blob object that provides a setBinaryStream() implementation
+sql.19=Cannot instantiate a SerialClob object with a null Clob object
+sql.20=Invalid Clob object. Calls to getCharacterStream or getAsciiStream return null which
cannot be serialized.
\ No newline at end of file

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialBlobTest.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/SerialBlobTest.java?view=diff&rev=500234&r1=500233&r2=500234
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialBlobTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialBlobTest.java
Fri Jan 26 05:18:41 2007
@@ -64,7 +64,7 @@
 
         try {
             new SerialBlob((byte[]) null);
-            fail("should throw SQLException");
+            fail("should throw NullPointerException");
         } catch (NullPointerException e) {
             // expected
         }

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialClobTest.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/SerialClobTest.java?view=diff&rev=500234&r1=500233&r2=500234
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialClobTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialClobTest.java
Fri Jan 26 05:18:41 2007
@@ -17,16 +17,80 @@
 
 package org.apache.harmony.sql.tests.javax.sql.rowset.serial;
 
+import java.io.ByteArrayInputStream;
+import java.io.CharArrayReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.sql.Clob;
+import java.sql.SQLException;
+
+import javax.sql.rowset.serial.SerialClob;
+import javax.sql.rowset.serial.SerialException;
+
 import junit.framework.TestCase;
 
 public class SerialClobTest extends TestCase {
 
-    public void testSerialClob$C() {
-        // TODO: Not yet implemented
-    }
+    public void testSerialClob$C() throws Exception {
+        char[] buf = new char[8];
+        SerialClob serialClob = new SerialClob(buf);
+
+        assertEquals(8, serialClob.length());
+
+        try {
+            new SerialClob((char[]) null);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+    }
+
+    public void testSerialClobLClob() throws Exception {
+        SerialClob serialClob;
+        MockSerialClob mockClob = new MockSerialClob();
+
+        mockClob.characterStream = new CharArrayReader(mockClob.buf);
+        mockClob.asciiStream = new ByteArrayInputStream(new byte[] { 1 });
+        serialClob = new SerialClob(mockClob);
+        assertEquals(mockClob.buf.length, serialClob.length());
+
+        mockClob.characterStream = null;
+        mockClob.asciiStream = new ByteArrayInputStream(new byte[] { 1 });
+        try {
+            new SerialClob(mockClob);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+
+        mockClob.characterStream = new CharArrayReader(new char[] { 1 });
+        mockClob.asciiStream = null;
+        try {
+            new SerialClob(mockClob);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+
+        mockClob.characterStream = new MockAbnormalReader();
+        mockClob.asciiStream = new ByteArrayInputStream(new byte[] { 1 });
+        try {
+            new SerialClob(mockClob);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }        
+        
+        try {
+            new SerialClob((Clob) null);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
 
-    public void testSerialClobLClob() {
-        // TODO: Not yet implemented
     }
 
     public void testLength() {
@@ -73,4 +137,70 @@
         // TODO: Not yet implemented
     }
 
+    static class MockSerialClob implements Clob {
+
+        char[] buf = { 1, 2, 3 };
+
+        public Reader characterStream;
+
+        public InputStream asciiStream;
+
+        public MockSerialClob() {
+        }
+
+        public InputStream getAsciiStream() throws SQLException {
+            return asciiStream;
+        }
+
+        public Reader getCharacterStream() throws SQLException {
+            return characterStream;
+        }
+
+        public String getSubString(long pos, int length) throws SQLException {
+            return null;
+        }
+
+        public long length() throws SQLException {
+            return buf.length;
+        }
+
+        public long position(Clob searchstr, long start) throws SQLException {
+            return 0;
+        }
+
+        public long position(String searchstr, long start) throws SQLException {
+            return 0;
+        }
+
+        public OutputStream setAsciiStream(long pos) throws SQLException {
+            return null;
+        }
+
+        public Writer setCharacterStream(long pos) throws SQLException {
+            return null;
+        }
+
+        public int setString(long pos, String str) throws SQLException {
+            return 0;
+        }
+
+        public int setString(long pos, String str, int offset, int len)
+                throws SQLException {
+            return 0;
+        }
+
+        public void truncate(long len) throws SQLException {
+
+        }
+    }
+
+    static class MockAbnormalReader extends java.io.Reader {
+        public int read(char[] cbuf, int off, int len) throws IOException {
+            throw new IOException();
+        }
+
+        public void close() throws IOException {
+
+        }
+    }
 }



Mime
View raw message