@Override public Object processInvocation(InterceptorContext interceptorContext) throws Exception { try { // beginSfsbCreation() will setup a "creation time" thread local store for tracking references to extended // persistence contexts. SFSBCallStack.beginSfsbCreation(); return interceptorContext.proceed(); } finally { // bean PostCreate event lifecycle has already completed. // endSfsbCreation() will clear the thread local knowledge of "creation time" referenced extended // persistence contexts. SFSBCallStack.endSfsbCreation(); } }
/** * Pops the current SFSB invocation off the invocation call stack * * @return the entity manager map */ public static Map<String, ExtendedEntityManager> popCall() { ArrayList<Map<String, ExtendedEntityManager>> stack = currentSFSBCallStack(); Map<String, ExtendedEntityManager> result = stack.remove(stack.size() - 1); stack.trimToSize(); return result; }
@Override public ExtendedEntityManager findExtendedPersistenceContext(String puScopedName) { ExtendedEntityManager result = null; // if current bean is injected from a parent bean that is also being created, current bean // can inherit only from the parent bean. if (SFSBCallStack.getSFSBCreationBeanNestingLevel() > 1) { SFSBInjectedXPCs currentInjectedXPCs = SFSBCallStack.getSFSBCreationTimeInjectedXPCs(puScopedName); result = currentInjectedXPCs.findExtendedPersistenceContextShallowInheritance(puScopedName); } else { // else inherit from parent bean that created current bean (if any). The parent bean is the one // that did a JNDI lookup of the current bean. Map<String, ExtendedEntityManager> handle = SFSBCallStack.getCurrentCall(); if (handle != null) { result = handle.get(puScopedName); if (result != null) { return result; } } } return result; } }
@Override public void registerExtendedPersistenceContext(String scopedPuName, ExtendedEntityManager entityManager) { if (SFSBCallStack.getSFSBCreationBeanNestingLevel() > 0) { SFSBCallStack.getSFSBCreationTimeInjectedXPCs(scopedPuName).registerDeepInheritance(scopedPuName, entityManager); } }
@Override public Object processInvocation(InterceptorContext context) throws Exception { final ComponentInstance componentInstance = context.getPrivateData(ComponentInstance.class); ManagedReference entityManagerRef = (ManagedReference) componentInstance.getInstanceData(SFSBInvocationInterceptor.CONTEXT_KEY); if(entityManagerRef != null) { Map<String, ExtendedEntityManager> entityManagers = (Map<String, ExtendedEntityManager>) entityManagerRef.getInstance(); SFSBCallStack.pushCall(entityManagers); } try { return context.proceed(); // call the next interceptor or target } finally { if(entityManagerRef != null) { SFSBCallStack.popCall(); } } } }
@Override public ExtendedEntityManager findExtendedPersistenceContext(String puScopedName) { ExtendedEntityManager result; SFSBInjectedXPCs currentInjectedXPCs = SFSBCallStack.getSFSBCreationTimeInjectedXPCs(puScopedName); // will look directly at the top level bean being created (registerExtendedPersistenceContext() registers xpc there). result = currentInjectedXPCs.findExtendedPersistenceContextDeepInheritance(puScopedName); if (result == null) { // walk up the BEAN call stack (this also covers the case of a bean method JNDI searching for another bean) for (Map<String, ExtendedEntityManager> handle : SFSBCallStack.currentSFSBCallStack()) { result = handle.get(puScopedName); if(result != null) { return result; } } } return result; } }
@Override public void userTransactionStarted() throws SystemException { Map<String, ExtendedEntityManager> currentActiveEntityManagers = SFSBCallStack.currentSFSBCallStackInvocation(); if (currentActiveEntityManagers != null && currentActiveEntityManagers.size() > 0) { for (ExtendedEntityManager extendedEntityManager: currentActiveEntityManagers.values()) { extendedEntityManager.internalAssociateWithJtaTx(); } } } }
@Override public void registerExtendedPersistenceContext(String scopedPuName, ExtendedEntityManager entityManager) { if (SFSBCallStack.getSFSBCreationBeanNestingLevel() > 0) { SFSBCallStack.getSFSBCreationTimeInjectedXPCs(scopedPuName).registerDeepInheritance(scopedPuName, entityManager); } }
@Override public Object processInvocation(InterceptorContext context) throws Exception { final ComponentInstance componentInstance = context.getPrivateData(ComponentInstance.class); ManagedReference entityManagerRef = (ManagedReference) componentInstance.getInstanceData(SFSBInvocationInterceptor.CONTEXT_KEY); if(entityManagerRef != null) { Map<String, ExtendedEntityManager> entityManagers = (Map<String, ExtendedEntityManager>) entityManagerRef.getInstance(); SFSBCallStack.pushCall(entityManagers); } try { return context.proceed(); // call the next interceptor or target } finally { if(entityManagerRef != null) { SFSBCallStack.popCall(); } } } }
@Override public ExtendedEntityManager findExtendedPersistenceContext(String puScopedName) { ExtendedEntityManager result; SFSBInjectedXPCs currentInjectedXPCs = SFSBCallStack.getSFSBCreationTimeInjectedXPCs(puScopedName); // will look directly at the top level bean being created (registerExtendedPersistenceContext() registers xpc there). result = currentInjectedXPCs.findExtendedPersistenceContextDeepInheritance(puScopedName); if (result == null) { // walk up the BEAN call stack (this also covers the case of a bean method JNDI searching for another bean) for (Map<String, ExtendedEntityManager> handle : SFSBCallStack.currentSFSBCallStack()) { result = handle.get(puScopedName); if(result != null) { return result; } } } return result; } }
@Override public void userTransactionStarted() throws SystemException { Map<String, ExtendedEntityManager> currentActiveEntityManagers = SFSBCallStack.currentSFSBCallStackInvocation(); if (currentActiveEntityManagers != null && currentActiveEntityManagers.size() > 0) { for (ExtendedEntityManager extendedEntityManager: currentActiveEntityManagers.values()) { extendedEntityManager.internalAssociateWithJtaTx(); } } } }
@Override public ExtendedEntityManager findExtendedPersistenceContext(String puScopedName) { ExtendedEntityManager result = null; // if current bean is injected from a parent bean that is also being created, current bean // can inherit only from the parent bean. if (SFSBCallStack.getSFSBCreationBeanNestingLevel() > 1) { SFSBInjectedXPCs currentInjectedXPCs = SFSBCallStack.getSFSBCreationTimeInjectedXPCs(puScopedName); result = currentInjectedXPCs.findExtendedPersistenceContextShallowInheritance(puScopedName); } else { // else inherit from parent bean that created current bean (if any). The parent bean is the one // that did a JNDI lookup of the current bean. Map<String, ExtendedEntityManager> handle = SFSBCallStack.getCurrentCall(); if (handle != null) { result = handle.get(puScopedName); if (result != null) { return result; } } } return result; } }
@Override public void registerExtendedPersistenceContext(String scopedPuName, ExtendedEntityManager entityManager) { if (SFSBCallStack.getSFSBCreationBeanNestingLevel() > 0) { SFSBCallStack.getSFSBCreationTimeInjectedXPCs(scopedPuName).registerShallowInheritance(scopedPuName, entityManager); } }
@Override public Object processInvocation(InterceptorContext interceptorContext) throws Exception { try { // beginSfsbCreation() will setup a "creation time" thread local store for tracking references to extended // persistence contexts. SFSBCallStack.beginSfsbCreation(); return interceptorContext.proceed(); } finally { // bean PostCreate event lifecycle has already completed. // endSfsbCreation() will clear the thread local knowledge of "creation time" referenced extended // persistence contexts. SFSBCallStack.endSfsbCreation(); } }
/** * gets the current SFSB invocation off the invocation call stack * * @return the entity manager map */ static Map<String, ExtendedEntityManager> getCurrentCall() { ArrayList<Map<String, ExtendedEntityManager>> stack = currentSFSBCallStack(); Map<String, ExtendedEntityManager> result = null; if (stack != null) { result = stack.get(stack.size() - 1); } return result; }
@Override public void registerExtendedPersistenceContext(String scopedPuName, ExtendedEntityManager entityManager) { if (SFSBCallStack.getSFSBCreationBeanNestingLevel() > 0) { SFSBCallStack.getSFSBCreationTimeInjectedXPCs(scopedPuName).registerShallowInheritance(scopedPuName, entityManager); } }
/** * gets the current SFSB invocation off the invocation call stack * * @return the entity manager map */ static Map<String, ExtendedEntityManager> getCurrentCall() { ArrayList<Map<String, ExtendedEntityManager>> stack = currentSFSBCallStack(); Map<String, ExtendedEntityManager> result = null; if (stack != null) { result = stack.get(stack.size() - 1); } return result; }
/** * Pops the current SFSB invocation off the invocation call stack * * @return the entity manager map */ public static Map<String, ExtendedEntityManager> popCall() { ArrayList<Map<String, ExtendedEntityManager>> stack = currentSFSBCallStack(); Map<String, ExtendedEntityManager> result = stack.remove(stack.size() - 1); stack.trimToSize(); return result; }
/** * Push the passed SFSB context handle onto the invocation call stack * * @param entityManagers the entity manager map */ public static void pushCall(Map<String, ExtendedEntityManager> entityManagers) { currentSFSBCallStack().add(entityManagers); if (entityManagers != null) { /** * JPA 2.0 spec section 7.9.1 Container Responsibilities: * "When a business method of the stateful session bean is invoked, * if the stateful session bean uses container managed transaction demarcation, * and the entity manager is not already associated with the current JTA transaction, * the container associates the entity manager with the current JTA transaction and * calls EntityManager.joinTransaction. * " */ for(ExtendedEntityManager extendedEntityManager: entityManagers.values()) { extendedEntityManager.internalAssociateWithJtaTx(); } } }
/** * Push the passed SFSB context handle onto the invocation call stack * * @param entityManagers the entity manager map */ public static void pushCall(Map<String, ExtendedEntityManager> entityManagers) { currentSFSBCallStack().add(entityManagers); if (entityManagers != null) { /** * JPA 2.0 spec section 7.9.1 Container Responsibilities: * "When a business method of the stateful session bean is invoked, * if the stateful session bean uses container managed transaction demarcation, * and the entity manager is not already associated with the current JTA transaction, * the container associates the entity manager with the current JTA transaction and * calls EntityManager.joinTransaction. * " */ for(ExtendedEntityManager extendedEntityManager: entityManagers.values()) { extendedEntityManager.internalAssociateWithJtaTx(); } } }