com.objectwave.transactionalSupport
Class ObjectEditor

java.lang.Object
  |
  +--com.objectwave.transactionalSupport.ObjectEditor
All Implemented Interfaces:
ObjectEditingView, java.io.Serializable, SetAndGetDelegateIF
Direct Known Subclasses:
RDBPersistentAdapter, SQLQuery

public class ObjectEditor
extends java.lang.Object
implements ObjectEditingView, java.io.Serializable

Tracks changes to a TransactionalObjectIF. If you wish to see verbose output of the ObjectEditor, start your application ow.objectEditVerbose=true

Version:
$Id: ObjectEditor.java,v 2.4 2002/03/23 13:42:11 dave_hoag Exp $
Author:
dhoag
See Also:
ObjectEditingView, Serialized Form

Nested Class Summary
static class ObjectEditor.Test
           
 
Field Summary
 java.lang.Object[] dataExchange
           
protected  java.lang.reflect.Field[] fds
           
protected static AccessSecurityIF security
           
 
Constructor Summary
ObjectEditor()
          Constructor for the ObjectEditor object
ObjectEditor(TransactionalObjectIF domainObject)
          Manage the changes for the transactional domainObject.
 
Method Summary
 java.util.Enumeration changes(TransactionLog log)
          An enumeration of ObjectChangeRequest objects for this particular transaction log;
 void clearChanges(TransactionLog log)
          Drop any changes associated with a specified transaction log.
protected  void clearChanges(TransactionLog log, boolean releaseObjects)
          Drop any changes associated with a specified transaction log.
 void commit(TransactionLog log, boolean force)
          In the event that we call setValue(aVal) to change an object.
 boolean containsAnyChanges()
          Are there ANY changes for ANY transaction log for this object.
 boolean containsAttributeChanges(TransactionLog log)
          If we have any changes which are not the result of a collection change, return true.
 boolean get(java.lang.reflect.Field adapt, boolean val)
           
 byte get(java.lang.reflect.Field adapt, byte val)
           
 char get(java.lang.reflect.Field adapt, char val)
           
 double get(java.lang.reflect.Field adapt, double val)
           
 float get(java.lang.reflect.Field adapt, float val)
           
 int get(java.lang.reflect.Field adapt, int oldValue)
          No longer uses the convience method.
 long get(java.lang.reflect.Field adapt, long val)
           
 java.lang.Object get(java.lang.reflect.Field adapt, java.lang.Object oldValue)
           
 short get(java.lang.reflect.Field adapt, short val)
           
 java.lang.String get(java.lang.reflect.Field adapt, java.lang.String val)
           
 java.util.Vector getCollectionChanges(TransactionLog log)
           
protected  java.lang.Object getDomainField(java.lang.reflect.Field adapt)
          Get the value from the domain object at field 'adapt'.
 TransactionalObjectIF getDomainObject()
          The object for which this EditingView represents.
protected  ObjectModified[] getFieldMap(TransactionLog log)
          For the provided TransactionLog, get the list of known changes.
protected static ObjectModified getMods(java.lang.reflect.Field field, ObjectModified[] list)
          Search the provided list of changes for change to the particular field.
 AccessSecurityIF getSecurity()
           
protected  java.lang.Object getValue(java.lang.reflect.Field adapt, java.lang.Object oldValue, TransactionLog log)
          The main workhorse method for all of the get methods.
 boolean isDirty()
          If we have any changes in the current transaction log, return true;
 boolean isTransient()
          A transient object.
 boolean lock(boolean wait)
          Pessimistically lock the object.
 java.lang.Thread lockedBy()
           
 void markChange(ObjectChangeRequest mod, TransactionLog log)
          Record that the TransactionalObject has been changed.
 void migrateChanges(TransactionLog log, TransactionLog newLog)
          Used by nested transactions.
protected  boolean noKnownLogs()
          protected final ObjectModified [] getFieldMap(final TransactionLog log) { if(log == singleLog) return fieldToChangeMap; if(objectMods == null) return null; return (ObjectModified [])objectMods.get(log); } protected synchronized final void putFieldMap(final TransactionLog log, final ObjectModified [] list) { if(singleLog == null) { singleLog = log; fieldToChangeMap = list; } else if(log == singleLog) { fieldToChangeMap = list; } else { if(objectMods == null) { objectMods = new HashMap(15); } objectMods.put(log, list); } } Abstract the implementation of keeping track of changes.
