Module eclipselink

Class AbstractTsLockingPolicy<T>

java.lang.Object
org.eclipse.persistence.descriptors.VersionLockingPolicy
org.eclipse.persistence.descriptors.AbstractTsLockingPolicy<T>
All Implemented Interfaces:
Serializable, Cloneable, org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
Direct Known Subclasses:
InstantLockingPolicy, LocalDateTimeLockingPolicy, TimestampLockingPolicy

public abstract class AbstractTsLockingPolicy<T> extends VersionLockingPolicy
Common timestamp version policy used for optimistic locking.
See Also:
  • Field Details

  • Constructor Details

    • AbstractTsLockingPolicy

      public AbstractTsLockingPolicy()
      Creates an instance of timestamp version policy used for optimistic locking. Defaults to using the time retrieved from the server.
    • AbstractTsLockingPolicy

      public AbstractTsLockingPolicy(String fieldName)
      Creates an instance of timestamp version policy used for optimistic locking. Defaults to using the time retrieved from the server.
      Parameters:
      fieldName - the field where the write lock value will be stored
    • AbstractTsLockingPolicy

      public AbstractTsLockingPolicy(org.eclipse.persistence.internal.helper.DatabaseField field)
      Creates an instance of timestamp version policy used for optimistic locking. Defaults to using the time retrieved from the server.
      Parameters:
      field - the field where the write lock value will be stored
  • Method Details

    • create

      public static AbstractTsLockingPolicy<?> create(String typeName, org.eclipse.persistence.internal.helper.DatabaseField field)
      AbstractTsLockingPolicy factory method.
      Parameters:
      typeName - raw MetadataClass name
      field - version field
    • compareWriteLockValues

      public int compareWriteLockValues(Object value1, Object value2)
      Description copied from class: VersionLockingPolicy
      INTERNAL: This method compares two writeLockValues. The writeLockValues should be non-null and of LocalDateTime, Instant or Timestamp type.
      Specified by:
      compareWriteLockValues in interface org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
      Overrides:
      compareWriteLockValues in class VersionLockingPolicy
      Parameters:
      value1 - the 1st value to compare
      value2 - the 2nd value to compare
      Returns:
      -1 if value1 is less (older) than value2, 0 if value1 equals value2, 1 if value1 is greater (newer) than value2.
    • getDefaultLockingFieldType

      protected <C> Class<C> getDefaultLockingFieldType()
      Description copied from class: VersionLockingPolicy
      INTERNAL: Return the default timestamp locking filed java type.
      Overrides:
      getDefaultLockingFieldType in class VersionLockingPolicy
      Returns:
      the default timestamp locking filed java type
    • getBaseValue

      public <C> C getBaseValue()
      Description copied from class: VersionLockingPolicy
      INTERNAL: Return base value that is older than all other values, it is used in the place of null in some situations.
      Specified by:
      getBaseValue in interface org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
      Overrides:
      getBaseValue in class VersionLockingPolicy
      Returns:
      timestamp base value
    • getInitialWriteValue

      protected <C> C getInitialWriteValue(org.eclipse.persistence.internal.sessions.AbstractSession session)
      Description copied from class: VersionLockingPolicy
      INTERNAL: Return initial locking value.
      Overrides:
      getInitialWriteValue in class VersionLockingPolicy
      Parameters:
      session - the database session
      Returns:
      the initial locking value
    • getNewLockValue

      public <C> C getNewLockValue(ModifyQuery query)
      Description copied from class: VersionLockingPolicy
      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.
      Overrides:
      getNewLockValue in class VersionLockingPolicy
      Parameters:
      query - modify query
      Returns:
      the new timestamp value
    • getValueToPutInCache

      public <C> C getValueToPutInCache(org.eclipse.persistence.internal.sessions.AbstractRecord row, org.eclipse.persistence.internal.sessions.AbstractSession session)
      Description copied from class: VersionLockingPolicy
      INTERNAL: Return the value that should be stored in the identity map. If the value is stored in the object, then return a null.
      Specified by:
      getValueToPutInCache in interface org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
      Overrides:
      getValueToPutInCache in class VersionLockingPolicy
      Parameters:
      row - the data row, e.g. database row
      session - the database session
      Returns:
      the value that should be stored in the identity map
    • getWriteLockValue

      public <C> C getWriteLockValue(Object domainObject, Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session)
      Description copied from class: VersionLockingPolicy
      INTERNAL: Return the optimistic lock value for the object.
      Specified by:
      getWriteLockValue in interface org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
      Overrides:
      getWriteLockValue in class VersionLockingPolicy
      Parameters:
      domainObject - the domain object (entity instance)
      primaryKey - the primary key
      session - the database session
      Returns:
      the optimistic lock value for the object
    • isNewerVersion

      public boolean isNewerVersion(Object current, Object domainObject, Object primaryKey, org.eclipse.persistence.internal.sessions.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 org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
      Overrides:
      isNewerVersion in class VersionLockingPolicy
      Parameters:
      current - the current value
      domainObject - the domain object (entity instance)
      primaryKey - the primary key
      session - the database session
      Returns:
      value of true if the first is newer than the second or false otherwise
    • isNewerVersion

      public boolean isNewerVersion(org.eclipse.persistence.internal.sessions.AbstractRecord row, Object domainObject, Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session)
      Description copied from class: VersionLockingPolicy
      INTERNAL: Compares two version values from the row and from the object (or cache).
      Specified by:
      isNewerVersion in interface org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
      Overrides:
      isNewerVersion in class VersionLockingPolicy
      Parameters:
      row - the data row, e.g. database row
      domainObject - the domain object (entity instance)
      primaryKey - the primary key
      session - the database session
      Returns:
      value of true if the first is newer than the second or false otherwise
    • isNewerVersion

      public boolean isNewerVersion(Object first, Object second)
      Description copied from class: VersionLockingPolicy
      INTERNAL: Compares two version values. Will return true if the firstLockFieldValue is newer than the secondWriteLockFieldValue.
      Overrides:
      isNewerVersion in class VersionLockingPolicy
      Parameters:
      first - first version value
      second - second version value
      Returns:
      value of true if the first is newer than the second or false otherwise
    • getWriteLockUpdateExpression

      public Expression getWriteLockUpdateExpression(ExpressionBuilder builder, org.eclipse.persistence.internal.sessions.AbstractSession session)
      Return an expression that updates the write lock.
      Specified by:
      getWriteLockUpdateExpression in interface org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
      Overrides:
      getWriteLockUpdateExpression in class VersionLockingPolicy
      Parameters:
      builder - the expression builder
      session - the database session
    • incrementWriteLockValue

      protected Number incrementWriteLockValue(Number value)
      Timestamp versioning should not be able to do this. Override the superclass behavior.
      Overrides:
      incrementWriteLockValue in class VersionLockingPolicy
      Parameters:
      value - the source value
    • setUsesServerTime

      public void setUsesServerTime(boolean useServer)
      Set time source policy.
      Parameters:
      useServer - set this policy to get the time from the server when true or from the local machine when false
    • useLocalTime

      public void useLocalTime()
      Set time source policy to get the time from the local machine.
    • useServerTime

      public void useServerTime()
      Set time source policy to get the time from the server.
    • usesLocalTime

      public boolean usesLocalTime()
      Return whether time source policy uses local time.
      Returns:
      value of true when policy uses local time or false otherwise.
    • usesServerTime

      public boolean usesServerTime()
      Return whether time source policy uses server time.
      Returns:
      value of true when policy uses server time or false otherwise.