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.db4ounit.common.fieldindex;
22:
23: import com.db4o.*;
24: import com.db4o.config.*;
25: import com.db4o.diagnostic.Diagnostic;
26: import com.db4o.diagnostic.DiagnosticListener;
27: import com.db4o.diagnostic.LoadedFromClassIndex;
28: import com.db4o.query.Query;
29:
30: import db4ounit.*;
31: import db4ounit.extensions.*;
32:
33: public class SecondLevelIndexTestCase extends AbstractDb4oTestCase
34: implements DiagnosticListener {
35:
36: public static void main(String[] arguments) {
37: new SecondLevelIndexTestCase().runSolo();
38: }
39:
40: public static class ItemPair {
41:
42: public Item item1;
43:
44: public Item item2;
45:
46: public ItemPair() {
47: }
48:
49: public ItemPair(Item item_, Item item2_) {
50: item1 = item_;
51: item2 = item2_;
52: }
53: }
54:
55: public static class Item {
56:
57: public String name;
58:
59: public Item() {
60: }
61:
62: public Item(String name_) {
63: name = name_;
64: }
65: }
66:
67: protected void configure(Configuration config) throws Exception {
68: config.diagnostic().addListener(this );
69: config.objectClass(Item.class).objectField("name")
70: .indexed(true);
71: config.objectClass(ItemPair.class).objectField("item1")
72: .indexed(true);
73: config.objectClass(ItemPair.class).objectField("item2")
74: .indexed(true);
75: super .configure(config);
76: }
77:
78: protected void db4oTearDownBeforeClean() throws Exception {
79: Db4o.configure().diagnostic().removeAllListeners();
80: }
81:
82: public void test() {
83: Item itemOne = new Item("one");
84: Item itemTwo = new Item("two");
85: store(new ItemPair(itemOne, itemTwo));
86: Query query = newQuery(ItemPair.class);
87: query.descend("item2").descend("name").constrain("two");
88: ObjectSet objectSet = query.execute();
89: Assert.areEqual(((ItemPair) objectSet.next()).item1, itemOne);
90: }
91:
92: public void onDiagnostic(Diagnostic d) {
93: Assert.isFalse(d instanceof LoadedFromClassIndex);
94: }
95:
96: }
|