protected  void putFieldMap(TransactionLog log, ObjectModified[] list)
          For the prodided transaction log, this provided list of changes exists.
protected  void putMod(ObjectModified[] list, ObjectModified mod, TransactionLog log)
           
protected  ObjectModified[] quickChanges(TransactionLog log)
          Used by the persistent code to avoid the enumeration overhead
 void rollback(TransactionLog log, boolean forget)
          Undo any changes made to this object in the provided transaction.
 void set(java.lang.reflect.Field adapt, boolean val, boolean originalVal)
          Delegate to the set(Field, Object, Object) method.
 void set(java.lang.reflect.Field adapt, byte val, byte originalVal)
          Delegate to the set(Field, Object, Object) method.
 void set(java.lang.reflect.Field adapt, char val, char originalVal)
          Delegate to the set(Field, Object, Object) method.
 void set(java.lang.reflect.Field adapt, java.util.Date val, java.util.Date originalVal)
          Delegate to the set(Field, Object, Object) method.
 void set(java.lang.reflect.Field adapt, double val, double originalVal)
          Delegate to the set(Field, Object, Object) method.
 void set(java.lang.reflect.Field adapt, float val, float originalVal)
          Delegate to the set(Field, Object, Object) method.
 void set(java.lang.reflect.Field adapt, int val, int originalVal)
          Delegate to the set(Field, Object, Object) method.
 void set(java.lang.reflect.Field adapt, long val, long originalVal)
          Delegate to the set(Field, Object, Object) method.
 void set(java.lang.reflect.Field adapt, java.lang.Object val, java.lang.Object originalVal)
          Delegate to the setValue(Field, Object, Object) method.
 void set(java.lang.reflect.Field adapt, short val, short originalVal)
          Delegate to the set(Field, Object, Object) method.
 void set(java.lang.reflect.Field adapt, java.lang.String val, java.lang.String originalVal)
          Delegate to the set(Field, Object, Object) method.
 void setAsTransient(boolean value)
          A transient object.
protected  void setDomainField(java.lang.reflect.Field adapt, java.lang.Object val)
          Set the value 'val' on the domain object at field 'adapt'.
 void setSecurity(AccessSecurityIF s)
          Security allows one to prevent access to a fields value.
protected  void setValue(java.lang.reflect.Field adapt, java.lang.Object val, java.lang.Object originalVal)
          The main workhorse method for all of the set methods.
 void unlock()
          Unlock the pessimistically
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

security

protected static AccessSecurityIF security

dataExchange

public final transient java.lang.Object[] dataExchange

fds

protected final transient java.lang.reflect.Field[] fds
Constructor Detail

ObjectEditor

public ObjectEditor()
Constructor for the ObjectEditor object


ObjectEditor

public ObjectEditor(TransactionalObjectIF domainObject)
Manage the changes for the transactional domainObject. Every instance of ObjectEditor is responsible for only one TransactionalObjectIF.

Parameters:
domainObject -
Method Detail

getMods

protected static final ObjectModified getMods(java.lang.reflect.Field field,
                                              ObjectModified[] list)
Search the provided list of changes for change to the particular field. While this is indeed a linear search, it beats the pants off performance wise on a HashMap lookup (since the lists are always small).

Parameters:
list - ObjectModified [] A list of changes.
field - The field for which we are looking for changes.
Returns:
The Mods value

set

public void set(java.lang.reflect.Field adapt,
                byte val,
                byte originalVal)
Delegate to the set(Field, Object, Object) method.

Specified by:
set in interface SetAndGetDelegateIF
Parameters:
adapt -
val -
originalVal -

set

public void set(java.lang.reflect.Field adapt,
                char val,
                char originalVal)
Delegate to the set(Field, Object, Object) method.

Specified by:
set in interface SetAndGetDelegateIF
Parameters:
adapt -
val -
originalVal -

set

public void set(java.lang.reflect.Field adapt,
                double val,
                double originalVal)
Delegate to the set(Field, Object, Object) method.

Specified by:
set in interface SetAndGetDelegateIF
Parameters:
adapt -
val -
originalVal -

set

