Search in sources :

Example 46 with BeanContext

use of org.apache.openejb.BeanContext in project tomee by apache.

the class EjbSelect method execute_long.

public static long execute_long(final Object obj, final String methodSignature, final Object... args) throws FinderException {
    final BeanContext beanContext = (BeanContext) obj;
    final Container container = beanContext.getContainer();
    if (!(container instanceof CmpContainer)) {
        throw new FinderException("Deployment is not connected to a CmpContainer " + beanContext.getDeploymentID());
    }
    final CmpContainer cmpContainer = (CmpContainer) container;
    final Number result = (Number) cmpContainer.select(beanContext, methodSignature, "long", args);
    return result.longValue();
}
Also used : BeanContext(org.apache.openejb.BeanContext) FinderException(javax.ejb.FinderException) CmpContainer(org.apache.openejb.core.cmp.CmpContainer) Container(org.apache.openejb.Container) CmpContainer(org.apache.openejb.core.cmp.CmpContainer)

Example 47 with BeanContext

use of org.apache.openejb.BeanContext in project tomee by apache.

the class EntityContainer method cancelTimers.

private void cancelTimers(final ThreadContext threadContext) {
    final BeanContext beanContext = threadContext.getBeanContext();
    final Object primaryKey = threadContext.getPrimaryKey();
    // if we have a real timerservice, stop all timers. Otherwise, ignore...
    if (primaryKey != null) {
        final EjbTimerService timerService = beanContext.getEjbTimerService();
        if (timerService != null && timerService instanceof EjbTimerServiceImpl) {
            for (final Timer timer : beanContext.getEjbTimerService().getTimers(primaryKey)) {
                timer.cancel();
            }
        }
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) Timer(javax.ejb.Timer) EJBObject(javax.ejb.EJBObject) EJBLocalObject(javax.ejb.EJBLocalObject) EjbTimerServiceImpl(org.apache.openejb.core.timer.EjbTimerServiceImpl) EjbTimerService(org.apache.openejb.core.timer.EjbTimerService)

Example 48 with BeanContext

use of org.apache.openejb.BeanContext in project tomee by apache.

the class EntityContainer method removeEJBObject.

protected void removeEJBObject(final Method callMethod, final Object[] args, final ThreadContext callContext, final InterfaceType type) throws OpenEJBException {
    callContext.setCurrentOperation(Operation.REMOVE);
    final BeanContext beanContext = callContext.getBeanContext();
    final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, type), callContext);
    EntityBean bean = null;
    try {
        bean = instanceManager.obtainInstance(callContext);
        ejbLoad_If_No_Transaction(callContext, bean);
        bean.ejbRemove();
        didRemove(bean, callContext);
        instanceManager.poolInstance(callContext, bean, callContext.getPrimaryKey());
    } catch (final Throwable e) {
        handleException(txPolicy, e, callContext, bean);
    } finally {
        afterInvoke(txPolicy, callContext);
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) EntityBean(javax.ejb.EntityBean) TransactionPolicy(org.apache.openejb.core.transaction.TransactionPolicy) EjbTransactionUtil.createTransactionPolicy(org.apache.openejb.core.transaction.EjbTransactionUtil.createTransactionPolicy)

Example 49 with BeanContext

use of org.apache.openejb.BeanContext in project tomee by apache.

the class CmpContainer method getBeanContextByClass.

private BeanContext getBeanContextByClass(Class type) {
    BeanContext beanContext = null;
    while (type != null && beanContext == null) {
        beanContext = beansByClass.get(type);
        type = type.getSuperclass();
    }
    return beanContext;
}
Also used : BeanContext(org.apache.openejb.BeanContext)

Example 50 with BeanContext

use of org.apache.openejb.BeanContext in project tomee by apache.

the class CmpContainer method findEJBObject.

