org.apache.torque.criteria
Class Criteria

java.lang.Object
  extended by org.apache.torque.criteria.Criteria
All Implemented Interfaces:
Serializable, Cloneable, CriteriaInterface<Criteria>

public class Criteria
extends Object
implements Serializable, Cloneable, CriteriaInterface<Criteria>

Encapsulates conditions to access rows in database tables.

Version:
$Id: Criteria.java 1397355 2012-10-11 22:52:33Z tfischer $
Author:
Frank Y. Kim, John D. McNally, Brett McLaughlin, Eric Dobbs, Henning P. Schmiedehausen, Sam Joseph, Martin Poeschl, Thomas Fischer, Scott Eade, Thomas Vandahl
See Also:
Serialized Form

Field Summary
static SqlEnum ALL
          Comparison type.
static SqlEnum ALT_NOT_EQUAL
          Comparison type.
static SqlEnum CURRENT_DATE
          "CURRENT_DATE" ANSI SQL function
static SqlEnum CURRENT_TIME
          "CURRENT_TIME" ANSI SQL function
static SqlEnum CURRENT_TIMESTAMP
          "CURRENT_TIMESTAMP" ANSI SQL function
static SqlEnum DISTINCT
          Comparison type.
static SqlEnum EQUAL
          Comparison type.
static SqlEnum GREATER_EQUAL
          Comparison type.
static SqlEnum GREATER_THAN
          Comparison type.
static SqlEnum ILIKE
          Comparison type.
static SqlEnum IN
          Comparison type.
static JoinType INNER_JOIN
          "INNER JOIN" SQL statement
static SqlEnum ISNOTNULL
          "IS NOT NULL" null comparison
static SqlEnum ISNULL
          "IS NULL" null comparison
static SqlEnum JOIN
          Comparison type.
static JoinType LEFT_JOIN
          "LEFT JOIN" SQL statement
static SqlEnum LESS_EQUAL
          Comparison type.
static SqlEnum LESS_THAN
          Comparison type.
static SqlEnum LIKE
          Comparison type.
static SqlEnum NOT_EQUAL
          Comparison type.
static SqlEnum NOT_ILIKE
          Comparison type.
static SqlEnum NOT_IN
          Comparison type.
static SqlEnum NOT_LIKE
          Comparison type.
static JoinType RIGHT_JOIN
          "RIGHT JOIN" SQL statement
 
Constructor Summary
Criteria()
          Creates a new instance with the default capacity.
Criteria(String dbName)
          Creates a new instance with the default capacity which corresponds to the specified database.
 
