You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-dev@db.apache.org by Andy Jefferson <an...@jpox.org> on 2008/01/03 16:02:14 UTC

Re: Make dirty of detached objects? Spec Chapter 23

> 23.17 Generated methods in least-derived PersistenceCapable class
> public final void jdoMakeDirty (String fieldName);

Adding on support for making fields of detached objects dirty means that this 
signature will likely have to change :-

1. field names are only known about in the "jdoFieldNames" String[] of each 
class. This doesn't matter with non-detached objects since the field name 
goes straight across to the StateManager. For detached objects a translation 
from field name to field number needs to happen to update the right part of 
jdoDetachedState.

2. Some classes in an inheritance tree can be detachable and some not (same 
issue as jdoIsDetached signature change in JDO-459)



With these in mind, for chapter 23 we can have the following
public void jdoMakeDirty(String fieldName)
{
    if (jdoStateManager != null)
        jdoStateManager.makeDirty(this, fieldName);
}
for non-detachable root classes, and
public void jdoMakeDirty(String fieldName)
{
    if (jdoStateManager != null)
        jdoStateManager.makeDirty(this, fieldName);
    if (jdoIsDetached())
    {
        if (fieldName != null && fieldName.indexOf('.') >= 0)
        {
            String className = fieldName.substring(0, 
fieldName.lastIndexOf('.'));
        if (className.equals(this.getClass().getName())) {
            for (int i = 0; i < jdoFieldNames.length; i++) {
                if (jdoFieldNames[i].equals(fieldName)) {
                    if (((BitSet) jdoDetachedState[2]).get(i + 
jdoInheritedFieldCount)) {
                        ((BitSet) jdoDetachedState[3]).set(i + 
jdoInheritedFieldCount);
                        return;
                    }
                    throw new JDODetachedFieldAccessException("You have just 
attempted to access a field/property that hasn't been detached. Please detach 
it first before performing this operation");
                }
            }
        }
        super.jdoMakeDirty(fieldName);
        }
    }
}
for detachable classes



-- 
Andy  (Java Persistent Objects - http://www.jpox.org)