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 ChangesPath
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.java27 Feb 2004 17:41:35 - 1.3
+++ DatabaseConfiguration.java22 Jun 2004 12:56:54 - 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 codeConnection/code and, codeStatement/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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]