FileDocCategorySizeDatePackage
DirectCollectionChangeRecord.javaAPI DocGlassfish v2 API15819Thu Jul 19 11:51:58 BST 2007oracle.toplink.essentials.internal.sessions

DirectCollectionChangeRecord

public class DirectCollectionChangeRecord extends ChangeRecord implements DirectCollectionChangeRecord

Purpose: This class holds the record of the changes made to a collection attribute of an object.

Description: Collections must be compared to each other and added and removed objects must be recorded seperately

see
OtherRelatedClasses prototype.changeset.DirectToFieldChangeRecord,prototype.changeset.SingleObjectChangeRecord

Fields Summary
protected HashMap
addObjectMap
protected HashMap
removeObjectMap
protected HashMap
commitAddMap
protected transient Object
originalCollection
Used for change tracking when customer sets entire collection
protected transient Object
latestCollection
Used for change tracking when customer sets entire collection
public static final NULL
Null
Constructors Summary
public DirectCollectionChangeRecord()
This defaul constructor is reference internally by SDK XML project to mapp this class


                       
      
        super();
    
public DirectCollectionChangeRecord(ObjectChangeSet owner)
This constructor returns a changeRecord representing the DirectCollection mapping

param
owner prototype.changeset.ObjectChangeSet that ObjectChangeSet that uses this record

        this.owner = owner;
    
Methods Summary
public voidaddAdditionChange(java.util.HashMap additions, java.util.HashMap databaseCount)
This method takes a hastable of primitive objects and adds them to the add list. the hashtable stores the number of times the object is in the list

param
objectChanges prototype.changeset.ObjectChangeSet

        Iterator enumtr = additions.keySet().iterator();
        while (enumtr.hasNext()) {
            Object object = enumtr.next();
            if (databaseCount.containsKey(object)){
                getCommitAddMap().put(object, databaseCount.get(object));
            }
            addAdditionChange(object, (Integer)additions.get(object));
        }
    
public voidaddAdditionChange(java.lang.Object key, java.lang.Integer count)
This method takes a single addition value and records it.

        if (getRemoveObjectMap().containsKey(key)){
            int removeValue = ((Integer)getRemoveObjectMap().get(key)).intValue();
            int addition = count.intValue();
            int result = removeValue - addition;
            if (result > 0 ) { // more removes still
                getRemoveObjectMap().put(key, new Integer(result));
            }else if (result < 0) { // more adds now
                getRemoveObjectMap().remove(key);
                getAddObjectMap().put(key, new Integer(Math.abs(result)));
            }else{ // equal
                getRemoveObjectMap().remove(key);
            }
        }else{
            if (this.getAddObjectMap().containsKey(key)){
                int addValue = ((Integer)this.getAddObjectMap().get(key)).intValue();
                addValue += count.intValue();
                this.getAddObjectMap().put(key, new Integer(addValue));
            }else{
                this.getAddObjectMap().put(key, count);
            }
        }
        // this is an attribute change track add keep count
        int addValue = count.intValue();
        int commitValue = 0;
        if (getCommitAddMap().containsKey(key)){
            commitValue = ((Integer)getCommitAddMap().get(key)).intValue();
        }
        getCommitAddMap().put(key, new Integer(addValue+commitValue));
    
public voidaddRemoveChange(java.util.HashMap additions, java.util.HashMap databaseCount)
This method takes a hashtable of primitive objects and adds them to the remove list. Each reference in the hashtable lists the number of this object that needs to be removed from the collection.

param
objectChanges prototype.changeset.ObjectChangeSet

        Iterator enumtr = additions.keySet().iterator();
        while (enumtr.hasNext()) {
            Object object = enumtr.next();
            if (databaseCount.containsKey(object)){
                getCommitAddMap().put(object, databaseCount.get(object));
            }
            addRemoveChange(object, (Integer)additions.get(object));
        }
    
