harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r521754 - 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 Fri, 23 Mar 2007 15:03:23 GMT
Author: ayza
Date: Fri Mar 23 08:03:21 2007
New Revision: 521754

URL: http://svn.apache.org/viewvc?view=rev&rev=521754
Log:
Applying patch from HARMONY-3459 ([classlib][sql] Implementation for SerialClob.truncate(long))

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=521754&r1=521753&r2=521754
==============================================================================
--- 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 Mar 23 08:03:21 2007
@@ -170,8 +170,13 @@
         return length;
     }
 
-    public void truncate(long len) throws SerialException,
-            NotImplementedException {
-        throw new NotImplementedException();
+    public void truncate(long length) throws SerialException {
+        if(length > len || length < 0) {
+            throw new SerialException(Messages.getString("sql.24"));
+        }
+        char[] truncatedBuffer = new char[(int) length];
+        System.arraycopy(buf, 0, truncatedBuffer, 0, (int)length);
+        buf = truncatedBuffer;
+        len = length;   
     }
 }

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=521754&r1=521753&r2=521754
==============================================================================
--- 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 Mar 23 08:03:21 2007
@@ -38,3 +38,4 @@
 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
+sql.24=Invalid length for truncate

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=521754&r1=521753&r2=521754
==============================================================================
--- 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 Mar 23 08:03:21 2007
@@ -252,10 +252,7 @@
     }
 
     public void testSetStringJLStringII() throws Exception {
-        String s = "hello";
-        char[] buf = s.toCharArray();
-        SerialClob serialClob = new SerialClob(buf);
-        
+        SerialClob serialClob = new SerialClob("hello".toCharArray());
         int count = serialClob.setString(1, "olleh", 0, 5);
         String sub = serialClob.getSubString(1, 5);
         assertEquals("olleh", sub);
@@ -305,8 +302,29 @@
         }
     }
 
-    public void testTruncate() {
-        // TODO: Not yet implemented
+    public void testTruncate() throws Exception {
+        SerialClob serialClob = new SerialClob("hello".toCharArray());
+        serialClob.truncate(3);
+        assertEquals(3, serialClob.length());
+        String s = serialClob.getSubString(1, 3);
+        assertEquals("hel", s);
+        serialClob.truncate(0);
+        assertEquals(0, serialClob.length());
+
+        serialClob = new SerialClob("hello".toCharArray());
+        try {
+            serialClob.truncate(10);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
+
+        try {
+            serialClob.truncate(-1);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
     }
 
     static class MockSerialClob implements Clob {



Mime
View raw message