Search in sources :

Example 51 with EJBObject

use of javax.ejb.EJBObject 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 52 with EJBObject

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

the class SafeProperties method instantiateEJBObjectImpl.

protected EJBObjectImpl instantiateEJBObjectImpl(EJBObject ejbStub, Object key) throws Exception {
    EJBObjectInvocationHandler handler = new EJBObjectInvocationHandler(proxyInvocationInfoMap, remoteIntf);
    EJBObjectImpl ejbObjImpl = handler;
    try {
        EJBObject ejbObjectProxy = (EJBObject) ejbObjectProxyCtor.newInstance(new Object[] { handler });
        handler.setEJBObject(ejbObjectProxy);
    } catch (ClassCastException e) {
        String msg = localStrings.getLocalString("ejb.basecontainer_invalid_remote_interface", "Remote component interface [{0}] is invalid since it does not extend javax.ejb.EJBObject.", remoteIntf);
        throw new IllegalArgumentException(msg, e);
    }
    if (ejbStub != null) {
        // associate the EJBObject with the stub
        ejbObjImpl.setStub(ejbStub);
    }
    if (key != null) {
        // associate the EJBObject with the key
        ejbObjImpl.setKey(key);
    }
    ejbObjImpl.setContainer(this);
    return ejbObjImpl;
}
Also used : EJBObject(javax.ejb.EJBObject) EJBLocalObject(javax.ejb.EJBLocalObject) EJBObject(javax.ejb.EJBObject)

Example 53 with EJBObject

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

the class FinderTestBean method runTest.

public String runTest() throws Exception {
    final BigFinderHome bigFinderHome = (BigFinderHome) lookup("BigFinderHome");
    final LittleFinderHome littleFinderHome = (LittleFinderHome) lookup("LittleFinderHome");
    for (int i = 1; i < 300; ++i) {
        bigFinderHome.findN(i);
        final Collection littleList = littleFinderHome.findAll();
        for (final Object obj : littleList) {
            final StringBuilder msg = new StringBuilder();
            if (!(obj instanceof LittleFinder)) {
                msg.append("Failed with " + i + " records. LittleFinder Remote is actually " + obj.getClass().getName() + " Implemented interfaces " + Arrays.toString(obj.getClass().getInterfaces()));
                if (obj instanceof EJBObject) {
                    final Object pk = ((EJBObject) obj).getPrimaryKey();
                    msg.append(" Primary key value is " + pk);
                }
                throw new EJBException(msg.toString());
            }
        }
    }
    return "Test succeeded";
}
Also used : EJBObject(javax.ejb.EJBObject) Collection(java.util.Collection) EJBObject(javax.ejb.EJBObject) EJBException(javax.ejb.EJBException)

Example 54 with EJBObject

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

Example 55 with EJBObject

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

the class JpaCmpEngine method executeUpdateQuery.

public int executeUpdateQuery(final BeanContext beanContext, final String signature, Object[] args) throws FinderException {
    final EntityManager entityManager = getEntityManager(beanContext);
    Query query = createNamedQuery(entityManager, signature);
    if (query == null) {
        final int parenIndex = signature.indexOf('(');
        if (parenIndex > 0) {
            final String shortName = signature.substring(0, parenIndex);
            query = createNamedQuery(entityManager, shortName);
        }
        if (query == null) {
            throw new FinderException("No query defined for method " + signature);
        }
    }
    // 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);
        }
        query.setParameter(i + 1, arg);
    }
    final int result = query.executeUpdate();
    return result;
}
Also used : FinderException(javax.ejb.FinderException) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) EJBObject(javax.ejb.EJBObject) EJBObject(javax.ejb.EJBObject) EJBLocalObject(javax.ejb.EJBLocalObject) EJBLocalObject(javax.ejb.EJBLocalObject)

Aggregations

EJBObject (javax.ejb.EJBObject)104 RemoteException (java.rmi.RemoteException)41 Handle (javax.ejb.Handle)28 ObjectGraph (org.apache.openejb.test.object.ObjectGraph)12 EJBLocalObject (javax.ejb.EJBLocalObject)8 EJBException (javax.ejb.EJBException)7 EncCmpObject (org.apache.openejb.test.entity.cmp.EncCmpObject)7 RmiIiopCmpObject (org.apache.openejb.test.entity.cmp.RmiIiopCmpObject)7 MarshalledObject (java.rmi.MarshalledObject)6 EncCmpHome (org.apache.openejb.test.entity.cmp.EncCmpHome)6 Test (org.junit.Test)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 NoSuchObjectException (java.rmi.NoSuchObjectException)4 RemoveException (javax.ejb.RemoveException)4 SystemException (javax.transaction.SystemException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 NotSerializableException (java.io.NotSerializableException)3 ObjectInputStream (java.io.ObjectInputStream)3