File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\index\RangeIndex.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 org.h2.engine.Session;
10 import org.h2.message.DbException;
11 import org.h2.result.Row;
12 import org.h2.result.SearchRow;
13 import org.h2.table.IndexColumn;
14 import org.h2.table.RangeTable;
15
16 /**
17 * An index for the SYSTEM_RANGE table.
18 * This index can only scan through all rows, search is not supported.
19 */
20 public class RangeIndex extends BaseIndex {
21
22 private final RangeTable rangeTable;
23
24 public RangeIndex(RangeTable table, IndexColumn[] columns) {
25 initBaseIndex(table, 0, "RANGE_INDEX", columns, IndexType.createNonUnique(true));
26 this.rangeTable = table;
27 }
28
29 public void close(Session session) {
30 // nothing to do
31 }
32
33 public void add(Session session, Row row) {
34 throw DbException.getUnsupportedException("SYSTEM_RANGE");
35 }
36
37 public void remove(Session session, Row row) {
38 throw DbException.getUnsupportedException("SYSTEM_RANGE");
39 }
40
41 public Cursor find(Session session, SearchRow first, SearchRow last) {
42 long min = rangeTable.getMin(session), start = min;
43 long max = rangeTable.getMax(session), end = max;
44 try {
45 start = Math.max(min, first == null ? min : first.getValue(0).getLong());
46 } catch (Exception e) {
47 // error when converting the value - ignore
48 }
49 try {
50 end = Math.min(max, last == null ? max : last.getValue(0).getLong());
51 } catch (Exception e) {
52 // error when converting the value - ignore
53 }
54 return new RangeCursor(start, end);
55 }
56
57 public double getCost(Session session, int[] masks) {
58 return 1;
59 }
60
61 public String getCreateSQL() {
62 return null;
63 }
64
65 public void remove(Session session) {
66 throw DbException.getUnsupportedException("SYSTEM_RANGE");
67 }
68
69 public void truncate(Session session) {
70 throw DbException.getUnsupportedException("SYSTEM_RANGE");
71 }
72
73 public boolean needRebuild() {
74 return false;
75 }
76
77 public void checkRename() {
78 throw DbException.getUnsupportedException("SYSTEM_RANGE");
79 }
80
81 public boolean canGetFirstOrLast() {
82 return true;
83 }
84
85 public Cursor findFirstOrLast(Session session, boolean first) {
86 long pos = first ? rangeTable.getMin(session) : rangeTable.getMax(session);
87 return new RangeCursor(pos, pos);
88 }
89
90 public long getRowCount(Session session) {
91 return rangeTable.getRowCountApproximation();
92 }
93
94 public long getRowCountApproximation() {
95 return rangeTable.getRowCountApproximation();
96 }
97
98 }
99