Package org.eclipse.persistence.descriptors

Examples of org.eclipse.persistence.descriptors.VersionLockingPolicy


        ClassDescriptor descriptor = getSession().getDescriptor(rmiClone);
        try {
            ObjectBuilder builder = descriptor.getObjectBuilder();
           
            if (registeredObject != rmiClone && descriptor.usesVersionLocking() && ! mergedNewObjects.containsKey(registeredObject)) {
                VersionLockingPolicy policy = (VersionLockingPolicy) descriptor.getOptimisticLockingPolicy();
                if (policy.isStoredInObject()) {
                    Object currentValue = builder.extractValueFromObjectForField(registeredObject, policy.getWriteLockField(), session);
               
                    if (policy.isNewerVersion(currentValue, rmiClone, session.keyFromObject(rmiClone), session)) {
                        throw OptimisticLockException.objectChangedSinceLastMerge(rmiClone);
                    }
                }
            }
           
View Full Code Here


        org.eclipse.persistence.queries.DoesExistQuery existQuery = descriptor.getQueryManager().getDoesExistQuery();
        // Optimize cache option to avoid executing the does exist query.
        if (existQuery.shouldCheckCacheForDoesExist()) {
            if (descriptor.usesVersionLocking()){
                VersionLockingPolicy policy = (VersionLockingPolicy)descriptor.getOptimisticLockingPolicy();
                Object baseValue = policy.getBaseValue();
                Object objectLockValue = policy.getWriteLockValue(clone, primaryKey, unitOfWork);
                if ( policy.isNewerVersion(objectLockValue, baseValue) ) {
                    throw OptimisticLockException.objectChangedSinceLastMerge(clone);
                }
            }
            Object registeredObject = unitOfWork.internalRegisterObject(clone, descriptor);
           
            if (unitOfWork.hasNewObjects() && unitOfWork.getNewObjectsOriginalToClone().containsKey(clone)) {
                mergedNewObjects.put(registeredObject, registeredObject);
            }
           
            return registeredObject;
        }

        // Check early return to check if it is a new object, i.e. null primary key.
        Boolean doesExist = (Boolean)existQuery.checkEarlyReturn(clone, primaryKey, unitOfWork, null);
        if (doesExist == Boolean.FALSE) {
            //bug272704: throw an exception if this object is new yet has a version set to avoid merging in deleted objects
            if (descriptor.usesVersionLocking()){
                VersionLockingPolicy policy = (VersionLockingPolicy)descriptor.getOptimisticLockingPolicy();
                Object baseValue = policy.getBaseValue();
                Object objectLockValue = policy.getWriteLockValue(clone, primaryKey, unitOfWork);
                if ( policy.isNewerVersion(objectLockValue, baseValue) ) {
                    throw OptimisticLockException.objectChangedSinceLastMerge(clone);
                }
            }
            Object registeredObject = unitOfWork.internalRegisterObject(clone, descriptor);
            mergedNewObjects.put(registeredObject, registeredObject);
            return registeredObject;
        }
   
        // Otherwise it is existing and not in the cache so it must be read.
        Object object = unitOfWork.readObject(clone);
        if (object == null) {
            //bug272704: throw an exception if this object is new yet has a version set to avoid merging in deleted objects
            if (descriptor.usesVersionLocking()){
                VersionLockingPolicy policy = (VersionLockingPolicy)descriptor.getOptimisticLockingPolicy();
                Object baseValue = policy.getBaseValue();
                Object objectLockValue = policy.getWriteLockValue(clone, primaryKey, unitOfWork);
                if ( policy.isNewerVersion(objectLockValue, baseValue) ) {
                    throw OptimisticLockException.objectChangedSinceLastMerge(clone);
                }
            }
           
            //bug6180972: avoid internal register's existence check and be sure to put the new object in the mergedNewObjects collection
View Full Code Here

        ClassDescriptor descriptor = this.session.getDescriptor(rmiClone);
        try {
            ObjectBuilder builder = descriptor.getObjectBuilder();
           
            if (registeredObject != rmiClone && descriptor.usesVersionLocking() && ! mergedNewObjects.containsKey(registeredObject)) {
                VersionLockingPolicy policy = (VersionLockingPolicy) descriptor.getOptimisticLockingPolicy();
                if (policy.isStoredInObject()) {
                    Object currentValue = builder.extractValueFromObjectForField(registeredObject, policy.getWriteLockField(), session);
               
                    if (policy.isNewerVersion(currentValue, rmiClone, session.keyFromObject(rmiClone, descriptor), session)) {
                        throw OptimisticLockException.objectChangedSinceLastMerge(rmiClone);
                    }
                }
            }
           
View Full Code Here

     * Raise an error instead of reincarnating the object.
     */
    public void checkNewObjectLockVersion(Object clone, Object primaryKey, ClassDescriptor descriptor, UnitOfWorkImpl unitOfWork) {
        //bug272704: throw an exception if this object is new yet has a version set to avoid merging in deleted objects
        if (descriptor.usesVersionLocking()){
            VersionLockingPolicy policy = (VersionLockingPolicy)descriptor.getOptimisticLockingPolicy();
            Object baseValue = policy.getBaseValue();
            Object objectLockValue = policy.getWriteLockValue(clone, primaryKey, unitOfWork);
            if (policy.isNewerVersion(objectLockValue, baseValue)) {
                throw OptimisticLockException.objectChangedSinceLastMerge(clone);
            }
        }
    }
View Full Code Here

        } else {
            Class lockType = getRawClass();
            getField().setType(lockType);

            if (isValidVersionLockingType(lockType) || isValidTimestampVersionLockingType(lockType)) {
                VersionLockingPolicy policy = isValidVersionLockingType(lockType) ? new VersionLockingPolicy(getField()) : new TimestampLockingPolicy(getField())
                policy.storeInObject();
                policy.setIsCascaded(getDescriptor().usesCascadedOptimisticLocking());
                getOwningDescriptor().setOptimisticLockingPolicy(policy);
            } else {
                throw ValidationException.invalidTypeForVersionAttribute(getAttributeName(), lockType, getJavaClass());
            }
        }
View Full Code Here

        ClassDescriptor descriptor = getSession().getDescriptor(rmiClone);
        try {
            ObjectBuilder builder = descriptor.getObjectBuilder();
           
            if (registeredObject != rmiClone && descriptor.usesVersionLocking() && ! mergedNewObjects.containsKey(registeredObject)) {
                VersionLockingPolicy policy = (VersionLockingPolicy) descriptor.getOptimisticLockingPolicy();
                if (policy.isStoredInObject()) {
                    Object currentValue = builder.extractValueFromObjectForField(registeredObject, policy.getWriteLockField(), session);
               
                    if (policy.isNewerVersion(currentValue, rmiClone, session.keyFromObject(rmiClone), session)) {
                        throw OptimisticLockException.objectChangedSinceLastMerge(rmiClone);
                    }
                }
            }
           
View Full Code Here

        org.eclipse.persistence.queries.DoesExistQuery existQuery = descriptor.getQueryManager().getDoesExistQuery();
        // Optimize cache option to avoid executing the does exist query.
        if (existQuery.shouldCheckCacheForDoesExist()) {
            if (descriptor.usesVersionLocking()){
                VersionLockingPolicy policy = (VersionLockingPolicy)descriptor.getOptimisticLockingPolicy();
                Object baseValue = policy.getBaseValue();
                Object objectLockValue = policy.getWriteLockValue(clone, primaryKey, unitOfWork);
                if ( policy.isNewerVersion(objectLockValue, baseValue) ) {
                    throw OptimisticLockException.objectChangedSinceLastMerge(clone);
                }
            }
            Object registeredObject = unitOfWork.internalRegisterObject(clone, descriptor);
           
            if (unitOfWork.hasNewObjects() && unitOfWork.getNewObjectsOriginalToClone().containsKey(clone)) {
                mergedNewObjects.put(registeredObject, registeredObject);
            }
           
            return registeredObject;
        }

        // Check early return to check if it is a new object, i.e. null primary key.
        Boolean doesExist = (Boolean)existQuery.checkEarlyReturn(clone, primaryKey, unitOfWork, null);
        if (doesExist == Boolean.FALSE) {
            //bug272704: throw an exception if this object is new yet has a version set to avoid merging in deleted objects
            if (descriptor.usesVersionLocking()){
                VersionLockingPolicy policy = (VersionLockingPolicy)descriptor.getOptimisticLockingPolicy();
                Object baseValue = policy.getBaseValue();
                Object objectLockValue = policy.getWriteLockValue(clone, primaryKey, unitOfWork);
                if ( policy.isNewerVersion(objectLockValue, baseValue) ) {
                    throw OptimisticLockException.objectChangedSinceLastMerge(clone);
                }
            }
            Object registeredObject = unitOfWork.internalRegisterObject(clone, descriptor);
            mergedNewObjects.put(registeredObject, registeredObject);
            return registeredObject;
        }
   
        // Otherwise it is existing and not in the cache so it must be read.
        Object object = unitOfWork.readObject(clone);
        if (object == null) {
            //bug272704: throw an exception if this object is new yet has a version set to avoid merging in deleted objects
            if (descriptor.usesVersionLocking()){
                VersionLockingPolicy policy = (VersionLockingPolicy)descriptor.getOptimisticLockingPolicy();
                Object baseValue = policy.getBaseValue();
                Object objectLockValue = policy.getWriteLockValue(clone, primaryKey, unitOfWork);
                if ( policy.isNewerVersion(objectLockValue, baseValue) ) {
                    throw OptimisticLockException.objectChangedSinceLastMerge(clone);
                }
            }
           
            //bug6180972: avoid internal register's existence check and be sure to put the new object in the mergedNewObjects collection
View Full Code Here

        ClassDescriptor descriptor = this.session.getDescriptor(rmiClone);
        try {
            ObjectBuilder builder = descriptor.getObjectBuilder();
           
            if (!isForRefresh && registeredObject != rmiClone && descriptor.usesVersionLocking() && ! mergedNewObjects.containsKey(registeredObject)) {
                VersionLockingPolicy policy = (VersionLockingPolicy) descriptor.getOptimisticLockingPolicy();
                if (policy.isStoredInObject()) {
                    Object currentValue = builder.extractValueFromObjectForField(registeredObject, policy.getWriteLockField(), session);
               
                    if (policy.isNewerVersion(currentValue, rmiClone, session.keyFromObject(rmiClone, descriptor), session)) {
                        throw OptimisticLockException.objectChangedSinceLastMerge(rmiClone);
                    }
                }
            }
           
View Full Code Here

     * Raise an error instead of reincarnating the object.
     */
    public void checkNewObjectLockVersion(Object clone, Object primaryKey, ClassDescriptor descriptor, UnitOfWorkImpl unitOfWork) {
        //bug272704: throw an exception if this object is new yet has a version set to avoid merging in deleted objects
        if (descriptor.usesVersionLocking()){
            VersionLockingPolicy policy = (VersionLockingPolicy)descriptor.getOptimisticLockingPolicy();
            Object baseValue = policy.getBaseValue();
            Object objectLockValue = policy.getWriteLockValue(clone, primaryKey, unitOfWork);
            if (policy.isNewerVersion(objectLockValue, baseValue)) {
                throw OptimisticLockException.objectChangedSinceLastMerge(clone);
            }
        }
    }
View Full Code Here

        } else {
            Class lockType = getRawClass();
            getField().setType(lockType);

            if (isValidVersionLockingType(lockType) || isValidTimestampVersionLockingType(lockType)) {
                VersionLockingPolicy policy = isValidVersionLockingType(lockType) ? new VersionLockingPolicy(getField()) : new TimestampLockingPolicy(getField())
                policy.storeInObject();
                policy.setIsCascaded(getDescriptor().usesCascadedOptimisticLocking());
                getOwningDescriptor().setOptimisticLockingPolicy(policy);
            } else {
                throw ValidationException.invalidTypeForVersionAttribute(getAttributeName(), lockType, getJavaClass());
            }
        }
View Full Code Here

TOP

Related Classes of org.eclipse.persistence.descriptors.VersionLockingPolicy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.