KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > dao > SurveyDAO


1 /*
2 -- GeiNuke --
3 Copyright (c) 2005 by Roberto Sidoti [geinuke@users.sourceforge.net]
4 http://www.hostingjava.it/-geinuke/
5
6 This file is part of GeiNuke.
7
8    GeiNuke is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    GeiNuke is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with GeiNuke; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */

22 package com.geinuke.dao;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.List JavaDoc;
27
28 import com.geinuke.bizlogic.BLException;
29 import com.geinuke.vo.SurveyAnswerVO;
30 import com.geinuke.vo.SurveyVO;
31 import com.geinuke.vo.SurveyVoteVO;
32 import com.geinuke.vo.WikiArticleVO;
33
34
35 public class SurveyDAO extends GeiDAO{
36     
37     public SurveyDAO() throws Exception JavaDoc {
38         super();
39         
40     }
41     
42     public void insertSurvey(SurveyVO s) throws Exception JavaDoc{
43         
44         try{
45             this.sqlMap().startTransaction();
46             this.sqlMap().insert("insSurvey",s);
47             this.sqlMap().commitTransaction();
48         }finally{
49             this.sqlMap().endTransaction();
50         }
51         
52     }
53     
54     public void insertSurveyAnswer(SurveyAnswerVO sa) throws Exception JavaDoc{
55         
56         try{
57             this.sqlMap().startTransaction();
58             this.sqlMap().insert("insSurveyAnswer",sa);
59             this.sqlMap().commitTransaction();
60         }finally{
61             this.sqlMap().endTransaction();
62         }
63         
64     }
65     
66     public ArrayList JavaDoc getSurveys()throws Exception JavaDoc{
67         ArrayList JavaDoc ll=null;
68         List JavaDoc list=null;
69         try{
70             this.sqlMap().startTransaction();
71             list=this.sqlMap().queryForList("getSurveys",null);
72             this.sqlMap().commitTransaction();
73         }finally{
74             this.sqlMap().endTransaction();
75         }
76         return new ArrayList JavaDoc(list);
77         
78     }
79     
80     public ArrayList JavaDoc getSurveysByStatus(int status)throws Exception JavaDoc{
81         ArrayList JavaDoc ll=null;
82         List JavaDoc list=null;
83         try{
84             this.sqlMap().startTransaction();
85             list=this.sqlMap().queryForList("getSurveysByStatus",new Integer JavaDoc(status));
86             this.sqlMap().commitTransaction();
87         }finally{
88             this.sqlMap().endTransaction();
89         }
90         return new ArrayList JavaDoc(list);
91         
92     }
93     
94     public ArrayList JavaDoc getSurveyAnswersByESID(int sid)throws Exception JavaDoc{
95         ArrayList JavaDoc ll=null;
96         List JavaDoc list=null;
97         try{
98             this.sqlMap().startTransaction();
99             list=this.sqlMap().queryForList("getSurveyAnswersByESID",new Integer JavaDoc(sid));
100             this.sqlMap().commitTransaction();
101         }finally{
102             this.sqlMap().endTransaction();
103         }
104         return new ArrayList JavaDoc(list);
105         
106     }
107     
108     public void updateSurveyAnswerVO(SurveyAnswerVO sa) throws Exception JavaDoc{
109         
110         try{
111             this.sqlMap().startTransaction();
112             this.sqlMap().update("updateSurveyAnswer",sa);
113             this.sqlMap().commitTransaction();
114         }finally{
115             this.sqlMap().endTransaction();
116         }
117         
118     }
119     
120     public void updateSurveyVO(SurveyVO su) throws Exception JavaDoc{
121         
122         try{
123             this.sqlMap().startTransaction();
124             this.sqlMap().update("updateSurvey",su);
125             this.sqlMap().commitTransaction();
126         }finally{
127             this.sqlMap().endTransaction();
128         }
129         
130     }
131     
132     public void delSurveyBySID(int sid) throws Exception JavaDoc{
133         
134         try{
135             this.sqlMap().startTransaction();
136             this.sqlMap().delete("delSurveyBySID",new Integer JavaDoc(sid));
137             this.sqlMap().commitTransaction();
138         }finally{
139             this.sqlMap().endTransaction();
140         }
141         
142     }
143     
144     public void delSurveyAnswersByESID(int esid) throws Exception JavaDoc{
145         
146         try{
147             this.sqlMap().startTransaction();
148             this.sqlMap().delete("delSurveyAnswersByESID",new Integer JavaDoc(esid));
149             this.sqlMap().commitTransaction();
150         }finally{
151             this.sqlMap().endTransaction();
152         }
153         
154     }
155     
156     public void delSurveyAnswerByAID(int aid) throws Exception JavaDoc{
157         
158         try{
159             this.sqlMap().startTransaction();
160             this.sqlMap().delete("delSurveyAnswerByAID",new Integer JavaDoc(aid));
161             this.sqlMap().commitTransaction();
162         }finally{
163             this.sqlMap().endTransaction();
164         }
165         
166     }
167     
168     public SurveyVO getSurveyBySID(int sid) throws Exception JavaDoc{
169         SurveyVO res=null;
170         try{
171             this.sqlMap().startTransaction();
172             res=(SurveyVO)this.sqlMap().queryForObject("getSurveyBySID",new Integer JavaDoc(sid));
173             this.sqlMap().commitTransaction();
174         }finally{
175             this.sqlMap().endTransaction();
176         }
177         return res;
178     }
179     
180     public boolean checkVote(int sid, int uid) throws Exception JavaDoc {
181         SurveyVoteVO vo=null;
182         boolean res=false;
183         try{
184             this.sqlMap().startTransaction();
185             HashMap JavaDoc hm=new HashMap JavaDoc();
186             hm.put("sid",new Integer JavaDoc(sid));
187             hm.put("uid",new Integer JavaDoc(uid));
188             
189             vo=(SurveyVoteVO)this.sqlMap().queryForObject("getVoteByUID",hm);
190             res=vo==null;
191             this.sqlMap().commitTransaction();
192         }finally{
193             this.sqlMap().endTransaction();
194         }
195         return res;
196     }
197
198
199     
200     public boolean checkVote(int sid, String JavaDoc ip) throws Exception JavaDoc {
201         SurveyVoteVO vo=null;
202         boolean res=false;
203         try{
204             this.sqlMap().startTransaction();
205             HashMap JavaDoc hm=new HashMap JavaDoc();
206             hm.put("sid",new Integer JavaDoc(sid));
207             hm.put("ip",ip);
208             
209             vo=(SurveyVoteVO)this.sqlMap().queryForObject("getVoteByIP",hm);
210             res=vo==null;
211             this.sqlMap().commitTransaction();
212         }finally{
213             this.sqlMap().endTransaction();
214         }
215         return res;
216     }
217     
218     public void insertVote(SurveyVoteVO vo) throws Exception JavaDoc{
219         try{
220             this.sqlMap().startTransaction();
221             this.sqlMap().insert("insertVote",vo);
222             this.sqlMap().commitTransaction();
223         }catch(Exception JavaDoc e){
224             e.printStackTrace();
225         }finally{
226             this.sqlMap().endTransaction();
227         }
228     }
229     
230 }
231
Popular Tags