KickJava   Java API By Example, From Geeks To Geeks.

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


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

23 package com.geinuke.dao;
24
25 import java.util.ArrayList JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.Hashtable JavaDoc;
28 import java.util.List JavaDoc;
29
30 import com.geinuke.vo.CategoryVO;
31 import com.geinuke.vo.NewsVO;
32 import com.geinuke.vo.TopicVO;
33
34
35 public class NewsDAO extends GeiDAO{
36
37     
38     public NewsDAO() throws Exception JavaDoc {
39         super();
40         
41     }
42     
43     public void insertNews(NewsVO n) throws Exception JavaDoc{
44         
45         try{
46             this.sqlMap().startTransaction();
47             this.sqlMap().insert("insNews",n);
48             this.sqlMap().commitTransaction();
49             
50         }finally{
51             this.sqlMap().endTransaction();
52         }
53         if(n.getCategories().size()>0){
54             this.insertNewsCategories(n);
55         }
56         if(n.getTopics().size()>0){
57             this.insertNewsTopics(n);
58         }
59         
60     }
61     
62     public void updateNews(NewsVO n) throws Exception JavaDoc{
63         
64         try{
65             this.sqlMap().startTransaction();
66             this.sqlMap().update("updateNews",n);
67             this.sqlMap().commitTransaction();
68         }finally{
69             this.sqlMap().endTransaction();
70         }
71         
72     }
73     
74     public void deleteNews(int nid) throws Exception JavaDoc{
75         
76         try{
77             this.sqlMap().startTransaction();
78             this.sqlMap().delete("deleteNews",new Integer JavaDoc(nid));
79             this.sqlMap().commitTransaction();
80         }finally{
81             this.sqlMap().endTransaction();
82         }
83         
84     }
85     
86     public List JavaDoc getAllNews()throws Exception JavaDoc{
87         List JavaDoc list=null;
88         try{
89             this.sqlMap().startTransaction();
90             list=this.sqlMap().queryForList("getAllNews","");
91             this.sqlMap().commitTransaction();
92         }finally{
93             this.sqlMap().endTransaction();
94         }
95         return list;
96         
97     }
98     
99     public NewsVO getNewsByNId(int nid)throws Exception JavaDoc{
100         NewsVO n=null;
101         try{
102             this.sqlMap().startTransaction();
103             n=(NewsVO)this.sqlMap().queryForObject("getNewsByNId",new Integer JavaDoc(nid));
104             this.sqlMap().commitTransaction();
105         }finally{
106             this.sqlMap().endTransaction();
107         }
108         return n;
109         
110     }
111     
112     
113     
114     public List JavaDoc getEnabledNews()throws Exception JavaDoc{
115         List JavaDoc list=null;
116         try{
117             this.sqlMap().startTransaction();
118             list=this.sqlMap().queryForList("getEnabledNews","");
119             this.sqlMap().commitTransaction();
120         }finally{
121             this.sqlMap().endTransaction();
122         }
123         return list;
124         
125     }
126     
127     public List JavaDoc getNewsByTopic(int tid)throws Exception JavaDoc{
128         List JavaDoc list=null;
129         try{
130             this.sqlMap().startTransaction();
131             list=this.sqlMap().queryForList("getNewsByTopic",new Integer JavaDoc(tid));
132             this.sqlMap().commitTransaction();
133         }finally{
134             this.sqlMap().endTransaction();
135         }
136         return list;
137         
138     }
139     
140     public List JavaDoc getNewsByTitleOrText(String JavaDoc text)throws Exception JavaDoc{
141         List JavaDoc list=null;
142         text="%"+text+"%";
143         try{
144             this.sqlMap().startTransaction();
145             list=this.sqlMap().queryForList("getNewsByTitleOrText",text);
146             this.sqlMap().commitTransaction();
147         }finally{
148             this.sqlMap().endTransaction();
149         }
150         //System.out.println(" text="+text+".");
151
//System.out.println(" getNewsByTitleOrText="+list.size());
152
return list;
153         
154     }
155     
156     public List JavaDoc getEnabledNewsByPeriod(Long JavaDoc[] bounds)throws Exception JavaDoc{
157         List JavaDoc list=null;
158         HashMap JavaDoc bo=null;
159         try{
160             bo=new HashMap JavaDoc();
161             bo.put("lowBound",bounds[0]);
162             bo.put("upBound",bounds[1]);
163             this.sqlMap().startTransaction();
164             list=this.sqlMap().queryForList("getEnabledNewsByPeriod",bo);
165             this.sqlMap().commitTransaction();
166         }finally{
167             this.sqlMap().endTransaction();
168         }
169         return list;
170         
171     }
172     
173     public List JavaDoc getDisabledNews()throws Exception JavaDoc{
174         List JavaDoc list=null;
175         try{
176             this.sqlMap().startTransaction();
177             list=this.sqlMap().queryForList("getDisabledNews","");
178             this.sqlMap().commitTransaction();
179         }finally{
180             this.sqlMap().endTransaction();
181         }
182         return list;
183         
184     }
185     
186     public void updateNewsCategories(NewsVO n) throws Exception JavaDoc{
187         
188         try{
189             ArrayList JavaDoc categories=n.getCategories();
190             CategoryVO c=null;
191             Hashtable JavaDoc h=new Hashtable JavaDoc();
192             this.sqlMap().startTransaction();
193             for(int i=0;i<categories.size();i++){
194                 c=(CategoryVO)categories.get(i);
195                 h.put("catId", new Integer JavaDoc( c.getCatId() ) );
196                 h.put("nId",new Integer JavaDoc( n.getNId() ));
197                 
198                 this.sqlMap().update("updateNewsCat",h);
199             }
200             this.sqlMap().commitTransaction();
201         }finally{
202             this.sqlMap().endTransaction();
203         }
204         
205     }
206     
207     public void insertNewsCategories(NewsVO n) throws Exception JavaDoc{
208         
209         try{
210             ArrayList JavaDoc categories=n.getCategories();
211             CategoryVO c=null;
212             Hashtable JavaDoc h=new Hashtable JavaDoc();
213             this.sqlMap().startTransaction();
214             for(int i=0;i<categories.size();i++){
215                 c=(CategoryVO)categories.get(i);
216                 h.put("catId", new Integer JavaDoc( c.getCatId() ) );
217                 h.put("nId",new Integer JavaDoc( n.getNId() ));
218                 
219                 this.sqlMap().insert("insNewsCat",h);
220             }
221             this.sqlMap().commitTransaction();
222         }finally{
223             this.sqlMap().endTransaction();
224         }
225         
226     }
227     
228     public void insertNewsTopics(NewsVO n) throws Exception JavaDoc{
229         
230         try{
231             ArrayList JavaDoc topics=n.getTopics();
232             TopicVO t=null;
233             Hashtable JavaDoc h=new Hashtable JavaDoc();
234             this.sqlMap().startTransaction();
235             for(int i=0;i<topics.size();i++){
236                 t=(TopicVO)topics.get(i);
237                 h.put("tId", new Integer JavaDoc( t.getTId() ) );
238                 h.put("nId",new Integer JavaDoc( n.getNId() ));
239                 this.sqlMap().insert("insNewsTop",h);
240             }
241             this.sqlMap().commitTransaction();
242         }finally{
243             this.sqlMap().endTransaction();
244         }
245         
246     }
247     
248     public void updateNewsTopics(NewsVO n) throws Exception JavaDoc{
249         
250         try{
251             ArrayList JavaDoc topics=n.getTopics();
252             TopicVO t=null;
253             Hashtable JavaDoc h=new Hashtable JavaDoc();
254             this.sqlMap().startTransaction();
255             for(int i=0;i<topics.size();i++){
256                 t=(TopicVO)topics.get(i);
257                 h.put("tId", new Integer JavaDoc( t.getTId() ) );
258                 h.put("nId",new Integer JavaDoc( n.getNId() ));
259                 this.sqlMap().update("updateNewsTop",h);
260             }
261             this.sqlMap().commitTransaction();
262         }finally{
263             this.sqlMap().endTransaction();
264         }
265         
266     }
267     
268     
269     
270     
271     
272
273 }
274
Popular Tags