org.ujorm.criterion
Class Criterion<UJO extends Ujo>

java.lang.Object
  extended by org.ujorm.criterion.Criterion<UJO>
Direct Known Subclasses:
BinaryCriterion, ValueCriterion

public abstract class Criterion<UJO extends Ujo>
extends java.lang.Object

An abstract immutable criterion provides a basic interface and static factory methods. You can use it:

There is allowed to join two instances (based on the same BO) to a binary tree by a new Criterion. Some common operators (and, or, not) are implemeted into a special join method of the Criteron class.

Example of use

// Make a criterion:
 Criterion<Person> crn1, crn2, criterion;
 crn1 = Criterion.where(CASH, Operator.GT, 10.0);
 crn2 = Criterion.where(CASH, Operator.LE, 20.0);
 criterion = crn1.and(crn2);

 // Use a criterion (1):
 CriteriaTool<Person> ct = CriteriaTool.where();
 List<Person> result = ct.select(persons, criterion);
 assertEquals(1, result.size());
 assertEquals(20.0, CASH.of(result.get(0)));

 // Use a criterion (2):
 Person person = result.get(0);
 boolean validation = criterion.evaluate(person);
 assertTrue(validation);
 

Using the parentheses

A Criterion instance composed from another criterions works as an expression separated by parentheses. See the next two examples:
// Consider instances:
 Criterion<Person> a, b, c, result;
 a = Criterion.where(CASH, Operator.GT, 10.0);
 b = Criterion.where(CASH, Operator.LE, 20.0);
 c = Criterion.where(NAME, Operator.STARTS, "P");

 // Expression #1: (a OR b) AND c :
 result = (a.or(b)).and(c); // or simply:
 result = a.or(b).and(c);

 // Expression #2: a AND (b OR c) :
 result = a.and(b.or(c));
 

Since:
0.90
Author:
Pavel Ponec

Constructor Summary
Criterion()
           
 
Method Summary
 Criterion<UJO> and(Criterion<UJO> criterion)
           
static
<UJO extends Ujo>
Criterion<UJO>
constant(UjoProperty<UJO,?> property, boolean constant)
          This is a special constant criterion independed on the property or the ujo entity.
 java.util.List<UJO> evaluate(java.lang.Iterable<UJO> ujoList)
          Returns a list of items which satisfies the condition in this Criterion.
 java.util.List<UJO> evaluate(UJO... ujoList)
          Returns a list of items which satisfies the condition in this Criterion.
abstract  boolean evaluate(UJO ujo)
          Apply the criterion to the UJO object
static
<UJO extends Ujo>
Criterion<UJO>
forAll(UjoProperty<UJO,?> property)
          This is a constant criterion independed on the property value or the ujo entity.
static
<UJO extends Ujo>
Criterion<UJO>
forNone(UjoProperty<UJO,?> property)
          This is a constant criterion independed on the property value or the ujo entity.
static
<UJO extends Ujo>
Criterion<UJO>
forSql(UjoProperty<UJO,?> property, java.lang.String sqlCondition)
          The method creates a new Criterion for a native condition (called Native Criterion) in SQL statejemt format.
abstract  java.lang.Object getLeftNode()
          Returns the left node of the parrent
abstract  AbstractOperator getOperator()
          Returns an operator
abstract  java.lang.Object getRightNode()
          Returns the right node of the parrent
 boolean isBinary()
          Is the class a Binary criterion?
 Criterion<UJO> join(BinaryOperator operator, Criterion<UJO> criterion)
           
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
newInstance(UjoProperty<UJO,TYPE> property, Operator operator, TYPE value)
          Deprecated. See the where(...) method.
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
newInstance(UjoProperty<UJO,TYPE> property, Operator operator, UjoProperty<?,TYPE> value)
          Deprecated. See the where(...) method.
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
newInstance(UjoProperty<UJO,TYPE> property, TYPE value)
          Deprecated. See the where(...) method.
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
newInstance(UjoProperty<UJO,TYPE> property, UjoProperty<UJO,TYPE> value)
          Deprecated. See the where(...) method.
 Criterion<UJO> not()
           
 Criterion<UJO> or(Criterion<UJO> criterion)
           
static
<UJO extends Ujo>
Criterion<UJO>
where(boolean value)
          This is an constane criterion independed on an entity.
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
where(UjoProperty<UJO,TYPE> property, Operator operator, TYPE value)
          New criterion instance
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
where(UjoProperty<UJO,TYPE> property, Operator operator, UjoProperty<?,TYPE> value)
          New criterion instance
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
where(UjoProperty<UJO,TYPE> property, TYPE value)
          New equals instance
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
where(UjoProperty<UJO,TYPE> property, UjoProperty<UJO,TYPE> value)
          New equals instance
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
whereIn(UjoProperty<UJO,TYPE> property, java.util.Collection<TYPE> list)
          Create new Criterion for operator IN to compare value to a list of constants.
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
whereIn(UjoProperty<UJO,TYPE> property, TYPE... list)
          Create new Criterion for operator IN to compare value to a list of constants
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
whereNotIn(UjoProperty<UJO,TYPE> property, java.util.Collection<TYPE> list)
          Create new Criterion for operator IN to compare value to a list of constants.
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
whereNotIn(UjoProperty<UJO,TYPE> property, TYPE... list)
          Create new Criterion for operator IN to compare value to a list of constants.
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
whereNotNull(UjoProperty<UJO,TYPE> property)
          Create new Criterion where a property value not equals to the NULL.
static
<UJO extends Ujo,TYPE>
Criterion<UJO>
whereNull(UjoProperty<UJO,TYPE> property)
          Create new Criterion where a property value equals to the NULL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Criterion

public Criterion()
Method Detail

evaluate

public abstract boolean evaluate(UJO ujo)
Apply the criterion to the UJO object

Returns:
Returns the value true in case the ujo object satisfies the condition.

evaluate

public final java.util.List<UJO> evaluate(java.lang.Iterable<UJO> ujoList)
Returns a list of items which satisfies the condition in this Criterion.

See Also:
CriteriaTool.select(java.util.List, org.ujorm.criterion.Criterion, org.ujorm.core.UjoComparator)

evaluate

public final java.util.List<UJO> evaluate(UJO... ujoList)
Returns a list of items which satisfies the condition in this Criterion.

See Also:
CriteriaTool.select(java.util.List, org.ujorm.criterion.Criterion, org.ujorm.core.UjoComparator)

join

public Criterion<UJO> join(BinaryOperator operator,
                           Criterion<UJO> criterion)

and

public Criterion<UJO> and(Criterion<UJO> criterion)

or

public Criterion<UJO> or(Criterion<UJO> criterion)

not

public Criterion<UJO> not()

getLeftNode

public abstract java.lang.Object getLeftNode()
Returns the left node of the parrent


getRightNode

public abstract java.lang.Object getRightNode()
Returns the right node of the parrent


getOperator

public abstract AbstractOperator getOperator()
Returns an operator


isBinary

public boolean isBinary()
Is the class a Binary criterion?


where

public static <UJO extends Ujo,TYPE> Criterion<UJO> where(UjoProperty<UJO,TYPE> property,
                                                          Operator operator,
                                                          TYPE value)
New criterion instance

Parameters:
property - UjoProperty
operator - Operator
  • VALUE - the parameter value
  • UjoProperty - reference to a related entity
  • List<TYPE> - list of values (TODO - this type is planned in the future)
Returns:
A new criterion

where

public static <UJO extends Ujo,TYPE> Criterion<UJO> where(UjoProperty<UJO,TYPE> property,
                                                          Operator operator,
                                                          UjoProperty<?,TYPE> value)
New criterion instance

Parameters:
property - UjoProperty
operator - Operator
  • VALUE - the parameter value
  • UjoProperty - reference to a related entity
  • List<TYPE> - list of values (TODO - this type is planned in the future)
Returns:
A new criterion

where

public static <UJO extends Ujo,TYPE> Criterion<UJO> where(UjoProperty<UJO,TYPE> property,
                                                          TYPE value)
New equals instance

Parameters:
property - UjoProperty
  • TYPE - parameter value
  • List<TYPE> - list of values
  • UjoProperty - reference to a related entity
Returns:
A the new immutable Criterion

whereIn

public static <UJO extends Ujo,TYPE> Criterion<UJO> whereIn(UjoProperty<UJO,TYPE> property,
                                                            java.util.Collection<TYPE> list)
Create new Criterion for operator IN to compare value to a list of constants.

Parameters:
property - A direct or indeirect Ujo property
list - A collection of the values. The collection argument can be the EMPTY, the Criterion result will be FALSE in this case.
Returns:
A the new immutable Criterion.

whereNotIn

public static <UJO extends Ujo,TYPE> Criterion<UJO> whereNotIn(UjoProperty<UJO,TYPE> property,
                                                               java.util.Collection<TYPE> list)
Create new Criterion for operator IN to compare value to a list of constants.

Parameters:
property - A direct or indeirect Ujo property
list - A collection of the values. The collection argument can be the EMPTY, the Criterion result will be TRUE in this case.
Returns:
A the new immutable Criterion.

whereIn

public static <UJO extends Ujo,TYPE> Criterion<UJO> whereIn(UjoProperty<UJO,TYPE> property,
                                                            TYPE... list)
Create new Criterion for operator IN to compare value to a list of constants

Parameters:
property - A reference to a related entity
list - A collection of the values. The collection argument can be the EMPTY, the Criterion result will be FALSE in this case.
Returns:
A the new immutable Criterion

whereNotIn

public static <UJO extends Ujo,TYPE> Criterion<UJO> whereNotIn(UjoProperty<UJO,TYPE> property,
                                                               TYPE... list)
Create new Criterion for operator IN to compare value to a list of constants.

Parameters:
property - A property direct or indeirect Ujo property
list - A collection of the values. The collection argument can be the EMPTY, the Criterion result will be TRUE in this case.
Returns:
A the new immutable Criterion.

