Author: jflesch
Date: 2007-07-08 19:57:55 +0000 (Sun, 08 Jul 2007)
New Revision: 13998
Modified:
trunk/apps/Thaw/src/thaw/fcp/FreenetURIHelper.java
trunk/apps/Thaw/src/thaw/plugins/index/Index.java
Log:
Fix bug #1448 : when we insert an index, we check that we update the revisions
of the links to the latest ones found
Modified: trunk/apps/Thaw/src/thaw/fcp/FreenetURIHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FreenetURIHelper.java 2007-07-08 19:44:10 UTC
(rev 13997)
+++ trunk/apps/Thaw/src/thaw/fcp/FreenetURIHelper.java 2007-07-08 19:57:55 UTC
(rev 13998)
@@ -293,6 +293,8 @@
/**
* this process is not costless.
+ * Ignore the revisions
+ * @return true if they match
*/
public static boolean compareKeys(String keyA, String keyB) {
if (keyA == keyB)
Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2007-07-08 19:44:10 UTC
(rev 13997)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2007-07-08 19:57:55 UTC
(rev 13998)
@@ -1173,6 +1173,29 @@
return header;
}
+
+ /**
+ * must be in a synchronized(db.dbLock)
+ */
+ private String findTheLatestKey(String linkKey) throws SQLException {
+ PreparedStatement st =
db.getConnection().prepareStatement("SELECT publicKey FROM indexes "+
+
"WHERE publicKey LIKE ?");
+ st.setString(1, FreenetURIHelper.getComparablePart(linkKey));
+
+ ResultSet set = st.executeQuery();
+
+ while (set.next()) {
+ /* we will assume that we have *always* the latest
version of the index */
+
+ String oKey = set.getString("publicKey");
+ if (FreenetURIHelper.compareKeys(oKey, linkKey))
+ return oKey;
+ }
+
+ return linkKey;
+ }
+
+
public Element getXMLLinks(final Document xmlDoc) {
final Element links = xmlDoc.createElement("indexes");
synchronized(db.dbLock) {
@@ -1185,9 +1208,11 @@
ResultSet set = st.executeQuery();
while (set.next()) {
+ String key =
findTheLatestKey(set.getString("publicKey"));
+
final Element xmlLink =
xmlDoc.createElement("index");
- xmlLink.setAttribute("key",
set.getString("publicKey"));
+ xmlLink.setAttribute("key", key);
if (xmlLink != null)
links.appendChild(xmlLink);