use of com.sun.enterprise.container.common.impl.PhysicalEntityManagerWrapper in project Payara by payara.
the class AsynchronousTask method destroyExtendedEMsForContext.
private void destroyExtendedEMsForContext(SessionContextImpl sc) {
for (PhysicalEntityManagerWrapper emWrapper : sc.getExtendedEntityManagers()) {
synchronized (extendedEMReferenceCountMap) {
EntityManager em = emWrapper.getEM();
if (extendedEMReferenceCountMap.containsKey(em)) {
EEMRefInfo refInfo = extendedEMReferenceCountMap.get(em);
if (refInfo.refCount > 1) {
refInfo.refCount--;
_logger.log(Level.FINE, "Decremented RefCount ExtendedEM em: " + em);
} else {
_logger.log(Level.FINE, "DESTROYED ExtendedEM em: " + em);
refInfo = extendedEMReferenceCountMap.remove(em);
eemKey2EEMMap.remove(refInfo.getKey());
try {
em.close();
} catch (Throwable th) {
_logger.log(Level.FINE, "Exception during em.close()", th);
}
}
}
}
}
}
use of com.sun.enterprise.container.common.impl.PhysicalEntityManagerWrapper in project Payara by payara.
the class AsynchronousTask method validateEMForClientTx.
@Override
protected void validateEMForClientTx(EjbInvocation inv, JavaEETransaction clientJ2EETx) throws EJBException {
SessionContextImpl sessionCtx = (SessionContextImpl) inv.context;
Map<EntityManagerFactory, PhysicalEntityManagerWrapper> entityManagerMap = sessionCtx.getExtendedEntityManagerMap();
for (Map.Entry<EntityManagerFactory, PhysicalEntityManagerWrapper> entry : entityManagerMap.entrySet()) {
EntityManagerFactory emf = entry.getKey();
// Extended persistence context for the propagated transaction.
if (clientJ2EETx.getTxEntityManagerResource(emf) != null) {
throw new EJBException("There is an active transactional persistence context for the same EntityManagerFactory as the current stateful session bean's extended persistence context");
}
// Now see if there's already a *different* extended
// persistence context within this transaction for the
// same EntityManagerFactory.
PhysicalEntityManagerWrapper physicalEM = (PhysicalEntityManagerWrapper) clientJ2EETx.getExtendedEntityManagerResource(emf);
if ((physicalEM != null) && entry.getValue().getEM() != physicalEM.getEM()) {
throw new EJBException("Detected two different extended persistence contexts for the same EntityManagerFactory within a transaction");
}
}
}
use of com.sun.enterprise.container.common.impl.PhysicalEntityManagerWrapper in project Payara by payara.
the class AsynchronousTask method enlistExtendedEntityManagers.
@Override
protected void enlistExtendedEntityManagers(ComponentContext ctx) {
if (ctx.getTransaction() != null) {
JavaEETransaction j2eeTx = (JavaEETransaction) ctx.getTransaction();
SessionContextImpl sessionCtx = (SessionContextImpl) ctx;
Map<EntityManagerFactory, PhysicalEntityManagerWrapper> entityManagerMap = sessionCtx.getExtendedEntityManagerMap();
for (Map.Entry<EntityManagerFactory, PhysicalEntityManagerWrapper> entry : entityManagerMap.entrySet()) {
EntityManagerFactory emf = entry.getKey();
PhysicalEntityManagerWrapper extendedEm = entry.getValue();
PhysicalEntityManagerWrapper extendedEmAssociatedWithTx = EntityManagerWrapper.getExtendedEntityManager(j2eeTx, emf);
// this extended EntityManagerFactory within the current tx
if (extendedEmAssociatedWithTx == null) {
j2eeTx.addExtendedEntityManagerMapping(emf, extendedEm);
sessionCtx.setEmfRegisteredWithTx(emf, true);
// entity manager with the transaction.
if (extendedEm.getSynchronizationType() == SYNCHRONIZED) {
extendedEm.getEM().joinTransaction();
}
}
}
}
}
use of com.sun.enterprise.container.common.impl.PhysicalEntityManagerWrapper in project Payara by payara.
the class AsynchronousTask method findExtendedEMFromInvList.
private PhysicalEntityManagerWrapper findExtendedEMFromInvList(EntityManagerFactory emf) {
PhysicalEntityManagerWrapper em = null;
ComponentInvocation compInv = (ComponentInvocation) invocationManager.getCurrentInvocation();
if (compInv != null) {
if (compInv.getInvocationType() == ComponentInvocation.ComponentInvocationType.EJB_INVOCATION) {
EjbInvocation ejbInv = (EjbInvocation) compInv;
if (ejbInv.context instanceof SessionContextImpl) {
SessionContextImpl ctxImpl = (SessionContextImpl) ejbInv.context;
if (ctxImpl.container instanceof StatefulSessionContainer) {
em = ctxImpl.getExtendedEntityManager(emf);
}
}
}
}
return em;
}
use of com.sun.enterprise.container.common.impl.PhysicalEntityManagerWrapper in project Payara by payara.
the class AsynchronousTask method delistExtendedEntityManagers.
@Override
protected void delistExtendedEntityManagers(ComponentContext ctx) {
if (ctx.getTransaction() != null) {
SessionContextImpl sessionCtx = (SessionContextImpl) ctx;
JavaEETransaction j2eeTx = (JavaEETransaction) sessionCtx.getTransaction();
Map<EntityManagerFactory, PhysicalEntityManagerWrapper> entityManagerMap = sessionCtx.getExtendedEntityManagerMap();
for (Map.Entry<EntityManagerFactory, PhysicalEntityManagerWrapper> entry : entityManagerMap.entrySet()) {
EntityManagerFactory emf = entry.getKey();
if (sessionCtx.isEmfRegisteredWithTx(emf)) {
j2eeTx.removeExtendedEntityManagerMapping(emf);
sessionCtx.setEmfRegisteredWithTx(emf, false);
}
}
}
}
Aggregations