001: /*
002: * Copyright (c) JForum Team
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms,
006: * with or without modification, are permitted provided
007: * that the following conditions are met:
008: *
009: * 1) Redistributions of source code must retain the above
010: * copyright notice, this list of conditions and the
011: * following disclaimer.
012: * 2) Redistributions in binary form must reproduce the
013: * above copyright notice, this list of conditions and
014: * the following disclaimer in the documentation and/or
015: * other materials provided with the distribution.
016: * 3) Neither the name of "Rafael Steil" nor
017: * the names of its contributors may be used to endorse
018: * or promote products derived from this software without
019: * specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
022: * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
023: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
024: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
025: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
026: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
028: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
029: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
031: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
032: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
033: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
034: * IN CONTRACT, STRICT LIABILITY, OR TORT
035: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
036: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
037: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
038: *
039: * Created on 24/05/2004 12:25:35
040: * The JForum Project
041: * http://www.jforum.net
042: */
043: package net.jforum.dao.sqlserver;
044:
045: import java.sql.PreparedStatement;
046: import java.sql.SQLException;
047: import java.util.List;
048:
049: import net.jforum.JForumExecutionContext;
050: import net.jforum.exceptions.DatabaseException;
051: import net.jforum.util.DbUtils;
052: import net.jforum.util.preferences.SystemGlobals;
053: import net.jforum.repository.ForumRepository;
054:
055: import org.apache.log4j.Logger;
056:
057: /**
058: * @author Andre de Andrade da Silva - andre.de.andrade@gmail.com
059: * @author Dirk Rasmussen - d.rasmussen@bevis.de (2007/02/19, modifs for MS SqlServer 2005)
060: * @see WEB-INF\config\database\sqlserver\sqlserver.sql (2007/02/19, MS SqlServer 2005 specific version!)
061: * @version $Id: SqlServerTopicDAO.java,v 1.14 2007/08/01 22:09:02 rafaelsteil Exp $
062: */
063: public class SqlServerTopicDAO extends
064: net.jforum.dao.generic.GenericTopicDAO {
065: private static final Logger logger = Logger
066: .getLogger(SqlServerTopicDAO.class);
067:
068: /**
069: * @see net.jforum.dao.TopicDAO#selectAllByForumByLimit(int, int, int)
070: */
071: public List selectAllByForumByLimit(int forumId, int startFrom,
072: int count) {
073: PreparedStatement p = null;
074: String sqlStmnt = SystemGlobals
075: .getSql("TopicModel.selectAllByForumByLimit");
076: if (logger.isDebugEnabled()) {
077: logger.debug("selectAllByForumByLimit(" + forumId + ","
078: + startFrom + "," + count + ")..., sqlStmnt="
079: + sqlStmnt);
080: }
081:
082: try {
083: p = JForumExecutionContext.getConnection()
084: .prepareStatement(sqlStmnt);
085:
086: p.setInt(1, forumId);
087: p.setInt(2, forumId);
088: p.setInt(3, startFrom);
089: p.setInt(4, startFrom + count);
090:
091: List list = super .fillTopicsData(p);
092: p = null;
093: return list;
094: } catch (SQLException e) {
095: logger.error(sqlStmnt, e);
096: throw new DatabaseException(e);
097: } finally {
098: DbUtils.close(p);
099: }
100: }
101:
102: /**
103: * @see net.jforum.dao.TopicDAO#selectRecentTopics(int)
104: */
105: public List selectRecentTopics(int limit) {
106: PreparedStatement p = null;
107: String sqlStmnt = SystemGlobals
108: .getSql("TopicModel.selectRecentTopicsByLimit");
109: if (logger.isDebugEnabled()) {
110: logger.debug("selectRecentTopics(" + limit
111: + ")..., sqlStmnt=" + sqlStmnt);
112: }
113:
114: try {
115: p = JForumExecutionContext.getConnection()
116: .prepareStatement(sqlStmnt);
117:
118: p.setInt(1, limit);
119:
120: List list = this .fillTopicsData(p);
121: p = null;
122: return list;
123: } catch (SQLException e) {
124: logger.error(sqlStmnt, e);
125: throw new DatabaseException(e);
126: } finally {
127: DbUtils.close(p);
128: }
129: }
130:
131: /**
132: * @see net.jforum.dao.TopicDAO#selectByUserByLimit(int, int, int)
133: */
134: public List selectByUserByLimit(int userId, int startFrom, int count) {
135: PreparedStatement p = null;
136: String sqlStmnt = SystemGlobals
137: .getSql("TopicModel.selectByUserByLimit");
138: sqlStmnt = sqlStmnt.replaceAll(":fids:", ForumRepository
139: .getListAllowedForums());
140: if (logger.isDebugEnabled()) {
141: logger.debug("selectByUserByLimit(" + userId + ","
142: + startFrom + "," + count + ")..., sqlStmnt="
143: + sqlStmnt);
144: }
145:
146: try {
147: p = JForumExecutionContext.getConnection()
148: .prepareStatement(sqlStmnt);
149:
150: p.setInt(1, userId);
151: p.setInt(2, startFrom);
152: p.setInt(3, count);
153:
154: List list = this .fillTopicsData(p);
155: p = null;
156: return list;
157: } catch (SQLException e) {
158: throw new DatabaseException(e);
159: } finally {
160: DbUtils.close(p);
161: }
162: }
163:
164: }
|