You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by eb...@apache.org on 2004/06/22 14:56:54 UTC
cvs commit: jakarta-commons/configuration/src/java/org/apache/commons/configuration DatabaseConfiguration.java
ebourg 2004/06/22 05:56:54
Modified: configuration/src/java/org/apache/commons/configuration
DatabaseConfiguration.java
Log:
Added a closeQuietly method similar to DbUtils.closeQuietly
Revision Changes Path
1.4 +28 -55 jakarta-commons/configuration/src/java/org/apache/commons/configuration/DatabaseConfiguration.java
Index: DatabaseConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/DatabaseConfiguration.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DatabaseConfiguration.java 27 Feb 2004 17:41:35 -0000 1.3
+++ DatabaseConfiguration.java 22 Jun 2004 12:56:54 -0000 1.4
@@ -20,6 +20,7 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -31,6 +32,9 @@
/**
* Configuration stored in a database.
*
+ * @since 1.0
+ *
+ * @author Emmanuel Bourg
* @version $Revision$, $Date$
*/
public class DatabaseConfiguration extends AbstractConfiguration
@@ -126,15 +130,7 @@
}
finally
{
- try
- {
- if (pstmt != null) { pstmt.close(); }
- if (conn != null) { conn.close(); }
- }
- catch (SQLException e)
- {
- log.error(e.getMessage(), e);
- }
+ closeQuietly(conn, pstmt);
}
return result;
@@ -179,15 +175,7 @@
finally
{
// clean up
- try
- {
- if (pstmt != null) { pstmt.close(); }
- if (conn != null) { conn.close(); }
- }
- catch (SQLException e)
- {
- log.error(e.getMessage(), e);
- }
+ closeQuietly(conn, pstmt);
}
}
@@ -230,15 +218,7 @@
finally
{
// clean up
- try
- {
- if (pstmt != null) { pstmt.close(); }
- if (conn != null) { conn.close(); }
- }
- catch (SQLException e)
- {
- log.error(e.getMessage(), e);
- }
+ closeQuietly(conn, pstmt);
}
return empty;
@@ -281,15 +261,7 @@
finally
{
// clean up
- try
- {
- if (pstmt != null) { pstmt.close(); }
- if (conn != null) { conn.close(); }
- }
- catch (SQLException e)
- {
- log.error(e.getMessage(), e);
- }
+ closeQuietly(conn, pstmt);
}
return found;
@@ -328,15 +300,7 @@
finally
{
// clean up
- try
- {
- if (pstmt != null) { pstmt.close(); }
- if (conn != null) { conn.close(); }
- }
- catch (SQLException e)
- {
- log.error(e.getMessage(), e);
- }
+ closeQuietly(conn, pstmt);
}
}
@@ -379,17 +343,26 @@
finally
{
// clean up
- try
- {
- if (pstmt != null) { pstmt.close(); }
- if (conn != null) { conn.close(); }
- }
- catch (SQLException e)
- {
- log.error(e.getMessage(), e);
- }
+ closeQuietly(conn, pstmt);
}
return keys.iterator();
+ }
+
+ /**
+ * Close a <code>Connection</code> and, <code>Statement</code>.
+ * Avoid closing if null and hide any SQLExceptions that occur.
+ */
+ private void closeQuietly(Connection conn, Statement stmt)
+ {
+ try
+ {
+ if (stmt != null) { stmt.close(); }
+ if (conn != null) { conn.close(); }
+ }
+ catch (SQLException e)
+ {
+ log.error(e.getMessage(), e);
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org