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 20 public class BTreeElement implements _Key { 21 22 25 private Object key; 26 27 30 31 private Object value; 32 33 36 37 38 41 42 protected BTreeNode childNode; 43 44 47 48 protected BTreeNode currentNode; 49 50 53 54 protected int position = -1; 55 56 59 private boolean isDummy; 60 61 62 public BTreeElement() { 63 isDummy = true; 64 } 65 66 public BTreeElement(Object key0,Object value0) { 67 key = key0; 68 value = value0; 69 isDummy = false; 70 } 71 72 76 public Object getKey() throws DException{ 77 return key; 78 } 79 80 84 85 86 public Object getValue() throws DException{ 87 return value; 88 } 89 90 93 94 public BTreeNode getChild() throws DException{ 95 return childNode; 96 } 97 98 public void setKey(Object key0) { 99 key = key0; 100 } 101 102 public void setValue(Object 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 getKeyValue() throws DException { 126 return getKey(); 127 } 128 129 public String toString() { 130 String str = ""; 131 try { 132 CbCzufIboemfs[] handlers = null; 133 try { 134 handlers = currentNode.getByteHandlers(); 135 } 136 catch (Exception ex) { 137 return " HANDLERS ARE NULL "; 138 } 139 Object kee = getObject(key,handlers); 140 str = "KEY : "+ ( kee instanceof Object [] ? P.print(kee) : kee) +" VALUE : "+value; 141 str += " child node :: " + getChildNodeKey(); 142 } 143 catch (Exception ex) { 144 } 145 return str; 146 } 147 148 private Object getObject(Object 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 [] values = new Object [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 getChildNodeKey(){ 185 return childNode; 186 } 187 188 public void clearChild() { 189 childNode = null; 190 } 191 192 } 193 | Popular Tags |