File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\index\PageBtreeCursor.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.index;
8
9 import org.h2.engine.Session;
10 import org.h2.result.Row;
11 import org.h2.result.SearchRow;
12
13 /**
14 * The cursor implementation for the page b-tree index.
15 */
16 public class PageBtreeCursor implements Cursor {
17
18 private final Session session;
19 private final PageBtreeIndex index;
20 private final SearchRow last;
21 private PageBtreeLeaf current;
22 private int i;
23 private SearchRow currentSearchRow;
24 private Row currentRow;
25
26 PageBtreeCursor(Session session, PageBtreeIndex index, SearchRow last) {
27 this.session = session;
28 this.index = index;
29 this.last = last;
30 }
31
32 /**
33 * Set the position of the current row.
34 *
35 * @param current the leaf page
36 * @param i the index within the page
37 */
38 void setCurrent(PageBtreeLeaf current, int i) {
39 this.current = current;
40 this.i = i;
41 }
42
43 public Row get() {
44 if (currentRow == null && currentSearchRow != null) {
45 currentRow = index.getRow(session, currentSearchRow.getKey());
46 }
47 return currentRow;
48 }
49
50 public SearchRow getSearchRow() {
51 return currentSearchRow;
52 }
53
54 public boolean next() {
55 if (current == null) {
56 return false;
57 }
58 if (i >= current.getEntryCount()) {
59 current.nextPage(this);
60 if (current == null) {
61 return false;
62 }
63 }
64 currentSearchRow = current.getRow(i);
65 currentRow = null;
66 if (last != null && index.compareRows(currentSearchRow, last) > 0) {
67 currentSearchRow = null;
68 return false;
69 }
70 i++;
71 return true;
72 }
73
74 public boolean previous() {
75 if (current == null) {
76 return false;
77 }
78 if (i < 0) {
79 current.previousPage(this);
80 if (current == null) {
81 return false;
82 }
83 }
84 currentSearchRow = current.getRow(i);
85 currentRow = null;
86 i--;
87 return true;
88 }
89
90 }
91