1 5 package org.h2.index; 6 7 import java.sql.SQLException ; 8 9 import org.h2.engine.Constants; 10 import org.h2.message.Message; 11 import org.h2.result.Row; 12 import org.h2.result.SearchRow; 13 14 17 public class BtreeCursor implements Cursor { 18 private BtreeIndex index; 19 private BtreePosition top; 20 private Row current; 21 private boolean first; 22 private SearchRow last; 23 24 BtreeCursor(BtreeIndex index, SearchRow last) { 25 this.index = index; 26 this.last = last; 27 first = true; 28 } 29 30 void setStackPosition(int position) { 31 top.position = position; 32 } 33 34 void push(BtreePage page, int position) { 35 if (Constants.CHECK && (top != null && top.page == page)) { 36 throw Message.getInternalError(); 37 } 38 top = new BtreePosition(page, position, top); 39 } 40 41 BtreePosition pop() { 42 BtreePosition t = top; 43 if (t == null) { 44 return null; 45 } 46 top = top.next; 47 return t; 48 } 49 50 void setCurrentRow(int pos) throws SQLException { 51 current = pos == POS_NO_ROW ? null : index.getRow(pos); 52 } 53 54 public Row get() throws SQLException { 55 return current; 56 } 57 58 public int getPos() { 59 return current.getPos(); 60 } 61 62 public boolean next() throws SQLException { 63 if (first) { 64 first = false; 65 return current != null; 66 } 67 top.page.next(this, top.position); 68 if(current != null && last != null) { 69 if (index.compareRows(current, last) > 0) { 70 current = null; 71 } 72 } 73 return current != null; 74 } 75 76 } 77 | Popular Tags |