Method Summary
 void addAlias(String alias, Criteria subselect)
          Allows one to specify an alias for a subselect.
 void addAlias(String alias, String table)
          Allows one to specify an alias for a table.
 Criteria addAscendingOrderByColumn(Column column)
          Adds an order by clause, explicitly specifying ascending.
 Criteria addAscendingOrderByColumn(Column column, boolean ignoreCase)
          Add an order by clause, explicitly specifying ascending.
 Criteria addAsColumn(String name, Column clause)
          Add an AS clause to the select columns.
 Criteria addDescendingOrderByColumn(Column column)
          Add order by column name, explicitly specifying descending.
 Criteria addDescendingOrderByColumn(Column column, boolean ignoreCase)
          Add order by column name, explicitly specifying descending.
 Criteria addFrom(FromElement fromElement)
          Adds a new Element to the from clause.
 Criteria addFrom(String tableName)
          Adds a table to the from clause, not using a joinType or joinCondition.
 Criteria addGroupByColumn(Column groupBy)
          Add a group by clause.
 Criteria addHaving(Criterion having)
          This method adds a prepared Criterion object to the Criteria as a having clause.
 Criteria addJoin(Column left, Column right)
          Adds a join to the criteria, E.g.
 Criteria addJoin(Column left, Column right, JoinType joinType)
          Adds a join to the criteria, E.g.
 Criteria addJoin(Column left, Column right, SqlEnum comparison, JoinType joinType)
          Adds a join to the criteria, E.g.
 Criteria addJoin(PreparedStatementPart leftTable, PreparedStatementPart rightTable, Criterion joinCondition, JoinType joinType)
          Adds a join to the criteria, E.g.
 Criteria addJoin(String leftTable, String rightTable, Criterion joinCondition, JoinType joinType)
          Adds a join to the criteria, E.g.
 Criteria addSelectColumn(Column column)
          Adds a select column to the Criteria.
 Criteria and(Criterion criterion)
          "AND"s Criterion object with the conditions in this Criteria.
 Criteria and(Object lValue, Object rValue)
          "AND"s a new condition with the conditions in this Criteria.
 Criteria and(Object lValue, Object rValue, SqlEnum comparison)
          "AND"s a new condition with the conditions in this Criteria.
 Criteria andDate(Object lValue, int year, int month, int day)
          Convenience method to AND a new date comparison with the conditions in this Criteria.
 Criteria andDate(Object lValue, int year, int month, int day, SqlEnum comparison)
          Convenience method to AND a new date comparison with the conditions in this Criteria.
 Criteria andIn(Object lValue, Collection<?> rValues)
          Convenience method to AND a "in" comparison with the conditions in this Criteria.
 Criteria andIn(Object lValue, Object[] rValues)
          Convenience method to AND a "in" comparison with the conditions in this Criteria.
 Criteria andNotIn(Object lValue, Collection<?> rValues)
          Convenience method to AND a "not in" comparison with the conditions in this Criteria.
 Criteria andNotIn(Object lValue, Object[] rValues)
          Convenience method to AND a "not in" comparison with the conditions in this Criteria.
 Criteria andVerbatimSql(String sql, Object[] replacements)
          Ands a verbatim sql condition to this Criteria.
 Criteria andVerbatimSql(String sql, Object[] replacements, Column toAddToFromClause1, Column toAddToFromClause2)
          ANDs a verbatim sql condition to this Criteria.
 Object clone()
          Returns a cloned object.
 boolean equals(Object object)
          Checks whether an object is equal to this Criteria.
 Map<String,Object> getAliases()
          Get the table aliases.
 Map<String,Column> getAsColumns()
          Get the column aliases.
 String getDbName()
          Get the Database name to be used for this criterion.
 Integer getFetchSize()
          Returns the JDBC statement fetch size to use for queries.
 UniqueList<FromElement> getFromElements()
          Get all elements in the from clause of the query.
 UniqueColumnList getGroupByColumns()
          Get all group by columns.
 Criterion getHaving()
          Get Having Criterion.
 List<Join> getJoins()
          Get the List of Joins.
 int getLimit()
          Get the upper limit for the number of records returned by a query.
 long getOffset()
          Get how many records should be skipped at the start of the result.
 UniqueList<OrderBy> getOrderByColumns()
          Get all order by columns.
 UniqueColumnList getSelectColumns()
          Return all select columns.
 UniqueList<String> getSelectModifiers()
          Return all select modifiers.
 Criteria getSubselectForAlias(String alias)
          Returns the subselect associated with an alias.
 String getTableForAlias(String alias)
          Returns the database table name associated with an alias.
 Criterion getTopLevelCriterion()
          Returns the top level Criterion.
 int hashCode()
          Returns the hash code value for this Criteria.
 boolean isIgnoreCase()
          Returns whether case should be ignored in where clauses and order by whenever String columns are encountered.
 boolean isSingleRecord()
          Returns whether the check that a query returns exactly one record is active.
 Criteria or(Criterion criterion)
          "OR"s a Criterion object with the conditions in this Criteria.
 Criteria or(Object lValue, Object rValue)
          "OR"s a new condition with the conditions in this Criteria.
 Criteria or(Object lValue, Object rValue, SqlEnum comparison)
          "OR"s a new condition with the conditions in this Criteria.
 Criteria orDate(Object lValue, int year, int month, int day)
          Convenience method to OR a new date comparison with the conditions in this Criteria.
 Criteria orDate(Object lValue, int year, int month, int day, SqlEnum comparison)
          Convenience method to OR a new date comparison with the conditions in this Criteria.
 Criteria orIn(Object lValue, Collection<?> rValues)
          Convenience method to OR a "in" comparison with the conditions in this Criteria.
 Criteria orIn(Object lValue, Object[] rValues)
          Convenience method to OR a "in" comparison with the conditions in this Criteria.
 Criteria orNotIn(Object lValue, Collection<?> rValues)
          Convenience method to OR a "not in" comparison with the conditions in this Criteria.
 Criteria orNotIn(Object lValue, Object[] rValues)
          Convenience method to OR a "not in" comparison with the conditions in this Criteria.
 Criteria orVerbatimSql(String sql, Object[] replacements)
          ORs a verbatim sql condition to this Criteria.
 Criteria orVerbatimSql(String sql, Object[] replacements, Column toAddToFromClause1, Column toAddToFromClause2)
          ORs a verbatim sql condition to this Criteria.
 void setAll()
          Adds "ALL " to the SQL statement.
 void setDbName(String dbName)
          Set the Database name.
 void setDistinct()
          Adds "DISTINCT " to the SQL statement.
 void setFetchSize(Integer fetchSize)
          Sets the JDBC statement fetch size to use for queries.
 Criteria setIgnoreCase(boolean ignoreCase)
          Sets whether case should be ignored in where clauses and order by whenever String columns are encountered.
 Criteria setLimit(int limit)
          Set a limit for the query
 Criteria setOffset(long offset)
          Set the offset.
 Criteria setSingleRecord(boolean b)
          Switch the check on or off that a query returns exactly one record.
 String toString()
          Build a string representation of the Criteria for debugging purposes.
 Criteria where(Criterion criterion)
          "AND"s Criterion object with the conditions in this Criteria.
 Criteria where(Object lValue, Object rValue)
          "AND"s a new condition with the conditions in this Criteria.
 Criteria where(Object lValue, Object rValue, SqlEnum comparison)
          "AND"s a new condition with the conditions in this Criteria.
 Criteria whereDate(Object lValue, int year, int month, int day)
          Convenience method to AND a new date comparison with the conditions in this Criteria.
 Criteria whereDate(Object lValue, int year, int month, int day, SqlEnum comparison)
          Convenience method to AND a new date comparison with the conditions in this Criteria.
 Criteria whereIn(Object lValue, Collection<?> rValues)
          Convenience method to AND a "in" comparison with the conditions in this Criteria.
 Criteria whereIn(Object lValue, Object[] rValues)
          Convenience method to AND a "in" comparison with the conditions in this Criteria.
 Criteria whereNotIn(Object lValue, Collection<?> rValues)
          Convenience method to AND a "not in" comparison with the conditions in this Criteria.
 Criteria whereNotIn(Object lValue, Object[] rValues)
          Convenience method to AND a "not in" comparison with the conditions in this Criteria.
 Criteria whereVerbatimSql(String sql, Object[] replacements)
          Convenience method to AND a verbatim sql condition to this Criteria.
 Criteria whereVerbatimSql(String sql, Object[] replacements, Column toAddToFromClause1, Column toAddToFromClause2)
          Convenience method to AND a verbatim sql condition to this Criteria.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EQUAL