public void set(java.lang.reflect.Field adapt,
                float val,
                float originalVal)
Delegate to the set(Field, Object, Object) method.

Specified by:
set in interface SetAndGetDelegateIF
Parameters:
adapt -
val -
originalVal -

set

public void set(java.lang.reflect.Field adapt,
                int val,
                int originalVal)
Delegate to the set(Field, Object, Object) method.

Specified by:
set in interface SetAndGetDelegateIF
Parameters:
adapt -
val -
originalVal -

set

public void set(java.lang.reflect.Field adapt,
                long val,
                long originalVal)
Delegate to the set(Field, Object, Object) method.

Specified by:
set in interface SetAndGetDelegateIF
Parameters:
adapt -
val -
originalVal -

set

public void set(java.lang.reflect.Field adapt,
                java.lang.Object val,
                java.lang.Object originalVal)
Delegate to the setValue(Field, Object, Object) method.

Specified by:
set in interface SetAndGetDelegateIF
Parameters:
adapt -
val -
originalVal -
See Also:
#setValue(java.lang.Field, java.lang.Object, java.lang.Object)

set

public void set(java.lang.reflect.Field adapt,
                java.lang.String val,
                java.lang.String originalVal)
Delegate to the set(Field, Object, Object) method.

Specified by:
set in interface SetAndGetDelegateIF
Parameters:
adapt -
val -
originalVal -

set

public void set(java.lang.reflect.Field adapt,
                java.util.Date val,
                java.util.Date originalVal)
Delegate to the set(Field, Object, Object) method.

Specified by:
set in interface SetAndGetDelegateIF
Parameters:
adapt -
val -
originalVal -

set

public void set(java.lang.reflect.Field adapt,
                short val,
                short originalVal)
Delegate to the set(Field, Object, Object) method.

Specified by:
set in interface SetAndGetDelegateIF
Parameters:
adapt -
val -
originalVal -

set

public void set(java.lang.reflect.Field adapt,
                boolean val,
                boolean originalVal)
Delegate to the set(Field, Object, Object) method.

Specified by:
set in interface SetAndGetDelegateIF
Parameters:
adapt -
val -
originalVal -

setAsTransient

public void setAsTransient(boolean value)
A transient object. We do not keep track of changes for 'transient' objects. Perhaps 'transient' is an incorrect term.

Specified by:
setAsTransient in interface ObjectEditingView
Parameters:
value - The new AsTransient value

setSecurity

public void setSecurity(AccessSecurityIF s)
Security allows one to prevent access to a fields value. In the event of a 'set' restriction, a runtime security exception will be thrown. A 'get' restriction will not throw an exception, but instead return an incorrect value.

Parameters:
s - The new Security value

setDomainField

protected void setDomainField(java.lang.reflect.Field adapt,
                              java.lang.Object val)
Set the value 'val' on the domain object at field 'adapt'.

Parameters:
adapt - The new DomainField value
val - The new DomainField value

setValue

protected void setValue(java.lang.reflect.Field adapt,
                        java.lang.Object val,
                        java.lang.Object originalVal)
The main workhorse method for all of the set methods.

Parameters:
adapt - The new Value value
val - The new Value value
originalVal - The new Value value

get

public byte get(java.lang.reflect.Field adapt,
                byte val)
Specified by:
get in interface SetAndGetDelegateIF
Parameters:
adapt -
val -
Returns:

get

public char get(java.lang.reflect.Field adapt,
                char val)
Specified by:
get in interface SetAndGetDelegateIF
Parameters:
adapt -
val -
Returns:

get

public double get(java.lang.reflect.Field adapt,
                  double val)
Specified by:
get in interface SetAndGetDelegateIF
Parameters:
adapt -
val -
Returns:

get

public float get(java.lang.reflect.Field adapt,
                 float val)
Specified by:
get in interface SetAndGetDelegateIF
Parameters:
adapt -
val -
Returns:

get

public int get(java.lang.reflect.Field adapt,
               int oldValue)
No longer uses the convience method. This must be as fast as possible.

Specified by:
get in interface SetAndGetDelegateIF
Parameters:
adapt -
oldValue -
Returns:

get

public long get(java.lang.reflect.Field adapt,
                long val)
Specified by:
get in interface SetAndGetDelegateIF
Parameters:
adapt -
val -
Returns:

