Hi Manu,
I think that a new accessor for this specific case is a good idea. The
set method is exactly what it should be. Though, I think that we should
drop the pkClass.isIntance test: this set method is always invoked with
a CMP value, which is the unique field defined by the compound PK
pkClass. Also, it seems that the get method should do something very
similar. When we get the GlobalIdentity via cmrField, we want to
retrieve the unique value of its underlying identity. To do that, we can
use IdentityDefiner.extractIdentity, and then CMPFieldNestedRowAccessor.get.
Thanks for your work on this issue!
Gianny
Manu George wrote:
Hi Gianny,
Regarding JIRA Geronimo-1374
Modifying CompoundPKTransform was a very bad idea :-(. But it is
required to create an Instance of the compound primary key somewhere
and use it to get the GlobalIdentity as CompoundPKTransform is the
transform used. Is it a good idea to write another accessor
specifically for this case? Then the creation of the PK instance can
be moved to the accessor. But this requires the acessor to have access
to the PKClass. Also this accessor will only be used for the special
case that causes this error.
The set method of the accessor will be
public void set(InTxCache cache, CacheRow row, Object value) {
GlobalIdentity id;
Object pkObject;
if (!pkClass.isInstance(value)) {
try {
pkObject = pkClass.newInstance();
Field[] fields = pkClass.getFields();
fields[0].set(pkObject, value);
} catch (IllegalArgumentException e) {
throw new EJBException("Cannot extract global
identity", e);
} catch (IllegalAccessException e) {
throw new EJBException("Cannot extract global
identity", e);
} catch (InstantiationException e) {
throw new EJBException("Cannot extract global
identity", e);
}
}
try {
id = transform.getGlobalIdentity(pkObject);
} catch (IdentityTransformException e) {
throw new EJBException("Cannot extract global identity", e);
}
cmpField.set(cache, row, value);
cmrField.set(cache, row, id);
}
OR
Should the existing accessor be modified to take care of this scenario?
OR
Is there some other way to resolve this issue?
Thanks
Manu