Aakash
Aakash

Reputation: 1791

Google app engine query with a list of string

I have a list of property values named 'token'. I am trying to filter an entity of kind

This is what i have tried.

List<String> tokens = getTokensFrom(invitations);
PersistenceManager pm = this.dataStoreService.getObjectDBConnection();
Query query = pm.newQuery(Invitations.class);
query.setFilter("tokens.contains(token)");
query.declareVariables(List.class.getName() + " tokens");
List<Invitations> invites = (List<Invitations>) query.execute(tokens);

But I'm getting the below error message.

Problem with query <SELECT FROM com.mypackage.shared.domainobjects.Invitations WHERE tokens.contains(token) VARIABLES java.util.List tokens>: Unsupported method <contains> while parsing expression: InvokeExpression{[VariableExpression{tokens}].contains(PrimaryExpression{token})}
com.google.appengine.datanucleus.query.DatastoreQuery$UnsupportedDatastoreFeatureException: Problem with query <SELECT FROM com.testbudha.shared.domainobjects.PublishedExam WHERE tokens.contains(token) VARIABLES java.util.Collection tokens>: Unsupported method <contains> while parsing expression: InvokeExpression{[VariableExpression{tokens}].contains(PrimaryExpression{token})}
    at com.google.appengine.datanucleus.query.DatastoreQuery.newUnsupportedQueryMethodException(DatastoreQuery.java:993)
    at com.google.appengine.datanucleus.query.DatastoreQuery.handleContainsOperation(DatastoreQuery.java:971)
    at com.google.appengine.datanucleus.query.DatastoreQuery.addExpression(DatastoreQuery.java:830)
    at com.google.appengine.datanucleus.query.DatastoreQuery.addFilters(DatastoreQuery.java:739)
    at com.google.appengine.datanucleus.query.DatastoreQuery.compile(DatastoreQuery.java:248)
    at com.google.appengine.datanucleus.query.JDOQLQuery.performExecute(JDOQLQuery.java:158)
    at org.datanucleus.store.query.Query.executeQuery(Query.java:1789)
    at org.datanucleus.store.query.Query.executeWithArray(Query.java:1666)
    at org.datanucleus.api.jdo.JDOQuery.execute(JDOQuery.java:243)

I had a similar problem previously but it works because the filter criteria was the other way round i.e. this.token.contains(tokens) where 'token' was part of the entity and was of type List of String. But I'm not sure why this is not working. Can someone please help me?

Upvotes: 0

Views: 230

Answers (1)

Neil Stockton
Neil Stockton

Reputation: 11531

You declare some variable called "tokens" yet pass in a parameter (presumably what you intended to be the tokens variable). A variable is not a parameter, they are different. Either use an explicit parameter, or an implicit parameter (with : prefix) as any decent JDO docs would tell you

Upvotes: 1

Related Questions