FileDocCategorySizeDatePackage
DeferredChangeDetectionPolicy.javaAPI DocGlassfish v2 API11644Tue May 22 16:54:16 BST 2007oracle.toplink.essentials.descriptors.changetracking

DeferredChangeDetectionPolicy

public class DeferredChangeDetectionPolicy extends Object implements ObjectChangePolicy, Serializable
PUBLIC: A DeferredChangeDetectionPolicy defers all change detection to the UnitOfWork's change detection process. Essentially, the calculateChanges() method will run for all objects in a UnitOfWork. This is the default ObjectChangePolicy.
author
Tom Ware

Fields Summary
Constructors Summary
Methods Summary
public java.lang.ObjectbuildBackupClone(java.lang.Object clone, ObjectBuilder builder, oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl uow)
INTERNAL: Build back up clone. Used if clone is new because listener should not be set.

        return builder.buildBackupClone(clone, uow);
    
public oracle.toplink.essentials.internal.sessions.ObjectChangeSetcalculateChanges(java.lang.Object clone, java.lang.Object backUp, oracle.toplink.essentials.internal.sessions.UnitOfWorkChangeSet changeSet, oracle.toplink.essentials.internal.sessions.AbstractSession session, oracle.toplink.essentials.descriptors.ClassDescriptor descriptor, boolean shouldRiseEvent)
INTERNAL: calculateChanges creates a change set for a particular object. In DeferredChangeDetectionPolicy all mappings will be compared against a backup copy of the object.

return
oracle.toplink.essentials.changesets.ObjectChangeSet an object change set describing the changes to this object
param
java.lang.Object clone the Object to compute a change set for
param
java.lang.Object backUp the old version of the object to use for comparison
param
oracle.toplink.essentials.internal.sessions.UnitOfWorkChangeSet the change set to add changes to
param
Session the current session
param
Descriptor the descriptor for this object
param
shouldRiseEvent indicates whether PreUpdate event should be risen (usually true)

        boolean isNew = ((backUp == null) || ((((UnitOfWorkImpl)session).isObjectNew(clone)) && (!descriptor.isAggregateDescriptor())));
 
        // PERF: Avoid events if no listeners.
        if (descriptor.getEventManager().hasAnyEventListeners() && shouldRiseEvent) {
            // The query is built for compatability to old event mechanism.
            WriteObjectQuery writeQuery = new WriteObjectQuery(clone.getClass());
            writeQuery.setObject(clone);
            writeQuery.setBackupClone(backUp);
            writeQuery.setSession(session);
            writeQuery.setDescriptor(descriptor);

            descriptor.getEventManager().executeEvent(new DescriptorEvent(DescriptorEventManager.PreWriteEvent, writeQuery));

            if (isNew) {
                descriptor.getEventManager().executeEvent(new DescriptorEvent(DescriptorEventManager.PreInsertEvent, writeQuery));
            } else {
                descriptor.getEventManager().executeEvent(new DescriptorEvent(DescriptorEventManager.PreUpdateEvent, writeQuery));
            }
        }

        ObjectChangeSet changes = createObjectChangeSet(clone, backUp, changeSet, isNew, session, descriptor);

        changes.setShouldModifyVersionField((Boolean)((UnitOfWorkImpl)session).getOptimisticReadLockObjects().get(clone));

        if (changes.hasChanges() || changes.hasForcedChanges()) {
            return changes;
        }
        return null;
    
public voidclearChanges(java.lang.Object object, oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl uow, oracle.toplink.essentials.descriptors.ClassDescriptor descriptor)
INTERNAL: This is a place holder for reseting the listener on one of the subclasses

    
public oracle.toplink.essentials.internal.sessions.ObjectChangeSetcreateObjectChangeSet(java.lang.Object clone, java.lang.Object backUp, oracle.toplink.essentials.internal.sessions.UnitOfWorkChangeSet changeSet, boolean isNew, oracle.toplink.essentials.internal.sessions.AbstractSession session, oracle.toplink.essentials.descriptors.ClassDescriptor descriptor)
INTERNAL: Create ObjectChangeSet

        return this.createObjectChangeSetThroughComparison(clone, backUp, changeSet, isNew, session, descriptor);
    
