Class Type

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

@Immutable public final class Type extends Object implements Serializable
Describes a type in the Cloud Spanner type system. Types can either be primitive (for example, INT64 and STRING) or composite (for example, ARRAY<INT64> or STRUCT<INT64,STRING>).

Type instances are immutable.

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Enumerates the categories of types.
    static final class 
    Describes an individual field in a STRUCT type.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Type
    array(Type elementType)
    Returns a descriptor for an array of elementType.
    static Type
    Returns the descriptor for the BOOL type.
    static Type
    Returns the descriptor for the BYTES type: a variable-length byte string.
    static Type
    Returns the descriptor for the DATE type: a timezone independent date in the range [0001-01-01, 9999-12-31).
    boolean
     
    static Type
    Returns the descriptor for the FLOAT64 type: a floating point type with the same value domain as a Java {code double}.
    Returns the type descriptor for elements of this ARRAY type.
    Returns the type code corresponding to this type.
    int
    getFieldIndex(String fieldName)
    Returns the index of the field named fieldName in this STRUCT type.
    Returns the full package name for elements of this Proto or @code Enum type.
    Returns the type name as used by the database in the given dialect.
    Returns the fields of this STRUCT type.
    int
     
    static Type
    Returns the descriptor for the INT64 type: an integral type with the same value domain as a Java long.
    static Type
    Returns the descriptor for the JSON type.
    static Type
    Returns the descriptor for the NUMERIC type.
    static Type
    Returns the descriptor for the JSONB type.
    static Type
    Returns the descriptor for the NUMERIC type with the PG_NUMERIC type annotation.
    static Type
    proto(String protoTypeFqn)
    To get the descriptor for the PROTO type.
    static Type
    protoEnum(String protoTypeFqn)
    To get the descriptor for the ENUM type.
    static Type
    Returns the descriptor for the STRING type: a variable-length Unicode character string.
    static Type
    Returns a descriptor for a STRUCT type: an ordered collection of named and typed fields.
    static Type
    Returns a descriptor for a STRUCT type: an ordered collection of named and typed fields.
    static Type
    Returns the descriptor for the TIMESTAMP type: a nano precision timestamp in the range [0000-01-01 00:00:00, 9999-12-31 23:59:59.999999999 UTC].
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • bool

      public static Type bool()
      Returns the descriptor for the BOOL type.
    • int64

      public static Type int64()
      Returns the descriptor for the INT64 type: an integral type with the same value domain as a Java long.
    • float64

      public static Type float64()
      Returns the descriptor for the FLOAT64 type: a floating point type with the same value domain as a Java {code double}.
    • numeric

      public static Type numeric()
      Returns the descriptor for the NUMERIC type.
    • pgNumeric

      public static Type pgNumeric()
      Returns the descriptor for the NUMERIC type with the PG_NUMERIC type annotation.
    • string

      public static Type string()
      Returns the descriptor for the STRING type: a variable-length Unicode character string.
    • json

      public static Type json()
      Returns the descriptor for the JSON type.
    • pgJsonb

      public static Type pgJsonb()
      Returns the descriptor for the JSONB type.
    • proto

      public static Type proto(String protoTypeFqn)
      To get the descriptor for the PROTO type.
      Parameters:
      protoTypeFqn - Proto fully qualified name (ex: "spanner.examples.music.SingerInfo").
    • protoEnum

      public static Type protoEnum(String protoTypeFqn)
      To get the descriptor for the ENUM type.
      Parameters:
      protoTypeFqn - Proto ENUM fully qualified name (ex: "spanner.examples.music.Genre")
    • bytes

      public static Type bytes()
      Returns the descriptor for the BYTES type: a variable-length byte string.
    • timestamp

      public static Type timestamp()
      Returns the descriptor for the TIMESTAMP type: a nano precision timestamp in the range [0000-01-01 00:00:00, 9999-12-31 23:59:59.999999999 UTC].
    • date

      public static Type date()
      Returns the descriptor for the DATE type: a timezone independent date in the range [0001-01-01, 9999-12-31).
    • array

      public static Type array(Type elementType)
      Returns a descriptor for an array of elementType.
    • struct

      public static Type struct(Iterable<Type.StructField> fields)
      Returns a descriptor for a STRUCT type: an ordered collection of named and typed fields.
    • struct

      public static Type struct(Type.StructField... fields)
      Returns a descriptor for a STRUCT type: an ordered collection of named and typed fields.
    • getCode

      public Type.Code getCode()
      Returns the type code corresponding to this type.
    • getArrayElementType

      public Type getArrayElementType()
      Returns the type descriptor for elements of this ARRAY type.
      Throws:
      IllegalStateException - if code() != Code.ARRAY
    • getStructFields

      public List<Type.StructField> getStructFields()
      Returns the fields of this STRUCT type.
      Returns:
      an immutable list of the fields
      Throws:
      IllegalStateException - if code() != Code.STRUCT
    • getProtoTypeFqn

      public String getProtoTypeFqn()
      Returns the full package name for elements of this Proto or @code Enum type.
      Throws:
      IllegalStateException - if code() != Code.PROTO or code() != Code.ENUM
    • getFieldIndex

      public int getFieldIndex(String fieldName)
      Returns the index of the field named fieldName in this STRUCT type.
      Throws:
      IllegalArgumentException - if there is not exactly one element of getStructFields() with Type.StructField.getName() equal to fieldName
      IllegalStateException - if code() != Code.STRUCT
    • toString

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

      public String getSpannerTypeName(Dialect dialect)
      Returns the type name as used by the database in the given dialect.
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object