views:

114

answers:

2

I am using JDO on google app engine. Each 'Employee' has a 'key'. I have a set of keys and wanted to retrieve all Employees whose key belongs to this set.

So I implemented it using the 'contains()' filter as specified here. The code works fine and looks like this -

List<Key> keys = getLookupKeys(....) ..//Get keys from somewhere.

Query query = pm.newQuery(Employee.class,":p.contains(key)"); //What is ":P" here?
List<Employee> employees = (List<Employee>) q.execute(keys); //This correctly gives me all I want

All that I wonder is what is this ":P" in this query? The Employee object does not have any field named 'p' neither my query declares any such parameter. So what does this 'p' point to? Does 'p' has any special meaning?

+3  A: 

I believe it's mapping an implicit input parameter. As there's only one parameter, you don't need to explicitly call setParameter, you can just use it. I believe it would have been okay as:

Query query = pm.newQuery(Employee.class,":keys.contains(key)");
List<Employee> employees = (List<Employee>) q.execute(keys); 

which might be clearer.

See the "implicit parameters" part of the Apache JDOQL docs for another example.

Jon Skeet
+3  A: 

Certainly, it passes for a smiley :-)

P.S - I know I should be serious in my replies, but just couldn't resist typing this when I saw this question

haha.. even when I checked in this code into svn(before asking the question here), my code comment just above the query was -" //This works but still I dont know what the ':P' stands for :P "
Gopi