File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\index\FunctionIndex.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.FunctionTable;
14 import org.h2.table.IndexColumn;
15
16 /**
17 * An index for a function that returns a result set. This index can only scan
18 * through all rows, search is not supported.
19 */
20 public class FunctionIndex extends BaseIndex {
21
22 private final FunctionTable functionTable;
23
24 public FunctionIndex(FunctionTable functionTable, IndexColumn[] columns) {
25 initBaseIndex(functionTable, 0, null, columns, IndexType.createNonUnique(true));
26 this.functionTable = functionTable;
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("ALIAS");
35 }
36
37 public void remove(Session session, Row row) {
38 throw DbException.getUnsupportedException("ALIAS");
39 }
40
41 public Cursor find(Session session, SearchRow first, SearchRow last) {
42 if (functionTable.isFast()) {
43 return new FunctionCursorResultSet(session, functionTable.getResultSet(session));
44 }
45 return new FunctionCursor(functionTable.getResult(session));
46 }
47
48 public double getCost(Session session, int[] masks) {
49 if (masks != null) {
50 throw DbException.getUnsupportedException("ALIAS");
51 }
52 long expectedRows;
53 if (functionTable.canGetRowCount()) {
54 expectedRows = functionTable.getRowCountApproximation();
55 } else {
56 expectedRows = database.getSettings().estimatedFunctionTableRows;
57 }
58 return expectedRows * 10;
59 }
60
61 public void remove(Session session) {
62 throw DbException.getUnsupportedException("ALIAS");
63 }
64
65 public void truncate(Session session) {
66 throw DbException.getUnsupportedException("ALIAS");
67 }
68
69 public boolean needRebuild() {
70 return false;
71 }
72
73 public void checkRename() {
74 throw DbException.getUnsupportedException("ALIAS");
75 }
76
77 public boolean canGetFirstOrLast() {
78 return false;
79 }
80
81 public Cursor findFirstOrLast(Session session, boolean first) {
82 throw DbException.getUnsupportedException("ALIAS");
83 }
84
85 public long getRowCount(Session session) {
86 return functionTable.getRowCount(session);
87 }
88
89 public long getRowCountApproximation() {
90 return functionTable.getRowCountApproximation();
91 }
92
93 public String getPlanSQL() {
94 return "function";
95 }
96
97 public boolean canScan() {
98 return false;
99 }
100
101 }
102