1 43 package net.jforum.dao.generic; 44 45 import java.sql.PreparedStatement ; 46 import java.sql.ResultSet ; 47 import java.util.ArrayList ; 48 import java.util.List ; 49 50 import net.jforum.JForumExecutionContext; 51 import net.jforum.entities.Ranking; 52 import net.jforum.util.preferences.SystemGlobals; 53 54 58 public class GenericRankingDAO implements net.jforum.dao.RankingDAO 59 { 60 63 public Ranking selectById(int rankingId) throws Exception 64 { 65 Ranking ranking = new Ranking(); 66 67 PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("RankingModel.selectById")); 68 p.setInt(1, rankingId); 69 70 ResultSet rs = p.executeQuery(); 71 if (rs.next()) { 72 ranking.setId(rankingId); 73 ranking.setTitle(rs.getString("rank_title")); 74 ranking.setImage(rs.getString("rank_image")); 75 ranking.setMin(rs.getInt("rank_min")); 76 ranking.setSpecial(rs.getInt("rank_special")); 77 } 78 79 rs.close(); 80 p.close(); 81 82 return ranking; 83 } 84 85 88 public List selectAll() throws Exception 89 { 90 List l = new ArrayList (); 91 PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("RankingModel.selectAll")); 92 ResultSet rs = p.executeQuery(); 93 94 while (rs.next()) { 95 Ranking ranking = new Ranking(); 96 97 ranking.setId(rs.getInt("rank_id")); 98 ranking.setTitle(rs.getString("rank_title")); 99 ranking.setImage(rs.getString("rank_image")); 100 ranking.setMin(rs.getInt("rank_min")); 101 ranking.setSpecial(rs.getInt("rank_special")); 102 103 l.add(ranking); 104 } 105 106 rs.close(); 107 p.close(); 108 109 return l; 110 } 111 112 115 public void delete(int rankingId) throws Exception 116 { 117 PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("RankingModel.delete")); 118 p.setInt(1, rankingId); 119 120 p.executeUpdate(); 121 p.close(); 122 } 123 124 127 public void update(Ranking ranking) throws Exception 128 { 129 PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("RankingModel.update")); 130 131 p.setString(1, ranking.getTitle()); 132 p.setString(2, ranking.getImage()); 133 p.setInt(3, ranking.getSpecial()); 134 p.setInt(4, ranking.getMin()); 135 p.setInt(5, ranking.getId()); 136 137 p.executeUpdate(); 138 p.close(); 139 } 140 141 144 public void addNew(Ranking ranking) throws Exception 145 { 146 PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("RankingModel.addNew")); 147 148 p.setString(1, ranking.getTitle()); 149 p.setInt(2, ranking.getMin()); 150 151 p.executeUpdate(); 152 p.close(); 153 } 154 155 } 156 | Popular Tags |