Search in sources :

Example 1 with ConditionAndOr

use of com.wplatform.ddal.command.expression.ConditionAndOr in project jdbc-shards by wplatform.

the class Select method addGlobalCondition.

@Override
public void addGlobalCondition(Parameter param, int columnId, int comparisonType) {
    addParameter(param);
    Expression comp;
    Expression col = expressions.get(columnId);
    col = col.getNonAliasExpression();
    if (col.isEverything(ExpressionVisitor.QUERY_COMPARABLE_VISITOR)) {
        comp = new Comparison(session, comparisonType, col, param);
    } else {
        // this condition will always evaluate to true, but need to
        // add the parameter, so it can be set later
        comp = new Comparison(session, Comparison.EQUAL_NULL_SAFE, param, param);
    }
    comp = comp.optimize(session);
    boolean addToCondition = true;
    if (isGroupQuery) {
        addToCondition = false;
        for (int i = 0; groupIndex != null && i < groupIndex.length; i++) {
            if (groupIndex[i] == columnId) {
                addToCondition = true;
                break;
            }
        }
        if (!addToCondition) {
            if (havingIndex >= 0) {
                having = expressions.get(havingIndex);
            }
            if (having == null) {
                having = comp;
            } else {
                having = new ConditionAndOr(ConditionAndOr.AND, having, comp);
            }
        }
    }
    if (addToCondition) {
        if (condition == null) {
            condition = comp;
        } else {
            condition = new ConditionAndOr(ConditionAndOr.AND, condition, comp);
        }
    }
}
Also used : Expression(com.wplatform.ddal.command.expression.Expression) Comparison(com.wplatform.ddal.command.expression.Comparison) ConditionAndOr(com.wplatform.ddal.command.expression.ConditionAndOr)

Aggregations

Comparison (com.wplatform.ddal.command.expression.Comparison)1 ConditionAndOr (com.wplatform.ddal.command.expression.ConditionAndOr)1 Expression (com.wplatform.ddal.command.expression.Expression)1