Transaction tx = tm.getTransaction();
VersionedObject manager = (VersionedObject)invocation.getMetaData(Versioned.VERSIONED, Versioned.VERSIONED_OBJECT);
Object version = manager.getVersion(tx);
if (version != null)
{
invocation.setTargetObject(version);
return invocation.invokeNext();
}
boolean isReadonly = false;
if (invocation instanceof MethodInvocation)
{
String readonly = (String)invocation.getMetaData(Versioned.VERSIONED, Versioned.READONLY);
if (readonly != null)
{
isReadonly = Boolean.getBoolean(readonly.toLowerCase());
}
}
else if (invocation instanceof FieldReadInvocation)
{
isReadonly = true;
}
else if (invocation instanceof FieldWriteInvocation)
{
isReadonly = false;
}
if (isReadonly) return invocation.invokeNext();
// Ok, we're in a tx, we're not readonly, there is no previous version, so create another
version = manager.createVersion(tx);
invocation.setTargetObject(version);
return invocation.invokeNext();