Search in sources :

Example 6 with EntityBean

use of javax.ejb.EntityBean in project Payara by payara.

the class ActiveTxCache method removeBean.

/**
 * container.preInvoke() must already be done.
 * So this will be called with the proper Tx context.
 * @exception RemoveException if an error occurs while removing the bean
 */
protected void removeBean(EjbInvocation inv) throws RemoveException {
    try {
        ejbProbeNotifier.ejbBeanDestroyedEvent(getContainerId(), containerInfo.appName, containerInfo.modName, containerInfo.ejbName);
        // Note: if there are concurrent invocations/transactions in
        // progress for this ejbObject, they will be serialized along with
        // this remove by the database. So we optimistically do ejbRemove.
        // call ejbRemove on the EJB
        // the EJB is allowed to veto the remove by throwing RemoveException
        EntityBean ejb = (EntityBean) inv.ejb;
        EntityContextImpl context = (EntityContextImpl) inv.context;
        callEJBRemove(ejb, context);
        // inv.ejbObject could be a EJBObject or a EJBLocalObject
        Object primaryKey = getInvocationKey(inv);
        if (isRemote) {
            removeEJBObjectFromStore(primaryKey);
        }
        if (isLocal) {
            // Remove the EJBLocalObject from ejbLocalObjectStore
            ejbLocalObjectStore.remove(primaryKey);
        }
        // Mark EJB as removed. Now releaseContext will add bean to pool
        containerStateManager.markObjectRemoved(context, true);
        // Remove any timers for this entity bean identity.
        cancelTimers(primaryKey);
    } catch (RemoveException ex) {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "entitybean.container.local_remove_exception", logParams);
            _logger.log(Level.FINE, "", ex);
        }
        throw ex;
    } catch (Exception ex) {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "entitybean.container.remove_bean_exception", logParams);
            _logger.log(Level.FINE, "", ex);
        }
        throw new EJBException(ex);
    }
}
Also used : RemoveException(javax.ejb.RemoveException) EntityBean(javax.ejb.EntityBean) EJBLocalObject(javax.ejb.EJBLocalObject) EJBObject(javax.ejb.EJBObject) EJBLocalRemoteObject(com.sun.ejb.containers.EJBLocalRemoteObject) EJBException(javax.ejb.EJBException) NoSuchEntityException(javax.ejb.NoSuchEntityException) RemoveException(javax.ejb.RemoveException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) FinderException(javax.ejb.FinderException) SystemException(javax.transaction.SystemException) CreateException(javax.ejb.CreateException) NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException)

Example 7 with EntityBean

use of javax.ejb.EntityBean in project Payara by payara.

the class ActiveTxCache method passivateEJB.

// Called from AbstractCache
protected boolean passivateEJB(ComponentContext ctx) {
    if (containerState != CONTAINER_STARTED) {
        return false;
    }
    EntityContextImpl context = (EntityContextImpl) ctx;
    if (!context.isInState(BeanState.READY)) {
        return false;
    }
    if (_logger.isLoggable(Level.FINEST)) {
        _logger.log(Level.FINEST, "EntityContainer.passivateEJB(): context = (" + ctx + ")");
    }
    EntityBean ejb = (EntityBean) context.getEJB();
    EjbInvocation inv = super.createEjbInvocation(ejb, context);
    inv.method = ejbPassivateMethod;
    Object pkey = context.getPrimaryKey();
    boolean wasPassivated = false;
    // check state after locking ctx
    if (!context.isInState(BeanState.READY))
        return false;
    try {
        invocationManager.preInvoke(inv);
        // remove EJB from readyStore
        removeContextFromReadyStore(pkey, context);
        // no Tx needed for ejbPassivate
        ejb.ejbPassivate();
        wasPassivated = true;
    } catch (Exception ex) {
        _logger.log(Level.FINE, "Exception in passivateEJB()", ex);
        // Error during ejbStore/Passivate, discard bean: EJB2.0 18.3.3
        forceDestroyBean(context);
        return false;
    } finally {
        invocationManager.postInvoke(inv);
    }
    // If a future EjbInvocation arrives for them, they'll get recreated.
    if (isRemote) {
        removeEJBObjectFromStore(pkey);
    }
    if (isLocal) {
        ejbLocalObjectStore.remove(pkey);
    }
    // after calling ejbStore and ejbPassivate.
    synchronized (context) {
        addPooledEJB(context);
    }
    return wasPassivated;
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation) EntityBean(javax.ejb.EntityBean) EJBLocalObject(javax.ejb.EJBLocalObject) EJBObject(javax.ejb.EJBObject) EJBLocalRemoteObject(com.sun.ejb.containers.EJBLocalRemoteObject) NoSuchEntityException(javax.ejb.NoSuchEntityException) RemoveException(javax.ejb.RemoveException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) FinderException(javax.ejb.FinderException) SystemException(javax.transaction.SystemException) CreateException(javax.ejb.CreateException) NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException)

