Reputation: 7198
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
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
Reputation: 3769
Upvotes: 1