KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > expression > Parameter


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.expression;
6
7 import java.sql.SQLException JavaDoc;
8
9 import org.h2.engine.Session;
10 import org.h2.message.Message;
11 import org.h2.table.ColumnResolver;
12 import org.h2.table.TableFilter;
13 import org.h2.value.Value;
14
15 /**
16  * @author Thomas
17  */

18 public class Parameter extends Expression implements ParameterInterface {
19
20     private Value value;
21     private int index;
22
23     public Parameter(int index) {
24         this.index = index;
25     }
26
27     public String JavaDoc getSQL() {
28         return "?" + (index + 1);
29     }
30
31     public void setValue(Value v) {
32         this.value = v;
33     }
34
35     public Value getParamValue() throws SQLException JavaDoc {
36         return value == null ? null : value;
37     }
38
39     public Value getValue(Session session) throws SQLException JavaDoc {
40         return getParamValue();
41     }
42
43     public int getType() {
44         return value == null ? Value.UNKNOWN : value.getType();
45     }
46
47     public void mapColumns(ColumnResolver resolver, int level) {
48         // can't map
49
}
50
51     public void checkMapped() {
52         // always ok
53
}
54
55     public void checkSet() throws SQLException JavaDoc {
56         if (value == null) {
57             throw Message.getSQLException(Message.PARAMETER_NOT_SET_1, String.valueOf(index + 1));
58         }
59     }
60
61     public Expression optimize(Session session) {
62         return this;
63     }
64
65     public boolean isConstant() {
66         return value != null;
67     }
68
69     public void setEvaluatable(TableFilter tableFilter, boolean b) {
70         // not bound
71
}
72
73     public int getScale() {
74         return value == null ? 0 : value.getScale();
75     }
76
77     public long getPrecision() {
78         return value == null ? 0 : value.getPrecision();
79     }
80
81     public void updateAggregate(Session session) {
82         // nothing to do
83
}
84
85     public boolean isEverything(ExpressionVisitor visitor) {
86         switch(visitor.type) {
87         case ExpressionVisitor.OPTIMIZABLE_MIN_MAX_COUNT_ALL:
88             return true;
89         case ExpressionVisitor.DETERMINISTIC:
90         case ExpressionVisitor.READONLY:
91             return true;
92         case ExpressionVisitor.INDEPENDENT:
93             return value != null;
94         case ExpressionVisitor.EVALUATABLE:
95             // the parameter _will_be_ evaluatable at execute time
96
return true;
97         case ExpressionVisitor.SET_MAX_DATA_MODIFICATION_ID:
98             // it is checked independently if the value is the same as the last time
99
return true;
100         default:
101             throw Message.getInternalError("type="+visitor.type);
102         }
103     }
104     
105     public int getCost() {
106         return 0;
107     }
108
109 }
110
Popular Tags