use of org.apache.openejb.core.ThreadContext in project tomee by apache.
the class CmpContainer method ejbPassivate.
private void ejbPassivate(final EntityBean entityBean) {
if (entityBean == null) {
throw new NullPointerException("entityBean is null");
}
final ThreadContext callContext = createThreadContext(entityBean);
callContext.setCurrentOperation(Operation.PASSIVATE);
final ThreadContext oldCallContext = ThreadContext.enter(callContext);
try {
entityBean.ejbPassivate();
} 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 ejbActivate.
private void ejbActivate(final EntityBean entityBean) {
if (entityBean == null) {
throw new NullPointerException("entityBean is null");
}
final ThreadContext callContext = createThreadContext(entityBean);
callContext.setCurrentOperation(Operation.ACTIVATE);
final ThreadContext oldCallContext = ThreadContext.enter(callContext);
try {
entityBean.ejbActivate();
} 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 ejbLoad.
private void ejbLoad(final EntityBean entityBean) {
if (entityBean == null) {
throw new NullPointerException("entityBean is null");
}
final ThreadContext callContext = createThreadContext(entityBean);
callContext.setCurrentOperation(Operation.LOAD);
final ThreadContext oldCallContext = ThreadContext.enter(callContext);
try {
entityBean.ejbLoad();
} catch (final RemoteException e) {
throw new EJBException(e);
} finally {
ThreadContext.exit(oldCallContext);
}
// if we call load we must call store
try {
// noinspection unchecked
Set<EntityBean> registeredEntities = (LinkedHashSet<EntityBean>) synchronizationRegistry.getResource(ENTITIES_TO_STORE);
if (registeredEntities == null) {
registeredEntities = new LinkedHashSet<EntityBean>();
synchronizationRegistry.putResource(ENTITIES_TO_STORE, registeredEntities);
synchronizationRegistry.registerInterposedSynchronization(new Synchronization() {
@Override
public void beforeCompletion() {
// noinspection unchecked
final Set<EntityBean> registeredEntities = (LinkedHashSet<EntityBean>) synchronizationRegistry.getResource(ENTITIES_TO_STORE);
if (registeredEntities == null) {
return;
}
for (final EntityBean entityBean : registeredEntities) {
ejbStore(entityBean);
}
}
@Override
public void afterCompletion(final int i) {
}
});
}
registeredEntities.add(entityBean);
} catch (final Exception e) {
// no-op
}
}
use of org.apache.openejb.core.ThreadContext in project tomee by apache.
the class EntityContext method getPrimaryKey.
public Object getPrimaryKey() throws IllegalStateException {
doCheck(Call.getPrimaryKey);
final ThreadContext threadContext = ThreadContext.getThreadContext();
return threadContext.getPrimaryKey();
}
use of org.apache.openejb.core.ThreadContext in project tomee by apache.
the class BaseEjbProxyHandler method getLiveHandleRegistry.
public ConcurrentMap getLiveHandleRegistry() {
final BeanContext beanContext = getBeanContext();
final ThreadContext tc = ThreadContext.getThreadContext();
if (tc != null && tc.getBeanContext() != beanContext && /* parent bean */
tc.getCurrentOperation() == Operation.BUSINESS) {
ProxyRegistry registry = tc.get(ProxyRegistry.class);
if (registry == null) {
registry = new ProxyRegistry();
tc.set(ProxyRegistry.class, registry);
}
return registry.liveHandleRegistry;
} else {
// use the tx if there
final SystemInstance systemInstance = SystemInstance.get();
final TransactionManager txMgr = systemInstance.getComponent(TransactionManager.class);
try {
final Transaction tx = txMgr.getTransaction();
if (tx != null && tx.getStatus() == Status.STATUS_ACTIVE) {
final TransactionSynchronizationRegistry registry = systemInstance.getComponent(TransactionSynchronizationRegistry.class);
final String resourceKey = ProxyRegistry.class.getName();
ConcurrentMap map = ConcurrentMap.class.cast(registry.getResource(resourceKey));
if (map == null) {
map = new ConcurrentHashMap();
registry.putResource(resourceKey, map);
try {
final ConcurrentMap tmp = map;
tx.registerSynchronization(new Synchronization() {
@Override
public void beforeCompletion() {
// no-op
}
@Override
public void afterCompletion(final int status) {
tmp.clear();
}
});
} catch (final RollbackException e) {
// not really possible since we check the status
// let it go to default
}
}
return map;
}
} catch (final SystemException e) {
// let it go to default
}
// back to default but it doesnt release the memory
ProxyRegistry proxyRegistry = beanContext.get(ProxyRegistry.class);
if (proxyRegistry == null) {
proxyRegistry = new ProxyRegistry();
beanContext.set(ProxyRegistry.class, proxyRegistry);
}
return proxyRegistry.liveHandleRegistry;
}
}
Aggregations