com.sun.mdm.index.query
Class Condition

java.lang.Object
  extended bycom.sun.mdm.index.query.Condition

public class Condition
extends java.lang.Object

The Condition class represents a condition in the WHERE clause of a SQL statement that is used to build a query object. Each condition in the clause requires a different instance of the Condition class. A condition contains a field name, an operator, and one or more values for the field. By default, conditions are joined to each other by AND operators, but you can specify OR by using the addConditions method and specifying "OR" as the join type. A Condition objet can be a condition container that includes both a left condition and a list of right conditions. By using the appropriate methods, you can build a next OR/AND condition tree.

For example, to create the condition statement "Enterprise.SystemSBR.Person.FirstName = John OR Enterprise.SystemSBR.Person.FirstName = James", use the following methods.

Condition condition = new Condition ("Enterprise.SystemSBR.Person.FirstName", "=", "John", true);

condition.addConditions("OR", new Condition("Enterprise.SystemSBR.Person.FirstName", "=", "James", true));


Field Summary
(package private)  Condition mCondition
           
(package private) static int PREPARE_ATLEAST_ONE
           
(package private) static int PREPARE_IN
           
(package private) static int PREPARE_NONE
           
 
Constructor Summary
Condition(Condition condition)
          This a copy constructor for the Condition class and creates a copy of the specified condition object enclosed in parenthesis.
Condition(java.lang.String field, java.lang.Object value)
          Creates a new instance of the Condition class where the operator is = (equals) by default.
Condition(java.lang.String field, java.lang.String operator, java.lang.Object value)
          Creates a new instance of the Condition class.
Condition(java.lang.String field, java.lang.String operator, java.lang.Object[] values)
          Creates a new instance of the Condition class that uses an array of values, and only supports the IN operator.
Condition(java.lang.String field, java.lang.String operator, java.lang.Object[] values, boolean prepare)
          Creates a new instance of the Condition class that uses an array of values, and only supports the IN operator.
Condition(java.lang.String field, java.lang.String operator, java.lang.Object value, boolean prepare)
          Creates a new instance of the Condition class.
 
Method Summary
 void addCondition(java.lang.String joinType, java.lang.String field, java.lang.Object value)
          Adds a new condition to a generated SQL statement where the operator within the condition is = (equals) by default.
 void addCondition(java.lang.String joinType, java.lang.String field, java.lang.String operator, java.lang.Object value)
          Adds a new condition to a generated SQL statement.
 void addCondition(java.lang.String joinType, java.lang.String field, java.lang.String operator, java.lang.Object[] values)
          Adds a new condition to a generated SQL statement using an array of values.
 void addCondition(java.lang.String joinType, java.lang.String field, java.lang.String operator, java.lang.Object value, boolean prepare)
          Adds a new condition to a generated SQL statement and specifies whether to bind the value to a prepared statement.
 void addConditions(java.lang.String joinType, Condition condition)
          Adds an existing condition to a generated SQL statement.
(package private)  void calcBlock()
          The Condition Tree is traversed to calculate if this node will be considered a Block or not.
(package private)  void chains(Condition otherCondition, java.util.Hashtable conditionsLookup)
           
(package private)  boolean compareWith(Condition otherCondTree, java.util.Map bindingAssociation)
          If the two conditions are EQUAL then a entry key = this & value = newCondition is added to the binding parameters.
 boolean equals(Condition theOtherCondition)
           
(package private) static java.lang.String formatDate(java.lang.Object value, java.lang.String returnType)
          Reformats a date to a String.
(package private)  java.lang.String getAlternateSubQuery()
          Retrieves a subquery for the condition expression.
(package private)  ConditionDescriptor getConditionDescriptor()
          Retrieves the condition descriptor for the prepared statement.
(package private)  java.lang.String getField()
          Retrieves the field name to be used for this condition in the WHERE clause.
(package private)  java.util.List getJoinConditionList()
          Retrieves a list of join operators for the conditions.
(package private)  Condition getLeftOperand()
           
(package private)  java.lang.String getObjectName()
          Retrieves the name of the object to which the field in this condition belongs.
(package private)  java.lang.String getOperator()
          Retrieves the SQL operator to be used for this condition in the WHERE clause.
(package private)  int getParamSize()
           
(package private)  int getPrepareStatus()
          Three types of status possible 1.
(package private)  java.lang.String getType()
          Retrieves the column type from an instance of the Condition class, based on the path of the condition field.
