harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r491774 - 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, 02 Jan 2007 10:41:04 GMT
Author: tellison
Date: Tue Jan  2 02:41:03 2007
New Revision: 491774

URL: http://svn.apache.org/viewvc?view=rev&rev=491774
Log:
Apply patch HARMONY-2935 ([classlib][sql] Implementation for SerialBlob.truncate(long length))

Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialBlob.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

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialBlob.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialBlob.java?view=diff&rev=491774&r1=491773&r2=491774
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialBlob.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialBlob.java
Tue Jan  2 02:41:03 2007
@@ -219,9 +219,12 @@
         return length;
     }
 
-    public void truncate(long len) throws SerialException,
-            NotImplementedException {
-        throw new NotImplementedException();
+    public void truncate(long length) throws SerialException {
+        if (length > this.len) {
+            throw new SerialException(Messages.getString("sql.17")); //$NON-NLS-1$
+        }
+        buf = getBytes(1, (int) length);
+        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=491774&r1=491773&r2=491774
==============================================================================
--- 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 Jan  2 02:41:03 2007
@@ -31,3 +31,4 @@
 sql.14=Invalid starting position or length
 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
\ 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=491774&r1=491773&r2=491774
==============================================================================
--- 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
Tue Jan  2 02:41:03 2007
@@ -286,6 +286,37 @@
         assertBlobPosition_BlobPattern(serialBlob);
     }
 
+    public void testTruncateJ() throws Exception {
+        byte[] buf = { 1, 2, 3, 4, 5, 6, 7, 8 };
+        SerialBlob serialBlob1 = new SerialBlob(buf);
+        MockSerialBlob mockBlob = new MockSerialBlob();
+        mockBlob.buf = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
+        SerialBlob serialBlob2 = new SerialBlob(mockBlob);
+        SerialBlob[] serialBlobs = { serialBlob1, serialBlob2 };
+
+        for (SerialBlob serialBlob : serialBlobs) {
+
+            serialBlob.truncate(3);
+            assertEquals(3L, serialBlob.length());
+            byte[] truncatedBytes = serialBlob.getBytes(1, 3);
+            assertTrue(Arrays.equals(new byte[] { 1, 2, 3 }, truncatedBytes));
+
+            try {
+                serialBlob.truncate(-1);
+                fail("should throw SerialException");
+            } catch (SerialException e) {
+                // expected
+            }
+            try {
+                serialBlob.truncate(10);
+                fail("should throw SerialException");
+            } catch (SerialException e) {
+                // expected
+            }
+
+        }
+    }
+    
     private void assertBlobPosition_BytePattern(Blob blob)
             throws SerialException, SQLException {
         byte[] pattern;



Mime
View raw message