views:

355

answers:

1

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!

+1  A: 

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 ...

JohnIdol
+1. no response... what do you expect for a Sunday?... a Sunny Sunday at that!
Dead account
given the subject and the weather I couldn't really expect any response :)
JohnIdol