Author: jflesch
Date: 2007-01-28 17:56:32 +0000 (Sun, 28 Jan 2007)
New Revision: 11643
Modified:
trunk/apps/Thaw/src/thaw/plugins/SqlConsole.java
trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java
trunk/apps/Thaw/src/thaw/plugins/index/Index.java
trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
Log:
When refreshing an index, don't remove the file recently added
Modified: trunk/apps/Thaw/src/thaw/plugins/SqlConsole.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/SqlConsole.java 2007-01-28 16:41:37 UTC
(rev 11642)
+++ trunk/apps/Thaw/src/thaw/plugins/SqlConsole.java 2007-01-28 17:56:32 UTC
(rev 11643)
@@ -199,6 +199,7 @@
if ("clear".equals(cmd.toLowerCase())) {
flushBuffer();
+ return;
}
if ("refresh".equals(cmd.toLowerCase())) {
Modified: trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java 2007-01-28
16:41:37 UTC (rev 11642)
+++ trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java 2007-01-28
17:56:32 UTC (rev 11643)
@@ -73,7 +73,7 @@
if (config.getValue("indexDatabaseVersion") == null) {
newDb = true;
- config.setValue("indexDatabaseVersion", "2");
+ config.setValue("indexDatabaseVersion", "3");
} else {
/* CONVERTIONS */
@@ -88,6 +88,13 @@
*/
}
+ if
("2".equals(config.getValue("indexDatabaseVersion"))) {
+ if (splashScreen != null)
+ splashScreen.setStatus("Converting
database ...");
+ if (convertDatabase_2_to_3(db))
+ config.setValue("indexDatabaseVersion",
"3");
+ }
+
/* ... */
}
@@ -165,6 +172,7 @@
+ "category INTEGER NULL,"
+ "indexParent INTEGER NOT NULL,"
+ "toDelete BOOLEAN DEFAULT FALSE NOT NULL,"
+ + "dontDelete BOOLEAN DEFAULT FALSE NOT NULL,"
+ "PRIMARY KEY (id),"
+ "FOREIGN KEY (indexParent) REFERENCES indexes (id),"
+ "FOREIGN KEY (category) REFERENCES categories
(id))");
@@ -178,6 +186,7 @@
+ "indexParent INTEGER NOT NULL,"
+ "indexTarget INTEGER NULL,"
+ "toDelete BOOLEAN DEFAULT false NOT NULL,"
+ + "dontDelete BOOLEAN DEFAULT false NOT NULL,"
+ "PRIMARY KEY (id),"
+ "FOREIGN KEY (indexParent) REFERENCES indexes (id),"
+ "FOREIGN KEY (indexTarget) REFERENCES indexes
(id))");
@@ -522,10 +531,12 @@
if (!sendQuery(db, "ALTER TABLE links ADD COLUMN toDelete
BOOLEAN DEFAULT false")) {
Logger.error(new DatabaseManager(), "Error while
converting the database (1 to 2) ! (adding column to link table)");
+ return false;
}
if (!sendQuery(db, "ALTER TABLE files ADD COLUMN toDelete
BOOLEAN DEFAULT false")) {
Logger.error(new DatabaseManager(), "Error while
converting the database (1 to 2) ! (adding column to file table)");
+ return false;
}
/* direct AND indirect parents */
@@ -616,4 +627,17 @@
return true;
}
+ public static boolean convertDatabase_2_to_3(Hsqldb db) {
+ if (!sendQuery(db, "ALTER TABLE links ADD COLUMN dontDelete
BOOLEAN DEFAULT false")) {
+ Logger.error(new DatabaseManager(), "Error while
converting the database (2 to 3) ! (adding column to link table)");
+ return false;
+ }
+
+ if (!sendQuery(db, "ALTER TABLE files ADD COLUMN dontDelete
BOOLEAN DEFAULT false")) {
+ Logger.error(new DatabaseManager(), "Error while
converting the database (2 to 3) ! (adding column to file table)");
+ return false;
+ }
+
+ return true;
+ }
}
Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2007-01-28 16:41:37 UTC
(rev 11642)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2007-01-28 17:56:32 UTC
(rev 11643)
@@ -627,6 +627,24 @@
setPublicKey(key, rev);
+
+ try {
+ PreparedStatement st;
+
+ String query = "UPDATE # SET dontDelete = FALSE
WHERE indexParent = ?";
+
+ st =
db.getConnection().prepareStatement(query.replaceFirst("#", "files"));
+ st.setInt(1, id);
+ st.execute();
+
+ st =
db.getConnection().prepareStatement(query.replaceFirst("#", "links"));
+ st.setInt(1, id);
+ st.execute();
+
+ } catch(SQLException e) {
+ Logger.error(this, "Error while reseting
dontDelete flags: "+e.toString());
+ }
+
} else {
Logger.warning(this, "Index not generated !");
return 0;
@@ -1158,7 +1176,7 @@
PreparedStatement st =
db.getConnection().prepareStatement("UPDATE links "+
"SET toDelete = TRUE "+
-
"WHERE indexParent = ?");
+
"WHERE indexParent = ? AND dontDelete = FALSE");
st.setInt(1, id);
st.execute();
} catch(SQLException exc) {
@@ -1257,7 +1275,7 @@
st =
db.getConnection().prepareStatement("UPDATE files "+
"SET
toDelete = TRUE "+
- "WHERE
indexParent = ?");
+ "WHERE
indexParent = ? AND dontDelete = FALSE");
st.setInt(1, id);
st.execute();
} catch(SQLException exc) {
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
2007-01-28 16:41:37 UTC (rev 11642)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
2007-01-28 17:56:32 UTC (rev 11643)
@@ -1154,8 +1154,8 @@
try {
selectSt =
db.getConnection().prepareStatement("SELECT id from files WHERE indexParent = ?
AND LOWER(filename) LIKE ? LIMIT 1");
st =
db.getConnection().prepareStatement("INSERT INTO files "+
- "(id,
filename, publicKey, localPath, mime, size, category, indexParent) "+
-
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
+ "(id,
filename, publicKey, localPath, mime, size, category, indexParent, dontDelete)
"+
+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, TRUE)");
nextId = DatabaseManager.getNextId(db, "files");
if (nextId < 0)