Search in sources :

Example 6 with EJBLocalObject

use of jakarta.ejb.EJBLocalObject in project tomee by apache.

the class CmrSet method getEntityBeans.

private static <Bean extends EntityBean> Set<Bean> getEntityBeans(final Collection<?> proxies, final Class type) {
    if (proxies == null) {
        return null;
    }
    final Set<Bean> entities = new HashSet<>();
    for (final Object value : proxies) {
        if (type != null && !type.isInstance(value)) {
            throw new IllegalArgumentException("Object is not an instance of " + type.getName() + ": " + (value == null ? "null" : value.getClass().getName()));
        }
        final Bean entity = Cmp2Util.<Bean>getEntityBean((EJBLocalObject) value);
        if (entity == null) {
            throw new IllegalArgumentException("Entity has been deleted");
        }
        entities.add(entity);
    }
    return entities;
}
Also used : EJBLocalObject(jakarta.ejb.EJBLocalObject) EntityBean(jakarta.ejb.EntityBean) HashSet(java.util.HashSet)

Example 7 with EJBLocalObject

use of jakarta.ejb.EJBLocalObject in project tomee by apache.

the class EntityEjbHomeHandler method removeByPrimaryKey.

protected Object removeByPrimaryKey(final Class interfce, final Method method, final Object[] args, final Object proxy) throws Throwable {
    final Object primKey = args[0];
    // Check for the common mistake of passing the ejbObject instead of ejbObject.getPrimaryKey()
    if (primKey instanceof EJBLocalObject) {
        final Class ejbObjectProxyClass = primKey.getClass();
        String ejbObjectName = null;
        for (final Class clazz : ejbObjectProxyClass.getInterfaces()) {
            if (EJBLocalObject.class.isAssignableFrom(clazz)) {
                ejbObjectName = clazz.getSimpleName();
                break;
            }
        }
        throw new RemoveException("Invalid argument '" + ejbObjectName + "', expected primary key.  Update to ejbLocalHome.remove(" + lcfirst(ejbObjectName) + ".getPrimaryKey())");
    } else if (primKey instanceof EJBObject) {
        final Class ejbObjectProxyClass = primKey.getClass();
        String ejbObjectName = null;
        for (final Class clazz : ejbObjectProxyClass.getInterfaces()) {
            if (EJBObject.class.isAssignableFrom(clazz)) {
                ejbObjectName = clazz.getSimpleName();
                break;
            }
        }
        throw new RemoveException("Invalid argument '" + ejbObjectName + "', expected primary key.  Update to ejbHome.remove(" + lcfirst(ejbObjectName) + ".getPrimaryKey())");
    }
    container.invoke(deploymentID, interfaceType, interfce, method, args, primKey);
    /* 
        * This operation takes care of invalidating all the EjbObjectProxyHandlers associated with
        * the same RegistryId. See this.createProxy().
        */
    invalidateAllHandlers(EntityEjbObjectHandler.getRegistryId(container, deploymentID, primKey));
    return null;
}
Also used : RemoveException(jakarta.ejb.RemoveException) EJBObject(jakarta.ejb.EJBObject) EJBObject(jakarta.ejb.EJBObject) EJBLocalObject(jakarta.ejb.EJBLocalObject) EJBLocalObject(jakarta.ejb.EJBLocalObject)

Aggregations

EJBLocalObject (jakarta.ejb.EJBLocalObject)7 EJBObject (jakarta.ejb.EJBObject)4 EntityBean (jakarta.ejb.EntityBean)2 BeanContext (org.apache.openejb.BeanContext)2 FinderException (jakarta.ejb.FinderException)1 RemoveException (jakarta.ejb.RemoveException)1 EntityManager (jakarta.persistence.EntityManager)1 Query (jakarta.persistence.Query)1 HashSet (java.util.HashSet)1 List (java.util.List)1 InternalErrorException (org.apache.openejb.InternalErrorException)1 ThreadContext (org.apache.openejb.core.ThreadContext)1 CmpContainer (org.apache.openejb.core.cmp.CmpContainer)1 EjbObjectProxyHandler (org.apache.openejb.core.ivm.EjbObjectProxyHandler)1 IntraVmProxy (org.apache.openejb.core.ivm.IntraVmProxy)1