1 21 package com.db4o.test.cluster; 22 23 import java.io.*; 24 import java.util.*; 25 26 import com.db4o.*; 27 import com.db4o.cluster.*; 28 import com.db4o.query.*; 29 import com.db4o.test.*; 30 31 32 public class ClusterQueryImplementsList { 33 34 public String _name; 35 36 public static final String SECOND_FILE = "second.yap"; 37 38 public ClusterQueryImplementsList(){ 39 } 40 41 public ClusterQueryImplementsList(String name){ 42 _name = name; 43 } 44 45 public void store(){ 46 new File(SECOND_FILE).delete(); 47 Test.store(new ClusterQueryImplementsList("inOne")); 48 Test.store(new ClusterQueryImplementsList("inBoth")); 49 ObjectContainer second = Db4o.openFile(SECOND_FILE); 50 second.set(new ClusterQueryImplementsList("inBoth")); 51 second.set(new ClusterQueryImplementsList("inTwo")); 52 second.close(); 53 } 54 55 public void test(){ 56 ObjectContainer second = Db4o.openFile(SECOND_FILE); 57 Cluster cluster = new Cluster(new ObjectContainer[]{ 58 Test.objectContainer(), 59 second 60 }); 61 tQuery(cluster, "inOne", 1); 62 tQuery(cluster, "inTwo", 1); 63 tQuery(cluster, "inBoth", 2); 64 tQuery(cluster, "inNone", 0); 65 second.close(); 66 } 67 68 private void tQuery(Cluster cluster, String name, int expected){ 69 Query q = cluster.query(); 70 q.constrain(this.getClass()); 71 q.descend("_name").constrain(name); 72 List list = q.execute(); 73 Test.ensure(list.size() == expected); 74 for (int i = 0; i < expected; i++) { 75 ClusterQueryImplementsList cqil = (ClusterQueryImplementsList) list.get(i); 76 Test.ensure(cqil._name.equals(name)); 77 } 78 } 79 80 } 81 | Popular Tags |