KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > jforum > dao > generic > GenericSmilieDAO


1 /*
2  * Copyright (c) 2003, Rafael Steil
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  * This file creation date: 13/01/2004 / 12:02:54
40  * The JForum Project
41  * http://www.jforum.net
42  */

43 package net.jforum.dao.generic;
44
45 import java.sql.PreparedStatement JavaDoc;
46 import java.sql.ResultSet JavaDoc;
47 import java.sql.SQLException JavaDoc;
48 import java.util.ArrayList JavaDoc;
49 import java.util.List JavaDoc;
50
51 import net.jforum.JForumExecutionContext;
52 import net.jforum.entities.Smilie;
53 import net.jforum.util.preferences.SystemGlobals;
54
55 /**
56  * @author Rafael Steil
57  * @version $Id: GenericSmilieDAO.java,v 1.5 2006/01/29 15:06:20 rafaelsteil Exp $
58  */

59 public class GenericSmilieDAO extends AutoKeys implements net.jforum.dao.SmilieDAO {
60
61     /**
62      * @see net.jforum.repository.SmilieDAO#addNew(net.jforum.entities.Smilie)
63      */

64     public int addNew(Smilie smilie) throws Exception JavaDoc
65     {
66         PreparedStatement JavaDoc p = this.getStatementForAutoKeys("SmiliesModel.addNew");
67         
68         p.setString(1, smilie.getCode());
69         p.setString(2, smilie.getUrl());
70         p.setString(3, smilie.getDiskName());
71         
72         this.setAutoGeneratedKeysQuery(SystemGlobals.getSql("SmiliesModel.lastGeneratedSmilieId"));
73         int id = this.executeAutoKeysQuery(p);
74
75         p.close();
76         return id;
77     }
78
79     /**
80      * @see net.jforum.repository.SmilieDAO#delete(int)
81      */

82     public void delete(int id) throws Exception JavaDoc
83     {
84         PreparedStatement JavaDoc p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("SmiliesModel.delete"));
85         p.setInt(1, id);
86         p.executeUpdate();
87         
88         p.close();
89     }
90
91     /**
92      * @see net.jforum.repository.SmilieDAO#update(net.jforum.entities.Smilie)
93      */

94     public void update(Smilie smilie) throws Exception JavaDoc
95     {
96         PreparedStatement JavaDoc p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("SmiliesModel.update"));
97         p.setString(1, smilie.getCode());
98         p.setString(2, smilie.getUrl());
99         p.setString(3, smilie.getDiskName());
100         p.setInt(4, smilie.getId());
101         
102         p.executeUpdate();
103         p.close();
104     }
105     
106     private Smilie getSmilie(ResultSet JavaDoc rs) throws SQLException JavaDoc
107     {
108         Smilie s = new Smilie();
109         
110         s.setId(rs.getInt("smilie_id"));
111         s.setCode(rs.getString("code"));
112         s.setUrl(rs.getString("url"));
113         s.setDiskName(rs.getString("disk_name"));
114         
115         return s;
116     }
117
118     /**
119      * @see net.jforum.repository.SmilieDAO#selectAll()
120      */

121     public List JavaDoc selectAll() throws Exception JavaDoc
122     {
123         List JavaDoc l = new ArrayList JavaDoc();
124         
125         PreparedStatement JavaDoc p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("SmiliesModel.selectAll"));
126         ResultSet JavaDoc rs = p.executeQuery();
127         while (rs.next()) {
128             l.add(this.getSmilie(rs));
129         }
130         
131         rs.close();
132         p.close();
133         
134         return l;
135     }
136
137     /**
138      * @see net.jforum.dao.SmilieDAO#selectById(int)
139      */

140     public Smilie selectById(int id) throws Exception JavaDoc
141     {
142         PreparedStatement JavaDoc p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("SmiliesModel.selectById"));
143         p.setInt(1, id);
144         
145         Smilie s = new Smilie();
146         
147         ResultSet JavaDoc rs = p.executeQuery();
148         if (rs.next()) {
149             s = this.getSmilie(rs);
150         }
151         
152         rs.close();
153         p.close();
154         
155         return s;
156     }
157 }
158
Popular Tags