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.engine.Session;
11: import org.h2.message.Message;
12: import org.h2.result.Row;
13: import org.h2.result.SearchRow;
14: import org.h2.table.IndexColumn;
15: import org.h2.table.RangeTable;
16: import org.h2.value.Value;
17: import org.h2.value.ValueLong;
18:
19: /**
20: * An index for the SYSTEM_RANGE table.
21: * This index can only scan through all rows, search is not supported.
22: */
23: public class RangeIndex extends BaseIndex {
24:
25: private long min, max;
26:
27: public RangeIndex(RangeTable table, IndexColumn[] columns,
28: long min, long max) {
29: super (table, 0, "RANGE_INDEX", columns, IndexType
30: .createNonUnique(true));
31: this .min = min;
32: this .max = max;
33: }
34:
35: public void close(Session session) throws SQLException {
36: }
37:
38: public void add(Session session, Row row) throws SQLException {
39: throw Message.getUnsupportedException();
40: }
41:
42: public void remove(Session session, Row row) throws SQLException {
43: throw Message.getUnsupportedException();
44: }
45:
46: public Cursor find(Session session, SearchRow first, SearchRow last)
47: throws SQLException {
48: long start = Math.max(min, first == null ? min : first
49: .getValue(0).getLong());
50: long end = Math.min(max, last == null ? max : last.getValue(0)
51: .getLong());
52: return new RangeCursor(start, end);
53: }
54:
55: public double getCost(Session session, int[] masks)
56: throws SQLException {
57: return 1;
58: }
59:
60: public String getCreateSQL() {
61: return null;
62: }
63:
64: public void remove(Session session) throws SQLException {
65: throw Message.getUnsupportedException();
66: }
67:
68: public void truncate(Session session) throws SQLException {
69: throw Message.getUnsupportedException();
70: }
71:
72: public boolean needRebuild() {
73: return false;
74: }
75:
76: public void checkRename() throws SQLException {
77: throw Message.getUnsupportedException();
78: }
79:
80: public boolean canGetFirstOrLast() {
81: return true;
82: }
83:
84: public SearchRow findFirstOrLast(Session session, boolean first)
85: throws SQLException {
86: return new Row(
87: new Value[] { ValueLong.get(first ? min : max) }, 0);
88: }
89:
90: }
|