File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\index\ScanCursor.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 scan index.
17 */
18 public class ScanCursor implements Cursor {
19 private final ScanIndex scan;
20 private Row row;
21 private final Session session;
22 private final boolean multiVersion;
23 private Iterator<Row> delta;
24
25 ScanCursor(Session session, ScanIndex scan, boolean multiVersion) {
26 this.session = session;
27 this.scan = scan;
28 this.multiVersion = multiVersion;
29 if (multiVersion) {
30 delta = scan.getDelta();
31 }
32 row = null;
33 }
34
35 public Row get() {
36 return row;
37 }
38
39 public SearchRow getSearchRow() {
40 return row;
41 }
42
43 public boolean next() {
44 if (multiVersion) {
45 while (true) {
46 if (delta != null) {
47 if (!delta.hasNext()) {
48 delta = null;
49 row = null;
50 continue;
51 }
52 row = delta.next();
53 if (!row.isDeleted() || row.getSessionId() == session.getId()) {
54 continue;
55 }
56 } else {
57 row = scan.getNextRow(row);
58 if (row != null && row.getSessionId() != 0 && row.getSessionId() != session.getId()) {
59 continue;
60 }
61 }
62 break;
63 }
64 return row != null;
65 }
66 row = scan.getNextRow(row);
67 return row != null;
68 }
69
70 public boolean previous() {
71 throw DbException.throwInternalError();
72 }
73
74 }
75