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 org.h2.engine.Session;
10: import org.h2.message.Message;
11: import org.h2.result.Row;
12: import org.h2.result.SearchRow;
13: import org.h2.table.Column;
14: import org.h2.table.IndexColumn;
15: import org.h2.table.MetaTable;
16: import org.h2.util.ObjectArray;
17:
18: /**
19: * The index implementation for meta data tables.
20: */
21: public class MetaIndex extends BaseIndex {
22:
23: private MetaTable meta;
24: private boolean scan;
25:
26: public MetaIndex(MetaTable meta, IndexColumn[] columns, boolean scan) {
27: super (meta, 0, null, columns, IndexType.createNonUnique(true));
28: this .meta = meta;
29: this .scan = scan;
30: }
31:
32: public void close(Session session) throws SQLException {
33: // nothing to do
34: }
35:
36: public void add(Session session, Row row) throws SQLException {
37: throw Message.getUnsupportedException();
38: }
39:
40: public void remove(Session session, Row row) throws SQLException {
41: throw Message.getUnsupportedException();
42: }
43:
44: public Cursor find(Session session, SearchRow first, SearchRow last)
45: throws SQLException {
46: ObjectArray rows = meta.generateRows(session, first, last);
47: return new MetaCursor(rows);
48: }
49:
50: public double getCost(Session session, int[] masks)
51: throws SQLException {
52: if (scan) {
53: return 10000;
54: }
55: return getCostRangeIndex(masks, 1000);
56: }
57:
58: public void truncate(Session session) throws SQLException {
59: throw Message.getUnsupportedException();
60: }
61:
62: public void remove(Session session) throws SQLException {
63: throw Message.getUnsupportedException();
64: }
65:
66: public int getColumnIndex(Column col) {
67: if (scan) {
68: // the scan index cannot use any columns
69: return -1;
70: }
71: return super .getColumnIndex(col);
72: }
73:
74: public void checkRename() throws SQLException {
75: throw Message.getUnsupportedException();
76: }
77:
78: public boolean needRebuild() {
79: return false;
80: }
81:
82: public String getCreateSQL() {
83: return null;
84: }
85:
86: public boolean canGetFirstOrLast() {
87: return false;
88: }
89:
90: public SearchRow findFirstOrLast(Session session, boolean first)
91: throws SQLException {
92: throw Message.getUnsupportedException();
93: }
94:
95: }
|