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 22:36:07
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.ResultSet;
047: import java.sql.SQLException;
048: import java.util.List;
049:
050: import net.jforum.JForumExecutionContext;
051: import net.jforum.exceptions.DatabaseException;
052: import net.jforum.util.DbUtils;
053: import net.jforum.util.preferences.SystemGlobals;
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: SqlServerUserDAO.java,v 1.11 2007/03/03 18:33:45 rafaelsteil Exp $
062: */
063: public class SqlServerUserDAO extends
064: net.jforum.dao.generic.GenericUserDAO {
065: private static final Logger logger = Logger
066: .getLogger(SqlServerUserDAO.class);
067:
068: /**
069: * @see net.jforum.dao.UserDAO#selectAll(int, int)
070: */
071: public List selectAll(int startFrom, int count) {
072: PreparedStatement p = null;
073: ResultSet rs = null;
074: String sqlStmnt = null;
075:
076: try {
077: if (count > 0) {
078: sqlStmnt = SystemGlobals
079: .getSql("UserModel.selectAllByLimit");
080: if (logger.isDebugEnabled()) {
081: logger.debug("selectAll(" + startFrom + "," + count
082: + ")..., sqlStmnt=" + sqlStmnt);
083: }
084: p = JForumExecutionContext.getConnection()
085: .prepareStatement(sqlStmnt);
086: p.setInt(1, startFrom);
087: p.setInt(2, startFrom + count);
088: } else {
089: sqlStmnt = SystemGlobals.getSql("UserModel.selectAll");
090: if (logger.isDebugEnabled()) {
091: logger.debug("selectAll(" + startFrom + "," + count
092: + ")..., sqlStmnt=" + sqlStmnt);
093: }
094: p = JForumExecutionContext.getConnection()
095: .prepareStatement(sqlStmnt);
096: }
097:
098: rs = p.executeQuery();
099:
100: return super .processSelectAll(rs);
101: } catch (SQLException e) {
102: logger.error(sqlStmnt, e);
103: throw new DatabaseException(e);
104: } finally {
105: DbUtils.close(rs, p);
106: }
107: }
108:
109: /**
110: * @see net.jforum.dao.UserDAO#selectAllByGroup(int, int, int)
111: */
112: public List selectAllByGroup(int groupId, int startFrom, int count) {
113: PreparedStatement p = null;
114: ResultSet rs = null;
115: String sqlStmnt = SystemGlobals
116: .getSql("UserModel.selectAllByGroup");
117: if (logger.isDebugEnabled()) {
118: logger.debug("selectAllByGroup(" + groupId + ","
119: + startFrom + "," + count + ")..., sqlStmnt="
120: + sqlStmnt);
121: }
122:
123: try {
124: p = JForumExecutionContext.getConnection()
125: .prepareStatement(sqlStmnt);
126: p.setInt(1, groupId);
127: p.setInt(2, startFrom);
128: p.setInt(3, count);
129:
130: rs = p.executeQuery();
131:
132: return this .processSelectAll(rs);
133: } catch (SQLException e) {
134: throw new DatabaseException(e);
135: } finally {
136: DbUtils.close(rs, p);
137: }
138: }
139:
140: /**
141: * @see net.jforum.dao.UserDAO#selectAllWithKarma(int, int)
142: */
143: public List selectAllWithKarma(int startFrom, int count) {
144: return super.loadKarma(this.selectAll(startFrom, count));
145: }
146: }
|