org.apache.openjpa.persistence.criteria
Class PredicateImpl

java.lang.Object
  extended by org.apache.openjpa.persistence.criteria.SelectionImpl<X>
      extended by org.apache.openjpa.persistence.criteria.ExpressionImpl<Boolean>
          extended by org.apache.openjpa.persistence.criteria.PredicateImpl
All Implemented Interfaces:
Expression<Boolean>, Predicate, Selection<Boolean>, TupleElement<Boolean>, CriteriaExpression
Direct Known Subclasses:
CompareByExample, Expressions.BinaryLogicalExpression, Expressions.IsEmpty, Expressions.IsMember, Expressions.IsNotEmpty, Expressions.IsNotNull, Expressions.IsNull, Expressions.Like, Expressions.Not, Expressions.SubqueryPredicate, PredicateImpl.And, PredicateImpl.Or

abstract class PredicateImpl
extends ExpressionImpl<Boolean>
implements Predicate

Predicate is a expression that evaluates to true or false. All boolean expressions are implemented as Predicate. A predicate can have zero or more predicate arguments. Default predicate operator is AND (conjunction). Two constant predicates are Predicate.TRUE and Predicate.FALSE. AND predicate with no argument evaluates to TRUE. OR predicate with no argument evaluates to FALSE. Negation of a Predicate creates a new Predicate.

Since:
2.0.0
Author:
Pinaki Poddar, Fay Wang

Nested Class Summary
(package private) static class PredicateImpl.And
          Concrete AND predicate.
(package private) static class PredicateImpl.Or
          Concrete OR predicate.
 
Nested classes/interfaces inherited from interface javax.persistence.criteria.Predicate
Predicate.BooleanOperator
 
Field Summary
protected  List<Predicate> _exps
           
static Predicate FALSE
           
static Predicate TRUE
           
 
Constructor Summary
protected PredicateImpl()
          An AND predicate with no arguments.
protected PredicateImpl(Predicate.BooleanOperator op)
          A predicate with the given operator.
protected PredicateImpl(Predicate.BooleanOperator op, Predicate... restrictions)
          A predicate of given operator with given arguments.
 
Method Summary
 void acceptVisit(CriteriaExpressionVisitor visitor)
          Accept visit from the given visitor.
 PredicateImpl add(Expression<Boolean> s)
          Adds the given predicate expression.
 StringBuilder asValue(AliasContext q)
          Get a string representation of this node as a value in the context of the given query.
 List<Expression<Boolean>> getExpressions()
           
 Predicate.BooleanOperator getOperator()
           
 boolean isEmpty()
           
 boolean isNegated()
          Is this predicate created by negating another predicate?
protected  PredicateImpl markNegated()
           
 PredicateImpl not()
          Returns a new predicate as the negation of this predicate.
(package private)  Expression toKernelExpression(ExpressionFactory factory, CriteriaQueryImpl<?> q)
          Bridge contract to convert this facade expression to a kernel expression.
(package private)  Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q)
          Bridge contract to convert this facade expression to a kernel value.
 
Methods inherited from class org.apache.openjpa.persistence.criteria.ExpressionImpl
as, in, in, in, in, isNotNull, isNull
 
Methods inherited from class org.apache.openjpa.persistence.criteria.SelectionImpl
alias, asProjection, assertValidName, asVariable, getAlias, getCompoundSelectionItems, getJavaType, isAliased, isAutoAliased, isCompoundSelection, setAutoAlias
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.persistence.criteria.Expression
as, in, in, in, in, isNotNull, isNull
 
Methods inherited from interface javax.persistence.criteria.Selection
alias, getCompoundSelectionItems, isCompoundSelection
 
Methods inherited from interface javax.persistence.TupleElement
getAlias, getJavaType
 

Field Detail

TRUE

public static final Predicate TRUE

FALSE

public static final Predicate FALSE

_exps

protected final List<Predicate> _exps
Constructor Detail

PredicateImpl

protected PredicateImpl()
An AND predicate with no arguments.


PredicateImpl

protected PredicateImpl(Predicate.BooleanOperator op)
A predicate with the given operator.


PredicateImpl

protected PredicateImpl(Predicate.BooleanOperator op,
                        Predicate... restrictions)
A predicate of given operator with given arguments.

Method Detail

add

public PredicateImpl add(Expression<Boolean> s)
Adds the given predicate expression.


getExpressions

public List<Expression<Boolean>> getExpressions()
Specified by:
getExpressions in interface Predicate

getOperator

public final Predicate.BooleanOperator getOperator()
Specified by:
getOperator in interface Predicate

isEmpty

public final boolean isEmpty()

isNegated

public final boolean isNegated()
Is this predicate created by negating another predicate?

Specified by:
isNegated in interface Predicate

not

public PredicateImpl not()
Returns a new predicate as the negation of this predicate.
Note: Default negation creates a Not expression with this receiver as delegate. Derived predicates can return the inverse expression, if exists. For example, NotEqual for Equal or LessThan for GreaterThanEqual etc.

Specified by:
not in interface Predicate

markNegated

protected PredicateImpl markNegated()

toValue

Value toValue(ExpressionFactory factory,
              CriteriaQueryImpl<?> q)
Description copied from class: ExpressionImpl
Bridge contract to convert this facade expression to a kernel value.

Specified by:
toValue in class ExpressionImpl<Boolean>
Parameters:
factory - creates the kernel expression
q - the query definition context of this expression
Returns:
an equivalent kernel value

toKernelExpression

Expression toKernelExpression(ExpressionFactory factory,
                              CriteriaQueryImpl<?> q)
Description copied from class: ExpressionImpl
Bridge contract to convert this facade expression to a kernel expression.

Overrides:
toKernelExpression in class ExpressionImpl<Boolean>
Parameters:
factory - creates the kernel expression
q - the query definition context of this expression
Returns:
an equivalent kernel expression

acceptVisit

public void acceptVisit(CriteriaExpressionVisitor visitor)
Description copied from interface: CriteriaExpression
Accept visit from the given visitor. The receiver is responsible to propagate the visitor to the constituent sub-nodes if any.

Specified by:
acceptVisit in interface CriteriaExpression
Overrides:
acceptVisit in class SelectionImpl<Boolean>
Parameters:
visitor - a processor to walk the nodes of a tree.

asValue

public StringBuilder asValue(AliasContext q)
Description copied from interface: CriteriaExpression
Get a string representation of this node as a value in the context of the given query.

Specified by:
asValue in interface CriteriaExpression
Overrides:
asValue in class SelectionImpl<Boolean>


Copyright © 2006-2010 Apache Software Foundation. All Rights Reserved.