/** * Appends a qualifier expression of this query. An equivalent to * {@link #and(Expression...)} that can be used a syntactic sugar. * * @return this object */ public ObjectSelect<T> where(Expression expression) { return and(expression); }
/** * AND's provided expressions to the existing WHERE clause expression. * * @return this object */ public ObjectSelect<T> and(Expression... expressions) { if (expressions == null || expressions.length == 0) { return this; } return and(Arrays.asList(expressions)); }
/** * Appends a qualifier expression of this query, using provided expression * String and an array of position parameters. This is an equivalent to * calling "and". * * @return this object */ public ObjectSelect<T> where(String expressionString, Object... parameters) { return and(ExpressionFactory.exp(expressionString, parameters)); }
@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); } } }