Example 8 with EntityBean

use of javax.ejb.EntityBean in project Payara by payara.

the class ActiveTxCache method activateEJBFromPool.

/**
 * Called from getContext and getEJBWithIncompleteTx
 * Get an EJB in the ready state (i.e. which is not doing any
 * invocations and doesnt have any incomplete Tx), for the
 * ejbObject provided in the EjbInvocation.
 * Concurrent invocations should get *different* instances.
 */
protected EntityContextImpl activateEJBFromPool(Object primaryKey, EjbInvocation inv) {
    EntityContextImpl context = null;
    // get a pooled EJB and activate it.
    context = getPooledEJB();
    // set EJBObject/LocalObject for the context
    if (inv.isLocal) {
        EJBLocalObjectImpl localObjImpl = internalGetEJBLocalObjectImpl(primaryKey, true);
        containerStateManager.attachObject(inv, context, null, localObjImpl);
    // No need to create/set EJBObject if this EJB isRemote too.
    // This saves remote object creation overhead.
    // The EJBObject and stub will get created lazily if needed
    // when EntityContext.getEJBObjectImpl is called.
    } else {
        // remote EjbInvocation
        EJBObjectImpl ejbObjImpl = internalGetEJBObjectImpl(primaryKey, null, true);
        containerStateManager.attachObject(inv, context, ejbObjImpl, null);
        if (isLocal) {
            // Create EJBLocalObject so EntityContext methods work
            containerStateManager.attachObject(inv, context, null, internalGetEJBLocalObjectImpl(primaryKey, true));
        }
    }
    context.setState(BeanState.READY);
    EntityBean ejb = (EntityBean) context.getEJB();
    EjbInvocation inv2 = super.createEjbInvocation(ejb, context);
    inv2.method = ejbActivateMethod;
    invocationManager.preInvoke(inv2);
    try {
        ejb.ejbActivate();
    // Note: ejbLoad will be called during preInvokeTx
    // since this EJB instance is being associated with
    // a Tx for the first time.
    } catch (Exception ex) {
        // Error during ejbActivate, discard bean: EJB2.0 18.3.3
        forceDestroyBean(context);
        throw new EJBException(ex);
    } finally {
        invocationManager.postInvoke(inv2);
    }
    context.setNewlyActivated(true);
    // recycler.initSoftRef(context);
    afterNewlyActivated(context);
    return context;
}
Also used : EJBLocalObjectImpl(com.sun.ejb.containers.EJBLocalObjectImpl) EjbInvocation(com.sun.ejb.EjbInvocation) EntityBean(javax.ejb.EntityBean) EJBObjectImpl(com.sun.ejb.containers.EJBObjectImpl) EJBException(javax.ejb.EJBException) NoSuchEntityException(javax.ejb.NoSuchEntityException) RemoveException(javax.ejb.RemoveException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) FinderException(javax.ejb.FinderException) SystemException(javax.transaction.SystemException) CreateException(javax.ejb.CreateException) NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException)

Example 9 with EntityBean

use of javax.ejb.EntityBean in project Payara by payara.

the class ReadOnlyBeanContainer method preInvokeNoTx.

