use of javax.ejb.EJBLocalObject 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;
}
use of javax.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;
}
use of javax.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;
}
use of javax.ejb.EJBLocalObject in project Payara by payara.
the class EJBLocalObjectInvocationHandler method invokeEJBLocalObjectMethod.
private Object invokeEJBLocalObjectMethod(String methodName, Object[] args) throws Exception {
// Return value is null if target method returns void.
Object returnValue = null;
int methodIndex = -1;
Exception caughtException = null;
// so optimize by comparing as few characters as possible.
try {
switch(methodName.charAt(0)) {
case 'r':
// void remove();
methodIndex = container.EJBLocalObject_remove;
container.onEjbMethodStart(methodIndex);
super.remove();
break;
case 'i':
// boolean isIdentical(EJBLocalObject)
// Convert the param into an EJBLocalObjectImpl. Can't
// assume it's an EJBLocalObject for an ejb that was deployed
// using dynamic proxies.
EJBLocalObject other = (EJBLocalObject) args[0];
EJBLocalObjectImpl otherImpl = EJBLocalObjectImpl.toEJBLocalObjectImpl(other);
methodIndex = container.EJBLocalObject_isIdentical;
container.onEjbMethodStart(methodIndex);
returnValue = super.isIdentical(otherImpl);
break;
case 'g':
if (methodName.charAt(3) == 'E') {
// EJBLocalHome getEJBLocalHome();
methodIndex = container.EJBLocalObject_getEJBLocalHome;
container.onEjbMethodStart(methodIndex);
returnValue = super.getEJBLocalHome();
} else {
// Object getPrimaryKey();
methodIndex = container.EJBLocalObject_getPrimaryKey;
container.onEjbMethodStart(methodIndex);
returnValue = super.getPrimaryKey();
}
break;
default:
throw new EJBException("unknown method = " + methodName);
}
} catch (Exception ex) {
caughtException = ex;
throw ex;
} finally {
if (methodIndex != -1) {
container.onEjbMethodEnd(methodIndex, caughtException);
}
}
return returnValue;
}
use of javax.ejb.EJBLocalObject in project Payara by payara.
the class EJBHashSet method add.
// -------------------------Public Methods------------------
/**
* Adds the specified element to this set if it is not already
* present.
*
* @param o element to be added to this set.
* @return <tt>true</tt> if the set did not already contain the specified
* element.
* @see java.util.HashSet
*/
public boolean add(Object o) {
// NOI18N
logger.finest("---EJBHashSet.add---");
assertIsValid();
assertInTransaction();
helper.assertInstanceOfLocalInterfaceImpl(o);
Object pc = helper.convertEJBLocalObjectToPC((EJBLocalObject) o, pm, true);
return pcSet.add(pc);
}
Aggregations