Search in sources :

Example 6 with EJBLocalObject

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

the class EJBHashSet method remove.

/**
 * Removes the given element from this set if it is present.
 *
 * @param o object to be removed from this set, if present.
 * @return <tt>true</tt> if the set contained the specified element.
 * @see java.util.HashSet
 */
public boolean remove(Object o) {
    // NOI18N
    logger.finest("---EJBHashSet.remove---");
    assertIsValid();
    assertInTransaction();
    helper.assertInstanceOfLocalInterfaceImpl(o);
    EJBLocalObject lo = (EJBLocalObject) o;
    return pcSet.remove(helper.convertEJBLocalObjectToPC(lo, pm, true));
}
Also used : EJBLocalObject(javax.ejb.EJBLocalObject)

Example 7 with EJBLocalObject

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

the class JDOEJB20HelperImpl method convertPCToEJBLocalObject.

/**
 * Converts persistence-capable instance to EJBLocalObject. Returns null if
 * the instance is already removed via cascade-delete operation.
 * @param pc the persistence-capable instance to be converted as an Object.
 * @param pm the associated instance of PersistenceManager.
 * @param context the EJBContext of the calling bean.
 * @return instance of EJBLocalObject.
 */
public EJBLocalObject convertPCToEJBLocalObject(Object pc, PersistenceManager pm, EJBContext context) {
    if (pc == null)
        return null;
    Object jdoObjectId = pm.getObjectId(pc);
    Object key = convertObjectIdToPrimaryKey(jdoObjectId);
    try {
        return CMPHelper.getEJBLocalObject(key, getContainer(), context);
    } catch (Exception ex) {
        EJBException e = new EJBException(I18NHelper.getMessage(messages, "EXC_ConvertPCToEJBLocalObjectCtx", key.toString()), // NOI18N
        ex);
        // NOI18N
        logger.throwing("JDOEJB20HelperImpl", "convertPCToEJBLocalObjectCtx", e);
        throw e;
    }
}
Also used : EJBLocalObject(javax.ejb.EJBLocalObject) EJBException(javax.ejb.EJBException) EJBException(javax.ejb.EJBException)

Example 8 with EJBLocalObject

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

the class SunContainerHelper method getContainer.

/**
 * Get a Container helper instance that will be passed unchanged to the
 * required methods.
 * This is SunContainerHelper specific code.
 *
 * The info argument is an Object array that consistes of a class to use
 * for the class loader and concreteImpl bean class name.
 * @see getEJBObject(Object, Object)
 * @see getEJBLocalObject(Object, Object)
 * @see getEJBLocalObject(Object, Object, EJBObject)
 * @see removeByEJBLocalObject(EJBLocalObject, Object)
 * @see removeByPK(Object, Object)
 * @param info Object with the request information that is application server
 * specific.
 * @return a Container helper instance as an Object.
 */
public Object getContainer(Object info) {
    Object[] params = (Object[]) info;
    String appName = (String) params[0];
    ServiceLocator habitat = Globals.getDefaultHabitat();
    ApplicationRegistry reg = habitat.getService(ApplicationRegistry.class);
    ApplicationInfo appInfo = reg.get(appName);
    Application app = appInfo.getMetaData(Application.class);
    EjbDescriptor desc = app.getEjbByName((String) params[1]);
    return habitat.<EjbContainerUtil>getService(EjbContainerUtil.class).getContainer(desc.getUniqueId());
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ApplicationRegistry(org.glassfish.internal.data.ApplicationRegistry) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) EjbContainerUtil(com.sun.ejb.containers.EjbContainerUtil) EJBObject(javax.ejb.EJBObject) EJBLocalObject(javax.ejb.EJBLocalObject)

Example 9 with EJBLocalObject

use of javax.ejb.EJBLocalObject in project spring-framework by spring-projects.

the class LocalSlsbInvokerInterceptor method invokeInContext.

/**
	 * This implementation "creates" a new EJB instance for each invocation.
	 * Can be overridden for custom invocation strategies.
	 * <p>Alternatively, override {@link #getSessionBeanInstance} and
	 * {@link #releaseSessionBeanInstance} to change EJB instance creation,
	 * for example to hold a single shared EJB instance.
	 */
