001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.test;
022:
023: import com.db4o.*;
024: import com.db4o.config.*;
025: import com.db4o.ext.*;
026: import com.db4o.foundation.*;
027:
028: public class TraverseIndexedFieldValues {
029:
030: private static final int COUNT = 30;
031:
032: public Atom _atom;
033:
034: public String _string;
035:
036: public int _int;
037:
038: public TraverseIndexedFieldValues() {
039:
040: }
041:
042: public TraverseIndexedFieldValues(Atom atom, String str, int anint) {
043: _atom = atom;
044: _string = str;
045: _int = anint;
046: }
047:
048: public void configure() {
049: ObjectClass objectClass = Db4o.configure().objectClass(
050: getClass());
051: objectClass.objectField("_atom").indexed(true);
052: objectClass.objectField("_string").indexed(true);
053: objectClass.objectField("_int").indexed(true);
054: }
055:
056: public void store() {
057: for (int i = 0; i < COUNT; i++) {
058: String str = "" + i;
059: Test.store(new TraverseIndexedFieldValues(new Atom(str),
060: str, i));
061: }
062: }
063:
064: public void test() {
065: final ExtObjectContainer oc = Test.objectContainer();
066: StoredClass sc = oc.storedClass(this );
067:
068: StoredField atomField = sc.storedField("_atom", null);
069: StoredField stringField = sc.storedField("_string", null);
070: StoredField intField = sc.storedField("_int", null);
071:
072: final Collection4 fieldValues = new Collection4();
073:
074: atomField.traverseValues(new Visitor4() {
075: public void visit(Object obj) {
076: oc.activate(obj, 1);
077: Test.ensure(!fieldValues.contains(obj));
078: Test.ensure(obj instanceof Atom);
079: fieldValues.add(obj);
080: }
081: });
082:
083: Test.ensure(fieldValues.size() == COUNT);
084:
085: fieldValues.clear();
086:
087: stringField.traverseValues(new Visitor4() {
088: public void visit(Object obj) {
089: Test.ensure(!fieldValues.contains(obj));
090: Test.ensure(obj instanceof String);
091: fieldValues.add(obj);
092: }
093: });
094:
095: Test.ensure(fieldValues.size() == COUNT);
096:
097: fieldValues.clear();
098:
099: intField.traverseValues(new Visitor4() {
100: public void visit(Object obj) {
101: Test.ensure(!fieldValues.contains(obj));
102: Test.ensure(obj instanceof Integer);
103: fieldValues.add(obj);
104: }
105: });
106:
107: Test.ensure(fieldValues.size() == COUNT);
108: }
109:
110: }
|