Class Key

java.lang.Object
com.google.cloud.spanner.Key
All Implemented Interfaces:
Serializable

public final class Key extends Object implements Serializable
Represents a row key in a Cloud Spanner table or index. A key is a tuple of values constrained to the scalar Cloud Spanner types: currently these are BOOLEAN, INT64, FLOAT64, STRING, BYTES and TIMESTAMP. Values may be null where the table definition permits it.

Key is used to define the row, or endpoints of a range of rows, to retrieve in read operations or to delete in a mutation.

Key instances are immutable.

See Also:
  • Method Details

    • of

      public static Key of(Object... values)
      Construct a key with parts specified by values. Each object in values must be either null or one of the following supported types:
      • Boolean for the BOOL Cloud Spanner type
      • Integer, Long for the INT64 Cloud Spanner type
      • Float, Double for the FLOAT64 Cloud Spanner type
      • BigDecimal for the NUMERIC Cloud Spanner type
      • String for the STRING Cloud Spanner type
      • String for the JSON Cloud Spanner type
      • ByteArray for the BYTES Cloud Spanner type
      • Timestamp for the TIMESTAMP Cloud Spanner type
      • Date for the DATE Cloud Spanner type
      Throws:
      IllegalArgumentException - if any member of values is not a supported type
    • newBuilder

      public static Key.Builder newBuilder()
      Returns a new builder for constructing a key.
    • size

      public int size()
      Returns the number of parts in this key, including null values.
    • getParts

      public Iterable<Object> getParts()
      Returns the parts in this key. Each part is represented by the corresponding Cloud Spanner type's canonical Java type, as listed below. Note that other types supported by of(Object...) are converted to one of the canonical types.
      • BOOL is represented by Boolean
      • INT64 is represented by Long
      • FLOAT64 is represented by Double
      • NUMERIC is represented by BigDecimal
      • STRING is represented by String
      • JSON is represented by String
      • BYTES is represented by ByteArray
      • TIMESTAMP is represented by Timestamp
      • DATE is represented by Date
      Returns:
      an unmodifiable list containing the key parts
    • toBuilder

      public Key.Builder toBuilder()
      Returns a builder initialized with the value of this key.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object