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());
}
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;
}
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";
}
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;
}
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;
}
Aggregations