org.apache.torque.criteria
Class Criterion

java.lang.Object
  extended by org.apache.torque.criteria.Criterion
All Implemented Interfaces:
Serializable

public class Criterion
extends Object
implements Serializable

Describes one or more where clause parts in the Criteria. Either the parts list is not null and represents this criterion or the column, value, comparison and ignoreStringCase columns are not null and represent this criterion.

See Also:
Serialized Form

Field Summary
static String AND
          Constant for the operator " AND ".
static String OR
          Constant for the operator " OR ".
 
Constructor Summary
Criterion(Criterion toCopy)
          Creates a shallow copy of the given Criterion.
Criterion(Object lValue, Object rValue)
          Create a new instance without verbatim sql, using equals as comparison operator.
Criterion(Object lValue, Object rValue, SqlEnum comparison)
          Create a new instance without verbatim sql.
Criterion(Object lValue, Object rValue, SqlEnum comparison, String sql, Object[] preparedStatementReplacements)
          Create a new instance.
 
Method Summary
 Criterion and(Criterion criterion)
          Replaces this criterion's condition with (this criterion's condition AND criterion).
 void appendTo(StringBuilder sb)
          Appends a debug String representation of the Criterion onto the String builder.
 boolean equals(Object obj)
          This method checks another Criteria.Criterion to see if they contain the same attributes.
 SqlEnum getComparison()
          Get the comparison.
 String getConjunction()
          Returns the conjunction for the parts of this criterion
 Object getLValue()
          Get the left hand side value of the comparison.
 List<Criterion> getParts()
          Returns the parts of which this criterion consists.
 Object[] getPreparedStatementReplacements()
          Returns the prepared statement replacements for a verbatim sql condition.
 Object getRValue()
          Get the right hand side value of the comparison.
 String getSql()
          Returns the verbatim sql for this condition.
 int hashCode()
          Returns a hash code value for the object.
 boolean isComposite()
          Returns whether this criterion is a composite criterion.
 boolean isIgnoreCase()
          Is ignore case on or off?
 boolean isVerbatimSqlCondition()
          Returns whether this Criterion represents a verbatim sql condition.
 Criterion or(Criterion criterion)
          Replaces this criterion's condition with (this criterion's condition OR criterion).
 Criterion setIgnoreCase(boolean b)
          Sets ignore case.
 void setLValue(Object lValue)
          Set the left hand side value of the comparison.
 void setRValue(Object rValue)
          Set the right hand side value of the comparison.
 String toString()
          Build a string representation of the Criterion for debug purposes.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

AND

public static final String AND
Constant for the operator " AND ".

See Also:
Constant Field Values

OR

public static final String OR
Constant for the operator " OR ".

See Also:
Constant Field Values
Constructor Detail

Criterion

public Criterion(Object lValue,
                 Object rValue,
                 SqlEnum comparison,
                 String sql,
                 Object[] preparedStatementReplacements)
Create a new instance. Either this Criterion represents a comparison without verbatim SQL; in this case the parameters lValue and comparison must be not null, rValue may be not null and sql and preparedStatementReplacements must be null; or it represents a verbatim sql condition, in which case the parameter comparison must be null and the sql must be not null (preparedStatementReplacements may be set to contain sql placeholder replacement values, and lValue and rValue can be set to add columns to the automatically computed from clause of the query).

Parameters:
lValue - the left hand side value of the comparison. If this value should be a value from the database, the object must implement the org.apache.torque.Column interface.
rValue - the right hand side value of the comparison. If this value should be a value from the database, the object must implement the org.apache.torque.Column interface.
comparison - The comparison operator. Either this parameter or sql must be not null.
sql - a verbatim sql condition. Either this parameter or comparison must be not null.
preparedStatementReplacements - Values for the placeholders in the verbatim sql condition.
Throws:
NullPointerException - if column is null.

Criterion

public Criterion(Object lValue,
                 Object rValue)
Create a new instance without verbatim sql, using equals as comparison operator.