(package private)  java.lang.Object getValue()
          Retrieves the value to be used for this condition in the WHERE clause.
(package private)  java.lang.Object getValues()
          Retrieves an array of values to be used for this condition in the WHERE clause.
 int hashCode()
           
 java.lang.String hashString()
           
(package private)  boolean isBlock()
          Returns an indicator of whether a condition node is a block.
(package private)  boolean isInOperator()
          Indicates whether the operator for the condition is IN.
(package private)  boolean isLeaf()
          Returns an indicator of whether a condition node is a leaf in the object tree.
(package private)  boolean isOldFormatConditionExpressionTree()
          This method will return true if and only if all the Conditions in the Condition Expression are connected by AND Operator.
(package private)  boolean isPrepare()
          Indicates whether the statement will be prepared.
(package private)  void parseTree()
           
(package private)  void propagatePrepareStatus(boolean prepareStatus)
           
(package private)  void setAlternateSubQuery(java.lang.String alternateSubQuery)
          Sets a subquery for the condition expression.
(package private)  void setConditionDescriptor(ConditionDescriptor condDesc)
           
(package private)  void setConditionsBlockList(java.util.List list)
          Sets a list of all conditions in a condition expression if the following is true:
(package private)  void setConditionsLeafList(java.util.List list)
          Sets a list of all conditions in a condition expression that are leafs in the object tree.
(package private)  void setPrepare(boolean prepare)
          Sets the prepared statement indicator for an instance of the Condition class.
 java.lang.String toString()
          Returns a String representation of this class
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

mCondition

Condition mCondition

PREPARE_ATLEAST_ONE

static int PREPARE_ATLEAST_ONE

PREPARE_IN

static int PREPARE_IN

PREPARE_NONE

static int PREPARE_NONE
Constructor Detail

Condition

public Condition(Condition condition)
This a copy constructor for the Condition class and creates a copy of the specified condition object enclosed in parenthesis. This condition arguement becomes the left condition in a condition container, allowing for nested AND/OR operators in the WHERE clauses of your queries.

Parameters:
condition - The Condition object to copy.
Throws:
None.

Condition

public Condition(java.lang.String field,
                 java.lang.Object value)
Creates a new instance of the Condition class where the operator is = (equals) by default.

Parameters:
field - The qualified field name for the condition (qualified field names are in the format object_name.field_name).
value - The value for the condition (do not use quotes).
Throws:
None.

Condition

public Condition(java.lang.String field,
                 java.lang.String operator,
                 java.lang.Object value)
Creates a new instance of the Condition class.

