Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Expression and ws qurey builder(Using expression )
Expression and ws qurey builder [message #655384] Sun, 20 February 2011 10:03 Go to next message
Chess is currently offline ChessFriend
Messages: 4
Registered: February 2011
Location: France
Junior Member
Hello,

I'am working on simple search web service that working with EclipseLink JPA.

For example :
Entity Address :
String street
String city

Entity Student
String name
Date createdate
Address adr

And my web service can search on student using 3 criteria :
-name
-operator ("EQUAL", "LESS", "LIKE", ..."
-value
An example request can be :
<criteria>
<name>street</name>
<operator>EQUAL</operator>
<value>.thesearchvalue</value>
</criteria>

If my web service make a search in the Student entity, I convert web service value to expression, so it look like

ExpressionBuilder eb = new ExpressionBuilder();
Expression expr = null;
if 'criteria.getOperator().equals("EQUAL") ) {
expr = eb.get(criteria.getName().equal(criteria.getValue());11
}
...

So the question :

All work fine, but if the web services want to search on "street" (name parameter = adr.Street), the get in expression seem not support direct reference on a "sub entity" :
expr = eb.get("adr.street").equal("thesearchvalue") dont wok. So instead, I must use :
expr = eb.get("adr").get("street").equal("thesearchvalue").
My finally question : Is there a way to dynamically build the expression if my "name" parameter reference a sub entity property. For example, if I parse the incoming name in a array :
name[0] = "adr"
name[1] = "street"
is there is a way to convert it in the equivalent expression object ?

A dirty solution may be something like that :
if (name.size() == 1)
expr = eb.get(name[0].equals....
else if (name.size() == 2)
expr = eb.get(name(0)).get(name(1)).equals...

Hope it exist a better solution.

Thanks for help.

[Updated on: Mon, 21 February 2011 18:06]

Report message to a moderator

Re: Expression and ws qurey builder [message #656858 is a reply to message #655384] Mon, 28 February 2011 19:28 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Not sure there is a better solution. You could use a for loop instead of if blocks, but still need to parse the dot notation.

You could instead use JPQL and just append the dot notation to the JPQL, but this may be more difficult to build dynamic queries.



James : Wiki : Book : Blog : Twitter
Previous Topic:CriteriaQuery with ManyToMany eager join fetch
Next Topic:Is there any deadlock bug fix for TopLink Essential?
Goto Forum:
  


Current Time: Thu Apr 25 12:10:39 GMT 2024

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

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

Back to the top