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));
}
}
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);
}
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);
}
}
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);
}
}
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);
}
}
Aggregations