Showing posts with label Google-Datastore. Show all posts
Showing posts with label Google-Datastore. Show all posts

Thursday, October 1, 2009

How to mimic SQL WHERE clause on Google Datastore queries

This puzzled me for a while as I never used JDO before crashing the app-engine party.

Assuming we have an Order class with a member variable named customer of type User:

//get current user
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();

//prepare query
PersistenceManager pm = PMF.get().getPersistenceManager();
String select_query = "select from " + Order.class.getName();
Query query = pm.newQuery(select_query);
query.setFilter("customer == paramCustomer");
query.declareParameters("com.google.appengine.api.users.User paramCustomer");

//execute query
List<OrderDTO> result= OrderUtils.getOrderDTOList((List<Order>) query.execute(user));

//feck-off --> I'll never get an MVP but I can swear on my blog!
pm.close();

Just wanted to share to spare some random googler (you) the same process.

Saturday, September 26, 2009

Google App Engine for JAVA Local Data Viewer!

I've been screaming like a sissy for a local Data Viewer since I put my hands on the Google App Engine. Turns out it has been there for a while (definitely not from the beginning) but I didn't know. It can be accessed when you're running the development server locally from the following URL (assuming you're running the default setup):

http://localhost:8080/_ah/admin/

You can browse your data and delete records but for the time being (at least on Java App Engine) edit operations are not supported, so don't bin just yet your dirty little hacks (a bunch of servlets in my case) for local development.