GenericSummaryDAO.java
Upload User: gdxydsw
Upload Date: 2019-01-29
Package Size: 16721k
Code Size: 4k
Category:

Java Develop

Development Platform:

Java

  1. /* Copyright (c) JForum Team
  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. import java.sql.PreparedStatement;
  43. import java.sql.ResultSet;
  44. import java.sql.SQLException;
  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. import net.jforum.JForumExecutionContext;
  51. import net.jforum.dao.DataAccessDriver;
  52. import net.jforum.dao.SummaryDAO;
  53. import net.jforum.entities.Post;
  54. import net.jforum.exceptions.DatabaseException;
  55. import net.jforum.util.DbUtils;
  56. import net.jforum.util.preferences.ConfigKeys;
  57. import net.jforum.util.preferences.SystemGlobals;
  58. /**
  59.  * @author Franklin Samir (franklin (at) portaljava [dot] com)
  60.  * @version $Id: GenericSummaryDAO.java,v 1.11 2006/08/23 02:13:41 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 selectLastPosts(Date firstDate, Date lastDate)
  68. {
  69. String query = SystemGlobals.getSql("SummaryDAO.selectPosts");
  70. PreparedStatement p = null;
  71. ResultSet rs = null;
  72. try {
  73. p = JForumExecutionContext.getConnection().prepareStatement(query);
  74. p.setTimestamp(1, new Timestamp(firstDate.getTime()));
  75. p.setTimestamp(2, new Timestamp(lastDate.getTime()));
  76. List posts = new ArrayList();
  77. rs = p.executeQuery();
  78. while (rs.next()) {
  79. posts.add(this.fillPost(rs));
  80. }
  81. return posts;
  82. }
  83. catch (SQLException e) {
  84. throw new DatabaseException(e);
  85. }
  86. finally {
  87. DbUtils.close(rs, p);
  88. }
  89. }
  90. private Post fillPost(ResultSet rs) throws SQLException
  91. {
  92. Post post = new Post();
  93. post.setId(rs.getInt("post_id"));
  94. post.setTopicId(rs.getInt("topic_id"));
  95. post.setForumId(rs.getInt("forum_id"));
  96. post.setUserId(rs.getInt("user_id"));
  97. Timestamp postTime = rs.getTimestamp("post_time");
  98. post.setTime(postTime);
  99. post.setSubject(rs.getString("post_subject"));
  100. post.setText(rs.getString("post_text"));
  101. post.setPostUsername(rs.getString("username"));
  102. SimpleDateFormat df = new SimpleDateFormat(SystemGlobals.getValue(ConfigKeys.DATE_TIME_FORMAT));
  103. post.setFormatedTime(df.format(postTime));
  104. post.setKarma(DataAccessDriver.getInstance().newKarmaDAO().getPostKarma(post.getId()));
  105. return post;
  106. }
  107. public List listRecipients()
  108. {
  109. String query = SystemGlobals.getSql("SummaryDAO.selectAllRecipients");
  110. PreparedStatement p = null;
  111. ResultSet rs = null;
  112. try {
  113. p = JForumExecutionContext.getConnection().prepareStatement(query);
  114. List recipients = new ArrayList();
  115. rs = p.executeQuery();
  116. String mail = null;
  117. while (rs.next()) {
  118. mail = rs.getString("user_email");
  119. if (mail != null && !mail.trim().equals("")) {
  120. recipients.add(mail);
  121. }
  122. }
  123. return recipients;
  124. }
  125. catch (SQLException e) {
  126. throw new DatabaseException(e);
  127. }
  128. finally {
  129. DbUtils.close(rs, p);
  130. }
  131. }
  132. }