1 25 26 package org.objectweb.easybeans.persistence; 27 28 import javax.persistence.EntityManager; 29 import javax.persistence.EntityManagerFactory; 30 31 import org.objectweb.easybeans.persistence.xml.JPersistenceUnitInfo; 32 33 37 public class JPersistenceContext { 38 39 42 private JPersistenceUnitInfo jPersistenceUnitInfo; 43 44 47 private EntityManagerFactory entityManagerFactory = null; 48 49 52 private TxEntityManagerHandler txEntityManagerHandler = null; 53 54 57 private TxEntityManager txEntityManager = null; 58 59 63 public JPersistenceContext(final JPersistenceUnitInfo jPersistenceUnitInfo) { 64 this.jPersistenceUnitInfo = jPersistenceUnitInfo; 65 init(); 66 } 67 68 71 private void init() { 72 this.entityManagerFactory = jPersistenceUnitInfo.getPersistenceProvider().createContainerEntityManagerFactory( 73 jPersistenceUnitInfo, null); 74 this.txEntityManagerHandler = new TxEntityManagerHandler(entityManagerFactory); 75 this.txEntityManager = new TxEntityManager(txEntityManagerHandler); 76 } 77 78 82 public EntityManager getTxEntityManager() { 83 return txEntityManager; 84 } 85 86 90 public EntityManagerFactory getEntityManagerFactory() { 91 return entityManagerFactory; 92 } 93 94 97 public void addCurrent() { 98 txEntityManagerHandler.addCurrent(); 99 } 100 101 102 105 public void closeCurrentAndReturnToPrevious() { 106 txEntityManagerHandler.closeCurrentAndReturnToPrevious(); 107 } 108 109 } 110 | Popular Tags |