org.josql.expressions
Class ExpressionList

java.lang.Object
  extended by org.josql.expressions.Expression
      extended by org.josql.expressions.ValueExpression
          extended by org.josql.expressions.ExpressionList

public class ExpressionList
extends ValueExpression

This class represents a list of expressions used within a SQL statement.

Expressions lists are created using pairs of "[]" brackets, i.e.

  [toString, 10, true]
 
Would create a list of expressions that should be treated as a unit.

Since expression lists are also expressions it is possible to nest them to the nth degree, if desired. i.e.

  [toString, [1, 2, 3, 4], [true, true]]
 


Constructor Summary
ExpressionList()
           
 
Method Summary
 void addExpression(Expression expr)
          Add an expression to the list.
 Object evaluate(Object o, Query q)
          Evaluates the value of this expression list.
 Class getExpectedReturnType(Query q)
          Get the expected return type, which is List.
 List getExpressions()
          Returns the expressions, a list of Expression objects.
 Object getValue(Object o, Query q)
          Gets the value of the expressions, this will return a list of the values for each of the expressions in the list.
 boolean hasFixedResult(Query q)
          Returns true if this expression list is empty (no expressions) or if ALL of the expressions have a fixed result.
 void init(Query q)
          Initialises this expression list, each expression in the list is inited.
 boolean isTrue(Object o, Query q)
          Returns true if one of the expression values is non-null.
 void setExpressions(List exprs)
          Set the expressions.
 String toString()
          Returns a string version of this expression list.
 
Methods inherited from class org.josql.expressions.Expression
isBracketed, setBracketed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExpressionList

public ExpressionList()
Method Detail

getExpectedReturnType

public Class getExpectedReturnType(Query q)
Get the expected return type, which is List.

Specified by:
getExpectedReturnType in class Expression
Parameters:
q - The Query object.
Returns:
List.

init

public void init(Query q)
          throws QueryParseException
Initialises this expression list, each expression in the list is inited.

Specified by:
init in class Expression
Parameters:
q - The Query object.
Throws:
QueryParseException - If one of the expressions cannot be inited.

getExpressions

public List getExpressions()
Returns the expressions, a list of Expression objects.

Returns:
The expressions.

addExpression

public void addExpression(Expression expr)
Add an expression to the list.

Parameters:
expr - The expression.

setExpressions

public void setExpressions(List exprs)
Set the expressions.

Parameters:
exprs - The expressions.

getValue

public Object getValue(Object o,
                       Query q)
                throws QueryExecutionException
Gets the value of the expressions, this will return a list of the values for each of the expressions in the list. In essence Expression.getValue(Object,Query) is called on each of the expressions.

Overrides:
getValue in class ValueExpression
Parameters:
o - The current object.
q - The Query object.
Returns:
A list of the values, if there are no expressions in the list then an empty list is returned.
Throws:
QueryExecutionException - If something goes wrong the acquisition of the values.

isTrue

public boolean isTrue(Object o,
                      Query q)
               throws QueryExecutionException
Returns true if one of the expression values is non-null. Note: for efficiency this method calls Expression.getValue(Object,Query) on each expression directly and returns true for the first non-null value found, as such if any of your expressions triggers side-effects then this method should not be used.

Specified by:
isTrue in class Expression
Parameters:
o - The current object.
q - The Query object.
Returns:
true if one of the expression values is non-null.
Throws:
QueryExecutionException - If a problem occurs during evaluation.

evaluate

public Object evaluate(Object o,
                       Query q)
                throws QueryExecutionException
Evaluates the value of this expression list. This is just a thin-wrapper around: getValue(Object,Query).

Specified by:
evaluate in class ValueExpression
Parameters:
o - The current object.
q - The Query object.
Returns:
The value of this expression list.
Throws:
QueryExecutionException - If there is a problem getting the values.

toString

public String toString()
Returns a string version of this expression list. Returns in the form: "[" Expression [ , Expression ]* "]".

Specified by:
toString in class Expression
Returns:
A string version of the expression list.

hasFixedResult

public boolean hasFixedResult(Query q)
Returns true if this expression list is empty (no expressions) or if ALL of the expressions have a fixed result.

Specified by:
hasFixedResult in class Expression
Parameters:
q - The Query object.
Returns:
See description.


  Copyright © 2008 Gary Bentley. All Rights Reserved.