KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > jforum > dao > generic > GenericSummaryDAO


1 /* Copyright (c) Rafael Steil
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms,
5  * with or without modification, are permitted provided
6  * that the following conditions are met:
7  *
8  * 1) Redistributions of source code must retain the above
9  * copyright notice, this list of conditions and the
10  * following disclaimer.
11  * 2) Redistributions in binary form must reproduce the
12  * above copyright notice, this list of conditions and
13  * the following disclaimer in the documentation and/or
14  * other materials provided with the distribution.
15  * 3) Neither the name of "Rafael Steil" nor
16  * the names of its contributors may be used to endorse
17  * or promote products derived from this software without
18  * specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
21  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
22  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
23  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
26  * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
31  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
33  * IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
37  *
38  * The JForum Project
39  * http://www.jforum.net
40  */

41 package net.jforum.dao.generic;
42
43 import java.sql.PreparedStatement JavaDoc;
44 import java.sql.ResultSet JavaDoc;
45 import java.sql.Timestamp JavaDoc;
46 import java.text.SimpleDateFormat JavaDoc;
47 import java.util.ArrayList JavaDoc;
48 import java.util.Date JavaDoc;
49 import java.util.List JavaDoc;
50
51 import net.jforum.JForumExecutionContext;
52 import net.jforum.dao.DataAccessDriver;
53 import net.jforum.dao.SummaryDAO;
54 import net.jforum.entities.Post;
55 import net.jforum.util.preferences.ConfigKeys;
56 import net.jforum.util.preferences.SystemGlobals;
57
58 /**
59  * @author Franklin Samir (franklin (at) portaljava [dot] com)
60  * @version $Id: GenericSummaryDAO.java,v 1.8 2006/01/29 15:06:21 rafaelsteil Exp $
61  */

62 public class GenericSummaryDAO extends AutoKeys implements SummaryDAO
63 {
64     /**
65      * @see net.jforum.dao.SummaryDAO#selectById(Date, Date)
66      */

67     public List JavaDoc selectLastPosts(Date JavaDoc firstDate, Date JavaDoc lastDate) throws Exception JavaDoc
68     {
69         String JavaDoc query = SystemGlobals.getSql("SummaryDAO.selectPosts");
70         PreparedStatement JavaDoc p = JForumExecutionContext.getConnection().prepareStatement(query);
71         p.setTimestamp(1, new Timestamp JavaDoc(firstDate.getTime()));
72         p.setTimestamp(2, new Timestamp JavaDoc(lastDate.getTime()));
73
74         List JavaDoc posts = new ArrayList JavaDoc();
75         ResultSet JavaDoc rs = p.executeQuery();
76
77         while (rs.next()) {
78             posts.add(this.fillPost(rs));
79         }
80         
81         rs.close();
82         p.close();
83
84         return posts;
85     }
86
87     private Post fillPost(ResultSet JavaDoc rs) throws Exception JavaDoc
88     {
89         Post post = new Post();
90         
91         post.setId(rs.getInt("post_id"));
92         post.setTopicId(rs.getInt("topic_id"));
93         post.setForumId(rs.getInt("forum_id"));
94         post.setUserId(rs.getInt("user_id"));
95         Timestamp JavaDoc postTime = rs.getTimestamp("post_time");
96         post.setTime(postTime);
97         post.setSubject(rs.getString("post_subject"));
98         post.setText(rs.getString("post_text"));
99         post.setPostUsername(rs.getString("username"));
100
101         SimpleDateFormat JavaDoc df = new SimpleDateFormat JavaDoc(SystemGlobals.getValue(ConfigKeys.DATE_TIME_FORMAT));
102         post.setFormatedTime(df.format(postTime));
103
104         post.setKarma(DataAccessDriver.getInstance().newKarmaDAO().getPostKarma(post.getId()));
105
106         return post;
107     }
108
109     public List JavaDoc listRecipients() throws Exception JavaDoc
110     {
111         String JavaDoc query = SystemGlobals.getSql("SummaryDAO.selectAllRecipients");
112         PreparedStatement JavaDoc p = JForumExecutionContext.getConnection().prepareStatement(query);
113
114         List JavaDoc recipients = new ArrayList JavaDoc();
115         ResultSet JavaDoc rs = p.executeQuery();
116
117         String JavaDoc mail = null;
118         while (rs.next()) {
119             
120             mail = rs.getString("user_email");
121             if(mail != null && !mail.trim().equals("") )
122                 recipients.add(mail);
123         }
124
125         rs.close();
126         p.close();
127
128         return recipients;
129     }
130 }
131
Popular Tags