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

Java Develop

Development Platform:

Java

  1. /*
  2.  * Copyright (c) JForum Team
  3.  * All rights reserved.
  4.  * 
  5.  * Redistribution and use in source and binary forms, 
  6.  * with or without modification, are permitted provided 
  7.  * that the following conditions are met:
  8.  * 
  9.  * 1) Redistributions of source code must retain the above 
  10.  * copyright notice, this list of conditions and the 
  11.  * following  disclaimer.
  12.  * 2)  Redistributions in binary form must reproduce the 
  13.  * above copyright notice, this list of conditions and 
  14.  * the following disclaimer in the documentation and/or 
  15.  * other materials provided with the distribution.
  16.  * 3) Neither the name of "Rafael Steil" nor 
  17.  * the names of its contributors may be used to endorse 
  18.  * or promote products derived from this software without 
  19.  * specific prior written permission.
  20.  * 
  21.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT 
  22.  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
  23.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
  24.  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
  25.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
  26.  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
  27.  * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 
  28.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
  29.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  30.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
  31.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
  32.  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
  33.  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
  34.  * IN CONTRACT, STRICT LIABILITY, OR TORT 
  35.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
  36.  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
  37.  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  38.  * 
  39.  * Created on 08/07/2007 11:29:41
  40.  * The JForum Project
  41.  * http://www.jforum.net
  42.  */
  43. package net.jforum.dao.generic;
  44. import java.sql.PreparedStatement;
  45. import java.sql.ResultSet;
  46. import java.sql.SQLException;
  47. import java.sql.Timestamp;
  48. import java.util.ArrayList;
  49. import java.util.Date;
  50. import java.util.List;
  51. import net.jforum.JForumExecutionContext;
  52. import net.jforum.dao.ModerationLogDAO;
  53. import net.jforum.entities.ModerationLog;
  54. import net.jforum.entities.User;
  55. import net.jforum.exceptions.DatabaseException;
  56. import net.jforum.util.DbUtils;
  57. import net.jforum.util.preferences.SystemGlobals;
  58. public class GenericModerationLogDAO extends AutoKeys implements ModerationLogDAO
  59. {
  60. public void add(ModerationLog log)
  61. {
  62. PreparedStatement p = null;
  63. try {
  64. p = this.getStatementForAutoKeys("ModerationLog.addNew");
  65. p.setInt(1, log.getUser().getId());
  66. p.setString(2, log.getDescription());
  67. p.setString(3, log.getOriginalMessage());
  68. p.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
  69. p.setInt(5, log.getType());
  70. p.setInt(6, log.getPostId());
  71. p.setInt(7, log.getTopicId());
  72. p.setInt(8, log.getPosterUser().getId());
  73. this.setAutoGeneratedKeysQuery(SystemGlobals.getSql("ModerationLog.lastGeneratedModerationLogId"));
  74. int logId = this.executeAutoKeysQuery(p);
  75. log.setId(logId);
  76. }
  77. catch (SQLException e) {
  78. throw new DatabaseException(e);
  79. }
  80. finally {
  81. DbUtils.close(p);
  82. }
  83. }
  84. public List selectAll(int start, int count)
  85. {
  86. List l = new ArrayList();
  87. String sql = SystemGlobals.getSql("ModerationLog.selectAll");
  88. PreparedStatement p = null;
  89. ResultSet rs = null;
  90. try {
  91. p = JForumExecutionContext.getConnection().prepareStatement(sql);
  92. p.setInt(1, start);
  93. p.setInt(2, count);
  94. rs = p.executeQuery();
  95. while (rs.next()) {
  96. l.add(this.makeLog(rs));
  97. }
  98. return l;
  99. }
  100. catch (SQLException e) {
  101. throw new DatabaseException(e);
  102. }
  103. finally {
  104. DbUtils.close(rs, p);
  105. }
  106. }
  107. protected ModerationLog makeLog(ResultSet rs) throws SQLException 
  108. {
  109. ModerationLog log = new ModerationLog();
  110. log.setId(rs.getInt("log_id"));
  111. log.setDescription(this.readDesriptionFromResultSet(rs));
  112. log.setOriginalMessage(this.readOriginalMessageFromResultSet(rs));
  113. log.setType(rs.getInt("log_type"));
  114. log.setDate(new Date(rs.getTimestamp("log_date").getTime()));
  115. log.setPostId(rs.getInt("post_id"));
  116. log.setTopicId(rs.getInt("topic_id"));
  117. User user = new User();
  118. user.setId(rs.getInt("user_id"));
  119. user.setUsername(rs.getString("username"));
  120. log.setUser(user);
  121. User posterUser = new User();
  122. posterUser.setId(rs.getInt("post_user_id"));
  123. posterUser.setUsername(rs.getString("poster_username"));
  124. log.setPosterUser(posterUser);
  125. return log;
  126. }
  127. protected String readDesriptionFromResultSet(ResultSet rs) throws SQLException
  128. {
  129. return rs.getString("log_description");
  130. }
  131. protected String readOriginalMessageFromResultSet(ResultSet rs) throws SQLException
  132. {
  133. return rs.getString("log_original_message");
  134. }
  135. public int totalRecords()
  136. {
  137. int total = 0;
  138. PreparedStatement p = null;
  139. ResultSet rs = null;
  140. try {
  141. p = JForumExecutionContext.getConnection().prepareStatement(
  142. SystemGlobals.getSql("ModerationLog.totalRecords"));
  143. rs = p.executeQuery();
  144. if (rs.next()) {
  145. total = rs.getInt(1);
  146. }
  147. }
  148. catch (SQLException e) {
  149. throw new DatabaseException(e);
  150. }
  151. finally {
  152. DbUtils.close(rs, p);
  153. }
  154. return total;
  155. }
  156. }