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.Config; 52 import net.jforum.util.preferences.SystemGlobals; 53 54 58 public class GenericConfigDAO implements net.jforum.dao.ConfigDAO 59 { 60 63 public void insert(Config config) throws Exception 64 { 65 PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ConfigModel.insert")); 66 p.setString(1, config.getName()); 67 p.setString(2, config.getValue()); 68 p.executeUpdate(); 69 p.close(); 70 } 71 72 75 public void update(Config config) throws Exception 76 { 77 PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ConfigModel.update")); 78 p.setString(1, config.getValue()); 79 p.setString(2, config.getName()); 80 p.executeUpdate(); 81 p.close(); 82 } 83 84 87 public void delete(Config config) throws Exception 88 { 89 PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ConfigModel.delete")); 90 p.setInt(1, config.getId()); 91 p.executeUpdate(); 92 p.close(); 93 } 94 95 98 public List selectAll() throws Exception 99 { 100 List l = new ArrayList (); 101 102 PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ConfigModel.selectAll")); 103 ResultSet rs = p.executeQuery(); 104 while (rs.next()) { 105 l.add(this.makeConfig(rs)); 106 } 107 108 rs.close(); 109 p.close(); 110 111 return l; 112 } 113 114 117 public Config selectByName(String name) throws Exception 118 { 119 PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ConfigModel.selectByName")); 120 p.setString(1, name); 121 ResultSet rs = p.executeQuery(); 122 Config c = null; 123 124 if (rs.next()) { 125 c = this.makeConfig(rs); 126 } 127 128 rs.close(); 129 p.close(); 130 131 return c; 132 } 133 134 protected Config makeConfig(ResultSet rs) throws Exception 135 { 136 Config c = new Config(); 137 c.setId(rs.getInt("config_id")); 138 c.setName(rs.getString("config_name")); 139 c.setValue(rs.getString("config_value")); 140 141 return c; 142 } 143 } 144 | Popular Tags |