* Returns the current EntityManager.
*/
private EntityManager getCurrent()
{
try {
TransactionImpl xa = (TransactionImpl) _ut.getTransaction();
if (xa == null)
return null;
EntityManagerItem item;
item = (EntityManagerItem) xa.getAttribute("resin.env.jpa.EntityManagerItem");
if (item != null) {
return item.getEntityManager();
}
if (_emf == null) {
_emf = _persistenceUnit.getEntityManagerFactoryDelegate();
if (_emf == null)
throw new IllegalStateException(L.l("{0}: EntityManagerFactory cannot be found from {1}",
this, _persistenceUnit));
}
EntityManager em;
if (xa != null && xa.getStatus() == Status.STATUS_ACTIVE) {
em = _emf.createEntityManager(_persistenceUnit.getProperties());
item = new EntityManagerItem(item, em, xa);
xa.setAttribute("resin.env.jpa.EntityManagerItem", item);
// _threadEntityManager.set(item);
xa.registerSynchronization(item);
return em;
}
/*