KickJava   Java API By Example, From Geeks To Geeks.

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


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.index.IndexCondition;
11 import org.h2.message.Message;
12 import org.h2.table.ColumnResolver;
13 import org.h2.table.TableFilter;
14 import org.h2.value.Value;
15 import org.h2.value.ValueBoolean;
16 import org.h2.value.ValueNull;
17
18 public class ValueExpression extends Expression {
19     private Value value;
20     
21     public static final ValueExpression NULL = new ValueExpression(ValueNull.INSTANCE);
22     
23     public static ValueExpression get(Value v) {
24         if(v == ValueNull.INSTANCE) {
25             return ValueExpression.NULL;
26         }
27         return new ValueExpression(v);
28     }
29     
30     private ValueExpression(Value value) {
31         this.value = value;
32     }
33
34     public Value getValue(Session session) {
35         return value;
36     }
37
38     public int getType() {
39         return value.getType();
40     }
41     
42     public void createIndexConditions(TableFilter filter) {
43         if(value.getType() == Value.BOOLEAN) {
44             boolean v = ((ValueBoolean)value).getBoolean().booleanValue();
45             if(!v) {
46                 filter.addIndexCondition(new IndexCondition(Comparison.FALSE, null, this));
47             }
48         }
49     }
50
51     public void mapColumns(ColumnResolver resolver, int level) throws SQLException JavaDoc {
52     }
53
54     public Expression optimize(Session session) throws SQLException JavaDoc {
55         return this;
56     }
57     
58     public boolean isConstant() {
59         return true;
60     }
61
62     public void setEvaluatable(TableFilter tableFilter, boolean b) {
63     }
64
65     public int getScale() {
66         return value.getScale();
67     }
68
69     public long getPrecision() {
70         return value.getPrecision();
71     }
72
73     public String JavaDoc getSQL() {
74         return value.getSQL();
75     }
76
77     public void updateAggregate(Session session) throws SQLException JavaDoc {
78     }
79
80     public boolean isEverything(ExpressionVisitor visitor) {
81         switch(visitor.type) {
82         case ExpressionVisitor.OPTIMIZABLE_MIN_MAX_COUNT_ALL:
83             return true;
84         case ExpressionVisitor.DETERMINISTIC:
85         case ExpressionVisitor.READONLY:
86             return true;
87         case ExpressionVisitor.INDEPENDENT:
88             return true;
89         case ExpressionVisitor.EVALUATABLE:
90             return true;
91         case ExpressionVisitor.SET_MAX_DATA_MODIFICATION_ID:
92             return true;
93         default:
94             throw Message.getInternalError("type="+visitor.type);
95         }
96     }
97
98     public int getCost() {
99         return 0;
100     }
101
102 }
103
Popular Tags