*/
protected void addCondition(List<ConditionExpression> conditions,
ValueNode condition,
List<ExpressionNode> projects)
throws StandardException {
DataTypeDescriptor conditionType = null;
TInstance conditionInst = null;
switch (condition.getNodeType()) {
case NodeTypes.BINARY_EQUALS_OPERATOR_NODE:
addComparisonCondition(conditions, projects,
(BinaryOperatorNode)condition, Comparison.EQ);
return;
case NodeTypes.BINARY_GREATER_THAN_OPERATOR_NODE:
addComparisonCondition(conditions, projects,
(BinaryOperatorNode)condition, Comparison.GT);
return;
case NodeTypes.BINARY_GREATER_EQUALS_OPERATOR_NODE:
addComparisonCondition(conditions, projects,
(BinaryOperatorNode)condition, Comparison.GE);
return;
case NodeTypes.BINARY_LESS_THAN_OPERATOR_NODE:
addComparisonCondition(conditions, projects,
(BinaryOperatorNode)condition, Comparison.LT);
return;
case NodeTypes.BINARY_LESS_EQUALS_OPERATOR_NODE:
addComparisonCondition(conditions, projects,
(BinaryOperatorNode)condition, Comparison.LE);
return;
case NodeTypes.BINARY_NOT_EQUALS_OPERATOR_NODE:
addComparisonCondition(conditions, projects,
(BinaryOperatorNode)condition, Comparison.NE);
return;
case NodeTypes.BETWEEN_OPERATOR_NODE:
addBetweenCondition(conditions, projects,
(BetweenOperatorNode)condition);
return;
case NodeTypes.IN_LIST_OPERATOR_NODE:
addInCondition(conditions, projects,
(InListOperatorNode)condition);
return;
case NodeTypes.SUBQUERY_NODE:
addSubqueryCondition(conditions, projects,
(SubqueryNode)condition);
return;
case NodeTypes.LIKE_OPERATOR_NODE:
addFunctionCondition(conditions, projects,
(TernaryOperatorNode)condition);
return;
case NodeTypes.IS_NULL_NODE:
case NodeTypes.IS_NOT_NULL_NODE:
addIsNullCondition(conditions, projects,
(IsNullNode)condition);
return;
case NodeTypes.IS_NODE:
addIsCondition(conditions, projects,
(IsNode)condition);
return;
case NodeTypes.OR_NODE:
case NodeTypes.AND_NODE:
case NodeTypes.NOT_NODE:
addLogicalFunctionCondition(conditions, projects, condition);
return;
case NodeTypes.BOOLEAN_CONSTANT_NODE:
conditions.add(new BooleanConstantExpression(((BooleanConstantNode)condition).getBooleanValue()));
return;
case NodeTypes.UNTYPED_NULL_CONSTANT_NODE:
conditions.add(new BooleanConstantExpression(null));
return;
case NodeTypes.PARAMETER_NODE:
assert (parameters != null) && parameters.contains(condition) : condition;
conditionType = condition.getType();
if (conditionType == null) {
conditionType = new DataTypeDescriptor(TypeId.BOOLEAN_ID, true);
condition.setType(conditionType);
}
conditionInst = typesTranslator.typeForSQLType(conditionType);
conditions.add(new ParameterCondition(((ParameterNode)condition)
.getParameterNumber(),
conditionType, condition, conditionInst));
return;
case NodeTypes.CAST_NODE:
// Use given cast type if it's suitable for a condition.
conditionType = condition.getType();
// CAST inside to BOOLEAN below.
condition = ((CastNode)condition).getCastOperand();
break;
case NodeTypes.JAVA_TO_SQL_VALUE_NODE:
conditions.add((ConditionExpression)
toExpression(((JavaToSQLValueNode)condition).getJavaValueNode(),
condition, true,
projects));
return;
}
// Anything else gets CAST to BOOLEAN, which may fail
// later due to lack of a suitable cast.
if (conditionType == null)
conditionType = condition.getType();
if (conditionType == null)
conditionType = new DataTypeDescriptor(TypeId.BOOLEAN_ID, true);
else if (!conditionType.getTypeId().isBooleanTypeId())
conditionType = new DataTypeDescriptor(TypeId.BOOLEAN_ID, conditionType.isNullable());
conditionInst = typesTranslator.typeForSQLType(conditionType);
conditions.add(new BooleanCastExpression(toExpression(condition, projects),
conditionType, condition, conditionInst));
}