KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > checker > DAOSupport


1 package org.dspace.checker;
2
3 import java.sql.Connection JavaDoc;
4 import java.sql.ResultSet JavaDoc;
5 import java.sql.SQLException JavaDoc;
6 import java.sql.Statement JavaDoc;
7
8 import org.apache.log4j.Logger;
9 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
22     private static final Logger LOG = Logger.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 JavaDoc stmt, Connection JavaDoc conn)
33     {
34         cleanup(stmt);
35         if (conn != null)
36         {
37             DatabaseManager.freeConnection(conn);
38         }
39     }
40
41     /**
42      * Utility method that cleans up the statement and connection.
43      *
44      * @param stmt
45      * A prepared statement to close.
46      * @param conn
47      * Corresponding connection to close.
48      * @param rs
49      * Result set to close
50      */

51     protected void cleanup(Statement JavaDoc stmt, Connection JavaDoc conn, ResultSet JavaDoc rs)
52     {
53         if (rs != null)
54         {
55             try
56             {
57                 rs.close();
58             }
59             catch (SQLException JavaDoc e)
60             {
61                 LOG.warn("Problem closing result set. " + e.getMessage(), e);
62             }
63         }
64         cleanup(stmt);
65
66         if (conn != null)
67         {
68             DatabaseManager.freeConnection(conn);
69         }
70     }
71
72     protected void cleanup(Statement JavaDoc stmt)
73     {
74         if (stmt != null)
75         {
76             try
77             {
78                 stmt.close();
79             }
80             catch (SQLException JavaDoc e)
81             {
82                 LOG.warn("Problem closing prepared statement. "
83                         + e.getMessage(), e);
84             }
85         }
86     }
87
88     protected void cleanup(Connection JavaDoc conn)
89     {
90         if (conn != null)
91         {
92             try
93             {
94                 conn.close();
95             }
96             catch (SQLException JavaDoc e)
97             {
98                 LOG.warn(e);
99             }
100         }
101     }
102
103 }
104
Popular Tags