01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (http://h2database.com/html/license.html).
04: * Initial Developer: H2 Group
05: */
06: package org.h2.index;
07:
08: import java.sql.SQLException;
09: import java.util.Iterator;
10: import org.h2.engine.Session;
11: import org.h2.result.Row;
12: import org.h2.result.SearchRow;
13:
14: /**
15: * The cursor implementation for the scan index.
16: */
17: public class ScanCursor implements Cursor {
18: private ScanIndex scan;
19: private Row row;
20: private final Session session;
21: private final boolean multiVersion;
22: private Iterator delta;
23:
24: ScanCursor(Session session, ScanIndex scan, boolean multiVersion) {
25: this .session = session;
26: this .scan = scan;
27: this .multiVersion = multiVersion;
28: if (multiVersion) {
29: delta = scan.getDelta();
30: }
31: row = null;
32: }
33:
34: public Row get() {
35: return row;
36: }
37:
38: public SearchRow getSearchRow() {
39: return row;
40: }
41:
42: public int getPos() {
43: return row.getPos();
44: }
45:
46: public boolean next() throws SQLException {
47: if (multiVersion) {
48: while (true) {
49: if (delta != null) {
50: if (!delta.hasNext()) {
51: delta = null;
52: row = null;
53: continue;
54: } else {
55: row = (Row) delta.next();
56: if (!row.getDeleted()
57: || row.getSessionId() == session
58: .getId()) {
59: continue;
60: }
61: }
62: } else {
63: row = scan.getNextRow(session, row);
64: if (row != null && row.getSessionId() != 0
65: && row.getSessionId() != session.getId()) {
66: continue;
67: }
68: }
69: break;
70: }
71: return row != null;
72: }
73: row = scan.getNextRow(session, row);
74: return row != null;
75: }
76: }
|