views:

237

answers:

1

I have following code running perfectly. It filter records based on single parameter.

public List GetOrders(String email) { PersistenceManager pm = PMF.get().getPersistenceManager(); Query query = pm.newQuery(Orders.class); query.setFilter("Email == pEmail"); query.setOrdering("Id desc"); query.declareParameters("String pEmail"); query.setRange(0,50);
return (List) query.execute(email); }

Now i want to filter on multiple parameters. sdate and edate is Start Date and End Date. In datastore it is saved as Date (not String).

public List GetOrders(String email,String icode,String sdate, String edate) { PersistenceManager pm = PMF.get().getPersistenceManager(); Query query = pm.newQuery(Orders.class); query.setFilter("Email == pEmail"); query.setFilter("ItemCode == pItemCode"); query.declareParameters("String pEmail"); query.declareParameters("String pItemCode"); .....//Set filter and declare other 2 parameters .....// ...... query.setRange(0,50);
query.setOrdering("Id desc"); return (List) query.execute(email,icode,sdate,edate); }

Any clue?


My first problem is solved. But still have some problem

1 : How I can filter by Date parameter (Getting as string in jsp) ?

2: The query.execute() method support upto 3 parameters. Is it possible to pass more?

+1  A: 

You can't use multiple SetFilter() to setup multiple conditions. You must use a single if-like condition, so it will be

query.setFilter("Email == pEmail && ItemCode == pItemCode");

same for declareParameters with a comma-separeted list as follows

Query.declareParameters("String pEmail, String pItemCode");
Tox'N
yeah it works.. Thanks..What about Date parameter? and what if i need to pass more than 3 parameter? It only support upto 3 parameters.
Manjoor