You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by da...@apache.org on 2002/06/20 16:42:23 UTC
cvs commit: jakarta-james/src/java/org/apache/james/mailrepository MimeMessageJDBCSource.java
danny 2002/06/20 07:42:23
Modified: src/java/org/apache/james/mailrepository
MimeMessageJDBCSource.java
Log:
Connections not being closed when exceptions occur.
Fixed it.
Revision Changes Path
1.7 +18 -7 jakarta-james/src/java/org/apache/james/mailrepository/MimeMessageJDBCSource.java
Index: MimeMessageJDBCSource.java
===================================================================
RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/mailrepository/MimeMessageJDBCSource.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- MimeMessageJDBCSource.java 18 Apr 2002 19:14:23 -0000 1.6
+++ MimeMessageJDBCSource.java 20 Jun 2002 14:42:23 -0000 1.7
@@ -67,8 +67,9 @@
* a repository with the entire message in the database, which is how James 1.2 worked.
*/
public synchronized InputStream getInputStream() throws IOException {
+ Connection conn =null;
try {
- Connection conn = repository.getConnection();
+ conn = repository.getConnection();
byte[] headers = null;
@@ -94,7 +95,7 @@
System.err.println(System.currentTimeMillis() - start);
}
- conn.close();
+
InputStream in = new ByteArrayInputStream(headers);
try {
@@ -108,7 +109,12 @@
return in;
} catch (SQLException sqle) {
throw new IOException(sqle.toString());
- }
+ }finally {
+ try {
+ conn.close();
+ } catch (Exception e) {
+ }
+ }
}
/**
@@ -120,9 +126,9 @@
System.err.println("no SQL statement to find size");
return super.getMessageSize();
}
-
+Connection conn=null;
try {
- Connection conn = repository.getConnection();
+ conn = repository.getConnection();
PreparedStatement retrieveMessageSize = conn.prepareStatement(retrieveMessageBodySizeSQL);
retrieveMessageSize.setString(1, key);
@@ -136,7 +142,7 @@
long size = rsRetrieveMessageSize.getLong(1);
rsRetrieveMessageSize.close();
retrieveMessageSize.close();
- conn.close();
+
try {
if (sr != null) {
@@ -155,7 +161,12 @@
return size;
} catch (SQLException sqle) {
throw new IOException(sqle.toString());
- }
+ }finally {
+ try {
+ conn.close();
+ } catch (Exception e) {
+ }
+ }
}
/**
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: cvs commit: jakarta-james/src/java/org/apache/james/mailrepository MimeMessageJDBCSource.java
Posted by Danny Angus <da...@apache.org>.
try {
conn.close();
} catch (Exception e) {
}
..will ignore NullPointerException too.
d.
> -----Original Message-----
> From: Eung-ju Park [mailto:colusvi@hotmail.com]
> Sent: 20 June 2002 15:52
> To: James Developers List
> Subject: Re: cvs commit:
> jakarta-james/src/java/org/apache/james/mailrepository
> MimeMessageJDBCSource.java
>
>
> Needs null check.
>
> if ( conn != null ) {
> try { conn.close() } catch ( SQLException ignore ) {}
> }
>
> ----- Original Message -----
> From: <da...@apache.org>
> To: <ja...@apache.org>
> Sent: Thursday, June 20, 2002 11:42 PM
> Subject: cvs commit:
> jakarta-james/src/java/org/apache/james/mailrepository
> MimeMessageJDBCSource.java
>
>
> > danny 2002/06/20 07:42:23
> >
> > Modified: src/java/org/apache/james/mailrepository
> > MimeMessageJDBCSource.java
> > Log:
> > Connections not being closed when exceptions occur.
> > Fixed it.
> >
> > Revision Changes Path
> > 1.7 +18 -7
> jakarta-james/src/java/org/apache/james/mailrepository/MimeMessage
> JDBCSource
> .java
> >
> > Index: MimeMessageJDBCSource.java
> > ===================================================================
> > RCS file:
> /home/cvs/jakarta-james/src/java/org/apache/james/mailrepository/M
> imeMessage
> JDBCSource.java,v
> > retrieving revision 1.6
> > retrieving revision 1.7
> > diff -u -r1.6 -r1.7
> > --- MimeMessageJDBCSource.java 18 Apr 2002 19:14:23 -0000 1.6
> > +++ MimeMessageJDBCSource.java 20 Jun 2002 14:42:23 -0000 1.7
> > @@ -67,8 +67,9 @@
> > * a repository with the entire message in the database, which is
> how James 1.2 worked.
> > */
> > public synchronized InputStream getInputStream() throws
> IOException
> {
> > + Connection conn =null;
> > try {
> > - Connection conn = repository.getConnection();
> > + conn = repository.getConnection();
> >
> > byte[] headers = null;
> >
> > @@ -94,7 +95,7 @@
> >
> System.err.println(System.currentTimeMillis() - start);
> > }
> >
> > - conn.close();
> > +
> >
> > InputStream in = new ByteArrayInputStream(headers);
> > try {
> > @@ -108,7 +109,12 @@
> > return in;
> > } catch (SQLException sqle) {
> > throw new IOException(sqle.toString());
> > - }
> > + }finally {
> > + try {
> > + conn.close();
> > + } catch (Exception e) {
> > + }
> > + }
> > }
> >
> > /**
> > @@ -120,9 +126,9 @@
> > System.err.println("no SQL statement to find size");
> > return super.getMessageSize();
> > }
> > -
> > +Connection conn=null;
> > try {
> > - Connection conn = repository.getConnection();
> > + conn = repository.getConnection();
> >
> > PreparedStatement retrieveMessageSize =
> conn.prepareStatement(retrieveMessageBodySizeSQL);
> > retrieveMessageSize.setString(1, key);
> > @@ -136,7 +142,7 @@
> > long size = rsRetrieveMessageSize.getLong(1);
> > rsRetrieveMessageSize.close();
> > retrieveMessageSize.close();
> > - conn.close();
> > +
> >
> > try {
> > if (sr != null) {
> > @@ -155,7 +161,12 @@
> > return size;
> > } catch (SQLException sqle) {
> > throw new IOException(sqle.toString());
> > - }
> > + }finally {
> > + try {
> > + conn.close();
> > + } catch (Exception e) {
> > + }
> > + }
> > }
> >
> > /**
> >
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> >
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: cvs commit: jakarta-james/src/java/org/apache/james/mailrepository MimeMessageJDBCSource.java
Posted by Eung-ju Park <co...@hotmail.com>.
Needs null check.
if ( conn != null ) {
try { conn.close() } catch ( SQLException ignore ) {}
}
----- Original Message -----
From: <da...@apache.org>
To: <ja...@apache.org>
Sent: Thursday, June 20, 2002 11:42 PM
Subject: cvs commit: jakarta-james/src/java/org/apache/james/mailrepository
MimeMessageJDBCSource.java
> danny 2002/06/20 07:42:23
>
> Modified: src/java/org/apache/james/mailrepository
> MimeMessageJDBCSource.java
> Log:
> Connections not being closed when exceptions occur.
> Fixed it.
>
> Revision Changes Path
> 1.7 +18 -7
jakarta-james/src/java/org/apache/james/mailrepository/MimeMessageJDBCSource
.java
>
> Index: MimeMessageJDBCSource.java
> ===================================================================
> RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/mailrepository/MimeMessage
JDBCSource.java,v
> retrieving revision 1.6
> retrieving revision 1.7
> diff -u -r1.6 -r1.7
> --- MimeMessageJDBCSource.java 18 Apr 2002 19:14:23 -0000 1.6
> +++ MimeMessageJDBCSource.java 20 Jun 2002 14:42:23 -0000 1.7
> @@ -67,8 +67,9 @@
> * a repository with the entire message in the database, which is
how James 1.2 worked.
> */
> public synchronized InputStream getInputStream() throws IOException
{
> + Connection conn =null;
> try {
> - Connection conn = repository.getConnection();
> + conn = repository.getConnection();
>
> byte[] headers = null;
>
> @@ -94,7 +95,7 @@
> System.err.println(System.currentTimeMillis() - start);
> }
>
> - conn.close();
> +
>
> InputStream in = new ByteArrayInputStream(headers);
> try {
> @@ -108,7 +109,12 @@
> return in;
> } catch (SQLException sqle) {
> throw new IOException(sqle.toString());
> - }
> + }finally {
> + try {
> + conn.close();
> + } catch (Exception e) {
> + }
> + }
> }
>
> /**
> @@ -120,9 +126,9 @@
> System.err.println("no SQL statement to find size");
> return super.getMessageSize();
> }
> -
> +Connection conn=null;
> try {
> - Connection conn = repository.getConnection();
> + conn = repository.getConnection();
>
> PreparedStatement retrieveMessageSize =
conn.prepareStatement(retrieveMessageBodySizeSQL);
> retrieveMessageSize.setString(1, key);
> @@ -136,7 +142,7 @@
> long size = rsRetrieveMessageSize.getLong(1);
> rsRetrieveMessageSize.close();
> retrieveMessageSize.close();
> - conn.close();
> +
>
> try {
> if (sr != null) {
> @@ -155,7 +161,12 @@
> return size;
> } catch (SQLException sqle) {
> throw new IOException(sqle.toString());
> - }
> + }finally {
> + try {
> + conn.close();
> + } catch (Exception e) {
> + }
> + }
> }
>
> /**
>
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>