????????????ü??
???????????? ???????[ 2011/9/21 9:20:10 ] ????????
???????????????????????????????????????????????????????????
ParticipantsInDB partsInDB = ...;
Participant kent = new Participant(...);
Participant paul = new Participant(...);
partsInDB.clear();
partsInDB.addParticipant(kent);
partsInDB.addParticipant(paul);
partsInDB.deleteParticipant(kent.getId());
System.out.println("There are "+partsInDB.getCount()+ "participants");
????????д???????????There are 1 participants?????????????????????????????There are 2 participants???????????е??????DBTable????????????getCount????????ParticipantsInDB??countParticipants??getCount??????????????????£??????????????????????????????????Щ??????Ч??λ?????????????false?????
??????????Щ?????????????????????
????ParticipantsInDB?????????DBTable???????????clear??getCount??????ParticipantsInDB??????clear????????????????????????е?λ??????getCount?????????С??????????ParticipantsInDB????getCount???????????????participants????????????е?????????????????true????false?????????????????????????????????????????????????????y???getCount???????????????????????????е????Ч???λ?????????????????
????????ParticipantsInDB??????????ü?????????getCount????????????????????????????
??????????????????м?й????
???????????????Щ????????????????????????????????????????????????м?й????ParticipantsInDB?????????DBTable??ParticipantsInDB????????????????????DBTable??
??????????ParticipantsInDB???????????????е?λ??????????????????????????????????????????????????????????????????????????Participants????????????????????????????Participants???????
?????????????????????????????????????磬???????????????2000???λ????????????????д????????????A??participants??????????1000???λ?????????B??participants?????????1000???λ????DBTable????????????????????????????????1000???λ??????participants????????????????2000??λ??????????????????????????????????е?????????????????e????????????????????????????????????????????????????????????????????
????????????????ж??ParticipantsInDB??DBTable????????????е?????ParticipantsInDB??????DBTable?????????????????ParticipantsInDB????getCount??????????????ParticipantsInDB?????DBTable????????????????????????????????????????ParticipantsInDB?????????????DBTable??
public class DBTable {
private Connection conn;
private String tableName;
public DBTable(String tableName) {
this.tableName = tableName;
this.conn = ...;
}
public void clear() {
PreparedStatement st = conn.prepareStatement("DELETE FROM "+tableName);
{
st.executeUpdate();
}finally{
st.close();
}
}
public int getCount() {
PreparedStatement st = conn.prepareStatement("SELECT COUNT(*) FROM "+tableName);
try {
ResultSet rs = st.executeQuery();
rs.next();
return rs.getInt(1);
}finally{
st.close();
}
}
public String getTableName() {
return tableName;
}
public Connection getConn() {
return conn;
}
}
public class ParticipantsInDB {
private DBTable table;
public ParticipantsInDB() {
table = new DBTable("participants");
}
public void addParticipant(Participant part) {
...
}
public void deleteParticipant(String participantId) {
setDeleteFlag(participantId?? true);
}
public void restoreParticipant(String participantId) {
set
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11