sylvain 02/04/03 04:22:11
Modified: src/scratchpad/src/org/apache/cocoon/components/source
BlobSource.java
Log:
Ensure JDBC connection is closed a the end of read, even if the stream isn't closed.
Cocoon most often "forgets" to close streams, causing a rapid connection pool
overflow...
Revision Changes Path
1.2 +53 -9
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/source/BlobSource.java
Index: BlobSource.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/source/BlobSource.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BlobSource.java 15 Mar 2002 18:49:32 -0000 1.1
+++ BlobSource.java 3 Apr 2002 12:22:11 -0000 1.2
@@ -88,7 +88,7 @@
* from people where userid='foo'</code>" in the datasource "<code>personel</code>"
*
* @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
- * @version $Id: BlobSource.java,v 1.1 2002/03/15 18:49:32 sylvain Exp $
+ * @version $Id: BlobSource.java,v 1.2 2002/04/03 12:22:11 sylvain Exp $
*/
public class BlobSource extends AbstractStreamSource {
@@ -281,23 +281,67 @@
Connection cnx;
- public JDBCInputStream(InputStream stream, Connection cnx) {
- super(stream);
- this.cnx = cnx;
- }
-
- public void close() throws IOException {
- super.close();
+ private final void closeCnx() throws IOException {
if (this.cnx != null) {
try {
- cnx.close();
+ Connection tmp = cnx;
cnx = null;
+ tmp.close();
} catch(Exception e) {
String msg = "Error closing the connection for " +
BlobSource.this.systemId;
BlobSource.this.getLogger().error(msg, e);
throw new IOException(msg + " : " + e.getMessage());
}
}
+ }
+
+ public JDBCInputStream(InputStream stream, Connection cnx) {
+ super(stream);
+ this.cnx = cnx;
+ }
+
+ public int read() throws IOException {
+ try {
+ int result = in.read();
+ if (result == -1) {
+ closeCnx();
+ }
+ return result;
+ } catch(IOException e) {
+ closeCnx();
+ throw e;
+ }
+ }
+
+ public int read(byte[] b) throws IOException {
+ try {
+ int result = in.read(b);
+ if (result == -1) {
+ closeCnx();
+ }
+ return result;
+ } catch(IOException e) {
+ closeCnx();
+ throw e;
+ }
+ }
+
+ public int read(byte[] b, int off, int len) throws IOException {
+ try {
+ int result = in.read(b, off, len);
+ if (result == -1) {
+ closeCnx();
+ }
+ return result;
+ } catch(IOException e) {
+ closeCnx();
+ throw e;
+ }
+ }
+
+ public void close() throws IOException {
+ super.close();
+ closeCnx();
}
}
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]