1 43 package net.jforum.dao.generic; 44 45 import java.sql.PreparedStatement ; 46 import java.sql.ResultSet ; 47 import java.sql.SQLException ; 48 import java.util.ArrayList ; 49 import java.util.List ; 50 51 import net.jforum.JForumExecutionContext; 52 import net.jforum.entities.Smilie; 53 import net.jforum.util.preferences.SystemGlobals; 54 55 59 public class GenericSmilieDAO extends AutoKeys implements net.jforum.dao.SmilieDAO { 60 61 64 public int addNew(Smilie smilie) throws Exception 65 { 66 PreparedStatement 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 82 public void delete(int id) throws Exception 83 { 84 PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("SmiliesModel.delete")); 85 p.setInt(1, id); 86 p.executeUpdate(); 87 88 p.close(); 89 } 90 91 94 public void update(Smilie smilie) throws Exception 95 { 96 PreparedStatement 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 rs) throws SQLException 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 121 public List selectAll() throws Exception 122 { 123 List l = new ArrayList (); 124 125 PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("SmiliesModel.selectAll")); 126 ResultSet 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 140 public Smilie selectById(int id) throws Exception 141 { 142 PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("SmiliesModel.selectById")); 143 p.setInt(1, id); 144 145 Smilie s = new Smilie(); 146 147 ResultSet 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 |