harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r517693 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/javax/sql/rowset/serial/ main/java/org/apache/harmony/sql/internal/nls/ test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/
Date Tue, 13 Mar 2007 13:31:02 GMT
Author: ayza
Date: Tue Mar 13 06:31:02 2007
New Revision: 517693

URL: http://svn.apache.org/viewvc?view=rev&rev=517693
Log:
Appying patch from HARMONY-3366 ([classlib][sql] Implementation for SerialClob.setString).

Modified:
    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/SerialClobTest.java

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=517693&r1=517692&r2=517693
==============================================================================
--- 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
Tue Mar 13 06:31:02 2007
@@ -36,20 +36,15 @@
     @SuppressWarnings("unused")
     private static final long serialVersionUID = -1662519690087375313L;
 
-    // required by serialized form
-    @SuppressWarnings("unused")
     private char[] buf;
 
     // required by serialized form
     @SuppressWarnings("unused")
     private Clob clob;
 
-    // required by serialized form
-    @SuppressWarnings("unused")
     private long len;
 
     // required by serialized form
-    @SuppressWarnings("unused")
     private long origLen;
 
     public SerialClob(char[] ch) throws SerialException, SQLException {
@@ -132,14 +127,23 @@
         throw new NotImplementedException();
     }
 
-    public int setString(long pos, String str) throws SerialException,
-            NotImplementedException {
-        throw new NotImplementedException();
+    public int setString(long pos, String str) throws SerialException {
+        return setString(pos, str, 0, str.length());
     }
 
-    public int setString(long pos, String str, int offset, int len)
-            throws SerialException, NotImplementedException {
-        throw new NotImplementedException();
+    public int setString(long pos, String str, int offset, int length)
+            throws SerialException {
+        if (pos < 1 || length < 0 || pos > (len - length + 1)) {
+            throw new SerialException(Messages.getString("sql.21")); // $NON-NLS-1$
+        }
+        if (offset < 0  || offset > (str.length() - length)) {
+            throw new SerialException(Messages.getString("sql.21")); // $NON-NLS-1$
+        }
+        if (length > len + offset) {
+            throw new SerialException(Messages.getString("sql.23")); // $NON-NLS-1$
+        }
+        str.getChars(offset, offset+length, buf, (int)pos-1);
+        return length;
     }
 
     public void truncate(long len) 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=517693&r1=517692&r2=517693
==============================================================================
--- 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
Tue Mar 13 06:31:02 2007
@@ -35,5 +35,6 @@
 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.
-sql.21=Invalid position in BLOB object set
+sql.21=Invalid position in CLOB object set
 sql.22=Invalid position and substring length
+sql.23=Buffer is not sufficient to hold the value

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=517693&r1=517692&r2=517693
==============================================================================
--- 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
Tue Mar 13 06:31:02 2007
@@ -162,12 +162,96 @@
         // TODO: Not yet implemented
     }
 
-    public void testSetStringJLString() {
-        // TODO: Not yet implemented
+    public void testSetStringJLString() throws Exception {
+        String s = "hello";
+        char[] buf = s.toCharArray();
+        SerialClob serialClob = new SerialClob(buf);
+        
+        int count = serialClob.setString(1, "olleh");
+        String sub = serialClob.getSubString(1, 5);
+        assertEquals("olleh", sub);
+        assertEquals(5, count);
+        
+        count = serialClob.setString(2, "mm");
+        sub = serialClob.getSubString(1, 5);
+        assertEquals("ommeh", sub);
+        assertEquals(2, count);
+        
+        try {
+            serialClob.setString(-1, "hello");
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
+        
+        try {
+            serialClob.setString(6, "hello");
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
+        
+        // Harmony-3335, non bug difference from RI
+        try {
+            serialClob.setString(2, "hello");
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
     }
 
-    public void testSetStringJLStringII() {
-        // TODO: Not yet implemented
+    public void testSetStringJLStringII() throws Exception {
+        String s = "hello";
+        char[] buf = s.toCharArray();
+        SerialClob serialClob = new SerialClob(buf);
+        
+        int count = serialClob.setString(1, "olleh", 0, 5);
+        String sub = serialClob.getSubString(1, 5);
+        assertEquals("olleh", sub);
+        assertEquals(5, count);
+        
+        count = serialClob.setString(2, "mmnn",1, 2);
+        sub = serialClob.getSubString(1, 5);
+        // RI's bug
+        assertEquals(2, count);
+        assertEquals("omneh", sub);
+        
+        try {
+            serialClob.setString(-1, "hello", 0, 5);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
+        
+        try {
+            serialClob.setString(6, "hello", 0, 5);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
+        
+        try {
+            serialClob.setString(1, "hello", 0, 6);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
+        
+        // Harmony-3335, non bug difference from RI
+        try {
+            serialClob.setString(2, "hello", 0, 5);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
+        
+        try {
+            // Harmony-3335
+            serialClob.setString(1, "hello", -1, 5);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
     }
 
     public void testTruncate() {



Mime
View raw message