de.mguennewig.pobjects
Class Predicate

java.lang.Object
  extended by de.mguennewig.pobjects.Predicate
All Implemented Interfaces:
Condition, Term, java.lang.Iterable<Term>

public class Predicate
extends java.lang.Object
implements Condition

A boolean expression to be used in the WHERE part of a SQL statement.

Author:
Michael Günnewig
See Also:
CheckConstraint, Query

Field Summary
static int EQUALS
          The == operator.
static int GREATER
          The > operator.
static int GREATER_EQUALS
          The >= operator.
static int IN
          The IN operator.
static int IS_NOT_NULL
          The IS NOT NULL operator.
static int IS_NULL
          The IS NULL operator.
static int LESS
          The < operator.
static int LESS_EQUALS
          The <= operator.
static int LIKE
          The LIKE operator.
static int NOT
          The NOT operator.
static int NOT_EQUALS
          The !
 
Fields inherited from interface de.mguennewig.pobjects.Condition
AND, OR
 
Constructor Summary
Predicate(Term left, int op, Term right)
          Creates a new Predicate.
 
Method Summary
static Predicate and(Term left, Term right)
          An AND expression of 2 Term's.
static Predicate between(Term left, Term lowerValue, Term upperValue)
           
 boolean equals(java.lang.Object obj)
          Tests whether this boolean expression is equal to another object.
static Predicate equals(Term left, Term right)
          Creates an `EQUALS' test for two terms.
 Term getLeftTerm()
          Returns the term on the left side/before of the operand or null if it does not exist.
 int getOperand()
          Returns the operand.
 java.lang.String getOperandName()
          Returns a textual representation of the operand.
 Term getRightTerm()
          Returns the term on the right side/after of the operand or null if it does not exist.
 java.lang.String getSqlValue(EvalContext eval)
          Returns the SQL equivalent expression for this predicate.
static Predicate greater(Term left, Term right)
           
static Predicate greaterEqual(Term left, Term right)
           
 int hashCode()
          
static Predicate in(Term left, LiteralSet set)
           
 boolean isConstant()
          Tests whether this expression returns a fixed value.
 boolean isJoin()
          Tests whether this expression enforces any kind of join.
static Predicate isNotNull(Term term)
          Creates an `IS NOT NULL' test.
static Predicate isNull(Term term)
          Creates an `IS NULL' tests.
 boolean isOuterJoin()
          Tests whether this expression enforces an outer join.
 boolean isSelection()
          Tests whether this expression is a selection.
 java.util.Iterator<Term> iterator()
           
static Predicate less(Term left, Term right)
           
static Predicate lessEqual(Term left, Term right)
           
static Predicate like(Term left, java.lang.String pattern)
           
static Predicate like(Term left, Term right)
           
static Predicate not(Term term)
          Negates the given term.
static Predicate notEquals(Term left, Term right)
          Creates a `NOT EQUALS' test for two terms.
static Predicate or(Term left, Term right)
          An OR expression of 2 Term's.
static java.lang.String quoteForLike(java.lang.String pattern)
          Quotes special SQL characters in the string for the LIKE operator.
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EQUALS

public static final int EQUALS
The == operator.

See Also:
Constant Field Values

NOT_EQUALS

public static final int NOT_EQUALS
The != operator.

See Also:
Constant Field Values

LESS

public static final int LESS
The < operator.

See Also:
Constant Field Values

LESS_EQUALS

public static final int LESS_EQUALS
The <= operator.

See Also:
Constant Field Values

GREATER

public static final int GREATER
The > operator.

See Also:
Constant Field Values

GREATER_EQUALS

public static final int GREATER_EQUALS
The >= operator.

See Also:
Constant Field Values

LIKE

public static final int LIKE
The LIKE operator.

See Also:
Constant Field Values

IN

public static final int IN
The IN operator.

See Also:
Constant Field Values

NOT

public static final int NOT
The NOT operator.

See Also:
Constant Field Values

IS_NULL

