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; }
/** * Sets the expression defining a ordering Java Bean property. */ public void setSortSpec(Expression sortSpec) { this.sortSpec = sortSpec; this.sortSpecString = (sortSpec != null) ? sortSpec.toString() : null; }
/** * Adds specified HAVING qualifier to the existing HAVING qualifier joining it using "AND". * @since 4.0 */ public void andHavingQualifier(Expression e) { havingQualifier = (havingQualifier != null) ? havingQualifier.andExp(e) : e; }
/** * Returns the result of evaluation of expression with object. */ public Object cayenneExp(Object object, String expression) { return Expression.fromString(expression).evaluate(object); } }
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; }
public Object transform(Object input) { if (!(input instanceof Expression)) { return input; } Expression expression = (Expression) input; if (expression.getType() != Expression.OBJ_PATH) { return input; } // convert obj_path to db_path String converted = toDbPath(createPathIterator((String) expression.getOperand(0))); Expression exp = ExpressionFactory.expressionOfType(Expression.DB_PATH); exp.setOperand(0, converted); return exp; } }
/** * 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); }
@Override public Iterator<CayenneMapEntry> resolvePathComponents(Expression pathExp) throws ExpressionException { if (pathExp.getType() != Expression.DB_PATH) { throw new ExpressionException("Invalid expression type: '" + pathExp.expName() + "', DB_PATH is expected."); } return new PathIterator((String) pathExp.getOperand(0)); }
if (expression.getType() != Expression.OBJ_PATH) { return input; StringTokenizer toks = new StringTokenizer(expression.toString(), "."); while (toks.hasMoreTokens() && entity != null) { String chunk = toks.nextToken(); exp.setOperand(0, buffer.toString()); return exp;
public Expression trimmedInExpression(Expression exp, int maxInSize) { Expression list = (Expression) exp.getOperand(1); Object[] objects = (Object[]) list.evaluate(null); if (objects.length <= maxInSize) { return exp; } Expression trimmed = trimmedInExpression((ASTPath) exp.getOperand(0), objects, maxInSize); if (exp instanceof ASTNotIn) { return trimmed.notExp(); } return trimmed; }
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); } } }
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 finishedChild(Expression parentNode, int childIndex, boolean hasMoreChildren) { Object childNode = parentNode.getOperand(childIndex); if (childNode instanceof ASTObjPath) { // validate and replace if needed ... note that we can only // replace non-root nodes during the traversal. Root node is // validated and replaced explicitly by the caller. ASTPath replacement = pathCache.getPathDescriptor(entity, (ASTObjPath) childNode).getPathExp(); if (replacement != childNode) { parentNode.setOperand(childIndex, replacement); } } }
PropertyNode(Expression pathExp) { this.pathExp = pathExp; this.propertyPath = (String) pathExp.getOperand(0); }
/** * Calculates expression boolean value with object as a context for path * expressions. * * @since 1.1 */ public boolean match(Object o) { return ConversionUtil.toBoolean(evaluate(o)); }
/** * Returns the first object in the list that matches the expression. * * @since 3.1 */ public <T> T first(List<T> objects) { for (T o : objects) { if (match(o)) { return o; } } return null; }
Expression pathExp = oe.translateToDbPath(Expression.fromString(path)); String labelPrefix = pathExp.toString().substring("db:".length()); Expression prefetchExp = Expression.fromString(prefetch.getPath()); Expression dbPrefetch = oe.translateToDbPath(prefetchExp); ObjRelationship targetRel = (ObjRelationship) prefetchExp.evaluate(oe); Iterator targetObjAttrs = targetRel .getTargetEntity() .iterator(); String labelPrefix = dbPrefetch.toString().substring("db:".length()); while (targetObjAttrs.hasNext()) { ObjAttribute oa = (ObjAttribute) targetObjAttrs.next();
public Expression notExp() { Expression exp = ExpressionFactory.expressionOfType(Expression.NOT); exp.setOperand(0, this); return exp; }