01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11: Suite 350, San Mateo, CA 94403, USA.
12:
13: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14: WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: for more details.
17:
18: You should have received a copy of the GNU General Public License along
19: with this program; if not, write to the Free Software Foundation, Inc.,
20: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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: public class ClusterQueryImplementsList {
32:
33: public String _name;
34:
35: public static final String SECOND_FILE = "second.yap";
36:
37: public ClusterQueryImplementsList() {
38: }
39:
40: public ClusterQueryImplementsList(String name) {
41: _name = name;
42: }
43:
44: public void store() {
45: new File(SECOND_FILE).delete();
46: Test.store(new ClusterQueryImplementsList("inOne"));
47: Test.store(new ClusterQueryImplementsList("inBoth"));
48: ObjectContainer second = Db4o.openFile(SECOND_FILE);
49: second.set(new ClusterQueryImplementsList("inBoth"));
50: second.set(new ClusterQueryImplementsList("inTwo"));
51: second.close();
52: }
53:
54: public void test() {
55: ObjectContainer second = Db4o.openFile(SECOND_FILE);
56: Cluster cluster = new Cluster(new ObjectContainer[] {
57: Test.objectContainer(), second });
58: tQuery(cluster, "inOne", 1);
59: tQuery(cluster, "inTwo", 1);
60: tQuery(cluster, "inBoth", 2);
61: tQuery(cluster, "inNone", 0);
62: second.close();
63: }
64:
65: private void tQuery(Cluster cluster, String name, int expected) {
66: Query q = cluster.query();
67: q.constrain(this .getClass());
68: q.descend("_name").constrain(name);
69: List list = q.execute();
70: Test.ensure(list.size() == expected);
71: for (int i = 0; i < expected; i++) {
72: ClusterQueryImplementsList cqil = (ClusterQueryImplementsList) list
73: .get(i);
74: Test.ensure(cqil._name.equals(name));
75: }
76: }
77:
78: }
|