What does “:P” mean in a JDO query

 ̄綄美尐妖づ 提交于 2019-12-22 10:48:35

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/3474056/what-does-p-mean-in-a-jdo-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!