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;
}
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;
}
Aggregations