Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » 2 or more constraints when doing anyOf
2 or more constraints when doing anyOf [message #1048620] Wed, 24 April 2013 18:36 Go to next message
brad Mising name is currently offline brad Mising nameFriend
Messages: 17
Registered: February 2010
Junior Member
In the documentation there is a note about using .anyOf twice in an Expression. The note mentions "you would use a single anyOf and a temporary variable" as a work around. I haven't seen any examples of this being done in the documentation. Does anyone have an example? I could be overlooking something simple here...

Link to Documentation:
http://wiki.eclipse.org/Introduction_to_EclipseLink_Expressions_(ELUG)#Using_EclipseLink_Expression_API_for_Joins

Thanks
-Brad
Re: 2 or more constraints when doing anyOf [message #1048662 is a reply to message #1048620] Wed, 24 April 2013 19:51 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1039
Registered: July 2009
Senior Member
Reuse the result of expression.anyOf() rather than call it again, the same way you would store the result of a get accessor method rather than repeatedly calling get for the value.

Instead of
ExpressionBuilder builder = new ExpressionBuilder();
Expression whereClause = builder.anyOf("projects").get("name").equal("Enterprise").or(builder.anyOf("projects").get("name").equal("Server"));
you would use:
ExpressionBuilder builder = new ExpressionBuilder();
Expression projects = builder.anyOf("projects");
Expression whereClause = projects.get("name").equal("Enterprise").or(projects.get("name").equal("Server"));

In the first example, you are making 2 different joins from the root over the projects collection, while in the second there will only be a single join what will check if name=Entierprise or name=Server.

Best Regards,
Chris
Re: 2 or more constraints when doing anyOf [message #1049311 is a reply to message #1048662] Thu, 25 April 2013 17:16 Go to previous message
brad Mising name is currently offline brad Mising nameFriend
Messages: 17
Registered: February 2010
Junior Member
Thanks for the tip, I will try that out. I also ran across an example in the documentation of something like this:
ExpressionBuilder subject = new ExpressionBuilder();
ExpressionBuilder name = new ExpressionBuilder();
ReportQuery subQuery = new ReportQuery(Name.class, name);

subQuery.retrievePrimaryKeys();
subQuery.setSelectionCriteria(
name.equal(subject.anyOf("names")).and(
name.get("first").toUpperCase().equal(firstName.toUpperCase())).and(
name.get("last").toUpperCase().equal(lastName.toUpperCase()))
);

This also got me the results I was looking for. The example I used is found in the javadoc for Expression. allOf.

Thanks
-Brad
Previous Topic:insert always null on embedded fields
Next Topic:problem with entityManager.createQuery(CriteriaQuery q)
Goto Forum:
  


Current Time: Mon Dec 22 23:37:24 GMT 2014

Powered by FUDForum. Page generated in 0.01625 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software