Author: toad
Date: 2008-07-12 00:33:39 +0000 (Sat, 12 Jul 2008)
New Revision: 21082
Modified:
branches/db4o/freenet/src/freenet/node/fcp/FCPPersistentRoot.java
Log:
Fix wierd query returning wrong client problem
Modified: branches/db4o/freenet/src/freenet/node/fcp/FCPPersistentRoot.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/fcp/FCPPersistentRoot.java
2008-07-12 00:11:37 UTC (rev 21081)
+++ branches/db4o/freenet/src/freenet/node/fcp/FCPPersistentRoot.java
2008-07-12 00:33:39 UTC (rev 21082)
@@ -6,8 +6,10 @@
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
import com.db4o.query.Predicate;
+import com.db4o.query.Query;
import freenet.node.NodeClientCore;
+import freenet.support.Logger;
/**
* Persistent root object for FCP.
@@ -43,16 +45,26 @@
}
public FCPClient registerForeverClient(final String name,
NodeClientCore core, FCPConnectionHandler handler, FCPServer server,
ObjectContainer container) {
- ObjectSet set = container.query(new Predicate() {
- public boolean match(FCPClient client) {
- if(!client.name.equals(name)) return false;
- return client.root == FCPPersistentRoot.this;
- }
- });
+ if(Logger.shouldLog(Logger.MINOR, this)) Logger.minor(this,
"Registering forever-client for "+name);
+ /**
+ * FIXME DB4O:
+ * Native queries involving strings seem to do wierd things. I
was getting
+ * the global queue returned here even though I compared with
the passed-in
+ * name! :<
+ * FIXME reproduce and file a bug for db4o.
+ */
+ Query query = container.query();
+ query.constrain(FCPClient.class);
+ query.descend("name").constrain(name);
+ query.descend("root").constrain(this);
+ ObjectSet set = query.execute();
if(set.hasNext()) {
FCPClient client = (FCPClient) set.next();
container.activate(client, 1);
client.setConnection(handler);
+ if(!(name.equals(client.name)))
+ Logger.error(this, "Returning "+client+" for
"+name);
+ if(Logger.shouldLog(Logger.MINOR, this))
Logger.minor(this, "Returning "+client+" for "+name);
return client;
}
FCPClient client = new FCPClient(name, handler, false, null,
ClientRequest.PERSIST_FOREVER, this, container);