com.objectwave.transactionalSupport
Class NoFieldObjectEditor

java.lang.Object
  |
  +--com.objectwave.transactionalSupport.NoFieldObjectEditor
All Implemented Interfaces:
ObjectEditingView, java.io.Serializable, SetAndGetDelegateIF

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

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

Version:
$Id: NoFieldObjectEditor.java,v 1.1 2002/02/01 21:46:40 dave_hoag Exp $
Author:
dhoag
See Also:
ObjectEditingView, Serialized Form

Nested Class Summary
static class NoFieldObjectEditor.Test
           
 
Constructor Summary
NoFieldObjectEditor()
          Constructor for the NoFieldObjectEditor object
NoFieldObjectEditor(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)
           
 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)
           
 boolean get(int adapt, boolean val)
           
 byte get(int adapt, byte val)
           
 char get(int adapt, char val)
           
 double get(int adapt, double val)
           
 float get(int adapt, float val)
           
 int get(int adapt, int oldValue)
          No longer uses the convience method.
 long get(int adapt, long val)
           
 java.lang.Object get(int adapt, java.lang.Object oldValue)
           
 short get(int adapt, short val)
           
 java.lang.String get(int adapt, java.lang.String val)
           
 java.util.Vector getCollectionChanges(TransactionLog log)
           
 TransactionalObjectIF getDomainObject()
          The object for which this EditingView represents.
protected  java.lang.Object getField(int idx)
          Gets the Field attribute of the NoFieldObjectEditor object
protected  NoFieldObjectModified[] getFieldMap(TransactionLog log)
          For the provided TransactionLog, get the list of known changes.
protected static NoFieldObjectModified getMods(int field, NoFieldObjectModified[] list)
          Search the provided list of changes for change to the particular field.
protected  java.lang.Object getValue(int adapt, java.lang.Object oldValue, TransactionLog log)
          The main workhorse method for all of the get methods.
 void initFieldSize(int size)
           
 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(NoFieldObjectModified 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 NoFieldObjectModified [] 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 NoFieldObjectModified [] 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, NoFieldObjectModified[] list)
          For the prodided transaction log, this provided list of changes exists.
protected  void putMod(NoFieldObjectModified[] list, NoFieldObjectModified mod, TransactionLog log)
           
protected  NoFieldObjectModified[] 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)
           
 void set(java.lang.reflect.Field adapt, byte val, byte originalVal)
           
 void set(java.lang.reflect.Field adapt, char val, char originalVal)
           
 void set(java.lang.reflect.Field adapt, java.util.Date val, java.util.Date originalVal)
           
 void set(java.lang.reflect.Field adapt, double val, double originalVal)
           
 void set(java.lang.reflect.Field adapt, float val, float originalVal)
           
 void set(java.lang.reflect.Field adapt, int val, int originalVal)
           
 void set(java.lang.reflect.Field adapt, long val, long originalVal)
           
 void set(java.lang.reflect.Field adapt, java.lang.Object val, java.lang.Object originalVal)
           
 void set(java.lang.reflect.Field adapt, short val, short originalVal)
           
 void set(java.lang.reflect.Field adapt, java.lang.String val, java.lang.String originalVal)
           
 void set(int adapt, boolean val, boolean originalVal)
          Delegate to the set(int, Object, Object) method.
 void set(int adapt, byte val, byte originalVal)
          Delegate to the set(int, Object, Object) method.
 void set(int adapt, char val, char originalVal)
          Delegate to the set(int, Object, Object) method.
 void set(int adapt, java.util.Date val, java.util.Date originalVal)
          Delegate to the set(int, Object, Object) method.
 void set(int adapt, double val, double originalVal)
          Delegate to the set(int, Object, Object) method.
 void set(int adapt, float val, float originalVal)
          Delegate to the set(int, Object, Object) method.
 void set(int adapt, int val, int originalVal)
          Delegate to the set(int, Object, Object) method.
 void set(int adapt, long val, long originalVal)
          Delegate to the set(int, Object, Object) method.
 void set(int adapt, java.lang.Object val, java.lang.Object originalVal)
          Delegate to the setValue(int, Object, Object) method.
 void set(int adapt, short val, short originalVal)
          Delegate to the set(int, Object, Object) method.
 void set(int adapt, java.lang.String val, java.lang.String originalVal)
          Delegate to the set(int, Object, Object) method.
 void setAsTransient(boolean value)
          A transient object.
protected  void setField(int idx, java.lang.Object value)
          Sets the Field attribute of the NoFieldObjectEditor object