public static final SqlEnum EQUAL
Comparison type.


NOT_EQUAL

public static final SqlEnum NOT_EQUAL
Comparison type.


ALT_NOT_EQUAL

public static final SqlEnum ALT_NOT_EQUAL
Comparison type.


GREATER_THAN

public static final SqlEnum GREATER_THAN
Comparison type.


LESS_THAN

public static final SqlEnum LESS_THAN
Comparison type.


GREATER_EQUAL

public static final SqlEnum GREATER_EQUAL
Comparison type.


LESS_EQUAL

public static final SqlEnum LESS_EQUAL
Comparison type.


LIKE

public static final SqlEnum LIKE
Comparison type.


NOT_LIKE

public static final SqlEnum NOT_LIKE
Comparison type.


ILIKE

public static final SqlEnum ILIKE
Comparison type.


NOT_ILIKE

public static final SqlEnum NOT_ILIKE
Comparison type.


DISTINCT

public static final SqlEnum DISTINCT
Comparison type.


IN

public static final SqlEnum IN
Comparison type.


NOT_IN

public static final SqlEnum NOT_IN
Comparison type.


ALL

public static final SqlEnum ALL
Comparison type.


JOIN

public static final SqlEnum JOIN
Comparison type.


ISNULL

public static final SqlEnum ISNULL
"IS NULL" null comparison


ISNOTNULL

public static final SqlEnum ISNOTNULL
"IS NOT NULL" null comparison


CURRENT_DATE

public static final SqlEnum CURRENT_DATE
"CURRENT_DATE" ANSI SQL function


CURRENT_TIME

public static final SqlEnum CURRENT_TIME
"CURRENT_TIME" ANSI SQL function


CURRENT_TIMESTAMP

public static final SqlEnum CURRENT_TIMESTAMP
"CURRENT_TIMESTAMP" ANSI SQL function


LEFT_JOIN

public static final JoinType LEFT_JOIN
"LEFT JOIN" SQL statement


RIGHT_JOIN

public static final JoinType RIGHT_JOIN
"RIGHT JOIN" SQL statement


INNER_JOIN

public static final JoinType INNER_JOIN
"INNER JOIN" SQL statement

Constructor Detail

Criteria

public Criteria()
Creates a new instance with the default capacity.


Criteria

public Criteria(String dbName)
Creates a new instance with the default capacity which corresponds to the specified database.

Parameters:
dbName - The database name.
Method Detail

addAsColumn

public Criteria addAsColumn(String name,
                            Column clause)
Add an AS clause to the select columns. Usage:

Criteria myCrit = new Criteria(); myCrit.addAsColumn( "alias", "ALIAS("+MyPeer.ID+")"); If the name already exists, it is replaced by the new clause.

Parameters:
name - wanted Name of the column
clause - SQL clause to select from the table
Returns:
A modified Criteria object.

getAsColumns

public Map<String,Column> getAsColumns()
Get the column aliases.

Specified by:
getAsColumns in interface CriteriaInterface<Criteria>
Returns:
A Map which map the column alias names to the alias clauses.

getAliases

public Map<String,Object> getAliases()
Get the table aliases.

Specified by:
getAliases in interface CriteriaInterface<Criteria>
Returns:
A Map which maps the table alias names to either the actual table names (String) or to a subselect (Criteria).

addAlias

public void addAlias(String alias,
                     String table)
Allows one to specify an alias for a table.

Specified by:
addAlias in interface CriteriaInterface<Criteria>
Parameters:
alias - the alias for the table name.
table - the table name as known in the database.

addAlias

public void addAlias(String alias,
                     Criteria subselect)
Allows one to specify an alias for a subselect.

Parameters:
alias - the alias for the subselect.
subselect - the Criteria for the subselect.

getTableForAlias

public String getTableForAlias(String alias)
Returns the database table name associated with an alias.

Specified by:
getTableForAlias in interface CriteriaInterface<Criteria>
Parameters:
alias - a String value.
Returns:
a String value, or null if the alias is not defined.
Throws:
IllegalArgumentException - if the alias with the name alias is defined but is no alias for a table name (e.g. it is an alias for a subselect).

getSubselectForAlias

public Criteria getSubselectForAlias(String alias)
Returns the subselect associated with an alias.

Parameters:
alias - a String value.
Returns:
a String value, or null if the alias is not defined.
Throws:
IllegalArgumentException - if the alias with the name alias is defined but is not an alias for a subselect (e.g. it is an alias for a table).

getTopLevelCriterion

public Criterion getTopLevelCriterion()
Returns the top level Criterion.

Returns:
the top level Criterion, or null if no Criterion is contained.

getDbName

public String getDbName()
Get the Database name to be used for this criterion.

Specified by:
getDbName in interface CriteriaInterface<Criteria>
Returns:
The database name, may be null.

setDbName

public void setDbName(String dbName)
Set the Database name. The value null denotes the database name provided by Torque.getDefaultDB() (but this is not resolved here).

Specified by:
setDbName in interface CriteriaInterface<Criteria>
Parameters:
dbName - The Database(Map) name.

addHaving

public Criteria addHaving(Criterion having)
This method adds a prepared Criterion object to the Criteria as a having clause. Usage:

Criteria crit = new Criteria(); Criterion c =new Criterion(MyPeer.ID, 5, Criteria.LESS_THAN); crit.addHaving(c);

Parameters:
having - A Criterion object
Returns:
A modified Criteria object.

getHaving

public Criterion getHaving()
Get Having Criterion.

Returns:
A Criterion that is the having clause.

addJoin

public Criteria addJoin(Column left,
                        Column right)
Adds a join to the criteria, E.g. to create the condition

AND PROJECT.PROJECT_ID=FOO.PROJECT_ID

use

criteria.addJoin(ProjectPeer.PROJECT_ID, FooPeer.PROJECT_ID)

Parameters:
left - A String with the left side of the join.
right - A String with the right side of the join.
Returns:
A modified Criteria object.

addJoin

public Criteria addJoin(Column left,
                        Column right,
                        JoinType joinType)
Adds a join to the criteria, E.g. to create the condition

PROJECT LEFT JOIN FOO ON PROJECT.PROJECT_ID=FOO.PROJECT_ID

use

criteria.addJoin(ProjectPeer.PROJECT_ID, FooPeer.PROJECT_ID, Criteria.LEFT_JOIN);

Parameters:
left - A String with the left side of the join.
right - A String with the right side of the join.
joinType - The operator used for the join: must be one of null, Criteria.LEFT_JOIN, Criteria.RIGHT_JOIN, Criteria.INNER_JOIN
Returns:
A modified Criteria object.

addJoin

public Criteria addJoin(Column left,
                        Column right,
                        SqlEnum comparison,
                        JoinType joinType)
Adds a join to the criteria, E.g. to create the condition

PROJECT LEFT JOIN FOO ON PROJECT.PROJECT_ID=FOO.PROJECT_ID

use

criteria.addJoin( ProjectPeer.PROJECT_ID, Criteria.NOT_EQUAL, FooPeer.PROJECT_ID, Criteria.LEFT_JOIN);

Parameters:
left - A String with the left side of the join condition.
right - A String with the right side of the join condition.
comparison - the comparison operator, not null. The operator CUSTOM is not supported.
joinType - The operator used for the join. Must be one of null, Criteria.LEFT_JOIN, Criteria.RIGHT_JOIN, Criteria.INNER_JOIN
Returns:
A modified Criteria object.

addJoin

public Criteria addJoin(String leftTable,
                        String rightTable,
                        Criterion joinCondition,
                        JoinType joinType)
Adds a join to the criteria, E.g. to create the condition

PROJECT LEFT JOIN FOO ON PROJECT.PROJECT_ID=FOO.PROJECT_ID

use

criteria.addJoin( ProjectPeer.TABLE_NAME, FooPeer.TABLE_NAME, new Criterion(ProjectPeer.PROJECT_ID, FooPeer.PROJECT_ID, Criteria.NOT_EQUAL) Criteria.LEFT_JOIN);

Parameters:
leftTable - the left table of the join, or null to determine the left table from the join condition.
rightTable - the left table of the join, or null to determine the left table from the join condition.
joinCondition - the join condition, not null.
joinType - The operator used for the join. Must be one of null, Criteria.LEFT_JOIN, Criteria.RIGHT_JOIN, Criteria.INNER_JOIN
Returns:
A modified Criteria object.

addJoin

public Criteria addJoin(PreparedStatementPart leftTable,
                        PreparedStatementPart rightTable,
                        Criterion joinCondition,
                        JoinType joinType)
Adds a join to the criteria, E.g. to create the condition

PROJECT LEFT JOIN FOO ON PROJECT.PROJECT_ID=FOO.PROJECT_ID

use

criteria.addJoin( new PreparedStatementPart(ProjectPeer.TABLE_NAME), new PreparedStatementPart(FooPeer.TABLE_NAME), new Criterion(ProjectPeer.PROJECT_ID, FooPeer.PROJECT_ID, Criteria.NOT_EQUAL) Criteria.LEFT_JOIN);

Parameters:
leftTable - the left table of the join, might contain an alias name, or null to be determined from the join clause.
rightTable - the right table of the join, might contain an alias name, or null to be determined from the join clause.
joinCondition - the join condition, not null.
joinType - The operator used for the join. Must be one of null, Criteria.LEFT_JOIN, Criteria.RIGHT_JOIN, Criteria.INNER_JOIN
Returns:
A modified Criteria object.

getJoins

