File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\index\PageDataCursor.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 java.util.Iterator;
10 import org.h2.engine.Session;
11 import org.h2.message.DbException;
12 import org.h2.result.Row;
13 import org.h2.result.SearchRow;
14
15 /**
16 * The cursor implementation for the page scan index.
17 */
18 class PageDataCursor implements Cursor {
19
20 private PageDataLeaf current;
21 private int idx;
22 private final long maxKey;
23 private Row row;
24 private final boolean multiVersion;
25 private final Session session;
26 private Iterator<Row> delta;
27
28 PageDataCursor(Session session, PageDataLeaf current, int idx, long maxKey, boolean multiVersion) {
29 this.current = current;
30 this.idx = idx;
31 this.maxKey = maxKey;
32 this.multiVersion = multiVersion;
33 this.session = session;
34 if (multiVersion) {
35 delta = current.index.getDelta();
36 }
37 }
38
39 public Row get() {
40 return row;
41 }
42
43 public SearchRow getSearchRow() {
44 return get();
45 }
46
47 public boolean next() {
48 if (!multiVersion) {
49 nextRow();
50 return checkMax();
51 }
52 while (true) {
53 if (delta != null) {
54 if (!delta.hasNext()) {
55 delta = null;
56 row = null;
57 continue;
58 }
59 row = delta.next();
60 if (!row.isDeleted() || row.getSessionId() == session.getId()) {
61 continue;
62 }
63 } else {
64 nextRow();
65 if (row != null && row.getSessionId() != 0 && row.getSessionId() != session.getId()) {
66 continue;
67 }
68 }
69 break;
70 }
71 return checkMax();
72 }
73
74 private boolean checkMax() {
75 if (row != null) {
76 if (maxKey != Long.MAX_VALUE) {
77 long x = current.index.getKey(row, Long.MAX_VALUE, Long.MAX_VALUE);
78 if (x > maxKey) {
79 row = null;
80 return false;
81 }
82 }
83 return true;
84 }
85 return false;
86 }
87
88 private void nextRow() {
89 if (idx >= current.getEntryCount()) {
90 current = current.getNextPage();
91 idx = 0;
92 if (current == null) {
93 row = null;
94 return;
95 }
96 }
97 row = current.getRowAt(idx);
98 idx++;
99 }
100
101 public boolean previous() {
102 throw DbException.throwInternalError();
103 }
104
105 }
106