where

public static <UJO extends Ujo,TYPE> Criterion<UJO> where(UjoProperty<UJO,TYPE> property,
                                                          UjoProperty<UJO,TYPE> value)
New equals instance

Parameters:
property - UjoProperty
value - Value or UjoProperty can be type a direct of indirect (for a relation) property
Returns:
A the new immutable Criterion

whereNull

public static <UJO extends Ujo,TYPE> Criterion<UJO> whereNull(UjoProperty<UJO,TYPE> property)
Create new Criterion where a property value equals to the NULL. The method is a shortcut to the next full expression:
 Criterin.where(Order.NOTE_PROPERTY, Operator.EQ, (String) null) 
for the String property type in this case.

Parameters:
property - UjoProperty
See Also:
whereNotNull(org.ujorm.UjoProperty), Operator.EQ

whereNotNull

public static <UJO extends Ujo,TYPE> Criterion<UJO> whereNotNull(UjoProperty<UJO,TYPE> property)
Create new Criterion where a property value not equals to the NULL. The method is a shortcut to the next full expression:
 Criterin.where(Order.NOTE_PROPERTY, Operator.EQ, (String) null) 
for the String property type in this case.

Parameters:
property - UjoProperty
See Also:
whereNull(org.ujorm.UjoProperty), Operator.NOT_EQ

where

public static <UJO extends Ujo> Criterion<UJO> where(boolean value)
This is an constane criterion independed on an entity. The method is deprecated in the ORM, use rather a one method from or .

See Also:
forAll(org.ujorm.UjoProperty), forNone(org.ujorm.UjoProperty)

constant

public static <UJO extends Ujo> Criterion<UJO> constant(UjoProperty<UJO,?> property,
                                                        boolean constant)
This is a special constant criterion independed on the property or the ujo entity. A result is the same like the parameter constant allways.

Parameters:
property - The parameter is required by Ujorm to location a basic database table and the join relations in case a composed Property
See Also:
Operator.XFIXED

forSql

public static <UJO extends Ujo> Criterion<UJO> forSql(UjoProperty<UJO,?> property,
                                                      java.lang.String sqlCondition)
The method creates a new Criterion for a native condition (called Native Criterion) in SQL statejemt format. Special features:

Parameters:
property - The parameter is required by Ujorm to location a basic database table and the join relations in case a composed Property
sqlCondition - a SQL condition in the String format, the NULL value or empty string is not accepted
See Also:
Operator.XSQL

forAll

public static <UJO extends Ujo> Criterion<UJO> forAll(UjoProperty<UJO,?> property)
This is a constant criterion independed on the property value or the ujo entity. The method evaluate(ujo) returns TRUE always.

Parameters:
property - The parameter is required by Ujorm to location a basic database table and the join relations in case a composed Property

forNone

public static <UJO extends Ujo> Criterion<UJO> forNone(UjoProperty<UJO,?> property)
This is a constant criterion independed on the property value or the ujo entity. The method evaluate(method) returns FALSE always.

Parameters:
property - The parameter is required by Ujorm to location a basic database table and the join relations in case a composed Property

newInstance

@Deprecated
public static <UJO extends Ujo,TYPE> Criterion<UJO> newInstance(UjoProperty<UJO,TYPE> property,
                                                                           Operator operator,
                                                                           TYPE value)
Deprecated. See the where(...) method.

New criterion instance

Parameters:
property - UjoProperty
operator - Operator
  • VALUE - the parameter value
  • UjoProperty - reference to a related entity
  • List<TYPE> - list of values (TODO - this type is planned in the future)
Returns:
A new criterion

newInstance

@Deprecated
public static <UJO extends Ujo,TYPE> Criterion<UJO> newInstance(UjoProperty<UJO,TYPE> property,
                                                                           Operator operator,
                                                                           UjoProperty<?,TYPE> value)
Deprecated. See the where(...) method.

New criterion instance

Parameters:
property - UjoProperty
operator - Operator
  • VALUE - the parameter value
  • UjoProperty - reference to a related entity
  • List<TYPE> - list of values (TODO - this type is planned in the future)
Returns:
A new criterion

newInstance

@Deprecated
public static <UJO extends Ujo,TYPE> Criterion<UJO> newInstance(UjoProperty<UJO,TYPE> property,
                                                                           TYPE value)
Deprecated. See the where(...) method.

New equals instance

Parameters:
property - UjoProperty
  • TYPE - parameter value
  • List<TYPE> - list of values
  • UjoProperty - reference to a related entity
Returns:
A the new immutable Criterion

newInstance

@Deprecated
public static <UJO extends Ujo,TYPE> Criterion<UJO> newInstance(UjoProperty<UJO,TYPE> property,
                                                                           UjoProperty<UJO,TYPE> value)
Deprecated. See the where(...) method.

New equals instance

Parameters:
property - UjoProperty
value - Value or UjoProperty can be type a direct of indirect (for a relation) property
Returns:
A the new immutable Criterion


Copyright © 2007-2012 PPonec