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.ix;
22:
23: import com.db4o.foundation.*;
24: import com.db4o.internal.*;
25:
26: /**
27: * Node for index tree, can be addition or removal node
28: */
29: public abstract class IxPatch extends IxTree {
30:
31: int _parentID;
32:
33: Object _value;
34:
35: private Queue4 _queue; // queue of patch objects for the same parent
36:
37: IxPatch(IndexTransaction a_ft, int a_parentID, Object a_value) {
38: super (a_ft);
39: _parentID = a_parentID;
40: _value = a_value;
41: }
42:
43: public Tree add(final Tree a_new) {
44: int cmp = compare(a_new);
45: if (cmp == 0) {
46: IxPatch patch = (IxPatch) a_new;
47: cmp = _parentID - patch._parentID;
48:
49: if (cmp == 0) {
50:
51: Queue4 queue = _queue;
52:
53: if (queue == null) {
54: queue = new NonblockingQueue();
55: queue.add(this );
56: }
57:
58: queue.add(patch);
59: patch._queue = queue;
60: patch._subsequent = _subsequent;
61: patch._preceding = _preceding;
62: patch.calculateSize();
63: return patch;
64: }
65: }
66: return add(a_new, cmp);
67: }
68:
69: public int compare(Tree a_to) {
70: Indexable4 handler = _fieldTransaction.i_index._handler;
71: return handler.compareTo(IxDeprecationHelper.comparableObject(
72: handler, trans(), _value));
73: }
74:
75: public boolean hasQueue() {
76: return _queue != null;
77: }
78:
79: public Queue4 detachQueue() {
80: Queue4 queue = _queue;
81: this ._queue = null;
82: return queue;
83: }
84:
85: protected Tree shallowCloneInternal(Tree tree) {
86: IxPatch patch = (IxPatch) super.shallowCloneInternal(tree);
87: patch._parentID = _parentID;
88: patch._value = _value;
89: patch._queue = _queue;
90: return patch;
91: }
92: }
|