gae jdoquery parameters with special characters

0 views
Skip to first unread message

user2397881 via StackOverflow

unread,
May 30, 2013, 7:43:01 AM5/30/13
to google-appengin...@googlegroups.com

I am writing a cloud endpoint api using JDO to fetch a list of users based on the emailid. I am passing emailId as a @Named parameter to the Api method and adding it to the query filter and i get the error message "Portion of expression could not be parsed: @gmail.com"

@Api (name="MyAppname", version="v1")
public class PersonEndpoint {

public Person validate(@Named("emailId") String emailId, @Named("role") String role){
.......

PersistenceManager pm=getPersistenceManager();
Query q = pm.newQuery(Person.class);
q.setFilter(" email == "+emailId+" && role == "+role);

try{
    person=(Person)q.execute();
}finally{
    q.closeAll();
    pm.close();
}

return person;
}

When i call the above api, the below error is thrown

javax.jdo.JDOUserException: Portion of expression could not be parsed: @gmail.com && role == collector
at org.datanucleus.api.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:519)
at org.datanucleus.api.jdo.JDOQuery.execute(JDOQuery.java:230)

How do we pass parameters with special characters as in email to the query filter?



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/16835144/gae-jdoquery-parameters-with-special-characters

DataNucleus via StackOverflow

unread,
May 30, 2013, 8:38:07 AM5/30/13
to google-appengin...@googlegroups.com

You do not embed text strings in a text string. Instead you define a parameter, and provide the parameter value to execute().

Query q = pm.newQuery(Person.class);
q.setFilter("email == :emailId && role == :role");
Map<String, String> paramValues = new HashMap();
paramValues.put("emailId", myEmailParam);
paramValues.put("role", myRoleParam);
List<Person> persons = (List<Person>)q.executeWithMap(paramValues);

All of this is defined with examples in the JDO spec, and in the docs for DataNucleus JDO. I'd strongly suggest you read them



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/16835144/gae-jdoquery-parameters-with-special-characters/16836318#16836318

DataNucleus via StackOverflow

unread,
May 30, 2013, 9:18:07 AM5/30/13
to google-appengin...@googlegroups.com

You do not embed text strings in a text string. Instead you define a parameter, and provide the parameter value to execute().

Query q = pm.newQuery(Person.class);
q.setFilter("email == :theEmail && role == :theRole");
Map<String, String> paramValues = new HashMap();
paramValues.put("theEmail", myEmailParam);
paramValues.put("theRole", myRoleParam);
List<Person> persons = (List<Person>)q.executeWithMap(paramValues);

DataNucleus via StackOverflow

unread,
May 30, 2013, 10:38:15 AM5/30/13
to google-appengin...@googlegroups.com

You do not embed text strings in a text string. Instead you define a parameter, and provide the parameter value to execute().

Query q = pm.newQuery(Person.class);
q.setFilter("emailId == :theEmail && role == :theRole");
Map<String, String> paramValues = new HashMap();
paramValues.put("theEmail", myEmailParam);
paramValues.put("theRole", myRoleParam);
List<Person> persons = (List<Person>)q.executeWithMap(paramValues);
Reply all
Reply to author
Forward
0 new messages