1 package com.daffodilwoods.daffodildb.server.datasystem.btree; 2 3 import com.daffodilwoods.database.resource.DException; 4 import com.daffodilwoods.daffodildb.server.datasystem.interfaces._Index; 5 import com.daffodilwoods.database.utility.P; 6 import com.daffodilwoods.daffodildb.utils.BufferRange; 7 8 public class BTreeNavigatorCurrent extends BTreeNavigator{ 9 10 public BTreeNavigatorCurrent(_Index btree){ 11 super(btree); 12 } 13 14 public Object getCurrentKey() throws DException{ 15 BTreeKey currentKey2 = (BTreeKey)currentKey; 16 return status != 0 ? null : currentKey2; 17 } 18 19 public Object getKey()throws DException{ 20 BTreeKey currentKey2 = (BTreeKey)currentKey; 21 22 if(status != 0) 23 new Exception ("CHECK THE CASE").printStackTrace(); 24 Object oldValue = currentKey2.getValue(); 25 BTreeElement element = currentKey2.getNode().getElement(currentKey2.getPosition(),null); 26 Object newValue = element.getValue(); 27 if(oldValue.equals(newValue)){ 28 return element.getKey(); 29 } 30 else 31 throw StaticExceptions.RECORD_DELETED_EXCEPTION ; 32 } 33 34 public Object getValue()throws DException{ 35 BTreeKey currentKey2 = (BTreeKey)currentKey; 36 if(status != 0) 37 new Exception ("CHECK THE CASE " + currentKey2.getNode() + " position " + 38 currentKey2.getPosition()).printStackTrace(); 39 return currentKey2.getValue(); 40 } 41 public Object getColumnValues(int columnIndex) throws DException{ 42 int[] columns = btree.getIndexInformation().getColumnIndexes(); 43 int pos = P.indexOf(columns,columnIndex); 44 Object value = currentKey.getKey(); 45 if(pos == -1) 46 throw StaticExceptions.NOT_POSSIBLE; 47 return columns.length == 1 ? value : ((Object [])value)[pos]; 48 } 49 50 public Object getColumnValues(int[] columnIndexes) throws DException{ 51 int[] columns = btree.getIndexInformation().getColumnIndexes(); 52 int[] indexes = null; 53 if((indexes = canGive(columns,columnIndexes)) == null) 54 throw StaticExceptions.NOT_POSSIBLE; 55 Object [] value = (Object [])currentKey.getKey(); 56 BufferRange[] values = new BufferRange[columnIndexes.length]; 57 for(int i = 0; i < columnIndexes.length; i++) { 58 values[i] = (BufferRange)value[indexes[i]]; 59 } 60 return values; 61 } 62 63 private int[] canGive(int[] btreeColumns,int[] columns) { 64 if(columns.length > btreeColumns.length ) 65 return null; 66 int[] positions = new int[columns.length]; 67 for(int i = 0; i < columns.length; i++) { 68 if((positions[i] = P.indexOf(btreeColumns,columns[i])) == -1){ 69 return null; 70 } 71 } 72 return positions; 73 } 74 75 public void move(Object key)throws DException{ 76 super.move(key); 77 status = (((BTreeKey)currentKey).getNode() == null || ((BTreeKey)currentKey).getPosition() == 0 ) ? -1 : 0; 78 } 79 80 91 } 92 | Popular Tags |