org.josql.expressions
Class Expression

java.lang.Object
  extended by org.josql.expressions.Expression
Direct Known Subclasses:
AliasedExpression, BinaryExpression, SelectItemExpression, ValueExpression

public abstract class Expression
extends Object

The base class for all expressions.


Constructor Summary
Expression()
           
 
Method Summary
abstract  Class getExpectedReturnType(Query q)
          Return the class of the object that "should" be returned from a call to the: getValue(Object,Query) method.
abstract  Object getValue(Object o, Query q)
          Get the value for this expression based upon the object passed in.
abstract  boolean hasFixedResult(Query q)
          Return whether the expression will evaluate to a fixed/constant result.
abstract  void init(Query q)
          Perform the necessary initialisation for this expression.
 boolean isBracketed()
           
abstract  boolean isTrue(Object o, Query q)
          This method allows ANY expression (including those that extend ValueExpression) to be used in the WHERE and HAVING clauses but ensuring that a boolean value is available for every expression.
 void setBracketed(boolean v)
           
abstract  String toString()
          Return a string representation of the expression, making this abstract forces sub-classes to provide an implementation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Expression

public Expression()
Method Detail

isTrue

public abstract boolean isTrue(Object o,
                               Query q)
                        throws QueryExecutionException
This method allows ANY expression (including those that extend ValueExpression) to be used in the WHERE and HAVING clauses but ensuring that a boolean value is available for every expression.

Parameters:
o - The current object to evaluate the expression on.
q - The Query object.
Returns:
true if the expression evaluates to true (well duh...).
Throws:
QueryExecutionException - If there is a problem with the execution of the expression.

hasFixedResult

public abstract boolean hasFixedResult(Query q)
Return whether the expression will evaluate to a fixed/constant result. This allows certain optimisations to be performed when an expression is evaluated. A "fixed result" is basically one in which multiple calls to either the: isTrue(Object,Query) or getValue(Object,Query) methods will return the same object (or that o1.equals (o2) == true) regardless of the object passed to the method.

Parameters:
q - The Query object.
Returns:
true if the expression evaluates to a fixed/constant result.

setBracketed

public void setBracketed(boolean v)

isBracketed

public boolean isBracketed()

getExpectedReturnType

public abstract Class getExpectedReturnType(Query q)
                                     throws QueryParseException
Return the class of the object that "should" be returned from a call to the: getValue(Object,Query) method. It may be that repeated executions of a query will return different classes from this method. In general sub-classes should take this variance into account.

Parameters:
q - The Query object.
Returns:
The expected type that will be returned from the getValue(Object,Query) method.
Throws:
QueryParseException - If something goes wrong with determining the type.

init

public abstract void init(Query q)
                   throws QueryParseException
Perform the necessary initialisation for this expression. The exact operations performed are defined by the sub-class.

Parameters:
q - The Query object.
Throws:
QueryParseException - If something goes wrong with the initialisation.

getValue

public abstract Object getValue(Object o,
                                Query q)
                         throws QueryExecutionException
Get the value for this expression based upon the object passed in. In general sub-classes should perform some operation on the object to generate their result. The Query object is provided so that sub-classes can gain access to the bind variables (if required), save values and so on. Whilst it may seem better to have the Query object as a member of this class this would then prevent the expression from being used separately from the Query (a design goal of JoSQL, i.e. independent processing).

Parameters:
o - The current object that the expression should be evaluated on.
q - The Query object.
Returns:
The value of the expression.
Throws:
QueryExecutionException - If something goes wrong with gaining the value.

toString

public abstract String toString()
Return a string representation of the expression, making this abstract forces sub-classes to provide an implementation.

Overrides:
toString in class Object
Returns:
A string representation of the expression.


  Copyright © 2008 Gary Bentley. All Rights Reserved.