public voidaddRemoveChange(java.lang.Object key, java.lang.Integer count)
This method takes a single remove change and integrates it with this changeset

        if (getAddObjectMap().containsKey(key)){
            int removeValue = ((Integer)getAddObjectMap().get(key)).intValue();
            int addition = count.intValue();
            int result = removeValue - addition;
            if (result > 0 ) { // more removes still
                getAddObjectMap().put(key, new Integer(result));
            }else if (result < 0) { // more adds now
                getAddObjectMap().remove(key);
                getRemoveObjectMap().put(key, new Integer(Math.abs(result)));
            }else{ // equal
                getAddObjectMap().remove(key);
            }
        }else{
            if (this.getRemoveObjectMap().containsKey(key)){
                int addValue = ((Integer)this.getRemoveObjectMap().get(key)).intValue();
                addValue += count.intValue();
                this.getRemoveObjectMap().put(key, new Integer(addValue));
            }else{
                this.getRemoveObjectMap().put(key, count);
            }
        }
        int removeValue = count.intValue();
        int commitValue = 0;
        if (getCommitAddMap().containsKey(key)){
            commitValue = ((Integer)getCommitAddMap().get(key)).intValue();
        }
        getCommitAddMap().put(key, new Integer(commitValue - removeValue));
        
    
public java.util.VectorgetAddObjectList()
ADVANCED: This method returns the list of added objects

        Vector vector = new Vector();
        for (Iterator iterator = getAddObjectMap().keySet().iterator(); iterator.hasNext();){
            Object object = iterator.next();
            int count = ((Integer)getAddObjectMap().get(object)).intValue();
            while (count > 0){
                vector.add(object);
                --count;
            }
        }
        return vector;
    
public java.util.HashMapgetAddObjectMap()
ADVANCED: This method returns the collection of objects that were added to the collection.

return
java.util.Vector

        if (this.addObjectMap == null) {
            this.addObjectMap = new HashMap(1);
        }
        return addObjectMap;
    
public java.util.HashMapgetCommitAddMap()
ADVANCED: This method returns the collection of objects that were added to the collection.

return
java.util.Vector

        if (this.commitAddMap == null) {
            this.commitAddMap = new HashMap(1);
        }
        return commitAddMap;
    
public java.lang.ObjectgetLatestCollection()
Used for change tracking when cutomer sets entire collection This is the last collection that was set on the object

        return latestCollection;
    
public java.lang.ObjectgetOriginalCollection()
Used for change tracking when cutomer sets entire collection This is the original collection that was set on the object when it was cloned

        return originalCollection;
    
public java.util.VectorgetRemoveObjectList()
ADVANCED: This method returns the list of removed objects

        Vector vector = new Vector();
        for (Iterator iterator = getRemoveObjectMap().keySet().iterator(); iterator.hasNext();){
            Object object = iterator.next();
            int count = ((Integer)getRemoveObjectMap().get(object)).intValue();
            while (count > 0){
                vector.add(object);
                --count;
            }
        }
        return vector;
    
public java.util.HashMapgetRemoveObjectMap()
ADVANCED: This method returns the collection of objects that were removed from the collection.

return
java.util.Vector

        if (this.removeObjectMap == null) {
            removeObjectMap = new HashMap(1);
        }
        return removeObjectMap;
    
public booleanhasChanges()
returns true if the change set has changes

        return (!(getAddObjectMap().isEmpty() && getRemoveObjectMap().isEmpty())) || getOwner().isNew();
    
