/** * 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.getIdentityMapAccessor().getWriteLockValue(primaryKey, domainObject.getClass()); } 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: * Return the number of versions different between these objects. */ public int getVersionDifference(Object currentValue, Object domainObject, Vector primaryKeys, AbstractSession session) { java.sql.Timestamp writeLockFieldValue; java.sql.Timestamp newWriteLockFieldValue = (java.sql.Timestamp)currentValue; if (newWriteLockFieldValue == null) { return 0;//merge it as either the object is new or being forced merged. } if (isStoredInCache()) { writeLockFieldValue = (java.sql.Timestamp)session.getIdentityMapAccessor().getWriteLockValue(primaryKeys, domainObject.getClass()); } else { writeLockFieldValue = (java.sql.Timestamp)lockValueFromObject(domainObject); } if ((writeLockFieldValue != null) && !(newWriteLockFieldValue.after(writeLockFieldValue))) { return 0; } //if the new value is newer then perform the update. Eventually this will be changed to //record the old version and compare that for equality return 2; }
/** * INTERNAL: * Compares the value with the value from the object (or cache). * Will return true if the object is newer. */ public boolean isNewerVersion(Object currentValue, Object domainObject, java.util.Vector primaryKey, AbstractSession session) { java.sql.Timestamp writeLockFieldValue; java.sql.Timestamp newWriteLockFieldValue = (java.sql.Timestamp)currentValue; if (isStoredInCache()) { writeLockFieldValue = (java.sql.Timestamp)session.getIdentityMapAccessor().getWriteLockValue(primaryKey, domainObject.getClass()); } else { writeLockFieldValue = (java.sql.Timestamp)lockValueFromObject(domainObject); } // bug 6342382: object's lock value is null, it is NOT newer than any newWriteLockFieldValue. if(writeLockFieldValue == null) { return false; } // 2.5.1.6 if the write lock value is null, then what ever we have is treated as newer. if (newWriteLockFieldValue == null) { return true; } if (!(newWriteLockFieldValue.after(writeLockFieldValue))) { return false; } return true; }
/** * INTERNAL: * Compares the value from the row and from the object (or cache). * Will return true if the object is newer than the row. */ public boolean isNewerVersion(AbstractRecord databaseRow, Object domainObject, java.util.Vector primaryKey, AbstractSession session) { java.sql.Timestamp writeLockFieldValue; java.sql.Timestamp newWriteLockFieldValue = (java.sql.Timestamp)session.getDatasourcePlatform().convertObject(databaseRow.get(getWriteLockField()), ClassConstants.TIMESTAMP); if (isStoredInCache()) { writeLockFieldValue = (java.sql.Timestamp)session.getIdentityMapAccessor().getWriteLockValue(primaryKey, domainObject.getClass()); } else { writeLockFieldValue = (java.sql.Timestamp)lockValueFromObject(domainObject); } // bug 6342382: object's lock value is null, it is NOT newer than any newWriteLockFieldValue. if(writeLockFieldValue == null) { return false; } // 2.5.1.6 if the write lock value is null, then what ever we have is treated as newer. if (newWriteLockFieldValue == null) { return true; } if (!(newWriteLockFieldValue.after(writeLockFieldValue))) { return false; } return true; }