/** * Creates a copy of this expression node, without copying children. */ public Expression shallowCopy() { return new ASTEqual(id); }
/** * Creates "Equal To" expression. */ public ASTEqual(SimpleNode path, Object value) { super(ExpressionParserTreeConstants.JJTEQUAL); jjtAddChild(path, 0); jjtAddChild(new ASTScalar(value), 1); connectChildren(); }
protected Object evaluateNode(Object o) throws Exception { int len = jjtGetNumChildren(); if (len != 2) { return Boolean.FALSE; } Object o1 = evaluateChild(0, o); Object o2 = evaluateChild(1, o); // TODO: maybe we need a comparison "strategy" here, instead of // a switch of all possible cases? ... there were other requests for // more relaxed type-unsafe comparison (e.g. numbers to strings) if (o1 == null && o2 == null) { return Boolean.TRUE; } else if (o1 != null) { // BigDecimals must be compared using compareTo ( // see CAY-280 and BigDecimal.equals JavaDoc) if (o1 instanceof BigDecimal) { if (o2 instanceof BigDecimal) { return ((BigDecimal) o1).compareTo((BigDecimal) o2) == 0 ? Boolean.TRUE : Boolean.FALSE; } return Boolean.FALSE; } return o1.equals(o2) ? Boolean.TRUE : Boolean.FALSE; } else { return Boolean.FALSE; } }
@Override protected String getEJBQLExpressionOperator(int index) { if (jjtGetChild(1) instanceof ASTScalar && ((ASTScalar) jjtGetChild(1)).getValue() == null) { // for ejbql, we need "is null" instead of "= null" return "is"; } return getExpressionOperator(index); }
public void injectValue(Object o) { // try to inject value, if one of the operands is scalar, and other is a // path Node[] args = new Node[] { jjtGetChild(0), jjtGetChild(1) }; int scalarIndex = -1; if (args[0] instanceof ASTScalar) { scalarIndex = 0; } else if (args[1] instanceof ASTScalar) { scalarIndex = 1; } if (scalarIndex != -1 && args[1 - scalarIndex] instanceof ASTObjPath) { // inject ASTObjPath path = (ASTObjPath) args[1 - scalarIndex]; try { path.injectValue(o, evaluateChild(scalarIndex, o)); } catch (Exception ex) { LOGGER.warn("Failed to inject value " + " on path " + path.getPath() + " to " + o, ex); } } } }
@Override protected Boolean evaluateSubNode(Object o, Object[] evaluatedChildren) throws Exception { Object o2 = evaluatedChildren[1]; return ASTEqual.evaluateImpl(o, o2) ? Boolean.FALSE : Boolean.TRUE; }
@Override protected Boolean evaluateSubNode(Object o, Object[] evaluatedChildren) throws Exception { Object o2 = evaluatedChildren[1]; return evaluateImpl(o, o2) ? Boolean.TRUE : Boolean.FALSE; }
/** * Creates a copy of this expression node, without copying children. */ @Override public Expression shallowCopy() { return new ASTEqual(id); }
/** * Creates "Equal To" expression. */ public ASTEqual(ASTPath path, Object value) { super(ExpressionParserTreeConstants.JJTEQUAL); jjtAddChild(path, 0); jjtAddChild(new ASTScalar(value), 1); connectChildren(); }
/** * @since 4.0 * @see ExpressionFactory#matchExp(String, Object) */ static Expression matchExp(Expression exp, Object value) { if(!(exp instanceof SimpleNode)) { throw new IllegalArgumentException("exp should be instance of SimpleNode"); } return new ASTEqual((SimpleNode)exp, value); }
private Expression match(ASTPath path, Map<String, Object> idMap) { Object value = idMap.get(path.getPath()); if (value == null) { throw new AgException(Status.BAD_REQUEST, "No ID value for path: " + path); } return new ASTEqual(path, value); }
/** * A convenience method to create an DB_PATH "equal to" expression. */ public static Expression matchDbExp(String pathSpec, Object value) { return new ASTEqual(new ASTDbPath(pathSpec), value); }
/** * A convenience method to create an DB_PATH "equal to" expression. */ public static Expression matchDbExp(String pathSpec, Object value) { return new ASTEqual(new ASTDbPath(pathSpec), value); }
/** * A convenience method to create an OBJ_PATH "equal to" expression. */ public static Expression matchExp(String pathSpec, Object value) { return new ASTEqual(new ASTObjPath(pathSpec), value); }
@SuppressWarnings("unchecked") public static <A> A findById(ObjectContext context, Class<A> type, AgEntity<?> agEntity, Object id) { ObjEntity entity = context.getEntityResolver().getObjEntity(type); // sanity checking... if (entity == null) { throw new AgException(Status.INTERNAL_SERVER_ERROR, "Unknown entity class: " + type); } if (id == null) { throw new AgException(Status.BAD_REQUEST, "No id specified"); } if (id instanceof Map) { Map<String, Object> ids = (Map<String, Object>) id; ObjectSelect<A> query = ObjectSelect.query(type); for (Map.Entry<String, Object> entry : ids.entrySet()) { query.and(ExpressionFactory.matchDbExp( entity.getDbEntity().getAttribute(entry.getKey()).getName(), entry.getValue() )); } return query.selectOne(context); } else { AgAttribute attribute = agEntity.getIds().iterator().next(); return ObjectSelect.query(type, new ASTEqual(attribute.getPathExp(), id)).selectOne(context); } } }
throw new ParseException(); ASTEqual jjtn001 = new ASTEqual(JJTEQUAL); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001);
throw new ParseException(); ASTEqual jjtn003 = new ASTEqual(JJTEQUAL); boolean jjtc003 = true; jjtree.openNodeScope(jjtn003);