KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > datasystem > btree > BTreeElement


1 package com.daffodilwoods.daffodildb.server.datasystem.btree;
2
3 import com.daffodilwoods.database.utility.P;
4 import com.daffodilwoods.database.resource.*;
5 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*;
6 import java.util.*;
7 import com.daffodilwoods.daffodildb.utils.byteconverter.CbCzufIboemfs;
8 import com.daffodilwoods.daffodildb.utils.BufferRange;
9
10
11 /**
12  *
13  * <p>Title: BTreeElement</p>
14  * <p>Description: BTreeElement is the smallest entity in IndexSystem.It represent a single element of
15  * BTree Node.
16  *
17  *
18  * Every BTree Element contains a pair of BtreeKey and BTreeValue and it's child node address . </p>
19  */

20 public class BTreeElement implements _Key {
21
22     /**
23      * Key of Element in Btree, It is made of Values of Columns on which Index is Maintained
24      */

25     private Object JavaDoc key;
26
27     /**
28      * Value of Element in BTree, which is Key of Record In table
29      */

30
31     private Object JavaDoc value;
32
33     /**
34      * This element is Deleted Or Not
35      */

36
37
38     /**
39      * child Node of this Element in BTree
40      */

41
42     protected BTreeNode childNode;
43
44     /**
45      * Node in which this element exists
46      */

47
48     protected BTreeNode currentNode;
49
50     /**
51      * Position Of This Elment In It's CurrentNode
52      */

53
54     protected int position = -1;
55
56     /**
57      * Is Btree element is Dummy
58      */

59     private boolean isDummy;
60
61
62     public BTreeElement() {
63         isDummy = true;
64     }
65
66     public BTreeElement(Object JavaDoc key0,Object JavaDoc value0) {
67         key = key0;
68         value = value0;
69         isDummy = false;
70     }
71
72     /**
73      * returns key of this btreeElement
74      * @return key of this btreeElement
75      */

76     public Object JavaDoc getKey() throws DException{
77         return key;
78     }
79
80     /**
81      * returns value of this btreeElement
82      * @return value of this btreeElement
83      */

84
85
86     public Object JavaDoc getValue() throws DException{
87         return value;
88     }
89
90     /**
91      * Returns the child node of this element
92      */

93
94     public BTreeNode getChild() throws DException{
95         return childNode;
96     }
97
98     public void setKey(Object JavaDoc key0) {
99         key = key0;
100     }
101
102     public void setValue(Object JavaDoc value0) {
103         value = value0;
104     }
105
106
107     public BTreeNode getCurrentNode() {
108         return currentNode;
109     }
110
111     public int getPosition() {
112         return position;
113     }
114
115     public void setCurrentNode(BTreeNode node) {
116         currentNode = node;
117     }
118
119     public void setPosition(int pos) {
120         if(pos == -1)
121             Thread.dumpStack();
122         position = pos;
123     }
124
125     public Object JavaDoc getKeyValue() throws DException {
126         return getKey();
127     }
128
129     public String JavaDoc toString() {
130       String JavaDoc str = "";
131       try {
132           CbCzufIboemfs[] handlers = null;
133           try {
134               handlers = currentNode.getByteHandlers();
135           }
136           catch (Exception JavaDoc ex) {
137                 return " HANDLERS ARE NULL ";
138           }
139           Object JavaDoc kee = getObject(key,handlers);
140           str = "KEY : "+ ( kee instanceof Object JavaDoc[] ? P.print(kee) : kee) +" VALUE : "+value;
141           str += " child node :: " + getChildNodeKey();
142       }
143       catch (Exception JavaDoc ex) {
144       }
145       return str;
146   }
147
148     private Object JavaDoc getObject(Object JavaDoc bb ,CbCzufIboemfs[] handlers) throws DException{
149         if(bb == null)
150             return null;
151         int [] columnTypes = currentNode.getColumnTypes();
152         if(bb instanceof BufferRange){
153             if(((BufferRange)bb).getNull())
154                 return null;
155             return handlers[0].getObject((BufferRange)bb,columnTypes[0]);
156         }
157         BufferRange[] bytes = (BufferRange[])bb;
158         Object JavaDoc[] values = new Object JavaDoc[bytes.length];
159         for (int i = 0; i < bytes.length; i++)
160             values[i] = bytes[i].getNull() ? null : handlers[i].getObject(bytes[i],columnTypes[i]).getObject();
161         return values;
162     }
163
164     public void setChild(BTreeNode node) throws DException{
165         childNode = node;
166         if(childNode != null){
167           childNode.setParentNode(currentNode);
168           childNode.setParentElement(this);
169         }
170     }
171
172     public void makeDummy() {
173         isDummy = true;
174     }
175
176     public boolean isDummy() {
177         return isDummy;
178     }
179
180     public void updateChild(BTreeNode node) throws DException{
181         setChild(node);
182     }
183
184     public Object JavaDoc getChildNodeKey(){
185         return childNode;
186     }
187
188     public void clearChild() {
189       childNode = null;
190     }
191
192 }
193
Popular Tags