Author: jflesch
Date: 2007-08-06 17:40:03 +0000 (Mon, 06 Aug 2007)
New Revision: 14492
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardAttachment.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
Log:
Fix the frost messages database cleanup
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
2007-08-06 17:00:16 UTC (rev 14491)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
2007-08-06 17:40:03 UTC (rev 14492)
@@ -754,7 +754,7 @@
public boolean destroy() {
Hsqldb db = factory.getDb();
- if (!KSKMessage.destroy(this, db))
+ if (!KSKMessage.destroyAll(this, db))
return false;
try {
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardAttachment.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardAttachment.java
2007-08-06 17:00:16 UTC (rev 14491)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardAttachment.java
2007-08-06 17:40:03 UTC (rev 14492)
@@ -255,11 +255,30 @@
}
- public static boolean destroy(KSKBoard board, Hsqldb db) {
+ public static boolean destroy(KSKMessage msg, Hsqldb db) {
try {
synchronized(db.dbLock) {
PreparedStatement st;
+ st =
db.getConnection().prepareStatement("DELETE FROM frostKSKAttachmentBoards "+
+ "WHERE
messageId = ?");
+ st.setInt(1, msg.getId());
+ st.execute();
+ }
+ } catch(SQLException e) {
+ Logger.error(null, "Can't destroy the message
attachments of the board because : "+e.toString());
+ return false;
+ }
+
+ return true;
+ }
+
+
+ public static boolean destroyAll(KSKBoard board, Hsqldb db) {
+ try {
+ synchronized(db.dbLock) {
+ PreparedStatement st;
+
st =
db.getConnection().prepareStatement("SELECT id FROM frostKSKMessages "+
"WHERE
boardId = ?");
st.setInt(1, board.getId());
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
2007-08-06 17:00:16 UTC (rev 14491)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
2007-08-06 17:40:03 UTC (rev 14492)
@@ -82,11 +82,32 @@
java.sql.Timestamp timestamp = new
java.sql.Timestamp(new Date().getTime() - (deleteAfter * 24 * 60*60*1000));
- st =
db.getConnection().prepareStatement("DELETE from frostKSKMessages WHERE date <
?");
+ st =
db.getConnection().prepareStatement("SELECT "+
+ " id,
msgId, inReplyToId, subject, "+
+ "
nick, sigId, date, rev, read, "+
+ "
archived "+
+ "FROM
frostKSKMessages WHERE date < ?");
st.setTimestamp(1, timestamp);
- st.execute();
+ ResultSet set = st.executeQuery();
+ while(set.next()) {
+ KSKMessage msg = new
KSKMessage(set.getInt("id"),
+
set.getString("msgId"),
+
set.getString("inReplyToId"),
+
set.getString("subject"),
+
set.getString("nick"),
+
set.getInt("sigId"),
+ null,
/* author Identity */
+
set.getTimestamp("date"),
+
set.getInt("rev"),
+
set.getBoolean("read"),
+
set.getBoolean("archived"),
+ null,
/* encryptedFor */
+ null /*
board */);
+ msg.destroy(db);
+ }
+
timestamp = new java.sql.Timestamp(new
Date().getTime() - (archiveAfter * 24 * 60*60*1000));
st =
db.getConnection().prepareStatement("UPDATE frostKSKMessages SET archived =
TRUE WHERE date < ?");
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
2007-08-06 17:00:16 UTC (rev 14491)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
2007-08-06 17:40:03 UTC (rev 14492)
@@ -267,11 +267,30 @@
}
- public static boolean destroy(KSKBoard board, Hsqldb db) {
+ public static boolean destroy(KSKMessage msg, Hsqldb db) {
try {
synchronized(db.dbLock) {
PreparedStatement st;
+ st =
db.getConnection().prepareStatement("DELETE FROM frostKSKAttachmentFiles "+
+ "WHERE
messageId = ?");
+ st.setInt(1, msg.getId());
+ st.execute();
+ }
+ } catch(SQLException e) {
+ Logger.error(null, "Can't destroy the file attachments
of the message because : "+e.toString());
+ return false;
+ }
+
+ return true;
+ }
+
+
+ public static boolean destroyAll(KSKBoard board, Hsqldb db) {
+ try {
+ synchronized(db.dbLock) {
+ PreparedStatement st;
+
st =
db.getConnection().prepareStatement("SELECT id FROM frostKSKMessages "+
"WHERE
boardId = ?");
st.setInt(1, board.getId());
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
2007-08-06 17:00:16 UTC (rev 14491)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
2007-08-06 17:40:03 UTC (rev 14492)
@@ -464,9 +464,9 @@
}
- public static boolean destroy(KSKBoard board, Hsqldb db) {
- if (!KSKFileAttachment.destroy(board, db)
- || !KSKBoardAttachment.destroy(board, db))
+ public static boolean destroyAll(KSKBoard board, Hsqldb db) {
+ if (!KSKFileAttachment.destroyAll(board, db)
+ || !KSKBoardAttachment.destroyAll(board, db))
return false;
try {
@@ -485,4 +485,33 @@
return true;
}
+
+
+ public boolean destroy(Hsqldb db) {
+ if (!KSKFileAttachment.destroy(this, db)
+ || !KSKBoardAttachment.destroy(this, db))
+ return false;
+
+ try {
+ synchronized(db.dbLock) {
+ PreparedStatement st;
+
+ /* to avoid the integrity constraint violations
*/
+ st =
db.getConnection().prepareStatement("UPDATE frostKSKMessages SET "+
+
"inReplyTo = NULL WHERE inReplyTo = ?");
+ st.setInt(1, id);
+ st.execute();
+
+ st =
db.getConnection().prepareStatement("DELETE FROM frostKSKMessages "+
+ "WHERE
id = ?");
+ st.setInt(1, id);
+ st.execute();
+ }
+ } catch(SQLException e) {
+ Logger.error(null, "Can't destroy the message
"+Integer.toString(id)+" because : "+e.toString());
+ return false;
+ }
+
+ return true;
+ }
}