FileDocCategorySizeDatePackage
DirectMapChangeRecord.javaAPI DocGlassfish v2 API11271Tue May 22 16:54:42 BST 2007oracle.toplink.essentials.internal.sessions

DirectMapChangeRecord

public class DirectMapChangeRecord extends ChangeRecord

Fields Summary
protected HashMap
addObjectsList
protected HashMap
removeObjectsList
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
Constructors Summary
public DirectMapChangeRecord()

        super();
    
public DirectMapChangeRecord(ObjectChangeSet owner)

        this.owner = owner;
    
Methods Summary
public voidaddAdditionChange(java.util.HashMap additions)
ADVANCED: Adds the items that were added to the collection

        if (getAddObjects().size() == 0) {
            addObjectsList = additions;
            return;
        }

        for (Iterator i = additions.keySet().iterator(); i.hasNext(); ) {
            Object key = i.next();
            if (getAddObjects().containsKey(key)) {
                getAddObjects().put(key, additions.get(key));
            } else if (additions.get(key).equals(getAddObjects().get(key))) {
                getAddObjects().put(key, additions.get(key));
            }
        }
    
public voidaddAdditionChange(java.lang.Object key, java.lang.Object value)
ADVANCED: Adds the items that were added to the collection

        if ( getRemoveObjects().containsKey(key) ) { 
            if ( value.equals(getRemoveObjects().get(key)) ) {
                getRemoveObjects().remove(key);
            }else {
                getAddObjects().put(key, value);
            }
        } else {
            getAddObjects().put(key, value);
        }
    
public voidaddRemoveChange(java.util.HashMap subtractions)
ADVANCED: Adds the items that were removed from the collection

        if (getRemoveObjects().size() == 0) {
            this.removeObjectsList = subtractions;
            return;
        }

        for (Iterator i = subtractions.keySet().iterator(); i.hasNext(); ) {
            Object key = i.next();
            if (!getRemoveObjects().containsKey(key)) {
                getRemoveObjects().put(key, subtractions.get(key));
            } else if (subtractions.get(key).equals(getRemoveObjects().get(key))) {
                getRemoveObjects().put(key, subtractions.get(key));
            }
        }
    
public voidaddRemoveChange(java.lang.Object key, java.lang.Object value)
ADVANCED: Adds the items that were removed from the collection

        //if an entry already exists in the remove it must remain untill added
        // as it contains the original removal.
        if ( getAddObjects().containsKey(key) ) {
            getAddObjects().remove(key);
        }else if ( ! getRemoveObjects().containsKey(key) ) {
            getRemoveObjects().put(key, value);
        }
    
public java.util.VectorgetAddAssociations()
INTERNAL: Use in SDK propject for the mapping of this change record

        Vector addAssociations = new Vector();

        for (Iterator i = getAddObjects().keySet().iterator(); i.hasNext(); ) {
            Association association = new Association();
            Object key = i.next();
            Object value = getAddObjects().get(key);

            association.setKey(key);
            association.setValue(value);
            addAssociations.add(association);
        }
        if (addAssociations.size() == 0) {
            return null;
        }
        return addAssociations;
    
public java.util.HashMapgetAddObjects()
INTERNAL: Returns the added items list

        if (addObjectsList == null) {
            // addObjectsList = new Hashtable();
            addObjectsList = new HashMap();
        }
        return addObjectsList;
    
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.VectorgetRemoveAssociations()
INTERNAL: Use in SDK propject for the mapping of this change record

        Vector removeAssociations = new Vector();

        for (Iterator i = getRemoveObjects().keySet().iterator(); i.hasNext(); ) {
            Association association = new Association();
            
            Object key = i.next();
            Object value = getAddObjects().get(key);

            association.setKey(key);
            association.setValue(value);
            removeAssociations.add(association);
        }
        if (removeAssociations.size() == 0) {
            return null;
        }
        return removeAssociations;
    
public java.util.HashMapgetRemoveObjects()
INTERNAL: Returns the removed items list

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

        return (!(getAddObjects().isEmpty() && getRemoveObjects().isEmpty())) || getOwner().isNew();
    
public voidmergeRecord(ChangeRecord mergeFromRecord, UnitOfWorkChangeSet mergeToChangeSet, UnitOfWorkChangeSet mergeFromChangeSet)
INTERNAL: This method will be used to merge one record into another

        Iterator addKeys = ((DirectMapChangeRecord)mergeFromRecord).getAddObjects().keySet().iterator();
        while (addKeys.hasNext()) {
            Object key = addKeys.next();

            if (!this.getAddObjects().containsKey(key)) {
                if (this.getRemoveObjects().containsKey(key)) {
                    this.getRemoveObjects().remove(key);
                } else {
                    this.getAddObjects().put(key, ((DirectMapChangeRecord)mergeFromRecord).getAddObjects().get(key));
                }
            }
        }

        Iterator removeKeys = ((DirectMapChangeRecord)mergeFromRecord).getRemoveObjects().keySet().iterator();
        while (removeKeys.hasNext()) {
            Object key = removeKeys.next();

            if (!this.getRemoveObjects().containsKey(key)) {
                if (this.getAddObjects().containsKey(key)) {
                    this.getAddObjects().remove(key);
                } else {
                    this.getRemoveObjects().put(key, ((DirectMapChangeRecord)mergeFromRecord).getRemoveObjects().get(key));
                }
            }
        }
    
public voidsetAddAssociations(java.util.Vector addAssociations)
INTERNAL: Use in SDK propject for the mapping of this change record

        HashMap addMap = new HashMap();

        for (Enumeration enumtr = addAssociations.elements(); enumtr.hasMoreElements();) {
            Association association = (Association)enumtr.nextElement();
            addMap.put(association.getKey(), association.getValue());
        }
        if (addMap.isEmpty()) {
            addObjectsList = null;
        }
        addObjectsList = addMap;
    
public voidsetAddObjects(java.util.HashMap addObjects)
INTERNAL: Sets the added items list

        this.addObjectsList = addObjects;
    
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 voidsetRemoveAssociations(java.util.Vector removeAssociations)
INTERNAL: Use in SDK propject for the mapping of this change record

        HashMap removeMap = new HashMap();

        for (Enumeration enumtr = removeAssociations.elements(); enumtr.hasMoreElements();) {
            Association association = (Association)enumtr.nextElement();
            removeMap.put(association.getKey(), association.getValue());
        }
        if (removeMap.isEmpty()) {
            removeObjectsList = null;
        }
        removeObjectsList = removeMap;
    
public voidsetRemoveObjects(java.util.HashMap removeObjects)
INTERNAL: Sets the removed items list

        this.removeObjectsList = removeObjects;
    
public voidupdateReferences(UnitOfWorkChangeSet mergeToChangeSet, 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