protected boolean parenthesisNeeded(Expression node, Expression parentNode) { if (parentNode == null) return false; // only unary expressions can go w/o parenthesis if (node.getOperandCount() > 1) return true; if (node.getType() == Expression.OBJ_PATH) return false; if (node.getType() == Expression.DB_PATH) return false; return true; }
private void resolveAutoAliases(Expression expression) { Map<String, String> aliases = expression.getPathAliases(); if (!aliases.isEmpty()) { if (pathSplitAliases == null) { pathSplitAliases = new HashMap<>(); } pathSplitAliases.putAll(aliases); } int len = expression.getOperandCount(); for (int i = 0; i < len; i++) { Object operand = expression.getOperand(i); if (operand instanceof Expression) { resolveAutoAliases((Expression) operand); } } }
public boolean equals(Object object) { if (!(object instanceof Expression)) { return false; } Expression e = (Expression) object; if (e.getType() != getType() || e.getOperandCount() != getOperandCount()) { return false; } // compare operands int len = e.getOperandCount(); for (int i = 0; i < len; i++) { if (!Util.nullSafeEquals(e.getOperand(i), getOperand(i))) { return false; } } return true; }
@Override public boolean equals(Object object) { if (!(object instanceof Expression)) { return false; } Expression e = (Expression) object; if (e.getType() != getType() || e.getOperandCount() != getOperandCount()) { return false; } // compare operands int len = e.getOperandCount(); for (int i = 0; i < len; i++) { if (!Util.nullSafeEquals(e.getOperand(i), getOperand(i))) { return false; } } return true; }
private ASTObjPath findChildPath(Expression exp) { if (exp instanceof ASTObjPath) { return (ASTObjPath) exp; } int len = exp.getOperandCount(); for (int i = 0; i < len; i++) { Object operand = exp.getOperand(i); if (!(operand instanceof Expression)) { continue; } ASTObjPath path = findChildPath((Expression) operand); if (path != null) { return path; } } return null; } }
public void startNode(Expression node, Expression parentNode) { if (node.getOperandCount() == 2) { // binary nodes are the only ones that currently require this detectObjectMatch(node); if (parenthesisNeeded(node, parentNode)) { qualBuf.append('('); } // super implementation has special handling // of LIKE_IGNORE_CASE and NOT_LIKE_IGNORE_CASE // Postgres uses ILIKE // ... } else { super.startNode(node, parentNode); } }
@Override public void startNode(Expression node, Expression parentNode) { if (node.getOperandCount() == 2) { // binary nodes are the only ones that currently require this detectObjectMatch(node); if (parenthesisNeeded(node, parentNode)) { out.append('('); } // super implementation has special handling // of LIKE_IGNORE_CASE and NOT_LIKE_IGNORE_CASE // OpenBase is case-insensitive by default // ... } else { super.startNode(node, parentNode); } }
public void startNode(Expression node, Expression parentNode) { if (node.getOperandCount() == 2) { // binary nodes are the only ones that currently require this detectObjectMatch(node); if (parenthesisNeeded(node, parentNode)) { qualBuf.append('('); } // super implementation has special handling // of LIKE_IGNORE_CASE and NOT_LIKE_IGNORE_CASE // OpenBase is case-insensitive by default // ... } else { super.startNode(node, parentNode); } }
public void endNode(Expression node, Expression parentNode) { if (node.getOperandCount() == 2) { // check if we need to use objectMatchTranslator to finish building the expression if (matchingObject) { appendObjectMatch(); } if (parenthesisNeeded(node, parentNode)) qualBuf.append(')'); // super implementation has special handling // of LIKE_IGNORE_CASE and NOT_LIKE_IGNORE_CASE // Postgres uses ILIKE // ... } else { super.endNode(node, parentNode); } }
public void endNode(Expression node, Expression parentNode) { if (node.getOperandCount() == 2) { // check if we need to use objectMatchTranslator to finish building the expression if (matchingObject) { appendObjectMatch(); } if (parenthesisNeeded(node, parentNode)) qualBuf.append(')'); // super implementation has special handling // of LIKE_IGNORE_CASE and NOT_LIKE_IGNORE_CASE // OpenBase is case-insensitive by default // ... } else { super.endNode(node, parentNode); } }
/** * @since 1.1 */ public void endNode(Expression node, Expression parentNode) { // check if we need to use objectMatchTranslator to finish building the expression if (node.getOperandCount() == 2 && matchingObject) { appendObjectMatch(); } if (parenthesisNeeded(node, parentNode)) { qualBuf.append(')'); } if (node.getType() == Expression.LIKE_IGNORE_CASE || node.getType() == Expression.NOT_LIKE_IGNORE_CASE) { qualBuf.append(')'); } }
@Override public void endNode(Expression node, Expression parentNode) { if (node.getOperandCount() == 2) { try { // check if we need to use objectMatchTranslator to finish // building the // expression if (matchingObject) { appendObjectMatch(); } if (PatternMatchNode.class.isAssignableFrom(node.getClass())) { appendLikeEscapeCharacter((PatternMatchNode) node); } if (parenthesisNeeded(node, parentNode)) { out.append(')'); } // super implementation has special handling // of LIKE_IGNORE_CASE and NOT_LIKE_IGNORE_CASE // OpenBase is case-insensitive by default // ... } catch (IOException ioex) { throw new CayenneRuntimeException("Error appending content", ioex); } } else { super.endNode(node, parentNode); } }
/** * Called before processing an expression to initialize * objectMatchTranslator if needed. */ protected void detectObjectMatch(Expression exp) { // On demand initialization of // objectMatchTranslator is not possible since there may be null // object values that would not allow to detect the need for // such translator in the right time (e.g.: null = dbpath) matchingObject = false; if (exp.getOperandCount() != 2) { // only binary expressions are supported return; } // check if there are DataObjects among direct children of the Expression for (int i = 0; i < 2; i++) { Object op = exp.getOperand(i); if (op instanceof DataObject || op instanceof ObjectId) { matchingObject = true; if (objectMatchTranslator == null) { objectMatchTranslator = new DataObjectMatchTranslator(); } else { objectMatchTranslator.reset(); } break; } } }
/** * Called before processing an expression to initialize * objectMatchTranslator if needed. */ protected void detectObjectMatch(Expression exp) { // On demand initialization of // objectMatchTranslator is not possible since there may be null // object values that would not allow to detect the need for // such translator in the right time (e.g.: null = dbpath) matchingObject = false; if (exp.getOperandCount() != 2) { // only binary expressions are supported return; } // check if there are DataObjects among direct children of the // Expression for (int i = 0; i < 2; i++) { Object op = exp.getOperand(i); if (op instanceof Persistent || op instanceof ObjectId) { matchingObject = true; if (objectMatchTranslator == null) { objectMatchTranslator = new DataObjectMatchTranslator(); } else { objectMatchTranslator.reset(); } break; } } }
@Override public void objectNode(Object leaf, Expression parentNode) { if (leaf instanceof JsonNode) { for (int i = 0; i < parentNode.getOperandCount(); i++) { if (leaf == parentNode.getOperand(i)) { parentNode.setOperand(i, convert((SimpleNode) parentNode, (JsonNode) leaf)); } } } // this is ASTList child case else if (leaf instanceof Object[]) { Object[] array = (Object[]) leaf; for (int i = 0; i < array.length; i++) { if (array[i] instanceof JsonNode) { array[i] = convert((SimpleNode) parentNode, (JsonNode) array[i]); } } } else if (leaf instanceof String) { for (int i = 0; i < parentNode.getOperandCount(); i++) { if (leaf == parentNode.getOperand(i)) { parentNode.setOperand(i, convert((SimpleNode) parentNode, TextNode.valueOf((String) leaf))); } } } }
@Override public int hashCode() { HashCodeBuilder builder = new HashCodeBuilder().append(getType()); int opCount = getOperandCount(); for(int i=0; i<opCount; i++) { builder.append(getOperand(i)); } return builder.toHashCode(); }
protected boolean parenthesisNeeded(Expression node, Expression parentNode) { if (node.getType() == Expression.FUNCTION_CALL) { return ((ASTFunctionCall)node).needParenthesis(); } if (parentNode == null) { return false; } // only unary expressions can go w/o parenthesis if (node.getOperandCount() > 1) { return true; } if (node.getType() == Expression.OBJ_PATH || node.getType() == Expression.DB_PATH || node.getType() == Expression.ASTERISK) { return false; } return true; }
/** * Traverses itself and child expressions, notifying visitor via callback methods as * it goes. * * @since 1.1 */ protected void traverse(Expression parentExp, TraversalHandler visitor) { visitor.startNode(this, parentExp); // recursively traverse each child int count = getOperandCount(); for (int i = 0; i < count; i++) { Object child = getOperand(i); if (child instanceof Expression) { Expression childExp = (Expression) child; childExp.traverse(this, visitor); } else { visitor.objectNode(child, this); } visitor.finishedChild(this, i, i < count - 1); } visitor.endNode(this, parentExp); }
/** * Traverses itself and child expressions, notifying visitor via callback * methods as it goes. * * @since 1.1 */ protected void traverse(Expression parentExp, TraversalHandler visitor) { visitor.startNode(this, parentExp); // recursively traverse each child int count = getOperandCount(); for (int i = 0; i < count; i++) { Object child = getOperand(i); if (child instanceof Expression && !(child instanceof ASTScalar)) { Expression childExp = (Expression) child; childExp.traverse(this, visitor); } else { visitor.objectNode(child, this); } visitor.finishedChild(this, i, i < count - 1); } visitor.endNode(this, parentExp); }
int count = getOperandCount(); for (int i = 0, j = 0; i < count; i++) { Object operand = getOperand(i);