1 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 29 public class Book { 30 31 public Person[] authors; 32 public String title; 33 34 public Book(){} 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[] { aaron, bill,chris})); 49 Test.store(new Book("Persistence using S.O.D.A.", new Person[]{aaron})); 50 Test.store(new Book("Persistence using JDO", new Person[]{bill, dave})); 51 Test.store(new Book("Don't want to find Phil", new Person[]{aaron, bill, neil})); 52 Test.store(new Book("Persistence by Jeff", new Person[]{nat})); 53 } 54 55 public void test(){ 56 Query qBooks = Test.query(); 57 qBooks.constrain(Book.class); 58 qBooks.descend("title").constrain("Persistence").like(); 59 Query qAuthors = qBooks.descend("authors"); 60 Query qFirstName = qAuthors.descend("firstName"); 61 Query qLastName = qAuthors.descend("lastName"); 62 Constraint cAaron = 63 qFirstName.constrain("Aaron").and( 64 qLastName.constrain("OneOK") 65 ); 66 Constraint cBill = 67 qFirstName.constrain("Bill").and( 68 qLastName.constrain("TwoOK") 69 ); 70 cAaron.or(cBill); 71 ObjectSet results = qAuthors.execute(); 72 Test.ensure(results.size() == 4); 73 while(results.hasNext()){ 74 Person person = (Person)results.next(); 75 Test.ensure(person.lastName.endsWith("OK")); 76 } 77 } 78 79 80 public String toString(){ 81 String ret = title; 82 if(authors != null){ 83 for (int i = 0; i < authors.length; i++) { 84 ret += "\n " + authors[i].toString(); 85 } 86 } 87 return ret; 88 } 89 } 90 | Popular Tags |