Search in sources :

Example 91 with EJBException

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);
    }
}
Also used : ThreadContext(org.apache.openejb.core.ThreadContext) RemoteException(java.rmi.RemoteException) OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException)

Example 92 with EJBException

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);
    }
}
Also used : ThreadContext(org.apache.openejb.core.ThreadContext) RemoteException(java.rmi.RemoteException) OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException)

Example 93 with EJBException

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
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) ThreadContext(org.apache.openejb.core.ThreadContext) Synchronization(javax.transaction.Synchronization) ObjectNotFoundException(javax.ejb.ObjectNotFoundException) EJBAccessException(javax.ejb.EJBAccessException) RemoveException(javax.ejb.RemoveException) OpenEJBException(org.apache.openejb.OpenEJBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) NoSuchObjectException(java.rmi.NoSuchObjectException) EjbTransactionUtil.handleApplicationException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleApplicationException) EjbTransactionUtil.handleSystemException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleSystemException) ApplicationException(org.apache.openejb.ApplicationException) FinderException(javax.ejb.FinderException) EntityBean(javax.ejb.EntityBean) RemoteException(java.rmi.RemoteException) OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException)

Example 94 with EJBException

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);
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) EJBLocalObject(javax.ejb.EJBLocalObject) EJBException(javax.ejb.EJBException) EntityBean(javax.ejb.EntityBean)

Example 95 with EJBException

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;
}
Also used : EntityManager(javax.persistence.EntityManager) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException) InitialContext(javax.naming.InitialContext)

Aggregations

EJBException (javax.ejb.EJBException)169 CreateException (javax.ejb.CreateException)51 RemoteException (java.rmi.RemoteException)45 RemoveException (javax.ejb.RemoveException)40 InitialContext (javax.naming.InitialContext)40 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)37 SystemException (javax.transaction.SystemException)37 FinderException (javax.ejb.FinderException)30 InvocationTargetException (java.lang.reflect.InvocationTargetException)24 OpenEJBException (org.apache.openejb.OpenEJBException)24 EJBObject (javax.ejb.EJBObject)18 NoSuchEntityException (javax.ejb.NoSuchEntityException)17 IOException (java.io.IOException)16 Test (org.junit.Test)16 EjbInvocation (com.sun.ejb.EjbInvocation)14 ConcurrentAccessException (javax.ejb.ConcurrentAccessException)14 IllegalLoopbackException (javax.ejb.IllegalLoopbackException)14 NamingException (javax.naming.NamingException)14 NotSerializableException (java.io.NotSerializableException)13 ConcurrentAccessTimeoutException (javax.ejb.ConcurrentAccessTimeoutException)13