Expression and ws qurey builder [message #655384] |
Sun, 20 February 2011 10:03 |
Chess 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03085 seconds