get

public java.lang.Object get(java.lang.reflect.Field adapt,
                            java.lang.Object oldValue)
Specified by:
get in interface SetAndGetDelegateIF
Parameters:
adapt -
oldValue -
Returns:

get

public short get(java.lang.reflect.Field adapt,
                 short val)
Specified by:
get in interface SetAndGetDelegateIF
Parameters:
adapt -
val -
Returns:

get

public java.lang.String get(java.lang.reflect.Field adapt,
                            java.lang.String val)
Parameters:
adapt -
val -
Returns:

get

public boolean get(java.lang.reflect.Field adapt,
                   boolean val)
Specified by:
get in interface SetAndGetDelegateIF
Parameters:
adapt -
val -
Returns:

getCollectionChanges

public java.util.Vector getCollectionChanges(TransactionLog log)
Parameters:
log - TransactionLog The current transaction context
Returns:
Vector of ObjectChangeRequests that represent collection changes.

getDomainObject

public TransactionalObjectIF getDomainObject()
Description copied from interface: ObjectEditingView
The object for which this EditingView represents.

Specified by:
getDomainObject in interface ObjectEditingView
Returns:
The DomainObject value

getSecurity

public AccessSecurityIF getSecurity()
Returns:
The Security value
See Also:
setSecurity(com.objectwave.transactionalSupport.AccessSecurityIF)

isDirty

public boolean isDirty()
If we have any changes in the current transaction log, return true;

