Advanced Customization > Services and Infrastructure Customization > Advanced Query Capabilities > SearchCondition
  
SearchCondition
A SearchCondition represents a SQL WHERE clause expression of the following form: <left side operand> <operator> <right side operand>
The following are examples:
MyTable.Column1 = 5
MyTable.Column2 LIKE "E%"
MyTable.Column3 = JoinTable.Column1
Operands can also be more complex, such as SQL functions or subselects. SearchCondition can use arbitrary RelationalExpression operands. The operands can be specified using the SearchCondition constructor or setter methods. The following are concrete ColumnExpression implementations:
ClassAttribute
This class represents a class attribute that can be used in a SQL statement. Introspection information is used to determine the associated table and column.
SQLFunction
This class represents a SQL function within a SQL statement.
SubSelectExpression
This class represents a subselect that can be used in a SQL statement. The subselect is specified via a StatementSpec attribute.
ConstantExpression
This class represents a constant in a SQL statement.
KeywordExpression
This class represents an expression that evaluates to a SQL keyword that can be used in a SQL statement.
RangeExpression
This class represents a range in a SQL WHERE clause.
DateExpression
This class represents a date constant in a SQL statement. This subclass of ConstantExpression is necessary to provide the special handling for date values.
ArrayExpression
This class represents an array of constants in a SQL IN clause.
TableColumn
This class represents a table column that can be used in a SQL statement. The exact table and column name specified are used directly in the SQL statement.
The following example builds a complex query to determine the WTPartMaster object with the oldest modify timestamp after a specified date cutoff. Following is the SQL for this query:
SELECT A0.*
FROM WTPartMaster A0
WHERE (A0.modifyStampA2 IN (SELECT MIN(B0.modifyStampA2)
FROM WTPartMaster B0
WHERE B0.modifyStampA2 > ’cutoff’) )
The following code constructs the query specification:
Class targetClass = wt.part.WTPartMaster.class;
QuerySpec subSelect = new QuerySpec();
subSelect.getFromClause().setAliasPrefix("B");
int subIndex = subSelect.appendClassList(targetClass, false);
int[] fromIndicies = { subIndex };
ClassAttribute subModifyStamp =
new ClassAttribute(targetClass,WTAttributeNameIfc.MODIFY_STAMP_NAME);
SQLFunction minFunction = SQLFunction.new SQLFunction(SQLFunction.
MINIMUM, subModifyStamp);
subSelect.appendSelect(minFunction, fromIndicies, false);
subSelect.appendWhere(new SearchCondition(subModifyStamp,
SearchCondition.GREATER_THAN, DateExpression.newExpression(cutoff)),
fromIndicies);


QuerySpec select = new QuerySpec();
int index = select.appendClassList(targetClass, true);
select.appendWhere(new SearchCondition(modifyStamp,SearchCondition.IN,
new SubSelectExpression(subSelect)), new int[] { index });