01: package org.compass.gps.device.jpa;
02:
03: import javax.persistence.EntityTransaction;
04: import javax.persistence.PersistenceException;
05:
06: /**
07: * A JPA Resource Local only {@link EntityManagerWrapper} implementation. Creates the
08: * <code>EntityManager</code>, and an <code>EntityTransaction</code>.
09: *
10: * @author kimchy
11: */
12: public class ResourceLocalEntityManagerWrapper extends
13: AbstractEntityManagerWrapper {
14:
15: private EntityTransaction transaction;
16:
17: @Override
18: protected void beginTransaction() throws PersistenceException {
19: transaction = entityManager.getTransaction();
20: transaction.begin();
21: }
22:
23: @Override
24: protected void commitTransaction() throws PersistenceException {
25: if (transaction == null) {
26: return;
27: }
28: try {
29: transaction.commit();
30: } finally {
31: transaction = null;
32: }
33: }
34:
35: @Override
36: protected void rollbackTransaction() throws PersistenceException {
37: if (transaction == null) {
38: return;
39: }
40: try {
41: transaction.rollback();
42: } finally {
43: transaction = null;
44: }
45: }
46:
47: @Override
48: protected boolean shouldCloseEntityManager() {
49: return true;
50: }
51: }
|