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:
10: import org.h2.message.Message;
11: import org.h2.result.Row;
12: import org.h2.result.SearchRow;
13: import org.h2.value.Value;
14: import org.h2.value.ValueLong;
15:
16: /**
17: * The cursor implementation for the range index.
18: */
19: public class RangeCursor implements Cursor {
20:
21: private boolean beforeFirst;
22: private long current;
23: private Row currentRow;
24: private long min, max;
25:
26: RangeCursor(long min, long max) {
27: this .min = min;
28: this .max = max;
29: beforeFirst = true;
30: }
31:
32: public Row get() {
33: return currentRow;
34: }
35:
36: public SearchRow getSearchRow() throws SQLException {
37: return currentRow;
38: }
39:
40: public int getPos() {
41: throw Message.getInternalError();
42: }
43:
44: public boolean next() throws SQLException {
45: if (beforeFirst) {
46: beforeFirst = false;
47: current = min;
48: } else {
49: current++;
50: }
51: currentRow = new Row(new Value[] { ValueLong.get(current) }, 0);
52: return current <= max;
53: }
54:
55: }
|