In this question, I solved the Google Datastore query problem for user data retrieval (com.google.appengine.api.users.User) as follows:
User user = userService.getCurrentUser(); 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);
This works well, but after a bit of clutter, I realized that this syntax is not very practical, since there is a need to create more complex queries, so I decided to manually create my filters, and now I got, for example, something like (where is the filter usually passed as a string variable, but now built into the string for its simplicity):
User user = userService.getCurrentUser(); String select_query = "select from " + Greeting.class.getName(); Query query = pm.newQuery(select_query); query.setFilter("author == '"+ user.getEmail() +"'"); greetings = (List<Greeting>) query.execute();
Obviously, this will not work even if this syntax with field = 'value' supported by JDOQL and it works fine in other fields (String types and enumerations). Another strange thing is that, looking at the data viewer in the application dashboard, the "author" field is saved as the "User" type, but the value is " user@gmail.com ", and then again when I set it as a parameter ( the case above, which works fine) I declare the parameter as a string, and then pass the instance of the user (user), which is serialized with a simple toString() (I think).
Any idea?
source share