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.legacy;
22:
23: import com.db4o.*;
24: import com.db4o.db4ounit.common.querying.MultiFieldIndexQueryTestCase.*;
25: import com.db4o.query.*;
26: import com.db4o.test.*;
27:
28: public class Book {
29:
30: public Person[] authors;
31: public String title;
32:
33: public Book() {
34: }
35:
36: public Book(String title, Person[] authors) {
37: this .title = title;
38: this .authors = authors;
39: }
40:
41: public void store() {
42: Person aaron = new Person("Aaron", "OneOK");
43: Person bill = new Person("Bill", "TwoOK");
44: Person chris = new Person("Chris", "ThreeOK");
45: Person dave = new Person("Dave", "FourOK");
46: Person neil = new Person("Neil", "Notwanted");
47: Person nat = new Person("Nat", "Neverwanted");
48: Test.store(new Book("Persistence possibilities", new Person[] {
49: aaron, bill, chris }));
50: Test.store(new Book("Persistence using S.O.D.A.",
51: new Person[] { aaron }));
52: Test.store(new Book("Persistence using JDO", new Person[] {
53: bill, dave }));
54: Test.store(new Book("Don't want to find Phil", new Person[] {
55: aaron, bill, neil }));
56: Test
57: .store(new Book("Persistence by Jeff",
58: new Person[] { nat }));
59: }
60:
61: public void test() {
62: Query qBooks = Test.query();
63: qBooks.constrain(Book.class);
64: qBooks.descend("title").constrain("Persistence").like();
65: Query qAuthors = qBooks.descend("authors");
66: Query qFirstName = qAuthors.descend("firstName");
67: Query qLastName = qAuthors.descend("lastName");
68: Constraint cAaron = qFirstName.constrain("Aaron").and(
69: qLastName.constrain("OneOK"));
70: Constraint cBill = qFirstName.constrain("Bill").and(
71: qLastName.constrain("TwoOK"));
72: cAaron.or(cBill);
73: ObjectSet results = qAuthors.execute();
74: Test.ensure(results.size() == 4);
75: while (results.hasNext()) {
76: Person person = (Person) results.next();
77: Test.ensure(person.lastName.endsWith("OK"));
78: }
79: }
80:
81: public String toString() {
82: String ret = title;
83: if (authors != null) {
84: for (int i = 0; i < authors.length; i++) {
85: ret += "\n " + authors[i].toString();
86: }
87: }
88: return ret;
89: }
90: }
|