File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\index\MetaIndex.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.ArrayList;
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 import org.h2.table.Column;
15 import org.h2.table.IndexColumn;
16 import org.h2.table.MetaTable;
17
18 /**
19 * The index implementation for meta data tables.
20 */
21 public class MetaIndex extends BaseIndex {
22
23 private final MetaTable meta;
24 private final boolean scan;
25
26 public MetaIndex(MetaTable meta, IndexColumn[] columns, boolean scan) {
27 initBaseIndex(meta, 0, null, columns, IndexType.createNonUnique(true));
28 this.meta = meta;
29 this.scan = scan;
30 }
31
32 public void close(Session session) {
33 // nothing to do
34 }
35
36 public void add(Session session, Row row) {
37 throw DbException.getUnsupportedException("META");
38 }
39
40 public void remove(Session session, Row row) {
41 throw DbException.getUnsupportedException("META");
42 }
43
44 public Cursor find(Session session, SearchRow first, SearchRow last) {
45 ArrayList<Row> rows = meta.generateRows(session, first, last);
46 return new MetaCursor(rows);
47 }
48
49 public double getCost(Session session, int[] masks) {
50 if (scan) {
51 return 10 * MetaTable.ROW_COUNT_APPROXIMATION;
52 }
53 return getCostRangeIndex(masks, MetaTable.ROW_COUNT_APPROXIMATION);
54 }
55
56 public void truncate(Session session) {
57 throw DbException.getUnsupportedException("META");
58 }
59
60 public void remove(Session session) {
61 throw DbException.getUnsupportedException("META");
62 }
63
64 public int getColumnIndex(Column col) {
65 if (scan) {
66 // the scan index cannot use any columns
67 return -1;
68 }
69 return super.getColumnIndex(col);
70 }
71
72 public void checkRename() {
73 throw DbException.getUnsupportedException("META");
74 }
75
76 public boolean needRebuild() {
77 return false;
78 }
79
80 public String getCreateSQL() {
81 return null;
82 }
83
84 public boolean canGetFirstOrLast() {
85 return false;
86 }
87
88 public Cursor findFirstOrLast(Session session, boolean first) {
89 throw DbException.getUnsupportedException("META");
90 }
91
92 public long getRowCount(Session session) {
93 return MetaTable.ROW_COUNT_APPROXIMATION;
94 }
95
96 public long getRowCountApproximation() {
97 return MetaTable.ROW_COUNT_APPROXIMATION;
98 }
99
100 public String getPlanSQL() {
101 return "meta";
102 }
103
104 }
105