Parameters:
lValue - the left hand side value of the comparison, not null. If this value should be a value from the database, the object must implement the org.apache.torque.Column interface.
rValue - the right hand side value of the comparison. If this value should be a value from the database, the object must implement the org.apache.torque.Column interface.

Criterion

public Criterion(Object lValue,
                 Object rValue,
                 SqlEnum comparison)
Create a new instance without verbatim sql.

Parameters:
lValue - the left hand side value of the comparison, not null. If this value should be a value from the database, the object must implement the org.apache.torque.Column interface.
rValue - the right hand side value of the comparison. If this value should be a value from the database, the object must implement the org.apache.torque.Column interface.
comparison - The comparison operator, not null.

Criterion

public Criterion(Criterion toCopy)
Creates a shallow copy of the given Criterion.

Parameters:
toCopy - the Criterion to copy from, not null.
Method Detail

getLValue

public Object getLValue()
Get the left hand side value of the comparison.

Returns:
the left hand side value of the comparison. If this value is a value computed by the database, the object implements the org.apache.torque.Column interface.

setLValue

public void setLValue(Object lValue)
Set the left hand side value of the comparison.

Parameters:
lValue - the left hand side value of the comparison. If this value is a value computed by the database, the object must implement the org.apache.torque.Column interface.

getComparison

public SqlEnum getComparison()
Get the comparison.

Returns:
A String with the comparison, or null if this Criterion represents a verbatim sql condition.

getRValue

public Object getRValue()
Get the right hand side value of the comparison.

Returns:
the right hand side value of the comparison. If this value is a value computed by the database, the object implements the org.apache.torque.Column interface.

setRValue

public void setRValue(Object rValue)
Set the right hand side value of the comparison.

Parameters:
rValue - the right hand side value of the comparison. If this value is a value computed by the database, the object must implement the org.apache.torque.Column interface.

getSql

public String getSql()
Returns the verbatim sql for this condition.

Returns:
the verbatim sql for this condition, or null if this Criterion does not represent a verbatim sql condition.

getPreparedStatementReplacements

public Object[] getPreparedStatementReplacements()
Returns the prepared statement replacements for a verbatim sql condition.

Returns:
the replacement values, or null.

isVerbatimSqlCondition

public boolean isVerbatimSqlCondition()
Returns whether this Criterion represents a verbatim sql condition.

Returns:
true if this Criterion represents a verbatim sql condition, false if the sql is computed from lValue, comparison and rValue.

setIgnoreCase

public Criterion setIgnoreCase(boolean b)
Sets ignore case. ignoreCase is ignored for a verbatim sql statement.

Parameters:
b - True if case should be ignored.
Returns:
A modified Criterion object.

isIgnoreCase

public boolean isIgnoreCase()
Is ignore case on or off?

Returns:
True if case is ignored.

getParts

public List<Criterion> getParts()
Returns the parts of which this criterion consists.

Returns:
an unmodifiable list of the clauses, or null if this criterion is not a composite criterion.

getConjunction

public String getConjunction()
Returns the conjunction for the parts of this criterion

Returns:
the conjunction, or null if this criterion is not a composite criterion.

isComposite

public boolean isComposite()
Returns whether this criterion is a composite criterion.

Returns:
true if this criterion is a composite criterion, false if it represents a single condition.

and

public Criterion and(Criterion criterion)
Replaces this criterion's condition with (this criterion's condition AND criterion).

Parameters:
criterion - the criterion to and with this criterion, not null.

or

public Criterion or(Criterion criterion)
Replaces this criterion's condition with (this criterion's condition OR criterion).

Parameters:
criterion - the criterion to and with this criterion, not null.

appendTo

public void appendTo(StringBuilder sb)
Appends a debug String representation of the Criterion onto the String builder.


toString

public String toString()
Build a string representation of the Criterion for debug purposes.

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

equals

public boolean equals(Object obj)
This method checks another Criteria.Criterion to see if they contain the same attributes.

Overrides:
equals in class Object

hashCode

public int hashCode()
Returns a hash code value for the object.

Overrides:
hashCode in class Object


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