01: package org.dspace.checker;
02:
03: import java.sql.Connection;
04: import java.sql.ResultSet;
05: import java.sql.SQLException;
06: import java.sql.Statement;
07:
08: import org.apache.log4j.Logger;
09: import org.dspace.storage.rdbms.DatabaseManager;
10:
11: /**
12: * Database Helper Class to cleanup database resources
13: *
14: * @author Jim Downing
15: * @author Grace Carpenter
16: * @author Nathan Sarr
17: *
18: */
19: public class DAOSupport {
20:
21: private static final Logger LOG = Logger
22: .getLogger(DAOSupport.class);
23:
24: /**
25: * Utility method that cleans up the statement and connection.
26: *
27: * @param stmt
28: * A prepared statement to close.
29: * @param conn
30: * Corresponding connection to close.
31: */
32: protected void cleanup(Statement stmt, Connection conn) {
33: cleanup(stmt);
34: if (conn != null) {
35: DatabaseManager.freeConnection(conn);
36: }
37: }
38:
39: /**
40: * Utility method that cleans up the statement and connection.
41: *
42: * @param stmt
43: * A prepared statement to close.
44: * @param conn
45: * Corresponding connection to close.
46: * @param rs
47: * Result set to close
48: */
49: protected void cleanup(Statement stmt, Connection conn, ResultSet rs) {
50: if (rs != null) {
51: try {
52: rs.close();
53: } catch (SQLException e) {
54: LOG.warn("Problem closing result set. "
55: + e.getMessage(), e);
56: }
57: }
58: cleanup(stmt);
59:
60: if (conn != null) {
61: DatabaseManager.freeConnection(conn);
62: }
63: }
64:
65: protected void cleanup(Statement stmt) {
66: if (stmt != null) {
67: try {
68: stmt.close();
69: } catch (SQLException e) {
70: LOG.warn("Problem closing prepared statement. "
71: + e.getMessage(), e);
72: }
73: }
74: }
75:
76: protected void cleanup(Connection conn) {
77: if (conn != null) {
78: try {
79: conn.close();
80: } catch (SQLException e) {
81: LOG.warn(e);
82: }
83: }
84: }
85:
86: }
|