KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > results > persistent > jdbc > NamedResults


1 /*
2  * Hammurapi
3  * Automated Java code review system.
4  * Copyright (C) 2004 Hammurapi Group
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (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 JavaDoc;
27 import java.sql.ResultSet JavaDoc;
28 import java.sql.SQLException JavaDoc;
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 Comparable JavaDoc, org.hammurapi.results.NamedResults {
41     
42     /**
43      * @param id
44      * @param factory
45      * @throws SQLException
46      */

47     public NamedResults(int id, ResultsFactory factory) throws SQLException JavaDoc {
48         super(id, factory);
49         factory.getSQLProcessor().processSelect(
50                 "SELECT NAME FROM RESULT WHERE ID=?",
51                 idParameterizer,
52                 new RowProcessor() {
53                     public boolean process(ResultSet JavaDoc rs) throws SQLException JavaDoc {
54                         name=rs.getString("NAME");
55                         return false;
56                     }
57                 });
58     }
59     
60     NamedResults(final String JavaDoc name, WaiverSet waiverSet, ResultsFactory factory) throws SQLException JavaDoc {
61         super(waiverSet, factory);
62         this.name=name;
63         factory.getSQLProcessor().processUpdate(
64                 "UPDATE RESULT SET NAME=? WHERE ID=?",
65                 new Parameterizer() {
66                     public void parameterize(PreparedStatement JavaDoc preparedStatement) throws SQLException JavaDoc {
67                         preparedStatement.setString(1, name);
68                         preparedStatement.setInt(2, getId());
69                     }
70                 });
71     }
72     
73     private String JavaDoc name;
74     
75     public String JavaDoc getName() {
76         return name;
77     }
78     
79     public int compareTo(Object JavaDoc obj) {
80         if (obj instanceof NamedResults) {
81             String JavaDoc otherName=((NamedResults) obj).getName();
82             if (name==null && otherName==null) {
83                 return 0;
84             } else if (name!=null) {
85                 return name.compareTo(otherName);
86             } else {
87                 return 1;
88             }
89         }
90         
91         return 2;
92     }
93 }
94
Popular Tags