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

Java Develop

Development Platform:

Java

  1. /*
  2.  * Copyright (c) JForum Team
  3.  * All rights reserved.
  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.  * 1) Redistributions of source code must retain the above 
  8.  * copyright notice, this list of conditions and the 
  9.  * following  disclaimer.
  10.  * 2)  Redistributions in binary form must reproduce the 
  11.  * above copyright notice, this list of conditions and 
  12.  * the following disclaimer in the documentation and/or 
  13.  * other materials provided with the distribution.
  14.  * 3) Neither the name of "Rafael Steil" nor 
  15.  * the names of its contributors may be used to endorse 
  16.  * or promote products derived from this software without 
  17.  * specific prior written permission.
  18.  * 
  19.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT 
  20.  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
  21.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
  22.  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
  23.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
  24.  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
  25.  * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 
  26.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
  27.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  28.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
  29.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
  30.  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
  31.  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
  32.  * IN CONTRACT, STRICT LIABILITY, OR TORT 
  33.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
  34.  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
  35.  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  36.  * 
  37.  * Created on 24/05/2004 22:36:07
  38.  * The JForum Project
  39.  * http://www.jforum.net
  40.  */
  41. package net.jforum.dao.sqlserver;
  42. import java.sql.PreparedStatement;
  43. import java.sql.ResultSet;
  44. import java.sql.SQLException;
  45. import java.util.List;
  46. import net.jforum.JForumExecutionContext;
  47. import net.jforum.exceptions.DatabaseException;
  48. import net.jforum.util.DbUtils;
  49. import net.jforum.util.preferences.SystemGlobals;
  50. import org.apache.log4j.Logger;
  51. /**
  52.  * @author Andre de Andrade da Silva - andre.de.andrade@gmail.com
  53.  * @author Dirk Rasmussen - d.rasmussen@bevis.de (2007/02/19, modifs for MS SqlServer 2005)
  54.  * @see WEB-INFconfigdatabasesqlserversqlserver.sql (2007/02/19, MS SqlServer 2005 specific version!)
  55.  * @version $Id: SqlServerUserDAO.java,v 1.11 2007/03/03 18:33:45 rafaelsteil Exp $
  56.  */
  57. public class SqlServerUserDAO extends net.jforum.dao.generic.GenericUserDAO
  58. {
  59. private static final Logger logger = Logger.getLogger(SqlServerUserDAO.class);
  60. /**
  61.  * @see net.jforum.dao.UserDAO#selectAll(int, int)
  62.  */
  63. public List selectAll(int startFrom, int count)
  64. {
  65. PreparedStatement p = null;
  66. ResultSet rs = null;
  67. String sqlStmnt = null;
  68. try {
  69. if (count > 0) {
  70. sqlStmnt = SystemGlobals.getSql("UserModel.selectAllByLimit");
  71. if (logger.isDebugEnabled())
  72. {
  73. logger.debug("selectAll("+startFrom+","+count+")..., sqlStmnt="+sqlStmnt);
  74. }
  75. p = JForumExecutionContext.getConnection().prepareStatement(sqlStmnt);
  76. p.setInt(1, startFrom);
  77. p.setInt(2, startFrom+count);
  78. }
  79. else {
  80. sqlStmnt = SystemGlobals.getSql("UserModel.selectAll");
  81. if (logger.isDebugEnabled())
  82. {
  83. logger.debug("selectAll("+startFrom+","+count+")..., sqlStmnt="+sqlStmnt);
  84. }
  85. p = JForumExecutionContext.getConnection().prepareStatement(sqlStmnt);
  86. }
  87. rs = p.executeQuery();
  88. return super.processSelectAll(rs);
  89. }
  90. catch (SQLException e) {
  91. logger.error(sqlStmnt, e);
  92. throw new DatabaseException(e);
  93. }
  94. finally {
  95. DbUtils.close(rs, p);
  96. }
  97. }
  98. /**
  99.  * @see net.jforum.dao.UserDAO#selectAllByGroup(int, int, int)
  100.  */
  101. public List selectAllByGroup(int groupId, int startFrom, int count)
  102. {
  103. PreparedStatement p = null;
  104. ResultSet rs = null;
  105. String sqlStmnt = SystemGlobals.getSql("UserModel.selectAllByGroup");
  106. if (logger.isDebugEnabled())
  107. {
  108. logger.debug("selectAllByGroup("+groupId+","+startFrom+","+count+")..., sqlStmnt="+sqlStmnt);
  109. }
  110. try {
  111. p = JForumExecutionContext.getConnection().prepareStatement(sqlStmnt);
  112. p.setInt(1, groupId);
  113. p.setInt(2, startFrom);
  114. p.setInt(3, count);
  115. rs = p.executeQuery();
  116. return this.processSelectAll(rs);
  117. }
  118. catch (SQLException e) {
  119. throw new DatabaseException(e);
  120. }
  121. finally {
  122. DbUtils.close(rs, p);
  123. }
  124. }
  125. /**
  126.  * @see net.jforum.dao.UserDAO#selectAllWithKarma(int, int)
  127.  */
  128. public List selectAllWithKarma(int startFrom, int count)
  129. {
  130. return super.loadKarma(this.selectAll(startFrom, count));
  131. }
  132. }