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 07/12/2006 21:01:17
040: * The JForum Project
041: * http://www.jforum.net
042: */
043: package net.jforum.dao.generic;
044:
045: import java.sql.PreparedStatement;
046: import java.sql.ResultSet;
047: import java.util.ArrayList;
048: import java.util.List;
049:
050: import net.jforum.JForumExecutionContext;
051: import net.jforum.dao.BanlistDAO;
052: import net.jforum.entities.Banlist;
053: import net.jforum.exceptions.DatabaseException;
054: import net.jforum.util.DbUtils;
055: import net.jforum.util.preferences.SystemGlobals;
056:
057: /**
058: * @author Rafael Steil
059: * @version $Id: GenericBanlistDAO.java,v 1.2 2007/03/24 23:26:50 rafaelsteil Exp $
060: */
061: public class GenericBanlistDAO extends AutoKeys implements BanlistDAO {
062: /**
063: * @see net.jforum.dao.BanlistDAO#delete(int)
064: */
065: public void delete(int banlistId) {
066: PreparedStatement p = null;
067:
068: try {
069: p = JForumExecutionContext
070: .getConnection()
071: .prepareStatement(
072: SystemGlobals.getSql("BanlistModel.delete"));
073: p.setInt(1, banlistId);
074: p.executeUpdate();
075: } catch (Exception e) {
076: throw new DatabaseException(e);
077: } finally {
078: DbUtils.close(p);
079: }
080: }
081:
082: /**
083: * @see net.jforum.dao.BanlistDAO#insert(net.jforum.entities.Banlist)
084: */
085: public void insert(Banlist b) {
086: PreparedStatement p = null;
087:
088: try {
089: p = JForumExecutionContext
090: .getConnection()
091: .prepareStatement(
092: SystemGlobals.getSql("BanlistModel.insert"));
093:
094: p.setInt(1, b.getUserId());
095: p.setString(2, b.getIp());
096: p.setString(3, b.getEmail());
097:
098: this .setAutoGeneratedKeysQuery(SystemGlobals
099: .getSql("BanlistModel.lastGeneratedBanlistId"));
100:
101: int id = this .executeAutoKeysQuery(p);
102:
103: b.setId(id);
104: } catch (Exception e) {
105: throw new DatabaseException(e);
106: } finally {
107: DbUtils.close(p);
108: }
109: }
110:
111: /**
112: * @see net.jforum.dao.BanlistDAO#selectAll()
113: */
114: public List selectAll() {
115: ResultSet rs = null;
116: PreparedStatement p = null;
117:
118: List l = new ArrayList();
119:
120: try {
121: p = JForumExecutionContext.getConnection()
122: .prepareStatement(
123: SystemGlobals
124: .getSql("BanlistModel.selectAll"));
125: rs = p.executeQuery();
126:
127: while (rs.next()) {
128: Banlist b = new Banlist();
129:
130: b.setId(rs.getInt("banlist_id"));
131: b.setUserId(rs.getInt("user_id"));
132: b.setEmail(rs.getString("banlist_email"));
133: b.setIp(rs.getString("banlist_ip"));
134:
135: l.add(b);
136: }
137: } catch (Exception e) {
138: throw new DatabaseException(e);
139: } finally {
140: DbUtils.close(rs, p);
141: }
142:
143: return l;
144: }
145: }
|