Parameters:
field - The qualified field name for the condition (qualified field names are in the format object_name.field_name.
operator - The condition operator. Supported operators include LIKE, =, >, <, >=, and <=.
value - The value for the condition (do not use quotes).
Throws:
None.

Condition

public Condition(java.lang.String field,
                 java.lang.String operator,
                 java.lang.Object[] values)
Creates a new instance of the Condition class that uses an array of values, and only supports the IN operator.

Parameters:
field - The qualified field name for the condition (qualified field names are in the format object_name.field_name).
operator - The condition operator (currently, IN is the only supported operator).
values - An array of values for the condition.
Throws:
None.

Condition

public Condition(java.lang.String field,
                 java.lang.String operator,
                 java.lang.Object[] values,
                 boolean prepare)
Creates a new instance of the Condition class that uses an array of values, and only supports the IN operator. You can also specify whether to bind the values to a prepared statement.

Parameters:
field - The qualified field name for the condition (qualified field names are in the format object_name.field_name).
operator - The condition operator (currently, IN is the only supported operator).
values - An array of values for the condition.
prepare - A Boolean indicator of whether to bind the values to a prepared statement. Specify true to bind the values; otherwise specify false.
Throws:
None.

Condition

public Condition(java.lang.String field,
                 java.lang.String operator,
                 java.lang.Object value,
                 boolean prepare)
Creates a new instance of the Condition class. This methods allows you to specify whether to bind the values to a prepared statement.

Parameters:
field - The qualified field name for the condition (qualified field names are in the format object_name.field_name).
operator - The condition operator. Supported operators include LIKE, =, >, and <.
value - The value for the condition (do not use quotes).
prepare - A Boolean indicator of whether to bind the values to a prepared statement. Specify true to bind the values; otherwise specify false.
Throws:
None.
Method Detail

addCondition

public void addCondition(java.lang.String joinType,
                         java.lang.String field,
                         java.lang.Object value)
Adds a new condition to a generated SQL statement where the operator within the condition is = (equals) by default.

Parameters:
joinType - The type of join operator to use between this condition and the previous one.
field - The qualified field name for the condition (qualified field names are in the format object_name.field_name.
value - The value for the condition (do not use quotes).
Returns:
void - None.
Throws:
None.

addCondition

public void addCondition(java.lang.String joinType,
                         java.lang.String field,
                         java.lang.String operator,
                         java.lang.Object value)
Adds a new condition to a generated SQL statement.

Parameters:
joinType - The type of join operator to use between this condition and the previous one.
field - The qualified field name for the condition (qualified field names are in the format object_name.field_name).
operator - The condition operator. Supported operators include LIKE, =, >, and <.
value - The value for the condition (do not use quotes).
Returns:
void - None.
Throws:
None.

addCondition

public void addCondition(java.lang.String joinType,
                         java.lang.String field,
                         java.lang.String operator,
                         java.lang.Object[] values)
Adds a new condition to a generated SQL statement using an array of values. This method only supports the IN operator within the new condition.

Parameters:
joinType - The type of join operator to use between this condition and the previous one.
field - The qualified field name for the condition (qualified field names are in the format object_name.field_name).
operator - The condition operator (currently, IN is the only supported operator).
values - An array of values for the condition.
Returns:
void - None.
Throws:
None.

addCondition

public void addCondition(java.lang.String joinType,
                         java.lang.String field,
                         java.lang.String operator,
                         java.lang.Object value,
                         boolean prepare)
Adds a new condition to a generated SQL statement and specifies whether to bind the value to a prepared statement.

Parameters:
joinType - The type of join operator to use between this condition and the previous one.
field - The qualified field name for the condition (qualified field names are in the format object_name.field_name).
operator - The condition operator. Supported operators include LIKE, =, >, and <.
value - The value for the condition.
prepare - A Boolean indicator of whether bind the value to a prepared statement. Specify true to bind the value; otherwise specify false.
Returns:
void - None.
Throws:
None.

addConditions

public void addConditions(java.lang.String joinType,
                          Condition condition)
Adds an existing condition to a generated SQL statement.

Parameters:
joinType - The type of join operator to use between this condition and the previous one.
condition - The condition to add to the statement.
Returns:
void - None.
Throws:
None.

calcBlock

void calcBlock()
The Condition Tree is traversed to calculate if this node will be considered a Block or not. A Condition Node is considered a Block if all its child nodes belongs to same Object as the this node itself. Node.isBlock() if Node.isLeaf() then Node.isBlock = true else If the Statement A is true then Node.isBlock = true else Node.isBlock = false end if end if Statement A: For each Children of the Node child.ObjectName == node.objectName & child.isBlock = true end for


chains

void chains(Condition otherCondition,
            java.util.Hashtable conditionsLookup)

compareWith

boolean compareWith(Condition otherCondTree,
                    java.util.Map bindingAssociation)
If the two conditions are EQUAL then a entry key = this & value = newCondition is added to the binding parameters. This is required to replace the old binding of the cached QueryObject with the new one.


equals

public boolean equals(Condition theOtherCondition)

formatDate

static java.lang.String formatDate(java.lang.Object value,
                                   java.lang.String returnType)
Reformats a date to a String.

Parameters:
value - The value to reformat.
returnType - The type of value to reformat. You can specify "DATE" or "TIMESTAMP".
Throws:
None.

getAlternateSubQuery

java.lang.String getAlternateSubQuery()
Retrieves a subquery for the condition expression. See the description for setAlternateSubQuery for more information.

Parameters:
None.

Returns:
String - The subquery for the condition expression.
Throws:
None.

getConditionDescriptor

ConditionDescriptor getConditionDescriptor()
Retrieves the condition descriptor for the prepared statement.

Parameters:
None.

Returns:
ConditionDescriptor - The condition descriptor.
Throws:
None.

getField

java.lang.String getField()
Retrieves the field name to be used for this condition in the WHERE clause.

Parameters:
None.

Returns:
String - The name of the field to use.
Throws:
None.

getJoinConditionList

java.util.List getJoinConditionList()
Retrieves a list of join operators for the conditions.

Parameters:
None.

Returns:
List - A list of join operators.
Throws:
None.

getLeftOperand

Condition getLeftOperand()

getObjectName

java.lang.String getObjectName()
Retrieves the name of the object to which the field in this condition belongs.

Parameters:
None.

Returns:
String - The name of the field's object.
Throws:
None.

getOperator

java.lang.String getOperator()
Retrieves the SQL operator to be used for this condition in the WHERE clause.

Parameters:
None.

Returns:
String - The operator for the WHERE clause.
Throws:
None.

getParamSize

int getParamSize()

getPrepareStatus

int getPrepareStatus()
Three types of status possible 1. One of the node is containing IN PREPARE_IN 2. At least one node is prepared PREPARE_ATLEAST_ONE 3. None of the node is prepared PREPARE_NONE When get a IN, just return as it takes the precedence. Or else keep traversing. However once ATLEAST_ONE is set, this value if retained.


getType

java.lang.String getType()
Retrieves the column type from an instance of the Condition class, based on the path of the condition field.

Parameters:
None.

Returns:
String - The type of database column used in the WHERE clause.
Throws:
None.

getValue

java.lang.Object getValue()
Retrieves the value to be used for this condition in the WHERE clause.

Parameters:
None.

Returns:
Object - The value for the WHERE clause.
Throws:
None.

getValues

java.lang.Object getValues()
Retrieves an array of values to be used for this condition in the WHERE clause.

Parameters:
None.

Returns:
Object - An array of values for the WHERE clause.
Throws:
None.

hashCode

public int hashCode()

hashString

public java.lang.String hashString()

isBlock

boolean isBlock()
Returns an indicator of whether a condition node is a block.

Parameters:
None.

Returns:
Boolean - A Boolean indicator of whether the node is a block. True indicates the node is a block; false indicates the node is not a block.
Throws:
None.

isInOperator

boolean isInOperator()
Indicates whether the operator for the condition is IN.

Parameters:
None.

Returns:
Boolean - An indicator of whether the operator in this condition is IN. Boolean true indicates the operator is IN; Boolean false indicates it is not.
Throws:
None.

isLeaf

boolean isLeaf()
Returns an indicator of whether a condition node is a leaf in the object tree.

Parameters:
None.

Returns:
Boolean - A Boolean indicator of whether the node is a leaf. True indicates the node is a leaf; false indicates the node is not a leaf.
Throws:
None.

isOldFormatConditionExpressionTree

boolean isOldFormatConditionExpressionTree()
This method will return true if and only if all the Conditions in the Condition Expression are connected by AND Operator. This is irrespective of weather the conditions are in Array structure or in a Condition Tree


isPrepare

boolean isPrepare()
Indicates whether the statement will be prepared.

Parameters:
None.

Returns:
Boolean - An indicator of whether the condition will be prepared. Boolean true indicates the condition will be prepared; Boolean false indicates it will not be prepared.
Throws:
None.

parseTree

void parseTree()

propagatePrepareStatus

void propagatePrepareStatus(boolean prepareStatus)

setAlternateSubQuery

void setAlternateSubQuery(java.lang.String alternateSubQuery)
Sets a subquery for the condition expression. If a condition expression contains objects whose fields are part of the select list, part of the condition expression must be converted to a subquery. The SQL constructor decides if the condition should return the condition expression as is or if part of the expression must be transformed into a subquery.

Parameters:
alternateSubQuery - A subquery for the condition expression.
Returns:
void - None.
Throws:
None.

setConditionDescriptor

void setConditionDescriptor(ConditionDescriptor condDesc)
Parameters:
condDesc - A Condition Object may represent a Condition Expression And to Calculate a Condition Descriptor requires to traverse to all the child Objects. A Condition Descriptor for a Condition represents a Condition Expression.

setConditionsBlockList

void setConditionsBlockList(java.util.List list)
Sets a list of all conditions in a condition expression if the following is true:

This keeps conditions together if they belong to the same object, and helps generate optimized queries.

Parameters:
list - A list of conditions.
Returns:
void - None.
Throws:
None.

setConditionsLeafList

void setConditionsLeafList(java.util.List list)
Sets a list of all conditions in a condition expression that are leafs in the object tree.

Parameters:
list - A list of conditions.
Returns:
void - None.
Throws:
None.

setPrepare

void setPrepare(boolean prepare)
Sets the prepared statement indicator for an instance of the Condition class.

Parameters:
prepare - A Boolean indicator of whether to prepare the statement for the condition. Specify true to prepare the statement; otherwise specify false.
Returns:
void - None.
Throws:
None.

toString

public java.lang.String toString()
Returns a String representation of this class

Returns:
a String representation of this class


Sun Microsystems, Inc.