public static final int IS_NULL
The IS NULL operator.

See Also:
Constant Field Values

IS_NOT_NULL

public static final int IS_NOT_NULL
The IS NOT NULL operator.

See Also:
Constant Field Values
Constructor Detail

Predicate

public Predicate(Term left,
                 int op,
                 Term right)
Creates a new Predicate.

Throws:
java.lang.IllegalArgumentException - if both terms are null.
Method Detail

equals

public boolean equals(java.lang.Object obj)
Tests whether this boolean expression is equal to another object.

Overrides:
equals in class java.lang.Object
Returns:
true if the other object is an existing boolean expression of the same kind with equal sub-terms.

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

getSqlValue

public java.lang.String getSqlValue(EvalContext eval)
Returns the SQL equivalent expression for this predicate.

Specified by:
getSqlValue in interface Term

isConstant

public final boolean isConstant()
Tests whether this expression returns a fixed value.

If true then the value of this expression can be computed without a database and object instance.

Specified by:
isConstant in interface Term
See Also:
Literal, LiteralSet

isJoin

public final boolean isJoin()
Tests whether this expression enforces any kind of join.

Specified by:
isJoin in interface Term
See Also:
isOuterJoin()

isSelection

public final boolean isSelection()
Tests whether this expression is a selection.

With selection is an expression meant that binds a Member to one Literal.

Specified by:
isSelection in interface Term

getOperand

public final int getOperand()
Returns the operand.

Specified by:
getOperand in interface Condition

iterator

public java.util.Iterator<Term> iterator()
Specified by:
iterator in interface java.lang.Iterable<Term>

getLeftTerm

public final Term getLeftTerm()
Returns the term on the left side/before of the operand or null if it does not exist.


getOperandName

public final java.lang.String getOperandName()
Returns a textual representation of the operand.


getRightTerm

public final Term getRightTerm()
Returns the term on the right side/after of the operand or null if it does not exist.


isOuterJoin

public final boolean isOuterJoin()
Tests whether this expression enforces an outer join.

See Also:
isJoin()

quoteForLike

public static java.lang.String quoteForLike(java.lang.String pattern)
Quotes special SQL characters in the string for the LIKE operator.


equals

public static Predicate equals(Term left,
                               Term right)
Creates an `EQUALS' test for two terms.


notEquals

public static Predicate notEquals(Term left,
                                  Term right)
Creates a `NOT EQUALS' test for two terms.


between

public static Predicate between(Term left,
                                Term lowerValue,
                                Term upperValue)

less

public static Predicate less(Term left,
                             Term right)

lessEqual

public static Predicate lessEqual(Term left,
                                  Term right)

greater

public static Predicate greater(Term left,
                                Term right)

greaterEqual

public static Predicate greaterEqual(Term left,
                                     Term right)

like

public static Predicate like(Term left,
                             java.lang.String pattern)

like

public static Predicate like(Term left,
                             Term right)

in

public static Predicate in(Term left,
                           LiteralSet set)

and

public static Predicate and(Term left,
                            Term right)
An AND expression of 2 Term's.

Parameters:
left - the left side of the AND expression.
right - the right side of the AND expression.
Throws:
java.lang.IllegalArgumentException - if any of the term's is a LiteralSet or null.

or

public static Predicate or(Term left,
                           Term right)
An OR expression of 2 Term's.

Parameters:
left - the left side of the OR expression.
right - the right side of the OR expression.
Throws:
java.lang.IllegalArgumentException - if any of the term's is a LiteralSet or null.

not

public static Predicate not(Term term)
Negates the given term.

Throws:
java.lang.IllegalArgumentException - if term is a LiteralSet.

isNull

public static Predicate isNull(Term term)
Creates an `IS NULL' tests.

Throws:
java.lang.IllegalArgumentException - if the term is null.

isNotNull

public static Predicate isNotNull(Term term)
Creates an `IS NOT NULL' test.

Throws:
java.lang.IllegalArgumentException - if the term is null.