GenericSmilieDAO.java
Upload User: gdxydsw
Upload Date: 2019-01-29
Package Size: 16721k
Code Size: 5k
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.  * 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. import java.sql.PreparedStatement;
  45. import java.sql.ResultSet;
  46. import java.sql.SQLException;
  47. import java.util.ArrayList;
  48. import java.util.List;
  49. import net.jforum.JForumExecutionContext;
  50. import net.jforum.entities.Smilie;
  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: GenericSmilieDAO.java,v 1.9 2007/02/25 13:48:33 rafaelsteil Exp $
  57.  */
  58. public class GenericSmilieDAO extends AutoKeys implements net.jforum.dao.SmilieDAO
  59. {
  60. /**
  61.  * @see net.jforum.repository.SmilieDAO#addNew(net.jforum.entities.Smilie)
  62.  */
  63. public int addNew(Smilie smilie)
  64. {
  65. PreparedStatement p = null;
  66. try {
  67. p = this.getStatementForAutoKeys("SmiliesModel.addNew");
  68. p.setString(1, smilie.getCode());
  69. p.setString(2, smilie.getUrl());
  70. p.setString(3, smilie.getDiskName());
  71. this.setAutoGeneratedKeysQuery(SystemGlobals.getSql("SmiliesModel.lastGeneratedSmilieId"));
  72. return this.executeAutoKeysQuery(p);
  73. }
  74. catch (SQLException e) {
  75. throw new DatabaseException(e);
  76. }
  77. finally {
  78. DbUtils.close(p);
  79. }
  80. }
  81. /**
  82.  * @see net.jforum.repository.SmilieDAO#delete(int, int)
  83.  */
  84. public void delete(int id)
  85. {
  86. PreparedStatement p = null;
  87. try {
  88. p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("SmiliesModel.delete"));
  89. p.setInt(1, id);
  90. p.executeUpdate();
  91. }
  92. catch (SQLException e) {
  93. throw new DatabaseException(e);
  94. }
  95. finally {
  96. DbUtils.close(p);
  97. }
  98. }
  99. /**
  100.  * @see net.jforum.repository.SmilieDAO#update(net.jforum.entities.Smilie)
  101.  */
  102. public void update(Smilie smilie)
  103. {
  104. PreparedStatement p = null;
  105. try {
  106. p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("SmiliesModel.update"));
  107. p.setString(1, smilie.getCode());
  108. p.setString(2, smilie.getUrl());
  109. p.setString(3, smilie.getDiskName());
  110. p.setInt(4, smilie.getId());
  111. p.executeUpdate();
  112. }
  113. catch (SQLException e) {
  114. throw new DatabaseException(e);
  115. }
  116. finally {
  117. DbUtils.close(p);
  118. }
  119. }
  120. private Smilie getSmilie(ResultSet rs) throws SQLException
  121. {
  122. Smilie s = new Smilie();
  123. s.setId(rs.getInt("smilie_id"));
  124. s.setCode(rs.getString("code"));
  125. s.setUrl(rs.getString("url"));
  126. s.setDiskName(rs.getString("disk_name"));
  127. return s;
  128. }
  129. /**
  130.  * @see net.jforum.repository.SmilieDAO#selectAll()
  131.  */
  132. public List selectAll()
  133. {
  134. List l = new ArrayList();
  135. PreparedStatement p = null;
  136. ResultSet rs = null;
  137. try {
  138. p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("SmiliesModel.selectAll"));
  139. rs = p.executeQuery();
  140. while (rs.next()) {
  141. l.add(this.getSmilie(rs));
  142. }
  143. return l;
  144. }
  145. catch (SQLException e) {
  146. throw new DatabaseException(e);
  147. }
  148. finally {
  149. DbUtils.close(rs, p);
  150. }
  151. }
  152. /**
  153.  * @see net.jforum.dao.SmilieDAO#selectById(int)
  154.  */
  155. public Smilie selectById(int id)
  156. {
  157. PreparedStatement p = null;
  158. ResultSet rs = null;
  159. try {
  160. p = JForumExecutionContext.getConnection()
  161. .prepareStatement(SystemGlobals.getSql("SmiliesModel.selectById"));
  162. p.setInt(1, id);
  163. Smilie s = new Smilie();
  164. rs = p.executeQuery();
  165. if (rs.next()) {
  166. s = this.getSmilie(rs);
  167. }
  168. return s;
  169. }
  170. catch (SQLException e) {
  171. throw new DatabaseException(e);
  172. }
  173. finally {
  174. DbUtils.close(rs, p);
  175. }
  176. }
  177. }