| 1 package com.daffodilwoods.daffodildb.server.datasystem.indexsystem; 2 3 import com.daffodilwoods.database.resource.DException; 4 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 5 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.booleanvalueexpression; 6 import com.daffodilwoods.daffodildb.utils.parser.*; 7 import com.daffodilwoods.daffodildb.server.sql99.dql.queryexpression.*; 8 import com.daffodilwoods.daffodildb.server.datasystem.btree.BTree; 9 import com.daffodilwoods.daffodildb.server.datasystem.btree.BTreeElement; 10 import com.daffodilwoods.daffodildb.server.datasystem.btree.BTreeKey; 11 12 15 16 public class BTreeIterator { 17 18 BTree btree; 19 booleanvalueexpression condition; 20 _VariableValues variableValues; 21 BTreeKey currentKey; 22 _Reference[] references; 23 24 public BTreeIterator(BTree btree0,booleanvalueexpression condition0,_VariableValues variableValues0,_Reference[] references0) { 25 btree = btree0; 26 condition = condition0; 27 variableValues = variableValues0; 28 references = references0; 29 } 30 31 public boolean first() throws DException{ 32 boolean flag = btree.first(currentKey); 33 while(flag) { 34 Object vals = currentKey.getKey(); 35 variableValues.setConditionVariableValue(references,vals instanceof Object [] ? (Object [])vals : new Object [] {vals},0); 36 if(condition.run(variableValues).hashCode() == 0){ 37 move(currentKey); 38 return true; 39 } 40 flag = btree.next(currentKey); 41 } 42 return false; 43 } 44 45 public boolean next() throws DException{ 46 boolean flag = btree.next(currentKey); 47 while(flag) { 48 Object vals = currentKey.getKey(); 49 variableValues.setConditionVariableValue(references,vals instanceof Object [] ? (Object [])vals : new Object [] {vals},0); 50 if(condition.run(variableValues).hashCode() == 0){ 51 move(currentKey); 52 return true; 53 } 54 flag = btree.next(currentKey); 55 } 56 return false; 57 } 58 59 public boolean last() throws DException{ 60 boolean flag = btree.last(currentKey); 61 while(flag) { 62 Object vals = currentKey.getKey(); 63 variableValues.setConditionVariableValue(references,vals instanceof Object [] ? (Object [])vals : new Object [] {vals},0); 64 if(condition.run(variableValues).hashCode() == 0){ 65 move(currentKey); 66 return true; 67 } 68 flag = btree.previous(currentKey); 69 } 70 return false; 71 } 72 73 public boolean previous() throws DException{ 74 boolean flag = btree.previous(currentKey); 75 while(flag) { 76 Object vals = currentKey.getKey(); 77 variableValues.setConditionVariableValue(references,vals instanceof Object [] ? (Object [])vals : new Object [] {vals},0); 78 if(condition.run(variableValues).hashCode() == 0){ 79 move(currentKey); 80 return true; 81 } 82 flag = btree.previous(currentKey); 83 } 84 return false; 85 } 86 87 public Object getKey() throws DException{ 88 return currentKey; 89 } 90 91 public Object getObject() throws DException{ 92 return currentKey == null ? null : currentKey.getValue(); 93 } 94 95 public void move(Object key) throws DException{ 96 currentKey = (BTreeKey)key; 97 } 98 } 99 | Popular Tags |