db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r349718 - 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 Tue, 29 Nov 2005 14:02:37 GMT
Author: tmnk
Date: Tue Nov 29 06:02:22 2005
New Revision: 349718

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

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/UTF8Reader.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/EmbedClob.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java?rev=349718&r1=349717&r2=349718&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java Tue Nov 29 06:02:22
2005
@@ -251,8 +251,17 @@
 			}
 			finally
 			{
-				if (clobReader != null)
-					clobReader.close();
+			    if (clobReader != null){
+				
+				try{
+				    clobReader.close();
+				    
+				}catch(IOException e){
+				    e.printStackTrace();
+				    throw new SQLException(e.getMessage());
+				    
+				}
+			    }
 				restoreContextStack();
 			}
 		}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/UTF8Reader.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/UTF8Reader.java?rev=349718&r1=349717&r2=349718&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/UTF8Reader.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/UTF8Reader.java Tue Nov 29
06:02:22 2005
@@ -26,9 +26,16 @@
 import java.io.UTFDataFormatException;
 import java.io.EOFException;
 import java.sql.SQLException;
+import org.apache.derby.iapi.types.Resetable;
+import org.apache.derby.iapi.error.StandardException;
+    
 
 /**
-*/
+ *
+ * If source InputStream of this class is Resetable, close method of this class reset the
source instead of close it,
+ * because the source InputStream can be shared.
+ *
+ */
 public final class UTF8Reader extends Reader
 {
 
@@ -140,7 +147,7 @@
 
 	}
 
-	public void close()
+	public void close() throws IOException
 	{
 		synchronized (lock) {
 			closeIn();
@@ -212,23 +219,33 @@
 	*/
 
 
-	private void closeIn() {
+	private void closeIn() throws IOException {
 		if (in != null) {
 			try {
+			    
+			    if(in instanceof Resetable){
+				((Resetable) in).resetStream();
+				
+			    }else{
 				in.close();
-			} catch (IOException ioe) {
+			    }
+			    
+			} catch (StandardException e) {
+			    e.printStackTrace();
+			    throw new IOException(e.getMessage());
+			    
 			} finally {
 				in = null;
 			}
 		}
 	}
-	private IOException utfFormatException(String s) {
+	private IOException utfFormatException(String s) throws IOException {
 		noMoreReads = true;
 		closeIn();
 		return new UTFDataFormatException(s);
 	}
 
-	private IOException utfFormatException() {
+	private IOException utfFormatException() throws IOException {
 		noMoreReads = true;
 		closeIn();
 		return new UTFDataFormatException();

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=349718&r1=349717&r2=349718&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
Tue Nov 29 06:02:22 2005
@@ -17,4 +17,6 @@
 Test of RepeatedStream
 first stream: 01234567
 second stream: 01234567
+first reader: 01234567
+second reader: 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=349718&r1=349717&r2=349718&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
Tue Nov 29 06:02:22 2005
@@ -19,4 +19,6 @@
 Test of RepeatedStream
 first stream: 01234567
 second stream: 01234567
+first reader: 01234567
+second reader: 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=349718&r1=349717&r2=349718&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
Tue Nov 29 06:02:22 2005
@@ -41,6 +41,7 @@
 import java.io.Reader;
 import java.io.StringReader;
 import java.io.ByteArrayInputStream;
+import java.io.CharArrayReader;
 
 /**
  * Test of JDBC result set Stream calls.
@@ -481,8 +482,11 @@
 
 	    prepareTestRepeatedStream(conn);
 	    readFromRepeatedStream(conn);
-	    cleanTestRepeatedStream(conn);
+	    cleanTest(conn);
 	    
+	    prepareTestRepeatedReader(conn);
+	    readFromRepeatedReader(conn);
+	    cleanTest(conn);
 	    
 	}
     
@@ -575,9 +579,99 @@
 		    is.close();
 	    }
 	}
-    
-    
-	private static void cleanTestRepeatedStream(Connection conn) 
+	
+	
+	private static void prepareTestRepeatedReader(Connection conn) throws SQLException {
+	
+	    PreparedStatement st = null;
+
+	    try{
+
+		st = conn.prepareStatement("create table testBlobX2 (a integer, b clob(1024K))");
+		st.execute();
+		st.close();
+
+		st = conn.prepareStatement("insert into testBlobX2(a,b) values(1,?)");
+
+		char[] testData = new char[1024 * 1024];
+	    
+		for(int i = 0;
+		    i < testData.length;
+		    i ++)
+		    testData[i] = (char) (i % Character.MAX_VALUE);
+	    
+		st.setCharacterStream(1, 
+				      new CharArrayReader(testData),
+				      testData.length);
+
+		st.executeUpdate();
+
+	    }finally{
+		if(st != null)
+		    st.close();
+	    }
+	
+	}
+	
+	
+	private static void readFromRepeatedReader(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 reader: ");
+		readHeadOfReader(rs);
+	    
+		System.out.print("second reader: ");
+		readHeadOfReader(rs);
+		
+	    }finally{
+		if(rs != null)
+		    rs.close();
+	    
+		if(st != null)
+		    st.close();
+	    
+	    }
+
+	}
+	
+	
+	private static void readHeadOfReader(ResultSet rs) 
+	    throws SQLException, IOException {
+	
+	    Reader reader = null;
+
+	    try{
+		reader = rs.getCharacterStream(1);
+
+		for( int i = 0 ;
+		     i < 8 ;
+		     i ++ ){
+		
+		    System.out.print(reader.read());
+		
+		}
+	    
+		System.out.println();
+	    
+	    }finally{
+		if(reader != null)
+		    reader.close();
+	    }
+	}
+	
+	
+	private static void cleanTest(Connection conn) 
 	    throws SQLException {
 	
 	    Statement st = null;



Mime
View raw message