1 package sellwin.db; 2 3 import sellwin.domain.*; 4 import sellwin.utils.*; 5 6 import java.sql.*; 7 8 12 13 18 public class AttendeeDB extends DBType implements DBInterface { 19 private Connection con; 20 21 private final static String selectQuery = 22 "SELECT " + 23 "activity_pk, person_pk, " + 24 "modified_by, modified_date " + 25 "FROM attendee" + 26 "WHERE pk="; 27 28 private final static String insertQuery = 29 "INSERT INTO attendee VALUES ( "; 30 31 private final static String deleteQuery = 32 "DELETE FROM attendee WHERE pk ="; 33 34 39 public AttendeeDB() { 40 } 41 42 46 public AttendeeDB(int dbType) { 47 DB_TYPE=dbType; 48 } 49 50 56 public AttendeeDB(Connection con) { 57 this.con = con; 58 } 59 60 65 public Connection getConnection() { 66 return this.con; 67 } 68 69 74 public void setConnection(Connection con) 75 throws SQLException { 76 77 this.con = con; 78 } 79 80 88 public final Object selectRow(Object pk) 89 throws SQLException { 90 91 Attendee attendee = new Attendee(); 92 attendee.setPK(((Long )pk).longValue()); 93 Statement stmt = null; 94 ResultSet rs = null; 95 String query = selectQuery + attendee.getPK(); 96 97 try { 98 stmt = con.createStatement(); 99 if (Prefs.DEBUG) LogWrite.write(query); 100 rs = stmt.executeQuery(query); 101 102 int i; 103 while (rs.next()) { 104 i=1; 105 attendee.setActivityPK(rs.getLong(i)); i++; 106 attendee.setPersonPK(rs.getLong(i)); i++; 107 AddressDB pdb = new AddressDB(DB_TYPE); 108 pdb.setConnection(getConnection()); 109 Address a = (Address)(pdb.selectRow(new Long (attendee.getPersonPK()))); 110 attendee.setPerson(a); 111 attendee.setModifiedBy(rs.getString(i)); i++; 112 attendee.setModifiedDate(rs.getDate(i)); 113 } 114 } catch (SQLException e) { 115 throw e; 116 } finally { 117 try { 118 if (rs != null) rs.close(); 119 } catch (SQLException x) { throw x; } 120 try { 121 if (stmt != null) stmt.close(); 122 } catch (SQLException x) { throw x; } 123 } 124 125 return attendee; 126 } 127 128 129 135 public void updateRow(Object obj) 136 throws SQLException { 137 138 } 139 140 148 public long insertRow(Object obj, boolean load) 149 throws SQLException { 150 151 Attendee attendee = (Attendee)obj; 152 153 if (!load) 154 attendee.setPK(DBUtils.generatePK()); 155 156 Statement stmt = null; 157 StringBuffer query = new StringBuffer (insertQuery); 158 159 try { 160 stmt = con.createStatement(); 161 162 query.append(attendee.getPK()).append(","); 163 query.append(attendee.getActivityPK()).append(","); 164 query.append(attendee.getPerson().getPK()).append(","); 165 query.append(JDBC.quoteMore(attendee.getModifiedBy())); 166 query.append(JDBC.quote(DateUtils.format(DB_TYPE, attendee.getModifiedDate()))); 167 query.append(")"); 168 169 if (Prefs.DEBUG) LogWrite.write(query.toString()); 170 int rc = stmt.executeUpdate(query.toString()); 171 } catch (SQLException e) { 172 throw e; 173 } finally { 174 try { if (stmt != null) stmt.close(); 175 } catch (SQLException x) { } 176 } 177 178 return attendee.getPK(); 179 } 180 181 188 public final void deleteRow(Object obj) 189 throws SQLException { 190 191 long pkValue = ((Long )obj).longValue(); 192 String query = deleteQuery + pkValue; 193 194 Statement stmt = null; 195 try { 196 stmt = con.createStatement(); 197 if (Prefs.DEBUG) LogWrite.write(query); 198 stmt.executeUpdate(query); 199 } catch (SQLException e) { 200 throw e; 201 } finally { 202 try { if (stmt != null) stmt.close(); 203 } catch (SQLException x) { } 204 } 205 } 206 211 public final void truncate() 212 throws SQLException { 213 214 String query = "truncate table attendee"; 215 216 Statement stmt = null; 217 try { 218 stmt = con.createStatement(); 219 if (Prefs.DEBUG) LogWrite.write(query); 220 stmt.executeUpdate(query); 221 } catch (SQLException e) { 222 throw e; 223 } finally { 224 try { if (stmt != null) stmt.close(); 225 } catch (SQLException x) { } 226 } 227 } 228 229 } 230 | Popular Tags |