tobik
tobik

Reputation: 7198

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?

Upvotes: 0

Views: 92

Answers (2)

Supra
Supra

Reputation: 1642

Getting the PM in filter and closing that PM after work is done (finally clause inside doFilter) is a good approach. This keeps the code clean, easy to maintain and easy to change if in future you are moving to JPA for instance

Upvotes: 0

Rick Mangi
Rick Mangi

Reputation: 3769

  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

Upvotes: 1

Related Questions