1 34 package org.dspace.checker; 35 36 import java.sql.Connection ; 37 import java.sql.PreparedStatement ; 38 import java.sql.ResultSet ; 39 import java.sql.SQLException ; 40 import java.sql.Statement ; 41 import java.util.ArrayList ; 42 import java.util.List ; 43 44 import org.apache.log4j.Logger; 45 import org.dspace.storage.rdbms.DatabaseManager; 46 47 57 public final class ChecksumResultDAO extends DAOSupport 58 { 59 62 private static final String FIND_CHECK_STRING = "select result_description " 63 + "from checksum_results where result_code = ?;"; 64 65 68 private static final Logger LOG = Logger.getLogger(ChecksumResultDAO.class); 69 70 73 public ChecksumResultDAO() 74 { 75 ; 76 } 77 78 85 public String getChecksumCheckStr(String code) 86 { 87 String description = null; 88 Connection conn = null; 89 PreparedStatement stmt = null; 90 ResultSet 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 e) 106 { 107 LOG.error("Problem selecting checker result description. " 108 + e.getMessage(), e); 109 throw new RuntimeException ("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 125 public List listAllCodes() 126 { 127 Connection conn = null; 128 Statement stmt = null; 129 ResultSet rs = null; 130 List codes = new ArrayList (); 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 code = rs.getString("result_code"); 140 codes.add(code); 141 } 142 return codes; 143 } 144 catch (SQLException e) 145 { 146 LOG.error("Problem listing checksum results codes: " 147 + e.getMessage(), e); 148 throw new RuntimeException ( 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 |