Search in sources :

Example 1 with ThreadContext

use of org.apache.openejb.core.ThreadContext in project tomee by apache.

the class RequestScopedThreadContextListener method contextEntered.

@Override
public void contextEntered(final ThreadContext oldContext, final ThreadContext newContext) {
    final BeanContext beanContext = newContext.getBeanContext();
    final WebBeansContext webBeansContext = beanContext.getModuleContext().getAppContext().getWebBeansContext();
    if (webBeansContext == null) {
        return;
    }
    final ContextsService contextsService = webBeansContext.getContextsService();
    final Context requestContext = CdiAppContextsService.class.cast(contextsService).getRequestContext(false);
    if (requestContext == null) {
        contextsService.startContext(RequestScoped.class, CdiAppContextsService.EJB_REQUEST_EVENT);
        newContext.set(DestroyContext.class, new DestroyContext(contextsService, newContext));
    }
}
Also used : WebBeansContext(org.apache.webbeans.config.WebBeansContext) BeanContext(org.apache.openejb.BeanContext) Context(javax.enterprise.context.spi.Context) ThreadContext(org.apache.openejb.core.ThreadContext) BeanContext(org.apache.openejb.BeanContext) ContextsService(org.apache.webbeans.spi.ContextsService) WebBeansContext(org.apache.webbeans.config.WebBeansContext)

Example 2 with ThreadContext

use of org.apache.openejb.core.ThreadContext in project tomee by apache.

the class CmpContainer method createThreadContext.

private ThreadContext createThreadContext(final EntityBean entityBean) {
    if (entityBean == null) {
        throw new NullPointerException("entityBean is null");
    }
    final BeanContext beanContext = getBeanContextByClass(entityBean.getClass());
    final KeyGenerator keyGenerator = beanContext.getKeyGenerator();
    final Object primaryKey = keyGenerator.getPrimaryKey(entityBean);
    return new ThreadContext(beanContext, primaryKey);
}
Also used : BeanContext(org.apache.openejb.BeanContext) ThreadContext(org.apache.openejb.core.ThreadContext) EJBLocalObject(javax.ejb.EJBLocalObject) EJBObject(javax.ejb.EJBObject)

Example 3 with ThreadContext

use of org.apache.openejb.core.ThreadContext in project tomee by apache.

the class CmpContainer method getEjbInstance.

public Object getEjbInstance(final BeanContext beanContext, final Object primaryKey) {
    final ThreadContext callContext = new ThreadContext(beanContext, primaryKey);
    final ThreadContext oldCallContext = ThreadContext.enter(callContext);
    try {
        return cmpEngine.loadBean(callContext, primaryKey);
    } finally {
        ThreadContext.exit(oldCallContext);
    }
}
Also used : ThreadContext(org.apache.openejb.core.ThreadContext)

Example 4 with ThreadContext

use of org.apache.openejb.core.ThreadContext in project tomee by apache.

the class CmpContainer method setEntityContext.

private void setEntityContext(final EntityBean entityBean) {
    if (entityBean == null) {
        throw new NullPointerException("entityBean is null");
    }
    // activating entity doen't have a primary key
    final BeanContext beanContext = getBeanContextByClass(entityBean.getClass());
    final ThreadContext callContext = new ThreadContext(beanContext, null);
    callContext.setCurrentOperation(Operation.SET_CONTEXT);
    final ThreadContext oldCallContext = ThreadContext.enter(callContext);
    try {
        entityBean.setEntityContext(new EntityContext(securityService));
    } catch (final RemoteException e) {
        throw new EJBException(e);
    } finally {
        ThreadContext.exit(oldCallContext);
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) ThreadContext(org.apache.openejb.core.ThreadContext) EntityContext(org.apache.openejb.core.entity.EntityContext) RemoteException(java.rmi.RemoteException) OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException)

Example 5 with ThreadContext

use of org.apache.openejb.core.ThreadContext in project tomee by apache.

the class CmpContainer method ejbStore.

private void ejbStore(final EntityBean entityBean) {
    if (entityBean == null) {
        throw new NullPointerException("entityBean is null");
    }
    final ThreadContext callContext = createThreadContext(entityBean);
    callContext.setCurrentOperation(Operation.STORE);
    final ThreadContext oldCallContext = ThreadContext.enter(callContext);
    try {
        entityBean.ejbStore();
    } catch (final RemoteException e) {
        throw new EJBException(e);
    } finally {
        ThreadContext.exit(oldCallContext);
    }
}
Also used : ThreadContext(org.apache.openejb.core.ThreadContext) RemoteException(java.rmi.RemoteException) OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException)

Aggregations

ThreadContext (org.apache.openejb.core.ThreadContext)68 BeanContext (org.apache.openejb.BeanContext)35 OpenEJBException (org.apache.openejb.OpenEJBException)23 Method (java.lang.reflect.Method)20 ApplicationException (org.apache.openejb.ApplicationException)14 EjbTransactionUtil.handleApplicationException (org.apache.openejb.core.transaction.EjbTransactionUtil.handleApplicationException)14 InterceptorStack (org.apache.openejb.core.interceptor.InterceptorStack)10 EjbTransactionUtil.handleSystemException (org.apache.openejb.core.transaction.EjbTransactionUtil.handleSystemException)10 TransactionPolicy (org.apache.openejb.core.transaction.TransactionPolicy)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 EJBException (javax.ejb.EJBException)9 SystemException (org.apache.openejb.SystemException)9 InterceptorData (org.apache.openejb.core.interceptor.InterceptorData)9 RemoteException (java.rmi.RemoteException)7 NamingException (javax.naming.NamingException)6 BeanTransactionPolicy (org.apache.openejb.core.transaction.BeanTransactionPolicy)6 JtaTransactionPolicy (org.apache.openejb.core.transaction.JtaTransactionPolicy)6 SystemInstance (org.apache.openejb.loader.SystemInstance)6 ArrayList (java.util.ArrayList)5 EJBAccessException (javax.ejb.EJBAccessException)5