@Override
public Object invokeInContext(MethodInvocation invocation) throws Throwable {
    Object ejb = null;
    try {
        ejb = getSessionBeanInstance();
        Method method = invocation.getMethod();
        if (method.getDeclaringClass().isInstance(ejb)) {
            // directly implemented
            return method.invoke(ejb, invocation.getArguments());
        } else {
            // not directly implemented
            Method ejbMethod = ejb.getClass().getMethod(method.getName(), method.getParameterTypes());
            return ejbMethod.invoke(ejb, invocation.getArguments());
        }
    } catch (InvocationTargetException ex) {
        Throwable targetEx = ex.getTargetException();
        if (logger.isDebugEnabled()) {
            logger.debug("Method of local EJB [" + getJndiName() + "] threw exception", targetEx);
        }
        if (targetEx instanceof CreateException) {
            throw new EjbAccessException("Could not create local EJB [" + getJndiName() + "]", targetEx);
        } else {
            throw targetEx;
        }
    } catch (NamingException ex) {
        throw new EjbAccessException("Failed to locate local EJB [" + getJndiName() + "]", ex);
    } catch (IllegalAccessException ex) {
        throw new EjbAccessException("Could not access method [" + invocation.getMethod().getName() + "] of local EJB [" + getJndiName() + "]", ex);
    } finally {
        if (ejb instanceof EJBLocalObject) {
            releaseSessionBeanInstance((EJBLocalObject) ejb);
        }
    }
}
Also used : EJBLocalObject(javax.ejb.EJBLocalObject) NamingException(javax.naming.NamingException) Method(java.lang.reflect.Method) CreateException(javax.ejb.CreateException) EJBLocalObject(javax.ejb.EJBLocalObject) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 10 with EJBLocalObject

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

the class JpaCmpEngine method executeSelectQuery.

private List<Object> executeSelectQuery(final Query query, Object[] args) {
    // process args
    if (args == null) {
        args = NO_ARGS;
    }
    for (int i = 0; i < args.length; i++) {
        Object arg = args[i];
        // ejb proxies need to be swapped out for real instance classes
        if (arg instanceof EJBObject) {
            arg = Cmp2Util.getEntityBean((EJBObject) arg);
        }
        if (arg instanceof EJBLocalObject) {
            arg = Cmp2Util.getEntityBean((EJBLocalObject) arg);
        }
        try {
            query.getParameter(i + 1);
        } catch (final IllegalArgumentException e) {
            // specified position does not exist
            continue;
        }
        query.setParameter(i + 1, arg);
    }
    // todo results should not be iterated over, but should instead
    // perform all work in a wrapper list on demand by the application code
    final List results = query.getResultList();
    for (final Object value : results) {
        if (value instanceof EntityBean) {
            // todo don't activate beans already activated
            final EntityBean entity = (EntityBean) value;
            cmpCallback.setEntityContext(entity);
            cmpCallback.ejbActivate(entity);
        }
    }
    // noinspection unchecked
    return results;
}
Also used : EJBObject(javax.ejb.EJBObject) EntityBean(javax.ejb.EntityBean) EJBObject(javax.ejb.EJBObject) EJBLocalObject(javax.ejb.EJBLocalObject) List(java.util.List) EJBLocalObject(javax.ejb.EJBLocalObject)

Aggregations

EJBLocalObject (javax.ejb.EJBLocalObject)17 EJBObject (javax.ejb.EJBObject)6 EJBException (javax.ejb.EJBException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 EntityBean (javax.ejb.EntityBean)2 BeanContext (org.apache.openejb.BeanContext)2 EjbContainerUtil (com.sun.ejb.containers.EjbContainerUtil)1 Method (java.lang.reflect.Method)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 CreateException (javax.ejb.CreateException)1 FinderException (javax.ejb.FinderException)1 RemoveException (javax.ejb.RemoveException)1 NamingException (javax.naming.NamingException)1 EntityManager (javax.persistence.EntityManager)1 Query (javax.persistence.Query)1 InternalErrorException (org.apache.openejb.InternalErrorException)1 ThreadContext (org.apache.openejb.core.ThreadContext)1 CmpContainer (org.apache.openejb.core.cmp.CmpContainer)1