SqlServerTopicDAO.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 24/05/2004 12:25:35
  40.  * The JForum Project
  41.  * http://www.jforum.net
  42.  */
  43. package net.jforum.dao.sqlserver;
  44. import java.sql.PreparedStatement;
  45. import java.sql.SQLException;
  46. import java.util.List;
  47. import net.jforum.JForumExecutionContext;
  48. import net.jforum.exceptions.DatabaseException;
  49. import net.jforum.util.DbUtils;
  50. import net.jforum.util.preferences.SystemGlobals;
  51. import net.jforum.repository.ForumRepository;
  52. import org.apache.log4j.Logger;
  53. /**
  54.  * @author Andre de Andrade da Silva - andre.de.andrade@gmail.com
  55.  * @author Dirk Rasmussen - d.rasmussen@bevis.de (2007/02/19, modifs for MS SqlServer 2005)
  56.  * @see WEB-INFconfigdatabasesqlserversqlserver.sql (2007/02/19, MS SqlServer 2005 specific version!)
  57.  * @version $Id: SqlServerTopicDAO.java,v 1.14 2007/08/01 22:09:02 rafaelsteil Exp $
  58.  */
  59. public class SqlServerTopicDAO extends net.jforum.dao.generic.GenericTopicDAO
  60. {
  61. private static final Logger logger = Logger.getLogger(SqlServerTopicDAO.class);
  62. /**
  63.  * @see net.jforum.dao.TopicDAO#selectAllByForumByLimit(int, int, int)
  64.  */
  65. public List selectAllByForumByLimit(int forumId, int startFrom, int count)
  66. {
  67. PreparedStatement p = null;
  68. String sqlStmnt = SystemGlobals.getSql("TopicModel.selectAllByForumByLimit");
  69. if (logger.isDebugEnabled())
  70. {
  71. logger.debug("selectAllByForumByLimit("+forumId+","+startFrom+","+count+")..., sqlStmnt="+sqlStmnt);
  72. }
  73. try {
  74. p = JForumExecutionContext.getConnection().prepareStatement(sqlStmnt);
  75. p.setInt(1, forumId);
  76. p.setInt(2, forumId);
  77. p.setInt(3, startFrom);
  78. p.setInt(4, startFrom+count);
  79. List list = super.fillTopicsData(p);
  80. p = null;
  81. return list;
  82. }
  83. catch (SQLException e) {
  84. logger.error(sqlStmnt, e);
  85. throw new DatabaseException(e);
  86. }
  87. finally {
  88. DbUtils.close(p);
  89. }
  90. }
  91. /**
  92.  * @see net.jforum.dao.TopicDAO#selectRecentTopics(int)
  93.  */
  94. public List selectRecentTopics(int limit)
  95. {
  96. PreparedStatement p = null;
  97. String sqlStmnt = SystemGlobals.getSql("TopicModel.selectRecentTopicsByLimit");
  98. if (logger.isDebugEnabled())
  99. {
  100. logger.debug("selectRecentTopics("+limit+")..., sqlStmnt="+sqlStmnt);
  101. }
  102. try {
  103. p = JForumExecutionContext.getConnection().prepareStatement(sqlStmnt);
  104. p.setInt(1, limit );
  105. List list = this.fillTopicsData(p);
  106. p = null;
  107. return list;
  108. }
  109. catch (SQLException e) {
  110. logger.error(sqlStmnt, e);
  111. throw new DatabaseException(e);
  112. }
  113. finally {
  114. DbUtils.close(p);
  115. }
  116. }
  117. /**
  118.  * @see net.jforum.dao.TopicDAO#selectByUserByLimit(int, int, int)
  119.  */
  120. public List selectByUserByLimit(int userId, int startFrom, int count)
  121. {
  122. PreparedStatement p = null;
  123. String sqlStmnt = SystemGlobals.getSql("TopicModel.selectByUserByLimit");
  124. sqlStmnt = sqlStmnt.replaceAll(":fids:", ForumRepository.getListAllowedForums());
  125. if (logger.isDebugEnabled())
  126. {
  127. logger.debug("selectByUserByLimit("+userId+","+startFrom+","+count+")..., sqlStmnt="+sqlStmnt);
  128. }
  129. try {
  130. p = JForumExecutionContext.getConnection().prepareStatement(sqlStmnt);
  131. p.setInt(1, userId);
  132. p.setInt(2, startFrom);
  133. p.setInt(3, count);
  134. List list = this.fillTopicsData(p);
  135. p = null;
  136. return list;
  137. }
  138. catch (SQLException e) {
  139. throw new DatabaseException(e);
  140. }
  141. finally {
  142. DbUtils.close(p);
  143. }
  144. }
  145. }