001: /*
002: * Copyright (c) 2004-2005, Hewlett-Packard Company and Massachusetts
003: * Institute of Technology. All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are
007: * met:
008: *
009: * - Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * - Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * - Neither the name of the Hewlett-Packard Company nor the name of the
017: * Massachusetts Institute of Technology nor the names of their
018: * contributors may be used to endorse or promote products derived from
019: * this software without specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
022: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
023: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
024: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
025: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
026: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
027: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
028: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
029: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
030: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
031: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
032: * DAMAGE.
033: */
034: package org.dspace.checker;
035:
036: import java.sql.Connection;
037: import java.sql.PreparedStatement;
038: import java.sql.ResultSet;
039: import java.sql.SQLException;
040: import java.sql.Statement;
041: import java.util.ArrayList;
042: import java.util.List;
043:
044: import org.apache.log4j.Logger;
045: import org.dspace.storage.rdbms.DatabaseManager;
046:
047: /**
048: * <p>
049: * Database Access for the checksum results information.
050: * </p>
051: *
052: * @author Jim Downing
053: * @author Grace Carpenter
054: * @author Nathan Sarr
055: *
056: */
057: public final class ChecksumResultDAO extends DAOSupport {
058: /**
059: * Find a specified description.
060: */
061: private static final String FIND_CHECK_STRING = "select result_description "
062: + "from checksum_results where result_code = ?";
063:
064: /**
065: * Usual Log4J Logger.
066: */
067: private static final Logger LOG = Logger
068: .getLogger(ChecksumResultDAO.class);
069:
070: /**
071: * Default constructor
072: */
073: public ChecksumResultDAO() {
074: ;
075: }
076:
077: /**
078: * Get the result description for the given result code
079: *
080: * @param code
081: * to get the description for.
082: * @return the found description.
083: */
084: public String getChecksumCheckStr(String code) {
085: String description = null;
086: Connection conn = null;
087: PreparedStatement stmt = null;
088: ResultSet rs = null;
089:
090: try {
091: conn = DatabaseManager.getConnection();
092: stmt = conn.prepareStatement(FIND_CHECK_STRING);
093: stmt.setString(1, code);
094:
095: rs = stmt.executeQuery();
096:
097: if (rs.next()) {
098: description = rs.getString(1);
099: }
100: } catch (SQLException e) {
101: LOG.error("Problem selecting checker result description. "
102: + e.getMessage(), e);
103: throw new RuntimeException(
104: "selecting checker result description. "
105: + e.getMessage(), e);
106: } finally {
107: cleanup(stmt, conn, rs);
108: }
109:
110: return description;
111: }
112:
113: /**
114: * Get a list of all the possible result codes.
115: *
116: * @return a list of all the result codes
117: */
118: public List listAllCodes() {
119: Connection conn = null;
120: Statement stmt = null;
121: ResultSet rs = null;
122: List codes = new ArrayList();
123: try {
124: conn = DatabaseManager.getConnection();
125: stmt = conn.createStatement();
126:
127: rs = stmt
128: .executeQuery("SELECT result_code FROM checksum_results");
129: while (rs.next()) {
130: String code = rs.getString("result_code");
131: codes.add(code);
132: }
133: return codes;
134: } catch (SQLException e) {
135: LOG.error("Problem listing checksum results codes: "
136: + e.getMessage(), e);
137: throw new RuntimeException(
138: "Problem listing checksum results codes: "
139: + e.getMessage(), e);
140: } finally {
141: cleanup(stmt, conn, rs);
142: }
143: }
144: }
|