如何从谷歌数据存储中按用户获取数据?

发布于 2024-07-17 12:18:52 字数 1231 浏览 8 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Saygoodbye 2024-07-24 12:18:52

讨论此帖子后在 Google 网上论坛上,我得到了这样的工作:

String select_query = "select from " + Greeting.class.getName(); 
Query query = pm.newQuery(select_query); 
query.setFilter("author == paramAuthor"); 
query.declareParameters("java.lang.String paramAuthor"); 
greetings = (List<Greeting>) query.execute(user);

JDQL 语法令人困惑......

After a discussion on this thread on Google Groups I got it working like this:

String select_query = "select from " + Greeting.class.getName(); 
Query query = pm.newQuery(select_query); 
query.setFilter("author == paramAuthor"); 
query.declareParameters("java.lang.String paramAuthor"); 
greetings = (List<Greeting>) query.execute(user);

JDQL syntax is puzzling ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文