Package oracle.kv

Class Version

java.lang.Object
oracle.kv.Version
All Implemented Interfaces:
Serializable, oracle.kv.impl.util.FastExternalizable

public class Version extends Object implements oracle.kv.impl.util.FastExternalizable, Serializable
A Version refers to a specific version of a key-value pair.

When a key-value pair is initially inserted in the KV Store, and each time it is updated, it is assigned a unique version token. The version is always returned by the put method, for example, put, and is also returned by get methods, for example, get. The version is important for two reasons:

  1. When an update or delete is to be performed, it may be important to only perform the update or delete if the last known value has not changed. For example, if an integer field in a previously known value is to be incremented, it is important that the previous value has not changed in the KV Store since it was obtained by the client. This can be guaranteed by passing the version of the previously known value to the putIfVersion or deleteIfVersion method. If the version specified does not match the current version of the value in the KV Store, these methods will not perform the update or delete operation and will return an indication of failure. Optionally, they will also return the current version and/or value so the client can retry the operation or take a different action.
  2. When a client reads a value that was previously written, it may be important to ensure that the KV Store node servicing the read operation has been updated with the information previously written. This can be accomplished by passing the version of the previously written value as a Consistency parameter to the read operation, for example, get. See Consistency.Version for more information.

It is important to be aware that the system may infrequently assign a new Version to a key-value pair, for example, when migrating data for better resource usage. Therefore, when using the putIfVersion or deleteIfVersion methods, one cannot assume that the Version will remain constant until it is changed by the application.

See Also:
  • Method Details

    • toByteArray

      public byte[] toByteArray()
      Returns this Version as a serialized byte array, such that fromByteArray(byte[]) may be used to reconstitute the Version. Values returned by calls to this method can be used with current and newer releases, but are not guaranteed to be compatible with earlier releases.
    • fromByteArray

      public static Version fromByteArray(byte[] versionBytes)
      Deserializes the given bytes that were returned earlier by toByteArray() and returns the resulting Version. Values created with either the current or earlier releases can be used with this method, but values created by later releases are not guaranteed to be compatible.
      Parameters:
      versionBytes - a byte array produced by toByteArray()
      Returns:
      a new Version object
      Throws:
      IllegalArgumentException - if versionBytes is null or corrupted
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object