01: /*
02: * Hammurapi
03: * Automated Java code review system.
04: * Copyright (C) 2004 Hammurapi Group
05: *
06: * This program is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU General Public License as published by
08: * the Free Software Foundation; either version 2 of the License, or
09: * (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: *
20: * URL: http://www.hammurapi.org
21: * e-Mail: support@hammurapi.biz
22: */
23:
24: package org.hammurapi.results.persistent.jdbc;
25:
26: import java.sql.PreparedStatement;
27: import java.sql.ResultSet;
28: import java.sql.SQLException;
29:
30: import org.hammurapi.WaiverSet;
31:
32: import com.pavelvlasov.sql.Parameterizer;
33: import com.pavelvlasov.sql.RowProcessor;
34:
35: /**
36: *
37: * @author Pavel Vlasov
38: * @version $Revision: 1.2 $
39: */
40: public class NamedResults extends AggregatedResults implements
41: Comparable, org.hammurapi.results.NamedResults {
42:
43: /**
44: * @param id
45: * @param factory
46: * @throws SQLException
47: */
48: public NamedResults(int id, ResultsFactory factory)
49: throws SQLException {
50: super (id, factory);
51: factory.getSQLProcessor().processSelect(
52: "SELECT NAME FROM RESULT WHERE ID=?", idParameterizer,
53: new RowProcessor() {
54: public boolean process(ResultSet rs)
55: throws SQLException {
56: name = rs.getString("NAME");
57: return false;
58: }
59: });
60: }
61:
62: NamedResults(final String name, WaiverSet waiverSet,
63: ResultsFactory factory) throws SQLException {
64: super (waiverSet, factory);
65: this .name = name;
66: factory.getSQLProcessor().processUpdate(
67: "UPDATE RESULT SET NAME=? WHERE ID=?",
68: new Parameterizer() {
69: public void parameterize(
70: PreparedStatement preparedStatement)
71: throws SQLException {
72: preparedStatement.setString(1, name);
73: preparedStatement.setInt(2, getId());
74: }
75: });
76: }
77:
78: private String name;
79:
80: public String getName() {
81: return name;
82: }
83:
84: public int compareTo(Object obj) {
85: if (obj instanceof NamedResults) {
86: String otherName = ((NamedResults) obj).getName();
87: if (name == null && otherName == null) {
88: return 0;
89: } else if (name != null) {
90: return name.compareTo(otherName);
91: } else {
92: return 1;
93: }
94: }
95:
96: return 2;
97: }
98: }
|