Package com.google.cloud.spanner
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,INT64andSTRING) or composite (for example,ARRAY<INT64>orSTRUCT<INT64,STRING>).Typeinstances are immutable.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classType.CodeEnumerates the categories of types.static classType.StructFieldDescribes an individual field in aSTRUCT type.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Typearray(Type elementType)Returns a descriptor for an array ofelementType.static Typebool()Returns the descriptor for theBOOL type.static Typebytes()Returns the descriptor for theBYTEStype: a variable-length byte string.static Typedate()Returns the descriptor for theDATEtype: a timezone independent date in the range [0001-01-01, 9999-12-31).booleanequals(Object o)static Typefloat64()Returns the descriptor for theFLOAT64type: a floating point type with the same value domain as a Java {code double}.TypegetArrayElementType()Returns the type descriptor for elements of thisARRAYtype.Type.CodegetCode()Returns the type code corresponding to this type.intgetFieldIndex(String fieldName)Returns the index of the field namedfieldNamein thisSTRUCTtype.List<Type.StructField>getStructFields()Returns the fields of thisSTRUCTtype.inthashCode()static Typeint64()Returns the descriptor for theINT64type: an integral type with the same value domain as a Javalong.static Typejson()Returns the descriptor for theJSONtype.static Typenumeric()Returns the descriptor for theNUMERICtype.static TypepgJsonb()Returns the descriptor for theJSONBtype.static TypepgNumeric()Returns the descriptor for theNUMERICtype with thePG_NUMERICtype annotation.static Typestring()Returns the descriptor for theSTRINGtype: a variable-length Unicode character string.static Typestruct(Type.StructField... fields)Returns a descriptor for aSTRUCTtype: an ordered collection of named and typed fields.static Typestruct(Iterable<Type.StructField> fields)Returns a descriptor for aSTRUCTtype: an ordered collection of named and typed fields.static Typetimestamp()Returns the descriptor for theTIMESTAMPtype: a nano precision timestamp in the range [0000-01-01 00:00:00, 9999-12-31 23:59:59.999999999 UTC].StringtoString()
-
-
-
Method Detail
-
bool
public static Type bool()
Returns the descriptor for theBOOL type.
-
int64
public static Type int64()
Returns the descriptor for theINT64type: an integral type with the same value domain as a Javalong.
-
float64
public static Type float64()
Returns the descriptor for theFLOAT64type: a floating point type with the same value domain as a Java {code double}.
-
numeric
public static Type numeric()
Returns the descriptor for theNUMERICtype.
-
pgNumeric
public static Type pgNumeric()
Returns the descriptor for theNUMERICtype with thePG_NUMERICtype annotation.
-
string
public static Type string()
Returns the descriptor for theSTRINGtype: a variable-length Unicode character string.
-
json
public static Type json()
Returns the descriptor for theJSONtype.
-
pgJsonb
public static Type pgJsonb()
Returns the descriptor for theJSONBtype.
-
bytes
public static Type bytes()
Returns the descriptor for theBYTEStype: a variable-length byte string.
-
timestamp
public static Type timestamp()
Returns the descriptor for theTIMESTAMPtype: 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 theDATEtype: a timezone independent date in the range [0001-01-01, 9999-12-31).
-
struct
public static Type struct(Iterable<Type.StructField> fields)
Returns a descriptor for aSTRUCTtype: an ordered collection of named and typed fields.
-
struct
public static Type struct(Type.StructField... fields)
Returns a descriptor for aSTRUCTtype: 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 thisARRAYtype.- Throws:
IllegalStateException- ifcode() != Code.ARRAY
-
getStructFields
public List<Type.StructField> getStructFields()
Returns the fields of thisSTRUCTtype.- Returns:
- an immutable list of the fields
- Throws:
IllegalStateException- ifcode() != Code.STRUCT
-
getFieldIndex
public int getFieldIndex(String fieldName)
Returns the index of the field namedfieldNamein thisSTRUCTtype.- Throws:
IllegalArgumentException- if there is not exactly one element ofgetStructFields()withType.StructField.getName()equal tofieldNameIllegalStateException- ifcode() != Code.STRUCT
-
-