@Override public void andQualifier(Expression e) { query.andQualifier(e); }
private static void processStartsWith(SelectContext<?> context, Expression expression) { // we can be called from different stages of the pipeline. Context may or may not have all the pieces in place.. if (context.getEntity() != null) { context.getEntity().andQualifier(expression); } // else - error? if (context.getSelect() != null) { context.getSelect().andQualifier(expression); } } }
<T extends DataObject> List<T> allItems(UpdateContext<T> context) { SelectQuery<T> query = SelectQuery.query(context.getType()); // apply various request filters identifying the span of the collection if (context.getParent() != null) { EntityResolver resolver = CayenneUpdateStartStage.cayenneContext(context).getEntityResolver(); query.andQualifier(context.getParent().qualifier(resolver)); } if (context.getEntity().getQualifier() != null) { query.andQualifier(context.getEntity().getQualifier()); } // TODO: use SelectBuilder to get Cayenne representation of the // resource, instead of duplicating this here... List<T> objects = CayenneUpdateStartStage.cayenneContext(context).select(query); if (context.isById() && objects.size() > 1) { throw new AgException(Response.Status.INTERNAL_SERVER_ERROR, String.format( "Found more than one object for ID '%s' and entity '%s'", context.getId(), context.getEntity().getAgEntity().getName())); } return objects; }
<T> SelectQuery<T> basicSelect(SelectContext<T> context) { // selecting by ID overrides any explicit SelectQuery... if (context.isById()) { Class<T> root = context.getType(); SelectQuery<T> query = new SelectQuery<>(root); query.andQualifier(buildIdQualifer(context.getEntity().getAgEntity(), context.getId())); return query; } return context.getSelect() != null ? context.getSelect() : new SelectQuery<>(context.getType()); }
query.andQualifier(qualifier); query.andQualifier(entity.getQualifier());
private <T extends DataObject> void deleteByParent(DeleteContext<T> context, ObjectContext cayenneContext, AgEntity<?> agParentEntity) { EntityParent<?> parent = context.getParent(); Object parentObject = Util.findById(cayenneContext, parent.getType(), agParentEntity, parent.getId().get()); if (parentObject == null) { ObjEntity entity = cayenneContext.getEntityResolver().getObjEntity(parent.getType()); throw new AgException(Response.Status.NOT_FOUND, "No parent object for ID '" + parent.getId() + "' and entity '" + entity.getName() + "'"); } Expression qualifier = parent.qualifier(cayenneContext.getEntityResolver()); SelectQuery<?> select = SelectQuery.query(context.getType()); select.andQualifier(qualifier); List<?> objects = cayenneContext.select(select); cayenneContext.deleteObjects(objects); cayenneContext.commitChanges(); }