harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r495298 - 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 Thu, 11 Jan 2007 17:23:04 GMT
Author: tellison
Date: Thu Jan 11 09:23:01 2007
New Revision: 495298

URL: http://svn.apache.org/viewvc?view=rev&rev=495298
Log:
Apply patch HARMONY-2978 ([classlib][sql] Implementation for SerialBlob.setBinaryStream(long
pos))

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=495298&r1=495297&r2=495298
==============================================================================
--- 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
Thu Jan 11 09:23:01 2007
@@ -24,7 +24,6 @@
 import java.sql.Blob;
 import java.sql.SQLException;
 
-import org.apache.harmony.luni.util.NotImplementedException;
 import org.apache.harmony.sql.internal.nls.Messages;
 
 public class SerialBlob implements Blob, Serializable, Cloneable {
@@ -198,8 +197,15 @@
     }
 
     public OutputStream setBinaryStream(long pos) throws SerialException,
-            SQLException, NotImplementedException {
-        throw new NotImplementedException();
+            SQLException {
+        if (blob == null) {
+            throw new SerialException(Messages.getString("sql.18")); //$NON-NLS-1$
+        }
+        OutputStream os = blob.setBinaryStream(pos);
+        if (os == null) {
+            throw new SerialException(Messages.getString("sql.18")); //$NON-NLS-1$
+        }
+        return os;
     }
 
     public int setBytes(long pos, byte[] theBytes) 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=495298&r1=495297&r2=495298
==============================================================================
--- 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
Thu Jan 11 09:23:01 2007
@@ -31,4 +31,5 @@
 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
+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

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=495298&r1=495297&r2=495298
==============================================================================
--- 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
Thu Jan 11 09:23:01 2007
@@ -17,6 +17,7 @@
 
 package org.apache.harmony.sql.tests.javax.sql.rowset.serial;
 
+import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.sql.Blob;
@@ -198,7 +199,7 @@
         byte[] expected = { 9, 10, 11, 4, 5, 6, 7, 8 };
         assertTrue(Arrays.equals(expected, res));
         assertEquals(3, count);
-        
+
         count = serialBlob.setBytes(3, theBytes, 1, 2);
         res = serialBlob.getBytes(1, buf.length);
         expected = new byte[] { 9, 10, 10, 11, 5, 6, 7, 8 };
@@ -307,10 +308,10 @@
             } catch (SerialException e) {
                 // expected
             }
-            
+
             // Non bug difference from RI, Harmony-2937
             assertEquals(3L, serialBlob.length());
-            
+
             try {
                 serialBlob.truncate(10);
                 fail("should throw SerialException");
@@ -320,7 +321,35 @@
 
         }
     }
-    
+
+    public void testSetBinaryStreamJ() throws Exception {
+        MockSerialBlob mockBlob = new MockSerialBlob();
+        mockBlob.binaryStream = new ByteArrayOutputStream();
+        SerialBlob serialBlob = new SerialBlob(mockBlob);
+        OutputStream os = serialBlob.setBinaryStream(1);
+        assertTrue(mockBlob.isSetBinaryStreamInvoked);
+        assertEquals(1L, mockBlob.pos);
+        assertSame(mockBlob.binaryStream, os);
+
+        mockBlob.binaryStream = null;
+        try {
+            serialBlob.setBinaryStream(1);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
+
+        byte[] buf = new byte[1];
+        serialBlob = new SerialBlob(buf);
+        try {
+            // Non bug difference from RI, Harmony-2971
+            serialBlob.setBinaryStream(1);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
+    }
+
     private void assertBlobPosition_BytePattern(Blob blob)
             throws SerialException, SQLException {
         byte[] pattern;
@@ -441,8 +470,14 @@
 
         public boolean isGetBytesInvoked;
 
+        public boolean isSetBinaryStreamInvoked;
+
         public boolean isAbnormal;
 
+        public OutputStream binaryStream;
+
+        public long pos;
+
         public MockSerialBlob() {
 
         }
@@ -476,7 +511,9 @@
         }
 
         public OutputStream setBinaryStream(long pos) throws SQLException {
-            return null;
+            isSetBinaryStreamInvoked = true;
+            this.pos = pos;
+            return binaryStream;
         }
 
         public int setBytes(long pos, byte[] theBytes) throws SQLException {



Mime
View raw message