Search in sources :

Example 6 with OQueryOperator

use of com.orientechnologies.orient.core.sql.operator.OQueryOperator 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

OQueryOperator (com.orientechnologies.orient.core.sql.operator.OQueryOperator)6 OMultiCollectionIterator (com.orientechnologies.common.collection.OMultiCollectionIterator)1 OException (com.orientechnologies.common.exception.OException)1 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)1 OQueryParsingException (com.orientechnologies.orient.core.exception.OQueryParsingException)1 OCommandSQLParsingException (com.orientechnologies.orient.core.sql.OCommandSQLParsingException)1 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 OIndexReuseType (com.orientechnologies.orient.core.sql.operator.OIndexReuseType)1 OQueryOperatorEquals (com.orientechnologies.orient.core.sql.operator.OQueryOperatorEquals)1 OQueryOperatorFactory (com.orientechnologies.orient.core.sql.operator.OQueryOperatorFactory)1 OQueryOperatorNot (com.orientechnologies.orient.core.sql.operator.OQueryOperatorNot)1 OQueryOperatorNotEquals (com.orientechnologies.orient.core.sql.operator.OQueryOperatorNotEquals)1 OQueryOperatorNotEquals2 (com.orientechnologies.orient.core.sql.operator.OQueryOperatorNotEquals2)1 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 LinkedHashSet (java.util.LinkedHashSet)1