1 5 package org.h2.index; 6 7 import java.sql.SQLException ; 8 9 import org.h2.result.Row; 10 import org.h2.result.SearchRow; 11 12 13 public class TreeCursor implements Cursor { 14 private TreeIndex tree; 15 private TreeNode node; 16 private boolean beforeFirst; 17 private SearchRow first, last; 18 19 TreeCursor(TreeIndex tree, TreeNode node, SearchRow first, SearchRow last) { 20 this.tree = tree; 21 this.node = node; 22 this.first = first; 23 this.last = last; 24 beforeFirst = true; 25 } 26 27 public Row get() { 28 return node == null ? null : node.row; 29 } 30 31 public int getPos() { 32 return node == null ? -1 : node.row.getPos(); 33 } 34 35 public boolean next() throws SQLException { 36 if(beforeFirst) { 37 beforeFirst = false; 38 if(node == null) { 39 return false; 40 } 41 if (first != null && tree.compareRows(node.row, first) < 0) { 42 node = tree.next(node); 43 } 44 } else { 45 node = tree.next(node); 46 } 47 if(node != null && last != null) { 48 if (tree.compareRows(node.row, last) > 0) { 49 node = null; 50 } 51 } 52 return node != null; 53 } 54 55 } 56 | Popular Tags |