如何从谷歌数据存储中按用户获取数据?
我正在使用 Google App Engine,但在 JDOQL 查询上遇到了一些问题。
该示例展示了如何从数据存储区获取内容:
PersistenceManager pm = PMF.get().getPersistenceManager();
String query = "select from " + Greeting.class.getName();
List<Greeting> greetings = (List<Greeting>) pm.newQuery(query).execute();
但是如果我只想为给定用户获取内容该怎么办?
在上面链接的页面底部,它显示我们可以执行以下操作:
select from guestbook.Greeting where author == '[email protected]'
但如果我尝试以下操作,它不会获取任何内容:
PersistenceManager pm = PMF.get().getPersistenceManager();
String query = "select from " + Greeting.class.getName() + " where author == '" + user.GetEmail() + "'";
List<Greeting> greetings = (List<Greeting>) pm.newQuery(query).execute();
其中 user
被获取,如同一示例所示:
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
我确信这是一项常见任务,但我就是无法让它发挥作用 - 感谢任何帮助!
I am playing with google app engine and having a bit of trouble on JDOQL queries.
The example shows how to fetch stuff from the datastore:
PersistenceManager pm = PMF.get().getPersistenceManager();
String query = "select from " + Greeting.class.getName();
List<Greeting> greetings = (List<Greeting>) pm.newQuery(query).execute();
But what if I want to fetch stuff only for a given user?
At the bottom of the page in the link above it shows we could something like:
select from guestbook.Greeting where author == '[email protected]'
But if I try the following it doesn't fetch anything:
PersistenceManager pm = PMF.get().getPersistenceManager();
String query = "select from " + Greeting.class.getName() + " where author == '" + user.GetEmail() + "'";
List<Greeting> greetings = (List<Greeting>) pm.newQuery(query).execute();
where user
is fetched as shown in the same example like this:
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
i am sure this is a common task but I just can't get it to work - any help appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
讨论此帖子后在 Google 网上论坛上,我得到了这样的工作:
JDQL 语法令人困惑......
After a discussion on this thread on Google Groups I got it working like this:
JDQL syntax is puzzling ...