GenericBanlistDAO.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.  * 
  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 07/12/2006 21:01:17
  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.util.ArrayList;
  47. import java.util.List;
  48. import net.jforum.JForumExecutionContext;
  49. import net.jforum.dao.BanlistDAO;
  50. import net.jforum.entities.Banlist;
  51. import net.jforum.exceptions.DatabaseException;
  52. import net.jforum.util.DbUtils;
  53. import net.jforum.util.preferences.SystemGlobals;
  54. /**
  55.  * @author Rafael Steil
  56.  * @version $Id: GenericBanlistDAO.java,v 1.2 2007/03/24 23:26:50 rafaelsteil Exp $
  57.  */
  58. public class GenericBanlistDAO extends AutoKeys implements BanlistDAO
  59. {
  60. /**
  61.  * @see net.jforum.dao.BanlistDAO#delete(int)
  62.  */
  63. public void delete(int banlistId)
  64. {
  65. PreparedStatement p = null;
  66. try {
  67. p = JForumExecutionContext.getConnection().prepareStatement(
  68. SystemGlobals.getSql("BanlistModel.delete"));
  69. p.setInt(1, banlistId);
  70. p.executeUpdate();
  71. }
  72. catch (Exception e) {
  73. throw new DatabaseException(e);
  74. }
  75. finally {
  76. DbUtils.close(p);
  77. }
  78. }
  79. /**
  80.  * @see net.jforum.dao.BanlistDAO#insert(net.jforum.entities.Banlist)
  81.  */
  82. public void insert(Banlist b)
  83. {
  84. PreparedStatement p = null;
  85. try {
  86. p = JForumExecutionContext.getConnection().prepareStatement(
  87. SystemGlobals.getSql("BanlistModel.insert"));
  88. p.setInt(1, b.getUserId());
  89. p.setString(2, b.getIp());
  90. p.setString(3, b.getEmail());
  91. this.setAutoGeneratedKeysQuery(SystemGlobals.getSql("BanlistModel.lastGeneratedBanlistId"));
  92. int id = this.executeAutoKeysQuery(p);
  93. b.setId(id);
  94. }
  95. catch (Exception e) {
  96. throw new DatabaseException(e);
  97. }
  98. finally {
  99. DbUtils.close(p);
  100. }
  101. }
  102. /**
  103.  * @see net.jforum.dao.BanlistDAO#selectAll()
  104.  */
  105. public List selectAll()
  106. {
  107. ResultSet rs = null;
  108. PreparedStatement p = null;
  109. List l = new ArrayList();
  110. try {
  111. p = JForumExecutionContext.getConnection().prepareStatement(
  112. SystemGlobals.getSql("BanlistModel.selectAll"));
  113. rs = p.executeQuery();
  114. while (rs.next()) {
  115. Banlist b = new Banlist();
  116. b.setId(rs.getInt("banlist_id"));
  117. b.setUserId(rs.getInt("user_id"));
  118. b.setEmail(rs.getString("banlist_email"));
  119. b.setIp(rs.getString("banlist_ip"));
  120. l.add(b);
  121. }
  122. }
  123. catch (Exception e) {
  124. throw new DatabaseException(e);
  125. }
  126. finally {
  127. DbUtils.close(rs, p);
  128. }
  129. return l;
  130. }
  131. }