public List<Join> getJoins()
Get the List of Joins.

Specified by:
getJoins in interface CriteriaInterface<Criteria>
Returns:
a List which contains objects of type Join, not null.

setAll

public void setAll()
Adds "ALL " to the SQL statement.

Specified by:
setAll in interface CriteriaInterface<Criteria>

setDistinct

public void setDistinct()
Adds "DISTINCT " to the SQL statement.

Specified by:
setDistinct in interface CriteriaInterface<Criteria>

setIgnoreCase

public Criteria setIgnoreCase(boolean ignoreCase)
Sets whether case should be ignored in where clauses and order by whenever String columns are encountered.

Parameters:
ignoreCase - True if case should be ignored.
Returns:
A modified Criteria object.

isIgnoreCase

public boolean isIgnoreCase()
Returns whether case should be ignored in where clauses and order by whenever String columns are encountered.

Specified by:
isIgnoreCase in interface CriteriaInterface<Criteria>
Returns:
True if case is ignored.

setSingleRecord

public Criteria setSingleRecord(boolean b)
Switch the check on or off that a query returns exactly one record. Set this to true if you want a TorqueException to be thrown if none or multiple records are returned when the query is executed. This should be used in situations where returning multiple rows would indicate an error of some sort. If your query might return multiple records but you are only interested in the first one then you should be using setLimit(1).

Parameters:
b - set to true if you expect the query to select exactly one record.
Returns:
A modified Criteria object.

isSingleRecord

public boolean isSingleRecord()
Returns whether the check that a query returns exactly one record is active.

Specified by:
isSingleRecord in interface CriteriaInterface<Criteria>
Returns:
True if the check for exactly one record is active.

setLimit

public Criteria setLimit(int limit)
Set a limit for the query

Specified by:
setLimit in interface CriteriaInterface<Criteria>
Parameters:
limit - The upper limit for the number of records returned by a query.
Returns:
A modified Criteria object.

getLimit

public int getLimit()
Get the upper limit for the number of records returned by a query.

Specified by:
getLimit in interface CriteriaInterface<Criteria>
Returns:
The value for limit.

setOffset

public Criteria setOffset(long offset)
Set the offset.

Specified by:
setOffset in interface CriteriaInterface<Criteria>
Parameters:
offset - how many records should be skipped at the start of the result.
Returns:
A modified Criteria object.

getOffset

public long getOffset()
Get how many records should be skipped at the start of the result.

Specified by:
getOffset in interface CriteriaInterface<Criteria>
Returns:
The value for offset.

getFetchSize

public Integer getFetchSize()
Returns the JDBC statement fetch size to use for queries.

Returns:
the fetch size, or null if none is set.

setFetchSize

public void setFetchSize(Integer fetchSize)
Sets the JDBC statement fetch size to use for queries.

Parameters:
fetchSize - the fetch size, or null for not set.

addSelectColumn

public Criteria addSelectColumn(Column column)
Adds a select column to the Criteria.

Parameters:
column - The select column to add.
Returns:
A modified Criteria object.

getSelectColumns

public UniqueColumnList getSelectColumns()
Return all select columns.

Specified by:
getSelectColumns in interface CriteriaInterface<Criteria>
Returns:
An List with the names of the select columns, not null

getSelectModifiers

public UniqueList<String> getSelectModifiers()
Return all select modifiers.

Specified by:
getSelectModifiers in interface CriteriaInterface<Criteria>
Returns:
An UniqueList with the select modifiers.

addGroupByColumn

public Criteria addGroupByColumn(Column groupBy)
Add a group by clause.

Parameters:
groupBy - The column to group by.
Returns:
A modified Criteria object.

getGroupByColumns

public UniqueColumnList getGroupByColumns()
Get all group by columns.

Specified by:
getGroupByColumns in interface CriteriaInterface<Criteria>
Returns:
An UniqueList with the name of the groupBy clause, not null.

addAscendingOrderByColumn

public Criteria addAscendingOrderByColumn(Column column)
Adds an order by clause, explicitly specifying ascending.

Parameters:
column - The column to order by.
Returns:
A modified Criteria object.

addAscendingOrderByColumn

public Criteria addAscendingOrderByColumn(Column column,
                                          boolean ignoreCase)
Add an order by clause, explicitly specifying ascending.

Parameters:
column - The column to order by.
ignoreCase - whether to ignore case on String columns.
Returns:
A modified Criteria object.

addDescendingOrderByColumn

public Criteria addDescendingOrderByColumn(Column column)
Add order by column name, explicitly specifying descending.

Parameters:
column - The column to order by.
Returns:
A modified Criteria object.

addDescendingOrderByColumn

public Criteria addDescendingOrderByColumn(Column column,
                                           boolean ignoreCase)
Add order by column name, explicitly specifying descending.

Parameters:
column - The column to order by.
ignoreCase - whether to ignore case on String columns.
Returns:
A modified Criteria object.

getOrderByColumns

public UniqueList<OrderBy> getOrderByColumns()
Get all order by columns.

Specified by:
getOrderByColumns in interface CriteriaInterface<Criteria>
Returns:
An UniqueList with the name of the order columns, not null.

getFromElements

public UniqueList<FromElement> getFromElements()
Get all elements in the from clause of the query.

