Hi all,
I am trying to get a simple replication working between two db4o databases, over a client/server connection, using java5. I kept running into NullPointerExceptions on the loaded objects, and on further investigation, discovered that Hashtable fields were not being replicated. Despite much fiddling with update and activation depths, and debugging with message levels, the hashtable objects (and entries) would not copy -- despite being flagged for replication .
I've written a test sample below. Notice that HashMaps (and other collection classes) seem to work perfectly fine, only Hashtables are affected.
import java.io.File;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import com.db4o.Db4o;
import com.db4o.ObjectContainer;
import com.db4o.ObjectServer;
import com.db4o.ObjectSet;
import com.db4o.config.ConfigScope;
import com.db4o.drs.Replication;
import com.db4o.drs.ReplicationSession;
public class HashTest {
//HashMap<Integer,Integer> test;
Hashtable<Integer,Integer> test;
public HashTest() {
//test = new HashMap<Integer,Integer>();
test = new Hashtable<Integer,Integer>();
}
public void put(int a, int b) {
test.put(a,b);
}
public String toString() {
return test.toString();
}
public static void main(String[] args) throws Exception {
File f1 = new File("test1.yap");
File f2 = new File("test2.yap");
if (f1.exists())
f1.delete();
if (f2.exists())
f2.delete();
Db4o.configure().generateUUIDs(ConfigScope.GLOBALLY);
Db4o.configure().generateVersionNumbers(ConfigScope.GLOBALLY);
Db4o.configure().updateDepth(10);
Db4o.configure().activationDepth(10);
ObjectServer server1 = Db4o.openServer("test1.yap", 8001);
server1.grantAccess("a", "b");
ObjectContainer client1 = Db4o.openClient("localhost",8001, "a", "b");
ObjectServer server2 = Db4o.openServer("test2.yap", 8002);
server2.grantAccess("a", "b");
ObjectContainer client2 = Db4o.openClient("localhost",8002, "a", "b");
HashTest testObj = new HashTest();
testObj.put(1,2);
testObj.put(3,4);
client1.set(testObj);
client1.commit();
List<HashTest> results1 = client1.query(HashTest.class);
System.out.println("DB 1");
for(HashTest obj : results1) {
System.out.println(obj);
}
System.out.println("Replication");
ReplicationSession replication = Replication.begin(client1, client2);
ObjectSet repObjs = replication.providerA().objectsChangedSinceLastReplication();
while(repObjs.hasNext()) {
Object o = repObjs.next();
System.out.println(o.getClass()+":"+o);
replication.replicate(o);
}
replication.commit();
List<HashTest> results2 = client2.query(HashTest.class);
System.out.println("DB 2");
for(HashTest obj : results2) {
System.out.println(obj);
}
client1.close();
client2.close();
server1.close();
server2.close();
}
}
Tests were ran in both stable (6.1) and development (7.0.21.8746).
Any ideas? Is Hashtable not fully supported by db4o and/or replication? I would change to HashMap as a workaround, but I am unsure about the sideaffects in our current codebase.
cheers
-Mark