Search in sources :

Example 1 with ExtendedEntityManager

use of org.jboss.as.jpa.container.ExtendedEntityManager in project wildfly by wildfly.

the class SFSBCreateInterceptor method processInvocation.

@Override
public Object processInvocation(InterceptorContext interceptorContext) throws Exception {
    ComponentInstance componentInstance = interceptorContext.getPrivateData(ComponentInstance.class);
    Map<String, ExtendedEntityManager> entityManagers = null;
    if (componentInstance.getInstanceData(SFSBInvocationInterceptor.CONTEXT_KEY) == null) {
        // Get all of the extended persistence contexts in use by the bean (some of which may of been inherited from
        // other beans).
        entityManagers = new HashMap<String, ExtendedEntityManager>();
        componentInstance.setInstanceData(SFSBInvocationInterceptor.CONTEXT_KEY, new ImmediateManagedReference(entityManagers));
    } else {
        ManagedReference entityManagerRef = (ManagedReference) componentInstance.getInstanceData(SFSBInvocationInterceptor.CONTEXT_KEY);
        entityManagers = (Map<String, ExtendedEntityManager>) entityManagerRef.getInstance();
    }
    final ExtendedEntityManager[] ems = CreatedEntityManagers.getDeferredEntityManagers();
    for (ExtendedEntityManager e : ems) {
        entityManagers.put(e.getScopedPuName(), e);
    }
    return interceptorContext.proceed();
}
Also used : ComponentInstance(org.jboss.as.ee.component.ComponentInstance) ImmediateManagedReference(org.jboss.as.naming.ImmediateManagedReference) ManagedReference(org.jboss.as.naming.ManagedReference) ImmediateManagedReference(org.jboss.as.naming.ImmediateManagedReference) ExtendedEntityManager(org.jboss.as.jpa.container.ExtendedEntityManager)

Example 2 with ExtendedEntityManager

use of org.jboss.as.jpa.container.ExtendedEntityManager in project wildfly by wildfly.

the class SFSBInvocationInterceptor method processInvocation.

@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 {
        // call the next interceptor or target
        return context.proceed();
    } finally {
        if (entityManagerRef != null) {
            SFSBCallStack.popCall();
        }
    }
}
Also used : ComponentInstance(org.jboss.as.ee.component.ComponentInstance) ManagedReference(org.jboss.as.naming.ManagedReference) ExtendedEntityManager(org.jboss.as.jpa.container.ExtendedEntityManager) Map(java.util.Map)

Aggregations

ComponentInstance (org.jboss.as.ee.component.ComponentInstance)2 ExtendedEntityManager (org.jboss.as.jpa.container.ExtendedEntityManager)2 ManagedReference (org.jboss.as.naming.ManagedReference)2 Map (java.util.Map)1 ImmediateManagedReference (org.jboss.as.naming.ImmediateManagedReference)1