// Called from BaseContainer just before invoking a business method
// whose tx attribute is TX_NEVER / TX_NOT_SUPPORTED / TX_SUPPORTS
// without a client tx.
protected void preInvokeNoTx(EjbInvocation inv) {
    EntityContextImpl context = (EntityContextImpl) inv.context;
    if (context.isInState(BeanState.DESTROYED))
        return;
    if (!inv.invocationInfo.isCreateHomeFinder) {
        // follow EJB2.0 section 12.1.6.1
        EntityBean e = (EntityBean) context.getEJB();
        try {
            callEJBLoad(e, context, false);
        } catch (NoSuchEntityException ex) {
            _logger.log(Level.FINE, "Exception in preInvokeNoTx()", ex);
            // Error during ejbLoad, so discard bean: EJB2.0 18.3.3
            forceDestroyBean(context);
            throw new NoSuchObjectLocalException("NoSuchEntityException thrown by ejbLoad, " + "EJB instance discarded");
        } catch (Exception ex) {
            // Error during ejbLoad, so discard bean: EJB2.0 18.3.3
            forceDestroyBean(context);
            throw new EJBException(ex);
        }
        context.setNewlyActivated(false);
    }
}
Also used : NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) EntityBean(javax.ejb.EntityBean) EJBException(javax.ejb.EJBException) NoSuchEntityException(javax.ejb.NoSuchEntityException) FinderException(javax.ejb.FinderException) NoSuchEntityException(javax.ejb.NoSuchEntityException) RemoveException(javax.ejb.RemoveException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) CreateException(javax.ejb.CreateException) NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException)

Example 10 with EntityBean

use of javax.ejb.EntityBean in project Payara by payara.

the class ActiveTxCache method enlistResourcesAndStore.

// Called from beforeCompletion and preFind
private void enlistResourcesAndStore(EntityContextImpl context) {
    EntityBean e = (EntityBean) context.getEJB();
    // NOTE : Use EjbInvocation instead of ComponentInvocation since
    // the context is available.  It is needed in case ejbStore/ejbLoad
    // makes use of EJB timer service in order to perform operations allowed
    // checks
    EjbInvocation inv = super.createEjbInvocation(e, context);
    invocationManager.preInvoke(inv);
    try {
        transactionManager.enlistComponentResources();
        callEJBStore(e, context);
    } catch (NoSuchEntityException ex) {
        // Error during ejbStore, so discard bean: EJB2.0 18.3.3
        forceDestroyBean(context);
        throw new NoSuchObjectLocalException("NoSuchEntityException thrown by ejbStore, EJB instance discarded", ex);
    } catch (Exception ex) {
        // Error during ejbStore, so discard bean: EJB2.0 18.3.3
        forceDestroyBean(context);
        throw new EJBException(ex);
    } finally {
        invocationManager.postInvoke(inv);
    }
}
Also used : NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) EjbInvocation(com.sun.ejb.EjbInvocation) EntityBean(javax.ejb.EntityBean) EJBException(javax.ejb.EJBException) NoSuchEntityException(javax.ejb.NoSuchEntityException) NoSuchEntityException(javax.ejb.NoSuchEntityException) RemoveException(javax.ejb.RemoveException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) FinderException(javax.ejb.FinderException) SystemException(javax.transaction.SystemException) CreateException(javax.ejb.CreateException) NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException)

Aggregations

EntityBean (javax.ejb.EntityBean)25 EJBLocalObject (javax.ejb.EJBLocalObject)13 EJBObject (javax.ejb.EJBObject)12 FinderException (javax.ejb.FinderException)12 RemoteException (java.rmi.RemoteException)11 BeanContext (org.apache.openejb.BeanContext)11 TransactionPolicy (org.apache.openejb.core.transaction.TransactionPolicy)11 EJBException (javax.ejb.EJBException)10 NoSuchEntityException (javax.ejb.NoSuchEntityException)10 RemoveException (javax.ejb.RemoveException)9 EjbTransactionUtil.createTransactionPolicy (org.apache.openejb.core.transaction.EjbTransactionUtil.createTransactionPolicy)9 CreateException (javax.ejb.CreateException)8 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)8 SystemException (javax.transaction.SystemException)7 EjbInvocation (com.sun.ejb.EjbInvocation)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 ObjectNotFoundException (javax.ejb.ObjectNotFoundException)4 OpenEJBException (org.apache.openejb.OpenEJBException)4 ProxyInfo (org.apache.openejb.ProxyInfo)4 EJBLocalRemoteObject (com.sun.ejb.containers.EJBLocalRemoteObject)3