protected  void setValue(int 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
 

Constructor Detail

NoFieldObjectEditor

public NoFieldObjectEditor()
Constructor for the NoFieldObjectEditor object


NoFieldObjectEditor

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

Parameters:
domainObject -
Method Detail

getMods

protected static final NoFieldObjectModified getMods(int field,
                                                     NoFieldObjectModified[] 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 - NoFieldObjectModified [] A list of changes.
field - The field for which we are looking for changes.
Returns:
The Mods value

setField

protected void setField(int idx,
                        java.lang.Object value)
Sets the Field attribute of the NoFieldObjectEditor object

Parameters:
idx - The new Field value
value - The new Field value

set

public void set(int adapt,
                byte val,
                byte originalVal)
Delegate to the set(int, Object, Object) method.

Parameters:
adapt -
val -
originalVal -

set

public void set(int adapt,
                char val,
                char originalVal)
Delegate to the set(int, Object, Object) method.

Parameters:
adapt -
val -
originalVal -

set

public void set(int adapt,
                double val,
                double originalVal)
Delegate to the set(int, Object, Object) method.

Parameters:
adapt -
val -
originalVal -

set

public void set(int adapt,
                float val,
                float originalVal)
Delegate to the set(int, Object, Object) method.

Parameters:
adapt -
val -
originalVal -

set

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

Parameters:
adapt -
val -
originalVal -

set

public void set(int adapt,
                long val,
                long originalVal)
Delegate to the set(int, Object, Object) method.

Parameters:
adapt -
val -
originalVal -

set

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

Parameters:
adapt -
val -
originalVal -
See Also:
#setValue(java.lang.int, java.lang.Object, java.lang.Object)

set

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

Parameters:
adapt -
val -
originalVal -

set

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

Parameters:
adapt -
val -
originalVal -

set

public void set(int adapt,
                short val,
                short originalVal)
Delegate to the set(int, Object, Object) method.

Parameters:
adapt -
val -
originalVal -

set

public void set(int adapt,
                boolean val,
                boolean originalVal)
Delegate to the set(int, Object, Object) method.

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

setValue

protected void setValue(int 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

set

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

set

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

set

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

set

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

set

public void set(java.lang.reflect.Field adapt,
                int val,
                int originalVal)
Specified by:
set in interface SetAndGetDelegateIF
Parameters:
adapt -
val -
originalVal -

set

public void set(java.lang.reflect.Field adapt,
                long val,
                long originalVal)
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)
Specified by:
set in interface SetAndGetDelegateIF
Parameters:
adapt -
val -
originalVal -

set

public void set(java.lang.reflect.Field adapt,
                java.lang.String val,
                java.lang.String originalVal)
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)
Specified by:
set in interface SetAndGetDelegateIF
Parameters:
adapt -
val -
originalVal -

set

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

set

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

getField

protected java.lang.Object getField(int idx)
Gets the Field attribute of the NoFieldObjectEditor object

Parameters:
idx -
Returns:
The Field value

get

public byte get(int adapt,
                byte val)
Parameters:
adapt -
val -
Returns:

get

public char get(int adapt,
                char val)
Parameters:
adapt -
val -
Returns:

get

public double get(int adapt,
                  double val)
Parameters:
adapt -
val -
Returns:

get

public float get(int adapt,
                 float val)
Parameters:
adapt -
val -
Returns:

get

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

Parameters:
adapt -
oldValue -
Returns:

get

public long get(int adapt,
                long val)
Parameters:
adapt -
val -
Returns:

get

public java.lang.Object get(int adapt,
                            java.lang.Object oldValue)
Parameters:
adapt -
oldValue -
Returns:

get

public short get(int adapt,
                 short val)
Parameters:
adapt -
val -
Returns:

get

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

get

public boolean get(int adapt,
                   boolean val)
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

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 NoFieldObjectModified[] getFieldMap(TransactionLog log)
    For the provided TransactionLog, get the list of known changes.

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

    getValue

    protected java.lang.Object getValue(int 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'.

    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)
    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 boolean get(java.lang.reflect.Field adapt,
                       boolean val)
    Specified by:
    get in interface SetAndGetDelegateIF
    Parameters:
    adapt -
    val -
    Returns:

    initFieldSize

    public void initFieldSize(int size)
    Parameters:
    size -

    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. 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(NoFieldObjectModified 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,
                                     NoFieldObjectModified[] 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 - NoFieldObjectModified [] This list will hold the changes.

    noKnownLogs

    protected final boolean noKnownLogs()
    protected final NoFieldObjectModified [] 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 NoFieldObjectModified [] 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 NoFieldObjectModified[] 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 NoFieldObjectModified objects should be returned to the queue.
    log - TransactionLog The transaction in question.

    putMod

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

    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: