Search in sources :

Example 1 with ObjectDescriptor

use of org.eclipse.persistence.internal.sessions.remote.ObjectDescriptor in project eclipselink by eclipse-ee4j.

the class MergeManager method mergeChangesForRefreshingRemoteObject.

/**
 * Recursively merge the RMI clone from the server
 * into the client unit of work working copy.
 * This will only be called if the working copy exists.
 */
protected Object mergeChangesForRefreshingRemoteObject(Object serverSideDomainObject) {
    ClassDescriptor descriptor = this.session.getDescriptor(serverSideDomainObject);
    Object primaryKey = descriptor.getObjectBuilder().extractPrimaryKeyFromObject(serverSideDomainObject, this.session);
    Object clientSideDomainObject = this.session.getIdentityMapAccessorInstance().getFromIdentityMap(primaryKey, serverSideDomainObject.getClass(), descriptor);
    if (clientSideDomainObject == null) {
        // the referenced object came back as null from the cache.
        ObjectDescriptor objectDescriptor = getObjectDescriptors().get(serverSideDomainObject);
        if (objectDescriptor == null) {
            // the object must have been added concurently before serialize generate a new ObjectDescriptor on this side
            objectDescriptor = new ObjectDescriptor();
            objectDescriptor.setKey(primaryKey);
            objectDescriptor.setObject(serverSideDomainObject);
            OptimisticLockingPolicy policy = descriptor.getOptimisticLockingPolicy();
            if (policy == null) {
                objectDescriptor.setWriteLockValue(null);
            } else {
                objectDescriptor.setWriteLockValue(policy.getBaseValue());
            }
        }
        // query is used for the cascade policy only
        org.eclipse.persistence.queries.ObjectLevelReadQuery query = new org.eclipse.persistence.queries.ReadObjectQuery();
        query.setCascadePolicy(this.getCascadePolicy());
        this.session.getIdentityMapAccessorInstance().putInIdentityMap(serverSideDomainObject, primaryKey, objectDescriptor.getWriteLockValue(), objectDescriptor.getReadTime(), descriptor);
        descriptor.getObjectBuilder().fixObjectReferences(serverSideDomainObject, getObjectDescriptors(), this.objectsAlreadyMerged.get(this.session), query, (DistributedSession) this.session);
        clientSideDomainObject = serverSideDomainObject;
    } else {
        // merge into the clientSideDomainObject from the serverSideDomainObject;
        // use clientSideDomainObject as the backup, as anything different should be merged
        descriptor.getObjectBuilder().mergeIntoObject(clientSideDomainObject, false, serverSideDomainObject, this, getSession());
        ObjectDescriptor objectDescriptor = getObjectDescriptors().get(serverSideDomainObject);
        if (objectDescriptor == null) {
            // the object must have been added concurently before serialize generate a new ObjectDescriptor on this side
            objectDescriptor = new ObjectDescriptor();
            objectDescriptor.setKey(primaryKey);
            objectDescriptor.setObject(serverSideDomainObject);
            OptimisticLockingPolicy policy = descriptor.getOptimisticLockingPolicy();
            if (policy == null) {
                objectDescriptor.setWriteLockValue(null);
            } else {
                objectDescriptor.setWriteLockValue(policy.getBaseValue());
            }
        }
        CacheKey key = this.session.getIdentityMapAccessorInstance().getCacheKeyForObjectForLock(primaryKey, clientSideDomainObject.getClass(), descriptor);
        // Check for null because when there is NoIdentityMap, CacheKey will be null
        if (key != null) {
            key.setReadTime(objectDescriptor.getReadTime());
        }
        if (descriptor.usesOptimisticLocking()) {
            this.session.getIdentityMapAccessor().updateWriteLockValue(primaryKey, clientSideDomainObject.getClass(), objectDescriptor.getWriteLockValue());
        }
    }
    return clientSideDomainObject;
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) ObjectDescriptor(org.eclipse.persistence.internal.sessions.remote.ObjectDescriptor) CacheKey(org.eclipse.persistence.internal.identitymaps.CacheKey) OptimisticLockingPolicy(org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy)

Aggregations

ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 OptimisticLockingPolicy (org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy)1 CacheKey (org.eclipse.persistence.internal.identitymaps.CacheKey)1 ObjectDescriptor (org.eclipse.persistence.internal.sessions.remote.ObjectDescriptor)1