Search code examples
google-app-enginejdo

GAE and JDO: any recommended techniques to work with persistance manager?


The basic example of using JDO in App Engine documentation is really simple:

PersistenceManager pm = PMF.get().getPersistenceManager();

Employee e = new Employee("Alfred", "Smith", new Date());

try {
    pm.makePersistent(e);
} finally {
    pm.close();
}

But in my opinion, it's kind of annoying to get and close persistence manager every time I want to access the storage, there's a lot of redundant code. So what would you recommend to avoid that?

For example, I came across a solution which recommended getting the PM in filter and attaching it to the request so I could access it directly from any servlet. The PM would be closed by the filter automatically as well. What do you think?


Solution

    1. Do it in a DAO layer where you can keep the boilerplate code out of your business logic
    2. Is it really that big a deal? I mean, typing stuff isn't the hard part of programming :)
    3. I wouldn't use JDO personally. Objectify is much easier as it was designed for appengine specifically