Returns:
An UniqueList with all from elements, not null. Empty if the from elements should be computed automatically.

addFrom

public Criteria addFrom(String tableName)
Adds a table to the from clause, not using a joinType or joinCondition.

Returns:
the modified Criteria object.

addFrom

public Criteria addFrom(FromElement fromElement)
Adds a new Element to the from clause.

Returns:
the modified Criteria object.

toString

public String toString()
Build a string representation of the Criteria for debugging purposes.

Overrides:
toString in class Object
Returns:
A String with the representation of the Criteria.

equals

public boolean equals(Object object)
Checks whether an object is equal to this Criteria. This is the case if the other object is also a Criteria and has the same attributes and criterions.

Overrides:
equals in class Object
Parameters:
object - the other object to check, can be null.
Returns:
true if the object is equal to this Criteria, false otherwise.

hashCode

public int hashCode()
Returns the hash code value for this Criteria.

Overrides:
hashCode in class Object
Returns:
a hash code value for this object.

clone

public Object clone()
Returns a cloned object.

Overrides:
clone in class Object

and

public Criteria and(Criterion criterion)
"AND"s Criterion object with the conditions in this Criteria. This is used as follows:

Criteria crit = new Criteria(); Criterion c = new Criterion(XXXPeer.ID, new Integer(5), Criteria.LESS_THAN); crit.and(c);

Parameters:
criterion - A Criterion object.
Returns:
A modified Criteria object.

and

public Criteria and(Object lValue,
                    Object rValue)
"AND"s a new condition with the conditions in this Criteria. Depending on rValue, the condition is constructed differently: Either rValue is a unary comparison operator (i.e. is a SqlEnum and getNumberOfCompareOperands() == 1) (e.g. Criteria.ISNULL), then lValue is taken as single operand of the operator ant the passed operator is used for comparison. Otherwise, an EQUAL comparison is used for comparing rValue and lValue.

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.g. string object), it is interpreted as literal value.
rValue - The right hand side of the comparison, may be null. If this object is a unary comparison operator, it is taken as comparison operator of the condition to add. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.g. string object), it is interpreted as literal value.
Returns:
A modified Criteria object.

and

public Criteria and(Object lValue,
                    Object rValue,
                    SqlEnum comparison)
"AND"s a new condition with the conditions in this Criteria.

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
rValue - The right hand side of the comparison, may be null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
comparison - the comparison, or Criteria.CUSTOM to specify the expression manually in the rValue parameter.
Returns:
A modified Criteria object.

andDate

public Criteria andDate(Object lValue,
                        int year,
                        int month,
                        int day)
Convenience method to AND a new date comparison with the conditions in this Criteria. Equal to

and(column, new GregorianCalendar(year, month,date), EQUAL);

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
year - The year to compare to.
month - The month to compare to.
day - The day to compare to.
Returns:
A modified Criteria object.

andDate

public Criteria andDate(Object lValue,
                        int year,
                        int month,
                        int day,
                        SqlEnum comparison)
Convenience method to AND a new date comparison with the conditions in this Criteria. Equal to

and(column, new GregorianCalendar(year, month,date), comparison);

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
year - The year to compare to.
month - The month to compare to.
day - The day to compare to.
comparison - The comparison operator.
Returns:
A modified Criteria object.

andIn

public Criteria andIn(Object lValue,
                      Object[] rValues)
Convenience method to AND a "in" comparison with the conditions in this Criteria. Creates the condition

FOO.NAME IN (${values})

where ${values} contains the values to compare against.

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
rValues - The values to compare against.
Returns:
A modified Criteria object.

andIn

public Criteria andIn(Object lValue,
                      Collection<?> rValues)
Convenience method to AND a "in" comparison with the conditions in this Criteria. Creates the condition

FOO.NAME IN (${values})

where ${values} contains the values to compare against.

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
rValues - The values to compare against.
Returns:
A modified Criteria object.

andNotIn

public Criteria andNotIn(Object lValue,
                         Object[] rValues)
Convenience method to AND a "not in" comparison with the conditions in this Criteria. Creates the condition

FOO.NAME NOT IN (${values})

where ${values} contains the values to compare against.

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
rValues - The values to compare against.
Returns:
A modified Criteria object.

andNotIn

public Criteria andNotIn(Object lValue,
                         Collection<?> rValues)
Convenience method to AND a "not in" comparison with the conditions in this Criteria. Creates the condition

FOO.NAME NOT IN (${values})

where ${values} contains the values to compare against.

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
rValues - The values to compare against.
Returns:
A modified Criteria object.

andVerbatimSql

public Criteria andVerbatimSql(String sql,
                               Object[] replacements)
Ands a verbatim sql condition to this Criteria. This is used as follows:

Criteria criteria = ...; criteria.andVerbatimSql("count(foo.x) = ?", new Object[] {0});

Parameters:
sql - the verbatim SQL to use.
replacements - the replacements for the "?" placeholders in SQL.
Returns:
the modified Criteria.

andVerbatimSql

public Criteria andVerbatimSql(String sql,
                               Object[] replacements,
                               Column toAddToFromClause1,
                               Column toAddToFromClause2)
ANDs a verbatim sql condition to this Criteria. This is used as follows:

