01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.query.QueryException;
19: import org.outerj.daisy.query.EvaluationInfo;
20:
21: import java.sql.PreparedStatement;
22: import java.sql.SQLException;
23:
24: /**
25: * Interface for predicate expressions, these are expression which
26: * evaluate to either "true" or "false". They are used in the "where"
27: * part of the query, or can be evaluated stand-alone.
28: */
29: public interface PredicateExpr extends Expression {
30: /**
31: * Evaluates the expression for the given document and version. The version
32: * parameter is allowed to be null, in which case version-dependent information
33: * will be retrieved from the document object.
34: */
35: boolean evaluate(ExprDocData data, EvaluationInfo evaluationInfo)
36: throws QueryException;
37:
38: /**
39: * Generate SQL for this expression by appending to a StringBuilder.
40: *
41: * <p>Note that the EvaluationInfo is available through the SqlGenerationContext.
42: */
43: void generateSql(StringBuilder sql, SqlGenerationContext context)
44: throws QueryException;
45:
46: /**
47: * @param bindPos the binding position on which to bind the next value
48: * @return the next binding position
49: */
50: int bindSql(PreparedStatement stmt, int bindPos,
51: EvaluationInfo evaluationInfo) throws SQLException,
52: QueryException;
53:
54: /**
55: * Checks if this PredicateExpr only uses stuff allowed in ACL object conditions.
56: * Returns null if successfull.
57: */
58: AclConditionViolation isAclAllowed();
59:
60: /**
61: * Checks if this conditionl expression could evaluate to true
62: * for a document, without really knowing everything about the document.
63: * The supplied Document object only needs to return the document type
64: * and collections, the other methods do not need to be implemented.
65: *
66: * <p>The result can be:
67: * <ul>
68: * <li>yes, if the expression is guaranteed to evaluate
69: * to true for such a document. For example, the simple
70: * expression 'true' will always be true regardless
71: * of the document.</li>
72: * <li>no,if the expression is guaranteed to evaluate to
73: * false for such a document. For example, the expression
74: * test "documentType = 'abc'" but the supplied document
75: * object is of another type.</li>
76: * <li>maybe, if the epxression could apply but the exact
77: * outcome depends on further information. For example,
78: * when the expression depends on the value of a field.
79: * </ul>
80: */
81: Tristate appliesTo(ExprDocData data, EvaluationInfo evaluationInfo)
82: throws QueryException;
83: }
|