db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r349079 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/jdbc/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/ testing/org/apache/derbyTesting/functionTe...
Date Sat, 26 Nov 2005 05:14:43 GMT
Author: tmnk
Date: Fri Nov 25 21:14:15 2005
New Revision: 349079

URL: http://svn.apache.org/viewcvs?rev=349079&view=rev
Log:
- DERBY-721 State of InputStream retrieved from resultset is not clean , if there exists previous
InputStream - Patch by Tomohito Nakayama (tomonaka@basil.ocn.ne.jp)

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/BinaryToRawStream.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/resultsetStream.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/resultsetStream.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/resultsetStream.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/BinaryToRawStream.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/BinaryToRawStream.java?rev=349079&r1=349078&r2=349079&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/BinaryToRawStream.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/BinaryToRawStream.java Fri
Nov 25 21:14:15 2005
@@ -21,6 +21,8 @@
 package org.apache.derby.impl.jdbc;
 
 import org.apache.derby.iapi.services.sanity.SanityManager;
+import org.apache.derby.iapi.types.Resetable;
+import org.apache.derby.iapi.error.StandardException;
 
 import java.io.InputStream;
 import java.io.IOException;
@@ -30,6 +32,11 @@
 	Converts a stream containing the Cloudscape stored binary form
 	to one that just contains the application's data.
 	Simply remove the length information.
+
+	If source stream implements Resetable interface , 
+	the source can be shared among other objects and 
+	not closed when close method of this class was called.
+
 */
 final class BinaryToRawStream
 extends java.io.FilterInputStream
@@ -96,4 +103,26 @@
 			//	len++;
 		}
 	}
+    
+    
+    public void close() throws IOException{
+	
+	//Escape from closing source InputStream ,
+	//because source InputStream can be shared between other stream.
+	
+	if(in instanceof Resetable){
+	    try{
+		((Resetable) in).resetStream();
+		
+	    }catch(StandardException e){
+		e.printStackTrace();
+		throw new IOException(e.getMessage());
+	    }
+	    
+	}else{
+	    super.close();
+	    
+	}
+    }
+    
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/resultsetStream.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/resultsetStream.out?rev=349079&r1=349078&r2=349079&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/resultsetStream.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/resultsetStream.out
Fri Nov 25 21:14:15 2005
@@ -14,4 +14,7 @@
 Test of getAsciiStream
 U+0041U+0042U+0043U+0044U+0045U+0046U+0047U+00c0U+00c1U+00c2U+00c3U+00c4U+00c5U+00ffU+003fU+003fU+003fU+003fU+003fU+003f
 U+0041U+0042U+0043U+0044U+0045U+0046U+0047U+00c0U+00c1U+00c2U+00c3U+00c4U+00c5U+00ffU+0100U+3042U+3044U+3046U+3048U+304a
+Test of RepeatedStream
+first stream: 01234567
+second stream: 01234567
 Test resultsetStream finished

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/resultsetStream.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/resultsetStream.out?rev=349079&r1=349078&r2=349079&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/resultsetStream.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/resultsetStream.out
Fri Nov 25 21:14:15 2005
@@ -16,4 +16,7 @@
 Test of getAsciiStream
 U+0041U+0042U+0043U+0044U+0045U+0046U+0047U+00c0U+00c1U+00c2U+00c3U+00c4U+00c5U+00ffU+003fU+003fU+003fU+003fU+003fU+003f
 U+0041U+0042U+0043U+0044U+0045U+0046U+0047U+00c0U+00c1U+00c2U+00c3U+00c4U+00c5U+00ffU+0100U+3042U+3044U+3046U+3048U+304a
+Test of RepeatedStream
+first stream: 01234567
+second stream: 01234567
 Test resultsetStream finished

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/resultsetStream.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/resultsetStream.java?rev=349079&r1=349078&r2=349079&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/resultsetStream.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/resultsetStream.java
Fri Nov 25 21:14:15 2005
@@ -40,6 +40,7 @@
 import java.util.zip.CRC32;
 import java.io.Reader;
 import java.io.StringReader;
+import java.io.ByteArrayInputStream;
 
 /**
  * Test of JDBC result set Stream calls.
@@ -285,6 +286,7 @@
 			stmt.close();
 			
 			TestOfGetAsciiStream.executeTestOfGetAsciiStream(con);
+			TestOfRepeatedStream.executeTestOfRepeatedStream(con);
 
 			con.close();
 
@@ -468,5 +470,130 @@
 		}
 		
 	}
+    
+    static class TestOfRepeatedStream{
+
+	
+	private static void executeTestOfRepeatedStream(Connection conn) 
+	    throws SQLException, IOException {
+	
+	    System.out.println("Test of RepeatedStream");
+
+	    prepareTestRepeatedStream(conn);
+	    readFromRepeatedStream(conn);
+	    cleanTestRepeatedStream(conn);
+	    
+	    
+	}
+    
+    
+	private static void prepareTestRepeatedStream(Connection conn) throws SQLException {
+	
+	    PreparedStatement st = null;
+
+	    try{
+
+		st = conn.prepareStatement("create table testBlobX2 (a integer, b blob(1024K))");
+		st.execute();
+		st.close();
+
+		st = conn.prepareStatement("insert into testBlobX2(a,b) values(1,?)");
+
+		byte[] testData = new byte[1024 * 1024];
+	    
+		for(int i = 0;
+		    i < testData.length;
+		    i ++)
+		    testData[i] = (byte) (i % 256);
+	    
+		st.setBinaryStream(1, 
+				   new ByteArrayInputStream(testData),
+				   testData.length);
+
+		st.executeUpdate();
+
+	    }finally{
+		if(st != null)
+		    st.close();
+	    }
+	
+	}
+
+
+	private static void readFromRepeatedStream(Connection conn) 
+	    throws SQLException ,IOException {
+	
+	    PreparedStatement st = null;
+	    ResultSet rs = null;
+	
+	    InputStream is = null;
+
+	    try{
+		st = conn.prepareStatement("SELECT b FROM testBlobX2 WHERE a = 1");
+		rs = st.executeQuery();
+	    
+		rs.next();
+	    
+		System.out.print("first stream: ");
+		readHeadOfStream(rs);
+	    
+		System.out.print("second stream: ");
+		readHeadOfStream(rs);
+
+	    }finally{
+		if(rs != null)
+		    rs.close();
+	    
+		if(st != null)
+		    st.close();
+	    
+	    }
+
+	}
+
+    
+	private static void readHeadOfStream(ResultSet rs) 
+	    throws SQLException, IOException {
+	
+	    InputStream is = null;
+
+	    try{
+		is = rs.getBinaryStream(1);
+
+		for( int i = 0 ;
+		     i < 8 ;
+		     i ++ ){
+		
+		    System.out.print(is.read());
+		
+		}
+	    
+		System.out.println();
+	    
+	    }finally{
+		if(is != null)
+		    is.close();
+	    }
+	}
+    
+    
+	private static void cleanTestRepeatedStream(Connection conn) 
+	    throws SQLException {
+	
+	    Statement st = null;
+
+	    try{
+		st = conn.createStatement();
+		st.execute("drop table testBlobX2");
+
+	    }finally{
+		if(st != null)
+		    st.close();
+	    }
+	}
+
+
+    }
+    
 
 }



Mime
View raw message