Hey guys I'm playing around with unions in 2.5. I haven't been able to find many examples of using an Union with subqueries so I am in the process of guess and test. Here's what I have found to work best so far with made up entities:
ExpressionBuilder archivedBooksExpressionBuilder = new ExpressionBuilder();
ReportQuery archivedBooksSubQuery = new ReportQuery(Book.class, archivedBooksExpressionBuilder);
archivedBooksSubQuery.addAttribute("bookKey");
archivedBooksSubQuery.setSelectionCriteria(archivedBooksExpressionBuilder.get("something").anyOf("anything").get("book").get("bookKey").in(dataAccessModel.getSomeKeys()));
ExpressionBuilder shelvedBooksExpressionBuilder = new ExpressionBuilder();
ReportQuery shelvedBooksSubQuery = new ReportQuery(Book.class, shelvedBooksExpressionBuilder);
shelvedBooksSubQuery.addAttribute("bookKey");
shelvedBooksSubQuery.setSelectionCriteria(shelvedBooksExpressionBuilder.anyOf("somethingElse").get("book").get("bookKey").in(dataAccessModel.getAnyKeys()));
archivedBooksSubQuery.union(shelvedBooksSubQuery);
return expressionBuilder.get("generalKey").in(archivedBooksSubQuery);
This doesn't create the UNION quite right. Any suggestions?
Thanks
-Brad