1 41 package net.jforum.dao.generic; 42 43 import java.sql.PreparedStatement ; 44 import java.sql.ResultSet ; 45 import java.sql.Timestamp ; 46 import java.text.SimpleDateFormat ; 47 import java.util.ArrayList ; 48 import java.util.Date ; 49 import java.util.List ; 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 62 public class GenericSummaryDAO extends AutoKeys implements SummaryDAO 63 { 64 67 public List selectLastPosts(Date firstDate, Date lastDate) throws Exception 68 { 69 String query = SystemGlobals.getSql("SummaryDAO.selectPosts"); 70 PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(query); 71 p.setTimestamp(1, new Timestamp (firstDate.getTime())); 72 p.setTimestamp(2, new Timestamp (lastDate.getTime())); 73 74 List posts = new ArrayList (); 75 ResultSet 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 rs) throws Exception 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 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 df = new SimpleDateFormat (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 listRecipients() throws Exception 110 { 111 String query = SystemGlobals.getSql("SummaryDAO.selectAllRecipients"); 112 PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(query); 113 114 List recipients = new ArrayList (); 115 ResultSet rs = p.executeQuery(); 116 117 String 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 |