Class TimestampLockingPolicy

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, OptimisticLockingPolicy

    public class TimestampLockingPolicy
    extends VersionLockingPolicy

    Purpose: Used to allow a single version timestamp to be used for optimistic locking.

    Since:
    TOPLink/Java 2.0
    See Also:
    Serialized Form
    • Constructor Detail

      • TimestampLockingPolicy

        public TimestampLockingPolicy()
        PUBLIC: Create a new TimestampLockingPolicy. Defaults to using the time retrieved from the server.
      • TimestampLockingPolicy

        public TimestampLockingPolicy​(java.lang.String fieldName)
        PUBLIC: Create a new TimestampLockingPolicy. Defaults to using the time retrieved from the server.
        Parameters:
        fieldName - the field where the write lock value will be stored.
      • TimestampLockingPolicy

        public TimestampLockingPolicy​(DatabaseField field)
        INTERNAL: Create a new TimestampLockingPolicy. Defaults to using the time retrieved from the server.
        Parameters:
        field - the field where the write lock value will be stored.
    • Method Detail

      • compareWriteLockValues

        public int compareWriteLockValues​(java.lang.Object value1,
                                          java.lang.Object value2)
        INTERNAL: This method compares two writeLockValues. The writeLockValues should be non-null and of type java.sql.Timestamp. Returns: -1 if value1 is less (older) than value2; 0 if value1 equals value2; 1 if value1 is greater (newer) than value2. Throws: NullPointerException if the passed value is null; ClassCastException if the passed value is of a wrong type.
        Specified by:
        compareWriteLockValues in interface OptimisticLockingPolicy
        Overrides:
        compareWriteLockValues in class VersionLockingPolicy
      • getDefaultLockingFieldType

        protected java.lang.Class getDefaultLockingFieldType()
        INTERNAL: Return the default timestamp locking filed java type, default is Timestamp.
        Overrides:
        getDefaultLockingFieldType in class VersionLockingPolicy
      • getVersionDifference

        public int getVersionDifference​(java.lang.Object currentValue,
                                        java.lang.Object domainObject,
                                        java.lang.Object primaryKeys,
                                        AbstractSession session)
        INTERNAL: Return the number of versions different between these objects.
        Specified by:
        getVersionDifference in interface OptimisticLockingPolicy
        Overrides:
        getVersionDifference in class VersionLockingPolicy
        Parameters:
        currentValue - the new lock value
        domainObject - the object containing the version to be compared to
        primaryKeys - a vector containing the primary keys of the domainObject
        session - the session to be used with the comparison
      • incrementWriteLockValue

        protected java.lang.Number incrementWriteLockValue​(java.lang.Number numberValue)
        INTERNAL: Timestamp versioning should not be able to do this. Override the superclass behavior.
        Overrides:
        incrementWriteLockValue in class VersionLockingPolicy
      • isNewerVersion

        public boolean isNewerVersion​(java.lang.Object currentValue,
                                      java.lang.Object domainObject,
                                      java.lang.Object primaryKey,
                                      AbstractSession session)
        INTERNAL: Compares the value with the value from the object (or cache). Will return true if the currentValue is newer than the domainObject.
        Specified by:
        isNewerVersion in interface OptimisticLockingPolicy
        Overrides:
        isNewerVersion in class VersionLockingPolicy
      • isNewerVersion

        public boolean isNewerVersion​(java.lang.Object firstLockFieldValue,
                                      java.lang.Object secondWriteLockFieldValue)
        INTERNAL: Compares two values. Will return true if the firstLockFieldValue is newer than the secondWriteLockFieldValue.
        Overrides:
        isNewerVersion in class VersionLockingPolicy
      • setUsesServerTime

        public void setUsesServerTime​(boolean usesServerTime)
        PUBLIC: Set if policy uses server time.
      • useLocalTime

        public void useLocalTime()
        PUBLIC: set this policy to get the time from the local machine.
      • useServerTime

        public void useServerTime()
        PUBLIC: set this policy to get the time from the server.
      • usesLocalTime

        public boolean usesLocalTime()
        PUBLIC: Return true if policy uses local time.
      • usesServerTime

        public boolean usesServerTime()
        PUBLIC: Return true if policy uses server time.