KickJava   Java API By Example, From Geeks To Geeks.

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


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.table.Column;
11 import org.h2.table.ColumnResolver;
12 import org.h2.table.TableFilter;
13 import org.h2.util.StringUtils;
14 import org.h2.value.Value;
15
16
17 /**
18  * @author Thomas
19  */

20 public abstract class Expression {
21     
22     private boolean addedToFilter;
23
24     public abstract Value getValue(Session session) throws SQLException JavaDoc;
25     public abstract int getType();
26     public abstract void mapColumns(ColumnResolver resolver, int level) throws SQLException JavaDoc;
27     public abstract Expression optimize(Session session) throws SQLException JavaDoc;
28     public abstract void setEvaluatable(TableFilter tableFilter, boolean b);
29     public abstract int getScale();
30     public abstract long getPrecision();
31     public abstract String JavaDoc getSQL();
32     public abstract void updateAggregate(Session session) throws SQLException JavaDoc;
33     public abstract boolean isEverything(ExpressionVisitor visitor);
34     public abstract int getCost();
35
36     public final boolean isEverything(int expressionVisitorType) {
37         ExpressionVisitor visitor = ExpressionVisitor.get(expressionVisitorType);
38         return isEverything(visitor);
39     }
40     
41     public boolean isConstant() {
42         return false;
43     }
44     
45     public boolean isAutoIncrement() {
46         return false;
47     }
48     
49     public Boolean JavaDoc getBooleanValue(Session session) throws SQLException JavaDoc {
50         // TODO optimization: is this required?
51
return getValue(session).getBoolean();
52     }
53
54     public void createIndexConditions(TableFilter filter) throws SQLException JavaDoc {
55         // default is do nothing
56
}
57
58     public String JavaDoc getColumnName() {
59         return getAlias();
60     }
61
62     public String JavaDoc getSchemaName() {
63         return null;
64     }
65
66     public String JavaDoc getTableName() {
67         return null;
68     }
69     
70     public int getNullable() {
71         return Column.NULLABLE_UNKNOWN;
72     }
73
74     public String JavaDoc getTableAlias() {
75         return null;
76     }
77
78     public String JavaDoc getAlias() {
79         return StringUtils.unEnclose(getSQL());
80     }
81
82     public boolean isWildcard() {
83         return false;
84     }
85     
86     public Expression getNonAliasExpression() {
87         return this;
88     }
89     
90     public void addFilterConditions(TableFilter filter, boolean outerJoin) {
91         if(!addedToFilter && !outerJoin && isEverything(ExpressionVisitor.EVALUATABLE)) {
92             filter.addFilterCondition(this, false);
93             addedToFilter = true;
94         }
95     }
96 }
97
Popular Tags