Expression and ws qurey builder [message #655384] |
Sun, 20 February 2011 05:03  |
Eclipse User |
|
|
|
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 13:06] by Moderator
|
|
|
Re: Expression and ws qurey builder [message #656858 is a reply to message #655384] |
Mon, 28 February 2011 14:28  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.08938 seconds