x = y
can be used in the SELECT part of the statement).There are various types of JoSQL expression (most of which map to their standard SQL equivalent):
- Binary expression - this type of expression represents the result of comparing a LHS with a RHS. For example 1 = 1. Just about all expressions that can be used in a WHERE clause are binary expressions.
- Aliased expression - this type of expression represents an expression that has an alias associated with it.
- Value expressions - this type of expression represents a value, such as a constant, a bind variable, the result of executing a function or even a sub-query.
Expression
interface that is implemented by an AbstractExpression
abstract class was overkill and not needed, hindsight has shown this to be a suitable choice):Expressions can be evaluated to a boolean value
That is each expression must indicate whether it is true or false (determined by calling: isTrue(java.lang.Object, org.josql.Query)). This may seem strange (especially for constant expressions) but it does allow for more flexibility and since consistent rules are used in the implementation this property can be exploited.For instance, consider the following statement:
SELECT ifThenElse (:value, firstValue, secondValue) FROM MyObject
firstValue
or secondValue
is evaluated and returned. Since the relevant expression object takes care of class issues the actually object provided for the bind variable does not matter, if the object is a number then any value greater than 0 will cause a true
value to returned and firstValue
will be called and the value returned; if the object is null then false
will be returned and secondValue
is called and the value returned and so on. This property of expressions can also be used in the WHERE clause, for example:SELECT * FROM MyObject WHERE firstValue
firstValue
method returns will determine whether the WHERE clause evaluates to true
and the relevant object returned in the results.Expressions must return a value
Each expression in JoSQL must return a value, even if the value is null
. In this way it means that comparisons between expressions can occur and the result of evaluating an expression is suitable for returning in query execution results. The value is gained by calling: getValue(java.lang.Object, org.josql.Query).
For example:
SELECT // Will use a value expression. 'hello world', // Will use a sub-select expression. (SELECT * FROM innerList), // Will use a boolean expression which is formed // from an accessor expression on the LHS // and a bind variable expression on the RHS. myAccessor = :myvalue, // Will use a function expression and a bind variable // expression as the argument. transform (:myvalue) FROM MyObject