Specified by:
isDirty in interface ObjectEditingView
Returns:
boolean Indicating one of the following:
  • There is no current transaction.
  • The current object is transient
  • There is a transaction and the current object is not transient and there are changes to the object.

  • isTransient

    public boolean isTransient()
    A transient object. We do not keep track of changes for 'transient' objects. Perhaps 'transient' is an incorrect term.

    Specified by:
    isTransient in interface ObjectEditingView
    Returns:
    The Transient value

    getFieldMap

    protected final ObjectModified[] getFieldMap(TransactionLog log)
    For the provided TransactionLog, get the list of known changes.

    Parameters:
    log - TransactionLog The transaction in question.
    Returns:
    ObjectModified [] The holder of the changes. The first null value is the end of the change list.

    getDomainField

    protected java.lang.Object getDomainField(java.lang.reflect.Field adapt)
    Get the value from the domain object at field 'adapt'.

    Parameters:
    adapt -
    Returns:
    The DomainField value

    getValue

    protected java.lang.Object getValue(java.lang.reflect.Field adapt,
                                        java.lang.Object oldValue,
                                        TransactionLog log)
    The main workhorse method for all of the get methods.

    Parameters:
    log - TransactionLog The current transaction context
    adapt -
    oldValue -
    Returns:
    Object The transactionally accurate value of the field 'adapt'.

    changes

    public java.util.Enumeration changes(TransactionLog log)
    An enumeration of ObjectChangeRequest objects for this particular transaction log;

    Specified by:
    changes in interface ObjectEditingView
    Parameters:
    log - TransactionLog The transaction in question.
    Returns:

    clearChanges

    public void clearChanges(TransactionLog log)
    Drop any changes associated with a specified transaction log. This is a dangerous move. Avoid doing this. Public only because of the interface.

    Specified by:
    clearChanges in interface ObjectEditingView
    Parameters:
    log - TransactionLog The transaction in question.

    commit

    public void commit(TransactionLog log,
                       boolean force)
                throws UpdateException
    In the event that we call setValue(aVal) to change an object. And then we call setValue(aVal) to restore that object to the originalValue then we want to toss the old Object Mods. In the event that we call setValue(aVal) to change an object. And then we call setValue(aVal) to restore that object to the originalValue then we want to toss the old Object Mods. In the event that we call setValue(aVal) to change an object. And then we call setValue(aVal) to restore that object to the originalValue then we want to toss the old Object Mods. In the event that we call setValue(aVal) to change an object. And then we call setValue(aVal) to restore that object to the originalValue then we want to toss the old Object Mods. In the event that we call setValue(aVal) to change an object. And then we call setValue(aVal) to restore that object to the originalValue then we want to toss the old Object Mods. In the event that we call setValue(aVal) to change an object. And then we call setValue(aVal) to restore that object to the originalValue then we want to toss the old Object Mods. Commit every change request for the specified transaction log. This will actually put the values into the Objects.

    Specified by:
    commit in interface ObjectEditingView
    Parameters:
    log - TransactionLog The current transaction context
    force -
    Throws:
    UpdateException

    containsAnyChanges

    public final boolean containsAnyChanges()
    Are there ANY changes for ANY transaction log for this object.

    Specified by:
    containsAnyChanges in interface ObjectEditingView
    Returns:

    containsAttributeChanges

    public boolean containsAttributeChanges(TransactionLog log)
    If we have any changes which are not the result of a collection change, return true. Similar to isDirty, but only ignores collection changes.

    Parameters:
    log - TransactionLog The current transaction context
    Returns:
    See Also:
    isDirty()

    lock

    public boolean lock(boolean wait)
    Pessimistically lock the object. Note that a thread calling lock() must eventually call unlock(), to allow and waiting threads access to this object. Failure to unlock this object will likely lead to stagnant threads, a prime candidate for a deadlock situation. In short, always unlock the object. This locking scheme is also reference-counted to accomodate the rare scenario where a thread may lock an object several times: the object remains locked until it has been unlocked the same number of times that it has been locked.

    Specified by:
    lock in interface ObjectEditingView
    Parameters:
    wait - boolean true if the current thread should wait until lock is available. Otherwise return immediately.
    Returns:
    boolean true if and only if the object was successfully locked.

    lockedBy

    public java.lang.Thread lockedBy()
    Returns:
    java.lang.Thread

    markChange

    public void markChange(ObjectChangeRequest mod,
                           TransactionLog log)
    Record that the TransactionalObject has been changed. The changes are encapsulated in the ObjectChangeRequest object, and the Transaction in which the change occurred is the the log.

    Parameters:
    log - TransactionLog The current transaction context
    mod -

    migrateChanges

    public void migrateChanges(TransactionLog log,
                               TransactionLog newLog)
    Used by nested transactions. A subtransaction has been commited. Move the sub transaction changes to the parent transaction.

    Specified by:
    migrateChanges in interface ObjectEditingView
    Parameters:
    log - TransactionLog The current transaction context
    newLog -

    rollback

    public void rollback(TransactionLog log,
                         boolean forget)
    Undo any changes made to this object in the provided transaction.

    Specified by:
    rollback in interface ObjectEditingView
    Parameters:
    log - TransactionLog The current transaction context
    forget -

    unlock

    public void unlock()
    Unlock the pessimistically

    Specified by:
    unlock in interface ObjectEditingView

    putFieldMap

    protected final void putFieldMap(TransactionLog log,
                                     ObjectModified[] list)
    For the prodided transaction log, this provided list of changes exists. You can't have two threads updating the field map at the same time.

    Parameters:
    log - TransactionLog The transaction in progress.
    list - ObjectModified [] This list will hold the changes.

    noKnownLogs

    protected final boolean noKnownLogs()
    protected final ObjectModified [] getFieldMap(final TransactionLog log) { if(log == singleLog) return fieldToChangeMap; if(objectMods == null) return null; return (ObjectModified [])objectMods.get(log); } protected synchronized final void putFieldMap(final TransactionLog log, final ObjectModified [] list) { if(singleLog == null) { singleLog = log; fieldToChangeMap = list; } else if(log == singleLog) { fieldToChangeMap = list; } else { if(objectMods == null) { objectMods = new HashMap(15); } objectMods.put(log, list); } } Abstract the implementation of keeping track of changes.

    Returns:

    quickChanges

    protected final ObjectModified[] quickChanges(TransactionLog log)
    Used by the persistent code to avoid the enumeration overhead

    Parameters:
    log - TransactionLog The transaction in question.
    Returns:

    clearChanges

    protected void clearChanges(TransactionLog log,
                                boolean releaseObjects)
    Drop any changes associated with a specified transaction log.

    Parameters:
    releaseObjects - boolean A true values indicates that ObjectModified objects should be returned to the queue.
    log - TransactionLog The transaction in question.

    putMod

    protected final void putMod(ObjectModified[] list,
                                ObjectModified mod,
                                TransactionLog log)
    Parameters:
    log - TransactionLog The current transaction context
    list -
    mod -