public voidmergeRecord(oracle.toplink.essentials.internal.sessions.ChangeRecord mergeFromRecord, oracle.toplink.essentials.internal.sessions.UnitOfWorkChangeSet mergeToChangeSet, oracle.toplink.essentials.internal.sessions.UnitOfWorkChangeSet mergeFromChangeSet)
INTERNAL: This method will be used to merge one record into another

        HashMap addMapToMerge = ((DirectCollectionChangeRecord)mergeFromRecord).getAddObjectMap();
        HashMap removeMapToMerge = ((DirectCollectionChangeRecord)mergeFromRecord).getRemoveObjectMap();
        //merge additions
        for (Iterator iterator = addMapToMerge.keySet().iterator(); iterator.hasNext();){
            Object added = iterator.next();
            if (!((DirectCollectionChangeRecord)mergeFromRecord).getCommitAddMap().containsKey(added)){
                // we have not recorded a change of this type in this class before so  add it
                this.getCommitAddMap().put(added, ((DirectCollectionChangeRecord)mergeFromRecord).getCommitAddMap().get(added));
            }
            this.addAdditionChange(added, (Integer)addMapToMerge.get(added));
        }
        //merge removals
        for (Iterator iterator = removeMapToMerge.keySet().iterator(); iterator.hasNext();){
            Object removed = iterator.next();
            if (!((DirectCollectionChangeRecord)mergeFromRecord).getCommitAddMap().containsKey(removed)){
                // we have not recorded a change of this type in this class before so  add it
                this.getCommitAddMap().put(removed, ((DirectCollectionChangeRecord)mergeFromRecord).getCommitAddMap().get(removed));
            }
            this.addRemoveChange(removed, (Integer)addMapToMerge.get(removed));
        }
   
public voidsetAddObjectList(java.util.Vector list)
INTERNAL: This method sets the list of added objects. It should only be used in RCM

        for (Iterator iterator = list.iterator(); iterator.hasNext();){
            Object object = iterator.next();
            this.addAdditionChange(object, new Integer(1));
        }
    
public voidsetCommitAddition(java.util.Hashtable additions)
This method takes a hashtable of primitives and adds them to the commit list. This count value provided is the number of instances that will need to be inserted into the database once a remove has occured. This is only set once for each object type

        Enumeration enumtr = additions.keys();
        while (enumtr.hasMoreElements()) {
            Object object = enumtr.nextElement();
            getCommitAddMap().put(object, additions.get(object));
        }
    
public voidsetLatestCollection(java.lang.Object latestCollection)
Used for change tracking when cutomer sets entire collection This is the last collection that was set on the object

        this.latestCollection = latestCollection;
    
public voidsetOriginalCollection(java.lang.Object originalCollection)
Used for change tracking when cutomer sets entire collection This is the original collection that was set on the object when it was cloned

        this.originalCollection = originalCollection;
    
public voidsetRemoveObjectList(java.util.Vector list)
INTERNAL: This method sets the list of added objects. It should only be used in RCM

        for (Iterator iterator = list.iterator(); iterator.hasNext();){
            Object object = iterator.next();
            this.addRemoveChange(object, new Integer(1));
        }
    
public voidstoreDatabaseCounts(java.lang.Object collection, oracle.toplink.essentials.internal.queryframework.ContainerPolicy containerPolicy, oracle.toplink.essentials.internal.sessions.AbstractSession session)
This method will iterate over the collection and store the database counts for the objects within the collection, this is used for minimal updates

        Object iterator = containerPolicy.iteratorFor(collection);
        while (containerPolicy.hasNext(iterator)){
            Object object = containerPolicy.next(iterator, session);
            if (getCommitAddMap().containsKey(object)){
                int count = ((Integer)getCommitAddMap().get(object)).intValue();
                getCommitAddMap().put(object, new Integer(++count));
            }else{
                getCommitAddMap().put(object, new Integer(1));
            }
        }
    
public voidupdateReferences(oracle.toplink.essentials.internal.sessions.UnitOfWorkChangeSet mergeToChangeSet, oracle.toplink.essentials.internal.sessions.UnitOfWorkChangeSet mergeFromChangeSet)
INTERNAL: This method will be used to update the objectsChangeSets references

        //nothing for this record type to do as it does not reference any changesets