KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 2004-2005, Hewlett-Packard Company and Massachusetts
3  * Institute of Technology. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * - Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * - Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * - Neither the name of the Hewlett-Packard Company nor the name of the
17  * Massachusetts Institute of Technology nor the names of their
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
32  * DAMAGE.
33  */

34 package org.dspace.checker;
35
36 import java.sql.Connection JavaDoc;
37 import java.sql.PreparedStatement JavaDoc;
38 import java.sql.ResultSet JavaDoc;
39 import java.sql.SQLException JavaDoc;
40 import java.sql.Statement JavaDoc;
41 import java.util.ArrayList JavaDoc;
42 import java.util.List JavaDoc;
43
44 import org.apache.log4j.Logger;
45 import org.dspace.storage.rdbms.DatabaseManager;
46
47 /**
48  * <p>
49  * Database Access for the checksum results information.
50  * </p>
51  *
52  * @author Jim Downing
53  * @author Grace Carpenter
54  * @author Nathan Sarr
55  *
56  */

57 public final class ChecksumResultDAO extends DAOSupport
58 {
59     /**
60      * Find a specified description.
61      */

62     private static final String JavaDoc FIND_CHECK_STRING = "select result_description "
63             + "from checksum_results where result_code = ?;";
64
65     /**
66      * Usual Log4J Logger.
67      */

68     private static final Logger LOG = Logger.getLogger(ChecksumResultDAO.class);
69
70     /**
71      * Default constructor
72      */

73     public ChecksumResultDAO()
74     {
75         ;
76     }
77
78     /**
79      * Get the result description for the given result code
80      *
81      * @param code
82      * to get the description for.
83      * @return the found description.
84      */

85     public String JavaDoc getChecksumCheckStr(String JavaDoc code)
86     {
87         String JavaDoc description = null;
88         Connection JavaDoc conn = null;
89         PreparedStatement JavaDoc stmt = null;
90         ResultSet JavaDoc rs = null;
91
92         try
93         {
94             conn = DatabaseManager.getConnection();
95             stmt = conn.prepareStatement(FIND_CHECK_STRING);
96             stmt.setString(1, code);
97
98             rs = stmt.executeQuery();
99
100             if (rs.next())
101             {
102                 description = rs.getString(1);
103             }
104         }
105         catch (SQLException JavaDoc e)
106         {
107             LOG.error("Problem selecting checker result description. "
108                     + e.getMessage(), e);
109             throw new RuntimeException JavaDoc("selecting checker result description. "
110                     + e.getMessage(), e);
111         }
112         finally
113         {
114             cleanup(stmt, conn, rs);
115         }
116
117         return description;
118     }
119
120     /**
121      * Get a list of all the possible result codes.
122      *
123      * @return a list of all the result codes
124      */

125     public List JavaDoc listAllCodes()
126     {
127         Connection JavaDoc conn = null;
128         Statement JavaDoc stmt = null;
129         ResultSet JavaDoc rs = null;
130         List JavaDoc codes = new ArrayList JavaDoc();
131         try
132         {
133             conn = DatabaseManager.getConnection();
134             stmt = conn.createStatement();
135
136             rs = stmt.executeQuery("SELECT result_code FROM checksum_results");
137             while (rs.next())
138             {
139                 String JavaDoc code = rs.getString("result_code");
140                 codes.add(code);
141             }
142             return codes;
143         }
144         catch (SQLException JavaDoc e)
145         {
146             LOG.error("Problem listing checksum results codes: "
147                     + e.getMessage(), e);
148             throw new RuntimeException JavaDoc(
149                     "Problem listing checksum results codes: " + e.getMessage(),
150                     e);
151         }
152         finally
153         {
154             cleanup(stmt, conn, rs);
155         }
156     }
157 }
158
Popular Tags