Search in sources :

Example 11 with EntityBean

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

the class ActiveTxCache 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.
@Override
protected void preInvokeNoTx(EjbInvocation inv) {
    EntityContextImpl context = (EntityContextImpl) inv.context;
    if (context.isInState(BeanState.DESTROYED)) {
        return;
    }
    if (context.isNewlyActivated() && !inv.invocationInfo.isCreateHomeFinder) {
        // follow EJB2.0 section 12.1.6.1
        EntityBean e = (EntityBean) context.getEJB();
        try {
            callEJBLoad(e, context, false);
        } catch (NoSuchEntityException ex) {
            // Error during ejbLoad, so discard bean: EJB2.0 18.3.3
            forceDestroyBean(context);
            throw new NoSuchObjectLocalException("NoSuchEntityException thrown by ejbLoad, EJB instance discarded", ex);
        } 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) 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 12 with EntityBean

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

the class ActiveTxCache method afterBegin.

// Called from BaseContainer.SyncImpl
protected void afterBegin(EJBContextImpl ctx) {
    EntityContextImpl context = (EntityContextImpl) ctx;
    // Note: EntityBeans are not allowed to be TX_BEAN_MANAGED
    if (context.isInState(BeanState.DESTROYED))
        return;
    if (!containerStateManager.isNullEJBObject(context) || !containerStateManager.isNullEJBLocalObject(context)) {
        // invocations will be correctly handled
        if (context.getTransaction() != null) {
            addIncompleteTxEJB(context);
        }
        // need to call ejbLoad since there can be more than
        // one active EJB instance per primaryKey. (Option B in 9.11.5).
        EntityBean e = (EntityBean) context.getEJB();
        try {
            callEJBLoad(e, context, true);
        } catch (NoSuchEntityException ex) {
            _logger.log(Level.FINE, "Exception in afterBegin()", ex);
            // Error during ejbLoad, so discard bean: EJB2.0 18.3.3
            forceDestroyBean(context);
            throw new NoSuchObjectLocalException("NoSuchEntityException thrown by ejbLoad, EJB instance discarded", ex);
        } 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) 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 13 with EntityBean

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

the class ActiveTxCache method passivateAndPoolEJB.

// called from addReadyEJB and afterCompletion
protected void passivateAndPoolEJB(EntityContextImpl context) {
    if (context.isInState(BeanState.DESTROYED) || context.isInState(BeanState.POOLED))
        return;
    // if ( context.isPooled() ) {
    // context.isPooled(false);
    // return;
    // }
    EntityBean ejb = (EntityBean) context.getEJB();
    synchronized (context) {
        EjbInvocation inv = super.createEjbInvocation(ejb, context);
        inv.method = ejbPassivateMethod;
        invocationManager.preInvoke(inv);
        try {
            ejb.ejbPassivate();
        } catch (Exception ex) {
            _logger.log(Level.FINE, "Exception in passivateAndPoolEJB()", ex);
            forceDestroyBean(context);
            return;
        } finally {
            invocationManager.postInvoke(inv);
        }
        // remove EJB(Local)Object from ejb(Local)ObjectStore
        Object primaryKey = context.getPrimaryKey();
        if (isRemote) {
            removeEJBObjectFromStore(primaryKey);
        }
        if (isLocal) {
            ejbLocalObjectStore.remove(primaryKey);
        }
        addPooledEJB(context);
    }
}
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 14 with EntityBean

use of javax.ejb.EntityBean in project tomee by apache.

the class CmpContainer method select.

public Object select(final BeanContext beanContext, final String methodSignature, final String returnType, final Object... args) throws FinderException {
    final String signature = beanContext.getAbstractSchemaName() + "." + methodSignature;
    try {
        // execute the select query
        final Collection<Object> results = cmpEngine.queryBeans(beanContext, signature, args);
        // 
        // process the results
        // 
        // If we need to return a set...
        final Collection<Object> proxies;
        if (returnType.equals("java.util.Set")) {
            // we collect values into a LinkedHashSet to preserve ordering
            proxies = new LinkedHashSet<Object>();
        } else {
            // otherwise use a simple array list
            proxies = new ArrayList<Object>();
        }
        final boolean isSingleValued = !returnType.equals("java.util.Collection") && !returnType.equals("java.util.Set");
        ProxyFactory proxyFactory = null;
        for (Object value : results) {
            // if this is a single valued query and we already have results, throw FinderException
            if (isSingleValued && !proxies.isEmpty()) {
                throw new FinderException("The single valued query " + methodSignature + "returned more than one item");
            }
            // if we have an EntityBean, we need to proxy it
            if (value instanceof EntityBean) {
                final EntityBean entityBean = (EntityBean) value;
                if (proxyFactory == null) {
                    final BeanContext result = getBeanContextByClass(entityBean.getClass());
                    if (result != null) {
                        proxyFactory = new ProxyFactory(result);
                    }
                }
                if (proxyFactory != null) {
                    if (beanContext.isRemoteQueryResults(methodSignature)) {
                        value = proxyFactory.createRemoteProxy(entityBean, this);
                    } else {
                        value = proxyFactory.createLocalProxy(entityBean, this);
                    }
                }
            }
            proxies.add(value);
        }
        // if not single valued, return the set
        if (!isSingleValued) {
            return proxies;
        }
        // single valued query that returned no rows, is an exception
        if (proxies.isEmpty()) {
            throw new ObjectNotFoundException();
        }
        // return the single item.... multiple return values was handled in for loop above
        return proxies.iterator().next();
    } catch (final RuntimeException e) {
        throw new EJBException(e);
    }
}
Also used : FinderException(javax.ejb.FinderException) BeanContext(org.apache.openejb.BeanContext) EntityBean(javax.ejb.EntityBean) ObjectNotFoundException(javax.ejb.ObjectNotFoundException) EJBLocalObject(javax.ejb.EJBLocalObject) EJBObject(javax.ejb.EJBObject) OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException)

Example 15 with EntityBean

use of javax.ejb.EntityBean 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)

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