@Override public Object keyForTarget(DataObject target) { // cases: // 1. "obj:" expressions are object properties // 2. "db:" expressions mapping to ID columns // 3. "db:" expressions mapping to object properties // Cayenne exp can handle 1 & 2; we'll need to manually handle case 3 return getOrCreatePathExpression().evaluate(target); }
/** * 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 result of evaluation of expression with object. */ public Object cayenneExp(Object object, String expression) { return ExpressionFactory.exp(expression).evaluate(object); } }
/** * 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 result of evaluation of expression with object. */ public Object cayenneExp(Object object, String expression) { return Expression.fromString(expression).evaluate(object); } }
public void startNode(Expression node, Expression parentNode) { // check if path nodes are compatibe with root entity if (node.getType() == Expression.OBJ_PATH || node.getType() == Expression.DB_PATH) { // this will throw an exception if the path is invalid node.evaluate(rootEntity); } } }
/** * Comparable interface implementation. Can compare two Java Beans based on the stored * expression. */ public int compare(Object o1, Object o2) { Expression exp = getSortSpec(); Object value1 = exp.evaluate(o1); Object value2 = exp.evaluate(o2); // nulls first policy... maybe make this configurable as some DB do if (value1 == null) { return (value2 == null) ? 0 : -1; } else if (value2 == null) { return 1; } if (this.caseInsensitive) { // TODO: to upper case should probably be defined as a separate expression // type value1 = ConversionUtil.toUpperCase(value1); value2 = ConversionUtil.toUpperCase(value2); } int compareResult = ConversionUtil.toComparable(value1).compareTo( ConversionUtil.toComparable(value2)); return (ascending) ? compareResult : -compareResult; }
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; }
boolean isToMany(String prefetch) { if (selectQuery == null) { return false; } Object root = selectQuery.getRoot(); // totally invalid path would result in ExpressionException try { Expression exp = ExpressionFactory.exp(prefetch); Object object = exp.evaluate(root); if (object instanceof Relationship) { return ((Relationship) object).isToMany(); } else { return false; } } catch (ExpressionException e) { return false; } }
Mapper createSafeKeyMapper(Mapper unsafe) { KeyAdapter keyAdapter; if (paths.size() > 1) { // TODO: mapping keyMapAdapters by type doesn't take into account // composition and hierarchy of the keys ... need a different // approach. for now resorting to the hacks below keyAdapter = keyAdapterFactory.adapter(List.class); } else { Object attributeOrRelationship = ExpressionFactory.exp(paths.iterator().next()).evaluate(entity); Class<?> type; if (attributeOrRelationship instanceof ObjAttribute) { type = ((ObjAttribute) attributeOrRelationship).getJavaClass(); } else if (attributeOrRelationship instanceof ObjRelationship) { type = ((ObjRelationship) attributeOrRelationship).getTargetEntity().getJavaClass(); } else { type = null; } keyAdapter = keyAdapterFactory.adapter(type); } return new SafeMapKeyMapper(unsafe, keyAdapter); }
Object value2 = null; try { value1 = exp.evaluate(o1); } catch (ExpressionException e) { if (pathExceptionSuppressed && e.getCause() instanceof org.apache.cayenne.reflect.UnresolvablePathException) { value2 = exp.evaluate(o2); } catch (ExpressionException e) { if (pathExceptionSuppressed && e.getCause() instanceof org.apache.cayenne.reflect.UnresolvablePathException) {
ObjRelationship targetRel = (ObjRelationship) prefetchExp.evaluate(oe); Iterator targetObjAttrs = targetRel .getTargetEntity()
ObjRelationship targetRel = (ObjRelationship) prefetchExp.evaluate(oe); ObjEntity targetEntity = targetRel.getTargetEntity(); prefetch.setEntityName(targetRel.getSourceEntity().getName());
ObjRelationship targetRel = (ObjRelationship) prefetchExp.evaluate(oe); ObjEntity targetEntity = targetRel.getTargetEntity();