org.josql.expressions
Class AndOrExpression

java.lang.Object
  extended by org.josql.expressions.Expression
      extended by org.josql.expressions.BinaryExpression
          extended by org.josql.expressions.AndOrExpression

public class AndOrExpression
extends BinaryExpression

Represents either an AND expression or a OR expression. Lazy evaluation is employed here such if the expression is: LHS OR RHS and LHS = true then the RHS is NOT evaluated, if the expression is: LHS AND RHS and LHS = false then the RHS is NOT evaluated (see isTrue(Object,Query)). This is important to note if you expect side-effects to occur in the RHS (bad practice anyway so don't do it!).


Field Summary
 
Fields inherited from class org.josql.expressions.BinaryExpression
left, right
 
Constructor Summary
AndOrExpression()
           
 
Method Summary
 boolean isAnd()
           
 boolean isTrue(Object o, Query q)
          Evaulates the expression and returns true if the expression evaulates to true.
 void setAnd(boolean v)
           
 String toString()
          Return a string version of this expression.
 
Methods inherited from class org.josql.expressions.BinaryExpression
getExpectedReturnType, getLeft, getRight, getValue, hasFixedResult, init, setLeft, setRight
 
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

AndOrExpression

public AndOrExpression()
Method Detail

isAnd

public boolean isAnd()

setAnd

public void setAnd(boolean v)

isTrue

public boolean isTrue(Object o,
                      Query q)
               throws QueryExecutionException
Evaulates the expression and returns true if the expression evaulates to true.

Type LHS RHS Result Notes
AND true true true Both LHS and RHS are evaulated.
AND true false false Both LHS and RHS are evaulated.
AND false unknown or false false Only the LHS is evaulated.
OR true unknown true Only the LHS is evaulated.
OR false true true Both the LHS and RHS are evaulated.
OR false false false Both the LHS and RHS are evaulated.

In general what this means is that you should "left-weight" your expressions so that the expression that returns true most often (or more likely to return true) should be on the LHS.

Specified by:
isTrue in class Expression
Parameters:
o - The current object to perform the expression on.
q - The query object.
Returns:
true if the expression evaulates to true, false otherwise.
Throws:
QueryExecutionException - If the expression cannot be evaulated.

toString

public String toString()
Return a string version of this expression. Note: any formatting of the statement (such as line breaks) will be removed.

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


  Copyright © 2008 Gary Bentley. All Rights Reserved.