private Object findEJBObject(final Method callMethod, final Object[] args, final ThreadContext callContext, final InterfaceType interfaceType) throws OpenEJBException {
    final BeanContext beanContext = callContext.getBeanContext();
    final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, interfaceType), callContext);
    try {
        final List<Object> results = cmpEngine.queryBeans(callContext, callMethod, args);
        final KeyGenerator kg = beanContext.getKeyGenerator();
        // single ProxyInfo object is returned.
        if (callMethod.getReturnType() == Collection.class || callMethod.getReturnType() == Enumeration.class) {
            final List<ProxyInfo> proxies = new ArrayList<>();
            for (final Object value : results) {
                final EntityBean bean = (EntityBean) value;
                if (value == null) {
                    proxies.add(null);
                } else {
                    // get the primary key
                    final Object primaryKey = kg.getPrimaryKey(bean);
                    // create a new ProxyInfo based on the deployment info and primary key and add it to the vector
                    proxies.add(new ProxyInfo(beanContext, primaryKey));
                }
            }
            if (callMethod.getReturnType() == Enumeration.class) {
                return new Enumerator(proxies);
            } else {
                return proxies;
            }
        } else {
            if (results.size() != 1) {
                throw new ObjectNotFoundException("A Enteprise bean with deployment_id = " + beanContext.getDeploymentID() + (args != null && args.length >= 1 ? " and primarykey = " + args[0] : "") + " Does not exist");
            }
            // create a new ProxyInfo based on the deployment info and primary key
            final EntityBean bean = (EntityBean) results.get(0);
            if (bean == null) {
                return null;
            } else {
                final Object primaryKey = kg.getPrimaryKey(bean);
                return new ProxyInfo(beanContext, primaryKey);
            }
        }
    } catch (final FinderException fe) {
        handleApplicationException(txPolicy, fe, false);
    } catch (final Throwable e) {
        // handle reflection exception
        handleSystemException(txPolicy, e, callContext);
    } finally {
        afterInvoke(txPolicy, callContext);
    }
    throw new AssertionError("Should not get here");
}
Also used : Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList) TransactionPolicy(org.apache.openejb.core.transaction.TransactionPolicy) EjbTransactionUtil.createTransactionPolicy(org.apache.openejb.core.transaction.EjbTransactionUtil.createTransactionPolicy) BeanContext(org.apache.openejb.BeanContext) ProxyInfo(org.apache.openejb.ProxyInfo) FinderException(javax.ejb.FinderException) Enumerator(org.apache.openejb.util.Enumerator) EntityBean(javax.ejb.EntityBean) ObjectNotFoundException(javax.ejb.ObjectNotFoundException) Collection(java.util.Collection) EJBLocalObject(javax.ejb.EJBLocalObject) EJBObject(javax.ejb.EJBObject)

Aggregations

BeanContext (org.apache.openejb.BeanContext)198 OpenEJBException (org.apache.openejb.OpenEJBException)40 ThreadContext (org.apache.openejb.core.ThreadContext)40 Method (java.lang.reflect.Method)38 ContainerSystem (org.apache.openejb.spi.ContainerSystem)28 ArrayList (java.util.ArrayList)27 AppContext (org.apache.openejb.AppContext)26 TransactionPolicy (org.apache.openejb.core.transaction.TransactionPolicy)26 NamingException (javax.naming.NamingException)24 InterceptorData (org.apache.openejb.core.interceptor.InterceptorData)23 Context (javax.naming.Context)22 ApplicationException (org.apache.openejb.ApplicationException)20 HashMap (java.util.HashMap)19 EJBLocalObject (javax.ejb.EJBLocalObject)18 EJBObject (javax.ejb.EJBObject)18 SystemException (org.apache.openejb.SystemException)18 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)17 ModuleContext (org.apache.openejb.ModuleContext)16 EjbTransactionUtil.createTransactionPolicy (org.apache.openejb.core.transaction.EjbTransactionUtil.createTransactionPolicy)16 FinderException (javax.ejb.FinderException)14