Closed GoogleCodeExporter closed 9 years ago
Hi Esin,
Which version are you looking at ? The current version implements a LIKE query,
but I add the "%" in the end, you shouldn't need to do that at the client side.
Here's the code:
Service
---------
KeyValuePair<String, Object> kvpair = new KeyValuePair<String, Object>("fname",
queryString + "%");
List<Food> foodList = baseDao.executeNamedQueryGetList("Food.findStartingWith",
kvpair);
Model
----------
@NamedQueries({
@NamedQuery(name = "Food.findStartingWith", query = "SELECT f FROM Food f WHERE f.name LIKE :fname")
})
Original comment by turkmen...@gmail.com
on 29 May 2014 at 8:15
In fact - I don't think there ever was a version that I didn't use LIKE.
Original comment by turkmen...@gmail.com
on 29 May 2014 at 8:16
The code (in FoodsService WS) in my workspace is:
// STATUS: untested
@WebMethod
public GetIngredientsResponse getIngredients( @WebParam(name="token") String token,
@WebParam(name="queryString") String queryString){
GetIngredientsResponse response = new GetIngredientsResponse();
if (token == null){
response.fail(ServiceErrorCode.MISSING_PARAM);
return response;
}
BaseDao baseDao = DaoFactory.getInstance().getBaseDao();
try {
ServiceCommons.authenticate(token, response);
} catch (InvalidTokenException e) {
response.fail(ServiceErrorCode.TOKEN_INVALID);
return response;
} catch (TokenExpiredException e) {
response.fail(ServiceErrorCode.TOKEN_EXPIRED);
return response;
}
try {
List<Food> foodList = baseDao.findByCriteria(Food.class, "name", queryString + "%");
List<FoodInfo> fiList = new ArrayList<FoodInfo>();
for (Food f : foodList){
FoodInfo fi = new FoodInfo();
fi.setFoodId(f.getId());
fi.setFoodName(f.getName());
fiList.add(fi);
}
response.setListOfIngredients(fiList);
}
catch (Exception e){
response.fail(ServiceErrorCode.INTERNAL_SERVER_ERROR);
return response;
}
response.succeed();
return response;
}
Original comment by esinkara...@gmail.com
on 29 May 2014 at 11:12
And also this code seems the latest version in the repository. I've checked the
repository through Browse feature of GoogleCodes
Original comment by esinkara...@gmail.com
on 29 May 2014 at 11:18
Caner,
You said you used the following query but I couldn't see any named query with
name the "findStartingWith" in the repository. That's weird.
List<Food> foodList = baseDao.executeNamedQueryGetList("Food.findStartingWith",
kvpair);
Original comment by esinkara...@gmail.com
on 29 May 2014 at 11:27
OK apparently there was a merge conflict. I remerged, maybe check this version??
Btw, I'm at work and I can only shortly peek at google code now and then
Original comment by turkmen...@gmail.com
on 30 May 2014 at 1:37
Original comment by turkmen...@gmail.com
on 1 Jun 2014 at 10:14
Original issue reported on code.google.com by
esinkara...@gmail.com
on 27 May 2014 at 7:50