KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > cluster > ClusterQueryImplementsList


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 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
32 public class ClusterQueryImplementsList {
33     
34     public String JavaDoc _name;
35     
36     public static final String JavaDoc SECOND_FILE = "second.yap";
37     
38     public ClusterQueryImplementsList(){
39     }
40     
41     public ClusterQueryImplementsList(String JavaDoc 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 JavaDoc 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