Search in sources :

Example 1 with OQueryOperatorNotEquals

use of com.orientechnologies.orient.core.sql.operator.OQueryOperatorNotEquals in project orientdb by orientechnologies.

the class OCommandExecutorSQLResultsetAbstract method optimizeBranch.

protected void optimizeBranch(final OSQLFilterCondition iParentCondition, OSQLFilterCondition iCondition) {
    if (iCondition == null)
        return;
    Object left = iCondition.getLeft();
    if (left instanceof OSQLFilterCondition) {
        // ANALYSE LEFT RECURSIVELY
        optimizeBranch(iCondition, (OSQLFilterCondition) left);
    } else if (left instanceof OSQLFunctionRuntime) {
        left = optimizeFunction((OSQLFunctionRuntime) left);
        iCondition.setLeft(left);
    }
    Object right = iCondition.getRight();
    if (right instanceof OSQLFilterCondition) {
        // ANALYSE RIGHT RECURSIVELY
        optimizeBranch(iCondition, (OSQLFilterCondition) right);
    } else if (right instanceof OSQLFunctionRuntime) {
        right = optimizeFunction((OSQLFunctionRuntime) right);
        iCondition.setRight(right);
    }
    final OQueryOperator oper = iCondition.getOperator();
    Object result = null;
    if (left instanceof OSQLFilterItemField && right instanceof OSQLFilterItemField) {
        if (((OSQLFilterItemField) left).getRoot().equals(((OSQLFilterItemField) right).getRoot())) {
            if (oper instanceof OQueryOperatorEquals)
                result = Boolean.TRUE;
            else if ((oper instanceof OQueryOperatorNotEquals) || (oper instanceof OQueryOperatorNotEquals2))
                result = Boolean.FALSE;
        }
    }
    if (result != null) {
        if (iParentCondition != null)
            if (iCondition == iParentCondition.getLeft())
                // REPLACE LEFT
                iCondition.setLeft(result);
            else
                // REPLACE RIGHT
                iCondition.setRight(result);
        else {
            // REPLACE ROOT CONDITION
            if (result instanceof Boolean && ((Boolean) result))
                compiledFilter.setRootCondition(null);
        }
    }
}
Also used : OSQLFilterCondition(com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition) OSQLFunctionRuntime(com.orientechnologies.orient.core.sql.functions.OSQLFunctionRuntime) OSQLFilterItemField(com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField) OQueryOperatorNotEquals(com.orientechnologies.orient.core.sql.operator.OQueryOperatorNotEquals) OQueryOperatorNotEquals2(com.orientechnologies.orient.core.sql.operator.OQueryOperatorNotEquals2) OQueryOperator(com.orientechnologies.orient.core.sql.operator.OQueryOperator) OQueryOperatorEquals(com.orientechnologies.orient.core.sql.operator.OQueryOperatorEquals)

Aggregations

OSQLFilterCondition (com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition)1 OSQLFilterItemField (com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField)1 OSQLFunctionRuntime (com.orientechnologies.orient.core.sql.functions.OSQLFunctionRuntime)1 OQueryOperator (com.orientechnologies.orient.core.sql.operator.OQueryOperator)1 OQueryOperatorEquals (com.orientechnologies.orient.core.sql.operator.OQueryOperatorEquals)1 OQueryOperatorNotEquals (com.orientechnologies.orient.core.sql.operator.OQueryOperatorNotEquals)1 OQueryOperatorNotEquals2 (com.orientechnologies.orient.core.sql.operator.OQueryOperatorNotEquals2)1