KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > query > model > ValueExpr


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.query.model;
17
18 import org.outerj.daisy.repository.Document;
19 import org.outerj.daisy.repository.Version;
20 import org.outerj.daisy.repository.query.QueryException;
21 import org.outerj.daisy.repository.query.EvaluationContext;
22 import org.outerj.daisy.query.QueryContext;
23
24 import java.sql.PreparedStatement JavaDoc;
25 import java.sql.SQLException JavaDoc;
26 import java.util.Locale JavaDoc;
27
28 /**
29  * An expression which evaluates to some value.
30  */

31 public interface ValueExpr extends Expression {
32     /**
33      * A method that should be called before any of the others.
34      */

35     void prepare(QueryContext context) throws QueryException;
36
37     /**
38      * Evaluates the expression without access to document information. This will only
39      * work for expressions that do not need access to information from the document
40      * (thus typically without identifiers), otherwise this will throw an exception.
41      *
42      * @param valueType Indicates the type of object to return. This parameter only matters when
43      */

44     Object JavaDoc evaluate(QValueType valueType, EvaluationContext evaluationContext) throws QueryException;
45
46     /**
47      * Evaluates this expression for the given document and/or version.
48      * The version argument can be null, in which case the data will be retrieved from
49      * the document object.
50      */

51     Object JavaDoc evaluate(QValueType valueType, Document document, Version version, EvaluationContext evaluationContext) throws QueryException;
52
53     /**
54      * Returns the ValueType of this expression, or null if undetermined.
55      */

56     QValueType getValueType();
57
58     /**
59      * Returns true if this ValueExpr represents a symbolic identifier.
60      *
61      * A symbolic identifier is an identifier that identifies an object by name
62      * in the query, but uses an ID to search on the database.
63      *
64      * <p>If this method returns true, then {@link #translateSymbolic} can
65      * be called to convert the symbolic value to the test value.
66      */

67     boolean isSymbolicIdentifier();
68
69     /**
70      * See {@link #isSymbolicIdentifier()}. This method should only be called
71      * if {@link #isSymbolicIdentifier()} returns true.
72      */

73     Object JavaDoc translateSymbolic(ValueExpr valueExpr, EvaluationContext evaluationContext) throws QueryException;
74
75     boolean isMultiValue();
76
77     /**
78      * Returns true for ValueExpr's which cannot be searched on (i.e. no
79      * SQL can be generated) and which cannot be evaluated. Thus valueExpr's
80      * which can be used in the select and order by parts of a query, but
81      * not in the where part.
82      */

83     boolean isOutputOnly();
84
85     /**
86      * Returns non-null if this ValueExpr is not fitted for use in ACL
87      * document selection expressions.
88      */

89     AclConditionViolation isAclAllowed();
90
91     /**
92      * Generates any SQL conditions needed outside of the main value expression (which is
93      * generated using {@link #generateSqlValueExpr(StringBuffer, SqlGenerationContext)}).
94      *
95      * <p>Should throw an exception if this is an output-only ValueExpr.
96      *
97      * @return null if not applicable
98      */

99     String JavaDoc getSqlPreConditions(SqlGenerationContext context) throws QueryException;
100
101     /**
102      * Generates the SQL for this expression.
103      *
104      * <p>Should throw an exception if this is an output-only ValueExpr.
105      */

106     void generateSqlValueExpr(StringBuffer JavaDoc sql, SqlGenerationContext context) throws QueryException;
107
108     int bindPreConditions(PreparedStatement JavaDoc stmt, int bindPos) throws SQLException JavaDoc, QueryException;
109
110     int bindValueExpr(PreparedStatement JavaDoc stmt, int bindPos, QValueType valueType,
111                       EvaluationContext evaluationContext) throws SQLException JavaDoc, QueryException;
112
113     String JavaDoc getTitle(Locale JavaDoc locale);
114
115     /**
116      * Get a textual representation of this expression, i.e. something that could be parsed
117      * again and give the same ValueExpr again.
118      */

119     String JavaDoc getExpression();
120
121     /**
122      * Identifies the type of data returned from the
123      * {@link #getOutputValue(org.outerj.daisy.repository.Document, org.outerj.daisy.repository.Version, EvaluationContext)} method.
124      */

125     QValueType getOutputValueType();
126
127     /**
128      * Returns the output value of this identifier for the given document and version.
129      * For symbolic identifiers this will be different from the value returned by
130      * {@link #evaluate(QValueType, org.outerj.daisy.repository.Document, org.outerj.daisy.repository.Version, EvaluationContext)}.
131      * The version is allowed to be null.
132      */

133     Object JavaDoc getOutputValue(Document document, Version version, EvaluationContext evaluationContext) throws QueryException;
134
135     boolean canTestAppliesTo();
136 }
137
Popular Tags