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 se...@apache.org on 2001/11/01 05:55:32 UTC
cvs commit: jakarta-james/src/java/org/apache/james/mailrepository JDBCMailRepository.java
serge 01/10/31 20:55:32
Modified: src/java/org/apache/james/mailrepository
JDBCMailRepository.java
Log:
Added finally blocks to make sure connections are closed.
Revision Changes Path
1.7 +40 -9 jakarta-james/src/java/org/apache/james/mailrepository/JDBCMailRepository.java
Index: JDBCMailRepository.java
===================================================================
RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/mailrepository/JDBCMailRepository.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- JDBCMailRepository.java 2001/09/27 21:12:29 1.6
+++ JDBCMailRepository.java 2001/11/01 04:55:32 1.7
@@ -285,8 +285,9 @@
public void store(MailImpl mc) {
//System.err.println("storing " + mc.getName());
+ Connection conn = null;
try {
- Connection conn = getConnection();
+ conn = getConnection();
//Need to determine whether need to insert this record, or update it.
@@ -414,7 +415,6 @@
conn.commit();
conn.setAutoCommit(true);
- conn.close();
synchronized (this) {
notifyAll();
@@ -422,13 +422,22 @@
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Exception caught while storing mail Container: " + e);
+ } finally {
+ if (conn != null) {
+ try {
+ conn.close();
+ } catch (SQLException sqle) {
+ //ignore
+ }
+ }
}
}
public MailImpl retrieve(String key) {
//System.err.println("retrieving " + key);
+ Connection conn = null;
try {
- Connection conn = getConnection();
+ conn = getConnection();
PreparedStatement retrieveMessage =
conn.prepareStatement(sqlQueries.getSqlString("retrieveMessageSQL", true));
@@ -463,7 +472,6 @@
mc.setMessage(message);
rsMessage.close();
retrieveMessage.close();
- conn.close();
return mc;
} catch (SQLException sqle) {
System.err.println("Error retrieving message");
@@ -476,6 +484,14 @@
} catch (Exception me) {
me.printStackTrace();
throw new RuntimeException("Exception while retrieving mail: " + me.getMessage());
+ } finally {
+ if (conn != null) {
+ try {
+ conn.close();
+ } catch (SQLException sqle) {
+ //ignore
+ }
+ }
}
}
@@ -486,15 +502,15 @@
public void remove(String key) {
//System.err.println("removing " + key);
if (lock(key)) {
+ Connection conn = null;
try {
- Connection conn = getConnection();
+ conn = getConnection();
PreparedStatement removeMessage =
conn.prepareStatement(sqlQueries.getSqlString("removeMessageSQL", true));
removeMessage.setString(1, key);
removeMessage.setString(2, repositoryName);
removeMessage.execute();
removeMessage.close();
- conn.close();
if (sr != null) {
sr.remove(key);
@@ -503,14 +519,22 @@
throw new RuntimeException("Exception while removing mail: " + me.getMessage());
} finally {
unlock(key);
+ if (conn != null) {
+ try {
+ conn.close();
+ } catch (SQLException sqle) {
+ //ignore
+ }
+ }
}
}
}
public Iterator list() {
//System.err.println("listing messages");
+ Connection conn = null;
try {
- Connection conn = getConnection();
+ conn = getConnection();
PreparedStatement listMessages =
conn.prepareStatement(sqlQueries.getSqlString("listMessagesSQL", true));
listMessages.setString(1, repositoryName);
@@ -522,11 +546,18 @@
}
rsListMessages.close();
listMessages.close();
- conn.close();
return messageList.iterator();
} catch (Exception me) {
- me.printStackTrace();
+ me.printStackTrace();
throw new RuntimeException("Exception while listing mail: " + me.getMessage());
+ } finally {
+ if (conn != null) {
+ try {
+ conn.close();
+ } catch (SQLException sqle) {
+ //ignore
+ }
+ }
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>