Print

Print


Author: [log in to unmask]
Date: Mon Nov 17 13:52:54 2014
New Revision: 1554

Log:
Move a few static utility methods to new class from DatabaseConditionsManager.

Added:
    java/trunk/conditions/src/main/java/org/hps/conditions/database/DatabaseUtilities.java

Added: java/trunk/conditions/src/main/java/org/hps/conditions/database/DatabaseUtilities.java
 =============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/database/DatabaseUtilities.java	(added)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/database/DatabaseUtilities.java	Mon Nov 17 13:52:54 2014
@@ -0,0 +1,42 @@
+package org.hps.conditions.database;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public final class DatabaseUtilities {
+    
+    /**
+     * Close a JDBC <code>Statement</code>.
+     * @param statement the Statement to close
+     */
+    public static void close(Statement statement) {
+        if (statement != null) {
+            try {
+                if (!statement.isClosed()) {
+                    statement.close();
+                }
+            } catch (SQLException x) {
+                throw new RuntimeException("Failed to close statement.", x);
+            }
+        }
+    }
+
+    /**
+     * Close the JDBC the <code>Statement</code> connected to the <code>ResultSet</code>.
+     * @param resultSet the ResultSet to close
+     */
+    public static void close(ResultSet resultSet) {
+        if (resultSet != null) {
+            try {
+                Statement statement = resultSet.getStatement();
+                if (!statement.isClosed()) {
+                    statement.close();
+                }
+            } catch (SQLException x) {
+                throw new RuntimeException("Failed to close statement.", x);
+            }
+        }
+    }
+
+}