1 package sellwin.db; 2 3 import sellwin.domain.*; 4 import sellwin.utils.*; 5 6 import java.sql.*; 7 import java.util.*; 8 9 13 14 19 public class DeleteInfoDB extends DBType implements DBInterface { 20 21 private Connection con; 22 23 private final static String selectQuery = 24 "SELECT " + 25 "class_name " + 26 "FROM delete_info " + 27 "WHERE pk="; 28 29 private final static String selectAllQuery = 30 "SELECT * FROM delete_info ORDER BY pk"; 31 32 private final static String insertQuery = 33 "INSERT INTO delete_info VALUES ( "; 34 35 private final static String deleteQuery = 36 "DELETE FROM delete_info WHERE pk ="; 37 38 private final static String deleteAllQuery = 39 "DELETE FROM delete_info"; 40 41 45 public DeleteInfoDB() { 46 } 47 48 52 public DeleteInfoDB(int dbType) { 53 DB_TYPE=dbType; 54 } 55 56 62 public DeleteInfoDB(Connection con) { 63 this.con = con; 64 } 65 66 71 public Connection getConnection() { 72 return this.con; 73 } 74 75 80 public void setConnection(Connection con) 81 throws SQLException { 82 83 this.con = con; 84 } 85 86 94 public final Object selectRow(Object pk) 95 throws SQLException { 96 97 DeleteInfo deleteInfo=null; 98 Statement stmt = null; 99 ResultSet rs = null; 100 Long l = (Long )pk; 101 102 String query = selectQuery + l.longValue(); 103 104 try { 105 stmt = con.createStatement(); 106 if (Prefs.DEBUG) LogWrite.write(query); 107 rs = stmt.executeQuery(query); 108 109 int i; 110 while (rs.next()) { 111 deleteInfo = new DeleteInfo(l.longValue(), rs.getString(1)); 112 } 113 } catch (SQLException e) { 114 throw e; 115 } finally { 116 try { 117 if (rs != null) rs.close(); 118 } catch (SQLException x) { throw x; } 119 try { 120 if (stmt != null) stmt.close(); 121 } catch (SQLException x) { throw x; } 122 } 123 124 return deleteInfo; 125 } 126 127 128 134 public void updateRow(Object obj) 135 throws SQLException { 136 137 DeleteInfo deleteInfo = (DeleteInfo)obj; 138 } 139 140 149 public long insertRow(Object obj, boolean load) 150 throws SQLException { 151 152 DeleteInfo deleteInfo = (DeleteInfo)obj; 153 154 Statement stmt = null; 155 StringBuffer query = new StringBuffer (insertQuery); 156 157 try { 158 stmt = con.createStatement(); 159 160 query.append(deleteInfo.pk).append(","); 161 query.append(JDBC.quoteMore(deleteInfo.className)); 162 query.append(")"); 163 164 if (Prefs.DEBUG) LogWrite.write(query.toString()); 165 int rc = stmt.executeUpdate(query.toString()); 166 } catch (SQLException e) { 167 throw e; 168 } finally { 169 try { if (stmt != null) stmt.close(); 170 } catch (SQLException x) { } 171 } 172 173 return deleteInfo.pk; 174 } 175 176 183 public final void deleteRow(Object obj) 184 throws SQLException { 185 186 long pkValue = ((Long )obj).longValue(); 187 String query = deleteQuery + pkValue; 188 189 Statement stmt = null; 190 try { 191 stmt = con.createStatement(); 192 if (Prefs.DEBUG) LogWrite.write(query); 193 stmt.executeUpdate(query); 194 } catch (SQLException e) { 195 throw e; 196 } finally { 197 try { if (stmt != null) stmt.close(); 198 } catch (SQLException x) { } 199 } 200 } 201 202 208 public final ArrayList selectAllRows() 209 throws SQLException { 210 211 DeleteInfo deleteInfo; 212 Statement stmt = null; 213 ResultSet rs = null; 214 String query = selectAllQuery; 215 ArrayList list = new ArrayList(); 216 217 try { 218 stmt = con.createStatement(); 219 if (Prefs.DEBUG) LogWrite.write(query); 220 rs = stmt.executeQuery(query); 221 222 while (rs.next()) { 223 deleteInfo = new DeleteInfo(rs.getLong(1), rs.getString(2)); 224 list.add(deleteInfo); 225 } 226 } catch (SQLException e) { 227 throw e; 228 } finally { 229 try { 230 if (rs != null) rs.close(); 231 } catch (SQLException x) { throw x; } 232 try { 233 if (stmt != null) stmt.close(); 234 } catch (SQLException x) { throw x; } 235 } 236 237 return list; 238 } 239 240 245 public final void deleteAllRows() 246 throws SQLException { 247 248 String query = deleteAllQuery; 249 250 Statement stmt = null; 251 try { 252 stmt = con.createStatement(); 253 if (Prefs.DEBUG) LogWrite.write(query); 254 stmt.executeUpdate(query); 255 } catch (SQLException e) { 256 throw e; 257 } finally { 258 try { if (stmt != null) stmt.close(); 259 } catch (SQLException x) { } 260 } 261 } 262 267 public final void truncate() 268 throws SQLException { 269 270 String query = "truncate table delete_info"; 271 272 Statement stmt = null; 273 try { 274 stmt = con.createStatement(); 275 if (Prefs.DEBUG) LogWrite.write(query); 276 stmt.executeUpdate(query); 277 } catch (SQLException e) { 278 throw e; 279 } finally { 280 try { if (stmt != null) stmt.close(); 281 } catch (SQLException x) { } 282 } 283 } 284 285 } 286 | Popular Tags |