public static OptimisticLockException unwrappingObjectDeletedSinceLastRead(Vector pkVector, String className) { Object[] args = { pkVector, className }; OptimisticLockException optimisticLockException = new OptimisticLockException(ExceptionMessageGenerator.buildMessage(OptimisticLockException.class, UNWRAPPING_OBJECT_DELETED_SINCE_LAST_READ, args)); optimisticLockException.setErrorCode(UNWRAPPING_OBJECT_DELETED_SINCE_LAST_READ); return optimisticLockException; }
/** * PUBLIC: * Return the object for which the problem was detected. */ public Object getObject() { return getQuery().getObject(); }
/** * INTERNAL: * This method adds the lock value to the translation row of the * passed in query. depending on the storage flag, the value is * either retrieved from the cache of the object. */ public void addLockValuesToTranslationRow(ObjectLevelModifyQuery query) { Object value; if (isStoredInCache()) { value = query.getSession().getIdentityMapAccessorInstance().getWriteLockValue(query.getPrimaryKey(), query.getObject().getClass(), getDescriptor()); } else { value = lockValueFromObject(query.getObject()); } if (value == null) { if (query.isDeleteObjectQuery()) { throw OptimisticLockException.noVersionNumberWhenDeleting(query.getObject(), query); } else { throw OptimisticLockException.noVersionNumberWhenUpdating(query.getObject(), query); } } query.getTranslationRow().put(this.writeLockField, value); }
/** * INTERNAL: * Check the row count for lock failure. */ public void validateDelete(int rowCount, Object object, DeleteObjectQuery query) { if (rowCount <= 0) { // Mark the object as invalid in the session cache. query.getSession().getParentIdentityMapSession(query, true, true).getIdentityMapAccessor().invalidateObject(object); throw OptimisticLockException.objectChangedSinceLastReadWhenDeleting(object, query); } }
/** * INTERNAL: * Check the row count for lock failure. */ public void validateUpdate(int rowCount, Object object, WriteObjectQuery query) { if (rowCount <= 0) { // Mark the object as invalid in the session cache. query.getSession().getParentIdentityMapSession(query, true, true).getIdentityMapAccessor().invalidateObject(object); throw OptimisticLockException.objectChangedSinceLastReadWhenUpdating(object, query); } }
/** * Check if the new object's version has been set, if so, then it was an existing object that was deleted. * 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); } } }
throw OptimisticLockException.batchStatementExecutionFailure();
/** * INTERNAL: * This method gets the write lock value from either the cache or * the object stored in the query. It then returns the new incremented value. */ public Object getNewLockValue(ModifyQuery query) { Class objectClass = query.getDescriptor().getJavaClass(); Number value; Number newWriteLockValue = null; if (isStoredInCache()) { value = (Number)query.getSession().getIdentityMapAccessorInstance().getWriteLockValue(((WriteObjectQuery)query).getPrimaryKey(), objectClass, getDescriptor()); } else { value = (Number)lockValueFromObject(((ObjectLevelModifyQuery)query).getObject()); } if (value == null) { throw OptimisticLockException.noVersionNumberWhenUpdating(((ObjectLevelModifyQuery)query).getObject(), (ObjectLevelModifyQuery)query); } // Increment the value, this goes to the database newWriteLockValue = incrementWriteLockValue(value); return newWriteLockValue; }
/** * INTERNAL: * This method will return the optimistic lock value for the object */ public Object getWriteLockValue(Object domainObject, java.util.Vector primaryKey, AbstractSession session) { java.sql.Timestamp writeLockFieldValue = null; if (isStoredInCache()) { writeLockFieldValue = (java.sql.Timestamp)session.getIdentityMapAccessorInstance().getWriteLockValue(primaryKey, domainObject.getClass(), getDescriptor()); } else { //CR#2281 notStoredInCache prevent ClassCastException Object lockValue = lockValueFromObject(domainObject); if (lockValue != null) { if (lockValue instanceof java.sql.Timestamp) { writeLockFieldValue = (java.sql.Timestamp)lockValueFromObject(domainObject); } else { throw OptimisticLockException.needToMapJavaSqlTimestampWhenStoredInObject(); } } } return writeLockFieldValue; }
/** * INTERNAL: * It is responsible for initializing the policy; */ public void initialize(AbstractSession session) { DatabaseMapping mapping = this.descriptor.getObjectBuilder().getMappingForField(getWriteLockField()); if (mapping == null) { if (isStoredInObject()) { if (this.descriptor.getObjectBuilder().getReadOnlyMappingsForField(getWriteLockField()) != null) { mapping = this.descriptor.getObjectBuilder().getReadOnlyMappingsForField(getWriteLockField()).get(0); session.getIntegrityChecker().handleError(DescriptorException.mappingCanNotBeReadOnly(mapping)); } else { session.getIntegrityChecker().handleError(OptimisticLockException.mustHaveMappingWhenStoredInObject(this.descriptor.getJavaClass())); } } else { return; } } if (isStoredInCache()) { session.getIntegrityChecker().handleError(DescriptorException.mustBeReadOnlyMappingWhenStoredInCache(mapping)); } // PERF: Cache the mapping if direct. if (mapping.isDirectToFieldMapping() && (this.descriptor.getObjectBuilder().getReadOnlyMappingsForField(getWriteLockField()) == null)) { this.lockMapping = (AbstractDirectMapping)mapping; } // If the version field is not in the primary table, then they cannot be batched together. if ((this.descriptor.getTables().size() > 0) && !getWriteLockField().getTable().equals(this.descriptor.getTables().get(0))) { this.descriptor.setHasMultipleTableConstraintDependecy(true); } }
/** * INTERNAL: * This method adds the lock value to the translation row of the * passed in query. depending on the storage flag, the value is * either retrieved from the cache of the object. */ public void addLockValuesToTranslationRow(ObjectLevelModifyQuery query) { Object value; if (isStoredInCache()) { value = query.getSession().getIdentityMapAccessorInstance().getWriteLockValue(query.getPrimaryKey(), query.getObject().getClass(), getDescriptor()); } else { value = lockValueFromObject(query.getObject()); } if (value == null) { if (query.isDeleteObjectQuery()) { throw OptimisticLockException.noVersionNumberWhenDeleting(query.getObject(), query); } else { throw OptimisticLockException.noVersionNumberWhenUpdating(query.getObject(), query); } } // EL bug 319759 if (query.isUpdateObjectQuery()) { query.setShouldValidateUpdateCallCacheUse(true); } query.getTranslationRow().put(this.writeLockField, value); }
/** * INTERNAL: * Check the row count for lock failure. */ public void validateDelete(int rowCount, Object object, DeleteObjectQuery query) { if (rowCount <= 0) { // Mark the object as invalid in the session cache. query.getSession().getParentIdentityMapSession(query, true, true).getIdentityMapAccessor().invalidateObject(object); throw OptimisticLockException.objectChangedSinceLastReadWhenDeleting(object, query); } }
/** * INTERNAL: * Check the row count for lock failure. */ public void validateUpdate(int rowCount, Object object, WriteObjectQuery query) { if (rowCount <= 0) { // Mark the object as invalid in the session cache. query.getSession().getParentIdentityMapSession(query, true, true).getIdentityMapAccessor().invalidateObject(object); throw OptimisticLockException.objectChangedSinceLastReadWhenUpdating(object, query); } }
/** * Check if the new object's version has been set, if so, then it was an existing object that was deleted. * 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); } } }
if (this.previousCall.hasOptimisticLock()) { if (rowCount != 1) { throw OptimisticLockException.batchStatementExecutionFailure(); throw OptimisticLockException.batchStatementExecutionFailure();
/** * INTERNAL: * This method gets the write lock value from either the cache or * the object stored in the query. It then returns the new incremented value. */ public Object getNewLockValue(ModifyQuery query) { Class objectClass = query.getDescriptor().getJavaClass(); Number value; Number newWriteLockValue = null; if (isStoredInCache()) { value = (Number)query.getSession().getIdentityMapAccessorInstance().getWriteLockValue(((WriteObjectQuery)query).getPrimaryKey(), objectClass, getDescriptor()); } else { value = (Number)lockValueFromObject(((ObjectLevelModifyQuery)query).getObject()); } if (value == null) { throw OptimisticLockException.noVersionNumberWhenUpdating(((ObjectLevelModifyQuery)query).getObject(), (ObjectLevelModifyQuery)query); } // Increment the value, this goes to the database newWriteLockValue = incrementWriteLockValue(value); return newWriteLockValue; }
/** * INTERNAL: * This method will return the optimistic lock value for the object. */ @Override public Object getWriteLockValue(Object domainObject, Object primaryKey, AbstractSession session) { java.sql.Timestamp writeLockFieldValue = null; if (isStoredInCache()) { writeLockFieldValue = (java.sql.Timestamp)session.getIdentityMapAccessorInstance().getWriteLockValue(primaryKey, domainObject.getClass(), getDescriptor()); } else { //CR#2281 notStoredInCache prevent ClassCastException Object lockValue = lockValueFromObject(domainObject); if (lockValue != null) { if (lockValue instanceof java.sql.Timestamp) { writeLockFieldValue = (java.sql.Timestamp)lockValueFromObject(domainObject); } else { throw OptimisticLockException.needToMapJavaSqlTimestampWhenStoredInObject(); } } } return writeLockFieldValue; }
/** * INTERNAL: * It is responsible for initializing the policy; */ public void initialize(AbstractSession session) { DatabaseMapping mapping = this.descriptor.getObjectBuilder().getMappingForField(getWriteLockField()); if (mapping == null) { if (isStoredInObject()) { if (this.descriptor.getObjectBuilder().getReadOnlyMappingsForField(getWriteLockField()) != null) { mapping = this.descriptor.getObjectBuilder().getReadOnlyMappingsForField(getWriteLockField()).get(0); session.getIntegrityChecker().handleError(DescriptorException.mappingCanNotBeReadOnly(mapping)); } else { session.getIntegrityChecker().handleError(OptimisticLockException.mustHaveMappingWhenStoredInObject(this.descriptor.getJavaClass())); } } else { return; } } if (isStoredInCache()) { session.getIntegrityChecker().handleError(DescriptorException.mustBeReadOnlyMappingWhenStoredInCache(mapping)); } // PERF: Cache the mapping if direct. if (mapping.isDirectToFieldMapping() && (this.descriptor.getObjectBuilder().getReadOnlyMappingsForField(getWriteLockField()) == null)) { this.lockMapping = (AbstractDirectMapping)mapping; } // If the version field is not in the primary table, then they cannot be batched together. if ((this.descriptor.getTables().size() > 0) && !getWriteLockField().getTable().equals(this.descriptor.getTables().get(0))) { this.descriptor.setHasMultipleTableConstraintDependecy(true); } }
public static OptimisticLockException mustHaveMappingWhenStoredInObject(Class aClass) { Object[] args = { aClass }; OptimisticLockException optimisticLockException = new OptimisticLockException(ExceptionMessageGenerator.buildMessage(OptimisticLockException.class, MUST_HAVE_MAPPING_WHEN_IN_OBJECT, args)); optimisticLockException.setErrorCode(MUST_HAVE_MAPPING_WHEN_IN_OBJECT); return optimisticLockException; }
/** * INTERNAL: * This method adds the lock value to the translation row of the * passed in query. depending on the storage flag, the value is * either retrieved from the cache of the object. */ public void addLockValuesToTranslationRow(ObjectLevelModifyQuery query) { Object value; if (isStoredInCache()) { value = query.getSession().getIdentityMapAccessorInstance().getWriteLockValue(query.getPrimaryKey(), query.getObject().getClass(), getDescriptor()); } else { value = lockValueFromObject(query.getObject()); } if (value == null) { if (query.isDeleteObjectQuery()) { throw OptimisticLockException.noVersionNumberWhenDeleting(query.getObject(), query); } else { throw OptimisticLockException.noVersionNumberWhenUpdating(query.getObject(), query); } } // EL bug 319759 if (query.isUpdateObjectQuery()) { query.setShouldValidateUpdateCallCacheUse(true); } query.getTranslationRow().put(this.writeLockField, value); }