Skip to main content


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: 1389
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 messageGo to next 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
Re: 2 or more constraints when doing anyOf [message #1775224 is a reply to message #1048662] Thu, 26 October 2017 13:37 Go to previous message
thorsten kruse is currently offline thorsten kruseFriend
Messages: 6
Registered: October 2017
Junior Member
I think, there is something wrong when conforming results in unit of work. Please have a look at stackoverflow.com questions/46936336/eclipselink-how-to-use-expression-anyof-with-cache
Previous Topic:Please refactor code - use sonar -EntityManagerSetupImpl - PreDeploy has 400 lines of code
Next Topic:<property name="eclipselink.canonicalmodel.generate_timestamp" value="false"/
Goto Forum:
  


Current Time: Sat Apr 20 03:19:37 GMT 2024

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

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

Back to the top