use of javax.ejb.EJBException 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 javax.ejb.EJBException 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 javax.ejb.EJBException 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 javax.ejb.EJBException in project tomee by apache.
the class SetValuedCmr method set.
public void set(final Set<Bean> relatedBeans, final Collection newProxies) {
if (sourceProperty == null) {
throw new EJBException("Internal error: this container managed relationship is unidirectional and, " + "this entity does not have a cmr field for the relationship");
}
// EJB 3.0 Section 8.3.8 "Collections Managed by the Container" bullet 4
if (newProxies == null) {
throw new IllegalArgumentException("null can not be set into a collection-valued cmr-field");
}
// clear back reference in the old related beans
if (relatedProperty != null) {
for (final Bean oldBean : relatedBeans) {
if (oldBean != null) {
toCmp2Entity(oldBean).OpenEJB_removeCmr(relatedProperty, source);
}
}
}
relatedBeans.clear();
for (final Iterator iterator = new ArrayList(newProxies).iterator(); iterator.hasNext(); ) {
final Proxy newProxy = (Proxy) iterator.next();
final Bean newBean = Cmp2Util.<Bean>getEntityBean(newProxy);
if (newProxy != null) {
// set the back reference in the new related bean
Object oldBackRef = null;
if (relatedProperty != null) {
oldBackRef = toCmp2Entity(newBean).OpenEJB_addCmr(relatedProperty, source);
}
// add the bean to our value map
relatedBeans.add(newBean);
// to clear the back reference in that old bean
if (relatedProperty != null && oldBackRef != null) {
toCmp2Entity(oldBackRef).OpenEJB_removeCmr(sourceProperty, newBean);
}
}
}
}
use of javax.ejb.EJBException in project tomee by apache.
the class JpaCmpEngine method getEntityManager.
private EntityManager getEntityManager(final BeanContext beanContext) {
EntityManager entityManager = null;
try {
entityManager = (EntityManager) beanContext.getJndiEnc().lookup(CMP_PERSISTENCE_CONTEXT_REF_NAME);
} catch (final NamingException ignored) {
// TODO see OPENEJB-1259 temporary hack until geronimo jndi integration works better
try {
entityManager = (EntityManager) new InitialContext().lookup("java:" + CMP_PERSISTENCE_CONTEXT_REF_NAME);
} catch (final NamingException ignored2) {
// ignore
}
}
if (entityManager == null) {
throw new EJBException("Entity manager not found at \"openejb/cmp\" in jndi ejb " + beanContext.getDeploymentID());
}
registerListener(entityManager);
return entityManager;
}
Aggregations