1 25 26 package org.objectweb.easybeans.persistence; 27 28 import javax.persistence.EntityManager; 29 import javax.transaction.Synchronization ; 30 import javax.transaction.Transaction ; 31 32 38 public class TxEntityManagerLifeCycle implements Synchronization { 39 40 43 private EntityManager entityManager = null; 44 45 48 private TxEntityManagerHandler txEntityManagerHandler = null; 49 50 53 private Transaction tx = null; 54 55 60 public TxEntityManagerLifeCycle(final EntityManager entityManager, final Transaction tx, 61 final TxEntityManagerHandler txEntityManagerHandler) { 62 this.entityManager = entityManager; 63 this.tx = tx; 64 this.txEntityManagerHandler = txEntityManagerHandler; 65 66 entityManager.joinTransaction(); 68 } 69 70 76 public void beforeCompletion() { 77 } 78 79 84 public void afterCompletion(final int status) { 85 txEntityManagerHandler.release(tx); 87 txEntityManagerHandler = null; 88 89 entityManager.close(); 91 92 } 93 94 } 95 | Popular Tags |