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.internal.fieldindex;
22:
23: import com.db4o.foundation.*;
24: import com.db4o.internal.*;
25: import com.db4o.internal.btree.*;
26: import com.db4o.internal.query.processor.*;
27:
28: public abstract class IndexedNodeBase implements IndexedNode {
29:
30: private final QConObject _constraint;
31:
32: public IndexedNodeBase(QConObject qcon) {
33: if (null == qcon) {
34: throw new ArgumentNullException();
35: }
36: if (null == qcon.getField()) {
37: throw new IllegalArgumentException();
38: }
39: _constraint = qcon;
40: }
41:
42: public TreeInt toTreeInt() {
43: return addToTree(null, this );
44: }
45:
46: public final BTree getIndex() {
47: return getYapField().getIndex(transaction());
48: }
49:
50: private FieldMetadata getYapField() {
51: return _constraint.getField().getYapField();
52: }
53:
54: public QCon constraint() {
55: return _constraint;
56: }
57:
58: public boolean isResolved() {
59: final QCon parent = constraint().parent();
60: return null == parent || !parent.hasParent();
61: }
62:
63: public BTreeRange search(final Object value) {
64: return getYapField().search(transaction(), value);
65: }
66:
67: public static TreeInt addToTree(TreeInt tree, final IndexedNode node) {
68: Iterator4 i = node.iterator();
69: while (i.moveNext()) {
70: FieldIndexKey composite = (FieldIndexKey) i.current();
71: tree = (TreeInt) Tree.add(tree, new TreeInt(composite
72: .parentID()));
73: }
74: return tree;
75: }
76:
77: public IndexedNode resolve() {
78: if (isResolved()) {
79: return null;
80: }
81: return IndexedPath.newParentPath(this , constraint());
82: }
83:
84: private Transaction transaction() {
85: return constraint().transaction();
86: }
87:
88: }
|