Criteria criteria = new Criteria(); criteria.andVerbatimSql( "count(foo.x) = ?", new Object[] {0}, FooPeer.X, null);

Parameters:
sql - the verbatim SQL to use.
replacements - the replacements for the "?" placeholders in SQL.
toAddToFromClause1 - a column to add to from clause, may be null.
toAddToFromClause2 - a column to add to from clause, may be null.
Returns:
the modified Criteria.

or

public Criteria or(Criterion criterion)
"OR"s a Criterion object with the conditions in this Criteria. This is used as follows:

Criteria crit = new Criteria(); Criterion c = new Criterion(XXXPeer.ID, new Integer(5), Criteria.LESS_THAN); crit.or(c);

Parameters:
criterion - A Criterion object.
Returns:
A modified Criteria object.

or

public Criteria or(Object lValue,
                   Object rValue)
"OR"s a new condition with the conditions in this Criteria. Depending on rValue, the condition is constructed differently: Either rValue is a unary comparison operator (i.e. is a SqlEnum and getNumberOfCompareOperands() == 1) (e.g. Criteria.ISNULL), then lValue is taken as single operand of the operator ant the passed operator is used for comparison. Otherwise, an EQUAL comparison is used for comparing rValue and lValue.

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.g. string object), it is interpreted as literal value.
rValue - The right hand side of the comparison, may be null. If this object is a unary comparison operator, it is taken as comparison operator of the condition to add. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.g. string object), it is interpreted as literal value.
Returns:
A modified Criteria object.

or

public Criteria or(Object lValue,
                   Object rValue,
                   SqlEnum comparison)
"OR"s a new condition with the conditions in this Criteria.

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
rValue - The right hand side of the comparison, may be null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
comparison - the comparison, or Criteria.CUSTOM to specify the expression manually in the value parameter.
Returns:
A modified Criteria object.

orDate

public Criteria orDate(Object lValue,
                       int year,
                       int month,
                       int day)
Convenience method to OR a new date comparison with the conditions in this Criteria. Equal to

or(column, new GregorianCalendar(year, month,date), EQUAL);

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
year - The year to compare to.
month - The month to compare to.
day - The day to compare to.
Returns:
A modified Criteria object.

orDate

public Criteria orDate(Object lValue,
                       int year,
                       int month,
                       int day,
                       SqlEnum comparison)
Convenience method to OR a new date comparison with the conditions in this Criteria. Equal to

or(column, new GregorianCalendar(year, month,date), comparison);

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
year - The year to compare to.
month - The month to compare to.
day - The day to compare to.
comparison - The comparison operator.
Returns:
A modified Criteria object.

orIn

public Criteria orIn(Object lValue,
                     Object[] rValues)
Convenience method to OR a "in" comparison with the conditions in this Criteria. Creates the condition

FOO.NAME IN (${values})

where ${values} contains the values to compare against.

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
rValues - The values to compare against.
Returns:
A modified Criteria object.

orIn

public Criteria orIn(Object lValue,
                     Collection<?> rValues)
Convenience method to OR a "in" comparison with the conditions in this Criteria. Creates the condition

FOO.NAME IN (${values})

where ${values} contains the values to compare against.

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
rValues - The values to compare against.
Returns:
A modified Criteria object.

orNotIn

public Criteria orNotIn(Object lValue,
                        Object[] rValues)
Convenience method to OR a "not in" comparison with the conditions in this Criteria. Creates the condition

FOO.NAME NOT IN (${values})

where ${values} contains the values to compare against.

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
rValues - The values to compare against.
Returns:
A modified Criteria object.

orNotIn

public Criteria orNotIn(Object lValue,
                        Collection<?> rValues)
Convenience method to OR a "not in" comparison with the conditions in this Criteria. Creates the condition

FOO.NAME NOT IN (${values})

where ${values} contains the values to compare against.

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
rValues - The values to compare against.
Returns:
A modified Criteria object.

orVerbatimSql

public Criteria orVerbatimSql(String sql,
                              Object[] replacements)
ORs a verbatim sql condition to this Criteria. This is used as follows:

Criteria criteria = ...; criteria.orVerbatimSql("count(foo.x) = ?", new Object[] {0});

Parameters:
sql - the verbatim SQL to use.
replacements - the replacements for the "?" placeholders in SQL.
Returns:
the modified Criteria.

orVerbatimSql

public Criteria orVerbatimSql(String sql,
                              Object[] replacements,
                              Column toAddToFromClause1,
                              Column toAddToFromClause2)
ORs a verbatim sql condition to this Criteria. This is used as follows:

Criteria criteria = new Criteria(); criteria.orVerbatimSql( "count(foo.x) = ?", new Object[] {0}, FooPeer.X, null);

Parameters:
sql - the verbatim SQL to use.
replacements - the replacements for the "?" placeholders in SQL.
toAddToFromClause1 - a column to add to from clause, may be null.
toAddToFromClause2 - a column to add to from clause, may be null.
Returns:
the modified Criteria.

where

public Criteria where(Criterion criterion)
"AND"s Criterion object with the conditions in this Criteria. Equivalent to #and(Criterion) but better to read if this is the first condition to be added to the Criteria.

