Author: tmnk Date: Wed Oct 19 04:36:14 2005 New Revision: 326534 URL: http://svn.apache.org/viewcvs?rev=326534&view=rev Log: - DERBY-609 Returning ByteArrayInputStream from ResultSet is not appropriate - Patch by Tomohito Nakayama (tomonaka@basil.ocn.ne.jp) Added: db/derby/code/trunk/java/client/org/apache/derby/client/am/CloseFilterInputStream.java (with props) db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/resultsetStream.out Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude Added: db/derby/code/trunk/java/client/org/apache/derby/client/am/CloseFilterInputStream.java URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/CloseFilterInputStream.java?rev=326534&view=auto ============================================================================== --- db/derby/code/trunk/java/client/org/apache/derby/client/am/CloseFilterInputStream.java (added) +++ db/derby/code/trunk/java/client/org/apache/derby/client/am/CloseFilterInputStream.java Wed Oct 19 04:36:14 2005 @@ -0,0 +1,114 @@ +/* + + Derby - Class org.apache.derby.client.am.CloseFilterInputStream + + Copyright (c) 2001, 2005 The Apache Software Foundation or its licensors, where applicable. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +package org.apache.derby.client.am; + +import java.io.InputStream; +import java.io.FilterInputStream; + +import java.io.IOException; + +class CloseFilterInputStream extends FilterInputStream { + + private static final String ALREADY_CLOSED_ERR_MEASSAGE = "This object is already closed."; + + private boolean closed; + + + public CloseFilterInputStream(InputStream is){ + + super(is); + closed = false; + + } + + + public int read() + throws IOException { + + if(closed){ + throw new IOException(ALREADY_CLOSED_ERR_MEASSAGE); + } + + return super.read(); + + } + + + public int read(byte[] b) + throws IOException { + + if(closed){ + throw new IOException(ALREADY_CLOSED_ERR_MEASSAGE); + } + + return super.read(b); + + } + + + public int read(byte[] b, + int off, + int len) + throws IOException{ + + if(closed){ + throw new IOException(ALREADY_CLOSED_ERR_MEASSAGE); + } + + return super.read(b, off, len); + + } + + + public long skip(long n) + throws IOException{ + + if(closed){ + throw new IOException(ALREADY_CLOSED_ERR_MEASSAGE); + } + + return super.skip(n); + + } + + + public int available() + throws IOException{ + + if(closed){ + throw new IOException(ALREADY_CLOSED_ERR_MEASSAGE); + } + + return super.available(); + + } + + + public void close() + throws IOException{ + + super.close(); + closed = true; + + } + + +} Propchange: db/derby/code/trunk/java/client/org/apache/derby/client/am/CloseFilterInputStream.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java?rev=326534&r1=326533&r2=326534&view=diff ============================================================================== --- db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java (original) +++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java Wed Oct 19 04:36:14 2005 @@ -20,7 +20,7 @@ package org.apache.derby.client.am; - +import java.io.IOException; public abstract class ResultSet implements java.sql.ResultSet, ResultSetCallbackInterface, @@ -35,6 +35,8 @@ public Section generatedSection_ = null; + private CloseFilterInputStream is_; + //---------------------navigational cheat-links------------------------------- // Cheat-links are for convenience only, and are not part of the conceptual model. // Warning: @@ -493,6 +495,9 @@ // Live life on the edge and run unsynchronized public boolean getBoolean(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getBoolean", column); } @@ -513,6 +518,9 @@ // Live life on the edge and run unsynchronized public byte getByte(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getByte", column); } @@ -533,6 +541,9 @@ // Live life on the edge and run unsynchronized public short getShort(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getShort", column); } @@ -553,6 +564,9 @@ // Live life on the edge and run unsynchronized public int getInt(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getInt", column); } @@ -573,6 +587,9 @@ // Live life on the edge and run unsynchronized public long getLong(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getLong", column); } @@ -593,6 +610,9 @@ // Live life on the edge and run unsynchronized public float getFloat(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getFloat", column); } @@ -613,6 +633,9 @@ // Live life on the edge and run unsynchronized public double getDouble(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getDouble", column); } @@ -633,6 +656,9 @@ // Live life on the edge and run unsynchronized public java.math.BigDecimal getBigDecimal(int column, int scale) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceDeprecatedEntry(this, "getBigDecimal", column, scale); } @@ -655,6 +681,9 @@ // Live life on the edge and run unsynchronized public java.math.BigDecimal getBigDecimal(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getBigDecimal", column); } @@ -676,6 +705,9 @@ // Live life on the edge and run unsynchronized public java.sql.Date getDate(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getDate", column); } @@ -695,6 +727,9 @@ // Live life on the edge and run unsynchronized public java.sql.Date getDate(int column, java.util.Calendar calendar) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getDate", column, calendar); } @@ -722,6 +757,9 @@ // Live life on the edge and run unsynchronized public java.sql.Time getTime(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getTime", column); } @@ -741,6 +779,9 @@ // Live life on the edge and run unsynchronized public java.sql.Time getTime(int column, java.util.Calendar calendar) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getTime", column, calendar); } @@ -768,6 +809,9 @@ // Live life on the edge and run unsynchronized public java.sql.Timestamp getTimestamp(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getTimestamp", column); } @@ -787,6 +831,9 @@ // Live life on the edge and run unsynchronized public java.sql.Timestamp getTimestamp(int column, java.util.Calendar calendar) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getTimestamp", column, calendar); } @@ -816,6 +863,9 @@ // Live life on the edge and run unsynchronized public String getString(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getString", column); } @@ -835,6 +885,9 @@ // Live life on the edge and run unsynchronized public byte[] getBytes(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getBytes", column); } @@ -854,6 +907,9 @@ // Live life on the edge and run unsynchronized public java.io.InputStream getBinaryStream(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getBinaryStream", column); } @@ -868,11 +924,14 @@ agent_.logWriter_.traceExit(this, "getBinaryStream", result); } setWasNull(column); // Placed close to the return to minimize risk of thread interference - return result; + return createCloseFilterInputStream(result); } // Live life on the edge and run unsynchronized public java.io.InputStream getAsciiStream(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getAsciiStream", column); } @@ -890,11 +949,14 @@ agent_.logWriter_.traceExit(this, "getAsciiStream", result); } setWasNull(column); // Placed close to the return to minimize risk of thread interference - return result; + return createCloseFilterInputStream(result); } // Live life on the edge and run unsynchronized public java.io.InputStream getUnicodeStream(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceDeprecatedEntry(this, "getUnicodeStream", column); } @@ -915,11 +977,14 @@ agent_.logWriter_.traceDeprecatedExit(this, "getUnicodeStream", result); } setWasNull(column); // Placed close to the return to minimize risk of thread interference - return result; + return createCloseFilterInputStream(result); } // Live life on the edge and run unsynchronized public java.io.Reader getCharacterStream(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getCharacterStream", column); } @@ -940,6 +1005,9 @@ // Live life on the edge and run unsynchronized public java.sql.Blob getBlob(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getBlob", column); } @@ -960,6 +1028,9 @@ // Live life on the edge and run unsynchronized public java.sql.Clob getClob(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getClob", column); } @@ -980,6 +1051,9 @@ // Live life on the edge and run unsynchronized public java.sql.Ref getRef(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getRef", column); } @@ -997,6 +1071,9 @@ // Live life on the edge and run unsynchronized public java.sql.Array getArray(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getArray", column); } @@ -1014,6 +1091,9 @@ // Live life on the edge and run unsynchronized public Object getObject(int column) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getObject", column); } @@ -1039,6 +1119,9 @@ // Live life on the edge and run unsynchronized public Object getObject(int column, java.util.Map map) throws SqlException { + + closeCloseFilterInputStream(); + if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getObject", column, map); } @@ -3898,4 +3981,45 @@ return result; } + + + private CloseFilterInputStream createCloseFilterInputStream(java.io.InputStream is) throws SqlException { + + if(is == null){ + return null; + } + + if( is_ == is ){ + return is_; + } + + closeCloseFilterInputStream(); + + is_ = new CloseFilterInputStream(is); + + return is_; + + } + + + private void closeCloseFilterInputStream() throws SqlException { + + if(is_ != null){ + try{ + is_.close(); + + }catch(IOException e){ + + throw new SqlException(agent_.logWriter_ , + e , + "Failed to close inputStream."); + + } + + is_ = null; + + } + } + + } Added: 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=326534&view=auto ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/resultsetStream.out (added) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/resultsetStream.out Wed Oct 19 04:36:14 2005 @@ -0,0 +1,14 @@ +Test resultsetStream starting +getColumnCount(): 1 +Checksum of first 200 bytes 3061553656 +Size of file = 3470 +getColumnCount(): 2 +Checksum of first 200 bytes 3061553656 +second columns is 3470 +FAILS DUE TO BUG 5710 +getColumnCount(): 1 +len=56 +number of reads=56 +EXPECTED SQLSTATE(null): End of Stream prematurely reached while reading InputStream, parameter #2. Remaining data has been padded with 0x0. +EXPECTED SQLSTATE(null): The specified size of the InputStream, parameter #2, is less than the actual InputStream length +Test resultsetStream finished Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude?rev=326534&r1=326533&r2=326534&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude Wed Oct 19 04:36:14 2005 @@ -1,4 +1,3 @@ -# excluding resultsetStream.java because this test uses java.io.FileInputStream throughout the test # excluding TestErrorStreamTarget.java since it's not relevant for clients # excluding scrollCursors2.java because updatable resultsets & scroll sensitive cursors are not supported # excluding batchUpdate.java for it hits a problem in networkserver ('beetle' 5561) @@ -8,7 +7,6 @@ # excluding jdbcapi/resultsetJdbc30.java because the features tested are not implemented by Derby Client # excluding jdbcapi/checkDataSource30.java - Client behaves differently. Need to look into this # excluding jdbcapi/statementJdbc30.java - Client behaves differently. Need to look into this -jdbcapi/resultsetStream.java lang/errorStream.java lang/scrollCursors2.java jdbcapi/batchUpdate.java