public oracle.toplink.essentials.internal.sessions.ObjectChangeSetcreateObjectChangeSetThroughComparison(java.lang.Object clone, java.lang.Object backUp, oracle.toplink.essentials.internal.sessions.UnitOfWorkChangeSet changeSet, boolean isNew, oracle.toplink.essentials.internal.sessions.AbstractSession session, oracle.toplink.essentials.descriptors.ClassDescriptor descriptor)
INTERNAL: Create ObjectChangeSet

        ObjectBuilder builder = descriptor.getObjectBuilder();
        ObjectChangeSet changes = builder.createObjectChangeSet(clone, changeSet, isNew, session);

        // The following code deals with reads that force changes to the flag associated with optimistic locking.
        if ((descriptor.usesOptimisticLocking()) && (changes.getPrimaryKeys() != null)) {
            changes.setOptimisticLockingPolicyAndInitialWriteLockValue(descriptor.getOptimisticLockingPolicy(), session);
        }

        // PERF: Avoid synchronized enumerator as is concurrency bottleneck.
        Vector mappings = descriptor.getMappings();
        int mappingsSize = mappings.size();
        for (int index = 0; index < mappingsSize; index++) {
            DatabaseMapping mapping = (DatabaseMapping)mappings.get(index);
            changes.addChange(mapping.compareForChange(clone, backUp, changes, session));
        }

        return changes;
    
public voiddissableEventProcessing(java.lang.Object changeTracker)
INTERNAL: This method is used to dissable changetracking temporarily

        //no-op
    
public voidenableEventProcessing(java.lang.Object changeTracker)
INTERNAL: This method is used to enable changetracking temporarily

        //no-op
    
public voidinitialize(oracle.toplink.essentials.internal.sessions.AbstractSession session, oracle.toplink.essentials.descriptors.ClassDescriptor descriptor)
INTERNAL: initialize the Policy

        //do nothing
    
public booleanisAttributeChangeTrackingPolicy()
Used to track instances of the change policies without doing an instance of check

        return false;
    
public booleanisDeferredChangeDetectionPolicy()
Used to track instances of the change policies without doing an instance of check

        return true;
    
public booleanisObjectChangeTrackingPolicy()
Used to track instances of the change policies without doing an instance of check

        return false;
    
public voidraiseInternalPropertyChangeEvent(java.lang.Object source, java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
INTERNAL: This may cause a property change event to be raised to a listner in the case that a listener exists. If there is no listener then this call is a no-op

        //no-op
    
public voidrevertChanges(java.lang.Object clone, oracle.toplink.essentials.descriptors.ClassDescriptor descriptor, oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl uow, oracle.toplink.essentials.internal.helper.IdentityHashtable cloneMapping)
INTERNAL: This method is used to revert an object within the unit of work

param
cloneMapping may not be the same as whats in the uow

        cloneMapping.put(clone, buildBackupClone(clone, descriptor.getObjectBuilder(), uow));
        clearChanges(clone, uow, descriptor);
    
public voidsetAggregateChangeListener(java.lang.Object parent, java.lang.Object aggregate, oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl uow, oracle.toplink.essentials.descriptors.ClassDescriptor descriptor, java.lang.String mappingAttribute)
INTERNAL: Assign Changelistner to an aggregate object

        //no-op
    
public voidsetChangeListener(java.lang.Object clone, oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl uow, oracle.toplink.essentials.descriptors.ClassDescriptor descriptor)
INTERNAL: Set ChangeListener for the clone

        //no-op
    
public voidsetChangeSetOnListener(oracle.toplink.essentials.internal.sessions.ObjectChangeSet objectChangeSet, java.lang.Object clone)
INTERNAL: Set the ObjectChangeSet on the Listener, initially used for aggregate support

        //no-op
    
public booleanshouldCompareForChange(java.lang.Object object, oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl unitOfWork, oracle.toplink.essentials.descriptors.ClassDescriptor descriptor)
INTERNAL: Return true if the Object should be compared, false otherwise. In DeferredChangeDetectionPolicy, true is always returned since always allow the UnitOfWork to calculate changes.

param
java.lang.Object object - the object that will be compared
param
oracle.toplink.essentials.publicinterface.UnitOfWork unitOfWork - the active unitOfWork
param
oracle.toplink.essentials.publicinterface.Descriptor descriptor - the descriptor for the current object

        return true;
    
public voidupdateWithChanges(java.lang.Object clone, oracle.toplink.essentials.internal.sessions.ObjectChangeSet objectChangeSet, oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl uow, oracle.toplink.essentials.descriptors.ClassDescriptor descriptor)
INTERNAL: Clear changes in the ChangeListener of the clone

        if (objectChangeSet == null) {
            return;
        }
        Object backupClone = uow.getCloneMapping().get(clone);
        if (backupClone != null) {
            MergeManager mergeManager = new MergeManager(uow);
            mergeManager.setCascadePolicy(MergeManager.NO_CASCADE);
            descriptor.getObjectBuilder().mergeChangesIntoObject(backupClone, objectChangeSet, clone, mergeManager);
        }
        clearChanges(clone, uow, descriptor);