Parameters:
criterion - A Criterion object.
Returns:
A modified Criteria object.

where

public Criteria where(Object lValue,
                      Object rValue)
"AND"s a new condition with the conditions in this Criteria. Equivalent to #and(Object, Object) but better to read if this is the first condition to be added to the Criteria. Depending on rValue, the condition is constructed differently: Either rValue is a unary comparison operator (i.e. is a SqlEnum and getNumberOfCompareOperands() == 1) (e.g. Criteria.ISNULL), then lValue is taken as single operand of the operator ant the passed operator is used for comparison. Otherwise, an EQUAL comparison is used for comparing rValue and lValue.

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.g. string object), it is interpreted as literal value.
rValue - The right hand side of the comparison, may be null. If this object is a unary comparison operator, it is taken as comparison operator of the condition to add. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.g. string object), it is interpreted as literal value.
Returns:
A modified Criteria object.

where

public Criteria where(Object lValue,
                      Object rValue,
                      SqlEnum comparison)
"AND"s a new condition with the conditions in this Criteria. Equivalent to #and(Column, Object, SqlEnum) but better to read if this is the first condition to be added to the Criteria.

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
rValue - The right hand side of the comparison, may be null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
comparison - the comparison, or Criteria.CUSTOM to specify the expression manually in the value parameter.
Returns:
A modified Criteria object.

whereDate

public Criteria whereDate(Object lValue,
                          int year,
                          int month,
                          int day)
Convenience method to AND a new date comparison with the conditions in this Criteria. Equivalent to #andDate(Column, int, int, int) but better to read if this is the first condition to be added to the Criteria.

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
year - The year to compare to.
month - The month to compare to.
day - The day to compare to.
Returns:
A modified Criteria object.

whereDate

public Criteria whereDate(Object lValue,
                          int year,
                          int month,
                          int day,
                          SqlEnum comparison)
Convenience method to AND a new date comparison with the conditions in this Criteria. Equivalent to #andDate(Column, int, int, int, SqlEnum) but better to read if this is the first condition to be added to the Criteria.

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
year - The year to compare to.
month - The month to compare to.
day - The day to compare to.
comparison - The comparison operator.
Returns:
A modified Criteria object.

whereIn

public Criteria whereIn(Object lValue,
                        Object[] rValues)
Convenience method to AND a "in" comparison with the conditions in this Criteria. Equivalent to #andIn(Column, Object[]) but better to read if this is the first condition to be added to the Criteria.

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
rValues - The values to compare against.
Returns:
A modified Criteria object.

whereIn

public Criteria whereIn(Object lValue,
                        Collection<?> rValues)
Convenience method to AND a "in" comparison with the conditions in this Criteria. Equivalent to #andIn(Column, Collection) but better to read if this is the first condition to be added to the Criteria.

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
rValues - The values to compare against.
Returns:
A modified Criteria object.

whereNotIn

public Criteria whereNotIn(Object lValue,
                           Object[] rValues)
Convenience method to AND a "not in" comparison with the conditions in this Criteria. Equivalent to #andNotIn(Column, Object[]) but better to read if this is the first condition to be added to the Criteria.

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
rValues - The values to compare against.
Returns:
A modified Criteria object.

whereNotIn

public Criteria whereNotIn(Object lValue,
                           Collection<?> rValues)
Convenience method to AND a "not in" comparison with the conditions in this Criteria. Equivalent to #andNotIn(Column, Collection) but better to read if this is the first condition to be added to the Criteria.

Parameters:
lValue - The left hand side of the comparison, not null. If this object implements the Column interface, it is interpreted as a (pseudo)column. If this object is c Criteria, it is interpreted as a subselect. In all other cases, (e.G. string object), it is interpreted as literal value.
rValues - The values to compare against.
Returns:
A modified Criteria object.

whereVerbatimSql

public Criteria whereVerbatimSql(String sql,
                                 Object[] replacements)
Convenience method to AND a verbatim sql condition to this Criteria. Equivalent to #andNotIn(String, String[]) but better to read if this is the first condition to be added to the Criteria. This is used as follows:

Criteria criteria = new Criteria(); criteria.whereVerbatimSql("count(foo.x) = ?", new Object[] {0});

Parameters:
sql - the verbatim SQL to use.
replacements - the replacements for the "?" placeholders in SQL.
Returns:
the modified Criteria.

whereVerbatimSql

public Criteria whereVerbatimSql(String sql,
                                 Object[] replacements,
                                 Column toAddToFromClause1,
                                 Column toAddToFromClause2)
Convenience method to AND a verbatim sql condition to this Criteria. Equivalent to #andNotIn(String, String[], Column, Column) but better to read if this is the first condition to be added to the Criteria. This is used as follows:

Criteria criteria = new Criteria(); criteria.whereVerbatimSql( "count(foo.x) = ?", new Object[] {0}, FooPeer.X, null);

Parameters:
sql - the verbatim SQL to use.
replacements - the replacements for the "?" placeholders in SQL.
toAddToFromClause1 - a column to add to from clause, may be null.
toAddToFromClause2 - a column to add to from clause, may be null.
Returns:
the modified Criteria.


Copyright © 2000-2012 The Apache Software Foundation. All Rights Reserved.