@Immutable public abstract class Value extends Object implements Serializable
NULL
or
non-NULL
; regardless, values always have an associated type.
The Value
API is optimized for construction, since this is the majority use-case when
using this class with the Cloud Spanner libraries. The factory method signatures and internal
representations are design to minimize memory usage and object creation while still maintaining
the immutability contract of this class. In particular, arrays of primitive types can be
constructed without requiring boxing into collections of wrapper types. The getters in this class
are intended primarily for test purposes, and so do not share the same performance
characteristics; in particular, getters for array types may be expensive.
Value
instances are immutable.
Modifier and Type | Field and Description |
---|---|
static Timestamp |
COMMIT_TIMESTAMP
Placeholder value to be passed to a mutation to make Cloud Spanner store the commit timestamp
in that column.
|
Modifier and Type | Method and Description |
---|---|
static Value |
bool(boolean v)
Returns a
BOOL value. |
static Value |
bool(Boolean v)
Returns a
BOOL value. |
static Value |
boolArray(boolean[] v)
Returns an
ARRAY<BOOL> value. |
static Value |
boolArray(boolean[] v,
int pos,
int length)
Returns an
ARRAY<BOOL> value that takes its elements from a region of an array. |
static Value |
boolArray(Iterable<Boolean> v)
Returns an
ARRAY<BOOL> value. |
static Value |
bytes(ByteArray v)
Returns a
BYTES value. |
static Value |
bytesArray(Iterable<ByteArray> v)
Returns an
ARRAY<BYTES> value. |
static Value |
date(Date v)
Returns a
DATE value. |
static Value |
dateArray(Iterable<Date> v)
Returns an
ARRAY<DATE> value. |
static Value |
float64(double v)
Returns a
FLOAT64 value. |
static Value |
float64(Double v)
Returns a
FLOAT64 value. |
static Value |
float64Array(double[] v)
Returns an
ARRAY<FLOAT64> value. |
static Value |
float64Array(double[] v,
int pos,
int length)
Returns an
ARRAY<FLOAT64> value that takes its elements from a region of an array. |
static Value |
float64Array(Iterable<Double> v)
Returns an
ARRAY<FLOAT64> value. |
abstract boolean |
getBool()
Returns the value of a
BOOL -typed instance. |
abstract List<Boolean> |
getBoolArray()
Returns the value of an
ARRAY<BOOL> -typed instance. |
abstract ByteArray |
getBytes()
Returns the value of a
BYTES -typed instance. |
abstract List<ByteArray> |
getBytesArray()
Returns the value of an
ARRAY<BYTES> -typed instance. |
abstract Date |
getDate()
Returns the value of a
DATE -typed instance. |
abstract List<Date> |
getDateArray()
Returns the value of an
ARRAY<DATE> -typed instance. |
abstract double |
getFloat64()
Returns the value of a
FLOAT64 -typed instance. |
abstract List<Double> |
getFloat64Array()
Returns the value of an
ARRAY<FLOAT64> -typed instance. |
abstract long |
getInt64()
Returns the value of a
INT64 -typed instance. |
abstract List<Long> |
getInt64Array()
Returns the value of an
ARRAY<INT64> -typed instance. |
abstract String |
getString()
Returns the value of a
STRING -typed instance. |
abstract List<String> |
getStringArray()
Returns the value of an
ARRAY<STRING> -typed instance. |
abstract Struct |
getStruct()
Returns the value of a
STRUCT -typed instance. |
abstract Timestamp |
getTimestamp()
Returns the value of a
TIMESTAMP -typed instance. |
abstract List<Timestamp> |
getTimestampArray()
Returns the value of an
ARRAY<TIMESTAMP> -typed instance. |
abstract Type |
getType()
Returns the type of this value.
|
static Value |
int64(long v)
Returns an
INT64 value. |
static Value |
int64(Long v)
Returns an
INT64 value. |
static Value |
int64Array(Iterable<Long> v)
Returns an
ARRAY<INT64> value. |
static Value |
int64Array(long[] v)
Returns an
ARRAY<INT64> value. |
static Value |
int64Array(long[] v,
int pos,
int length)
Returns an
ARRAY<INT64> value that takes its elements from a region of an array. |
abstract boolean |
isCommitTimestamp()
Returns true if this is a commit timestamp value.
|
abstract boolean |
isNull()
Returns
true if this instance represents a NULL value. |
static Value |
string(String v)
Returns a
STRING value. |
static Value |
stringArray(Iterable<String> v)
Returns an
ARRAY<STRING> value. |
static Value |
struct(Struct v)
Returns a non-
NULL {#code STRUCT} value. |
static Value |
struct(Type type,
Struct v)
Returns a
STRUCT value of Type type. |
static Value |
structArray(Type elementType,
Iterable<Struct> v)
Returns an
ARRAY<STRUCT<...>> value. |
static Value |
timestamp(Timestamp v)
Returns a
TIMESTAMP value. |
static Value |
timestampArray(Iterable<Timestamp> v)
Returns an
ARRAY<TIMESTAMP> value. |
String |
toString() |
public static final Timestamp COMMIT_TIMESTAMP
Note that this particular timestamp instance has no semantic meaning. In particular the value of seconds and nanoseconds in this timestamp are meaningless. This placeholder can only be used for columns that have set the option "(allow_commit_timestamp=true)" in the schema.
When reading the value stored in such a column, the value returned is an actual timestamp corresponding to the commit time of the transaction, which has no relation to this placeholder.
public static Value bool(@Nullable Boolean v)
BOOL
value.v
- the value, which may be nullpublic static Value bool(boolean v)
BOOL
value.public static Value int64(@Nullable Long v)
INT64
value.v
- the value, which may be nullpublic static Value int64(long v)
INT64
value.public static Value float64(@Nullable Double v)
FLOAT64
value.v
- the value, which may be nullpublic static Value float64(double v)
FLOAT64
value.public static Value string(@Nullable String v)
STRING
value.v
- the value, which may be nullpublic static Value bytes(@Nullable ByteArray v)
BYTES
value.v
- the value, which may be nullpublic static Value date(@Nullable Date v)
DATE
value. The range [1678-01-01, 2262-01-01) is the legal interval for
cloud spanner dates. A write to a date column is rejected if the value is outside of that
interval.public static Value struct(Type type, @Nullable Struct v)
STRUCT
value of Type
type.type
- the type of the STRUCT
valuev
- the struct STRUCT
value. This may be null
to produce a value for which
isNull()
is true
. If non-null
, StructReader.getType()
must match
type.public static Value boolArray(@Nullable boolean[] v)
ARRAY<BOOL>
value.v
- the source of element values, which may be null to produce a value for which isNull()
is true
public static Value boolArray(@Nullable boolean[] v, int pos, int length)
ARRAY<BOOL>
value that takes its elements from a region of an array.v
- the source of element values, which may be null to produce a value for which isNull()
is true
pos
- the start position of v
to copy values from. Ignored if v
is null
.length
- the number of values to copy from v
. Ignored if v
is null
.public static Value boolArray(@Nullable Iterable<Boolean> v)
ARRAY<BOOL>
value.v
- the source of element values. This may be null
to produce a value for which
isNull()
is true
. Individual elements may also be null
.public static Value int64Array(@Nullable long[] v)
ARRAY<INT64>
value.v
- the source of element values, which may be null to produce a value for which isNull()
is true
public static Value int64Array(@Nullable long[] v, int pos, int length)
ARRAY<INT64>
value that takes its elements from a region of an array.v
- the source of element values, which may be null to produce a value for which isNull()
is true
pos
- the start position of v
to copy values from. Ignored if v
is null
.length
- the number of values to copy from v
. Ignored if v
is null
.public static Value int64Array(@Nullable Iterable<Long> v)
ARRAY<INT64>
value.v
- the source of element values. This may be null
to produce a value for which
isNull()
is true
. Individual elements may also be null
.public static Value float64Array(@Nullable double[] v)
ARRAY<FLOAT64>
value.v
- the source of element values, which may be null to produce a value for which isNull()
is true
public static Value float64Array(@Nullable double[] v, int pos, int length)
ARRAY<FLOAT64>
value that takes its elements from a region of an array.v
- the source of element values, which may be null to produce a value for which isNull()
is true
pos
- the start position of v
to copy values from. Ignored if v
is null
.length
- the number of values to copy from v
. Ignored if v
is null
.public static Value float64Array(@Nullable Iterable<Double> v)
ARRAY<FLOAT64>
value.v
- the source of element values. This may be null
to produce a value for which
isNull()
is true
. Individual elements may also be null
.public static Value stringArray(@Nullable Iterable<String> v)
ARRAY<STRING>
value.v
- the source of element values. This may be null
to produce a value for which
isNull()
is true
. Individual elements may also be null
.public static Value bytesArray(@Nullable Iterable<ByteArray> v)
ARRAY<BYTES>
value.v
- the source of element values. This may be null
to produce a value for which
isNull()
is true
. Individual elements may also be null
.public static Value timestampArray(@Nullable Iterable<Timestamp> v)
ARRAY<TIMESTAMP>
value.v
- the source of element values. This may be null
to produce a value for which
isNull()
is true
. Individual elements may also be null
.public static Value dateArray(@Nullable Iterable<Date> v)
ARRAY<DATE>
value. The range [1678-01-01, 2262-01-01) is the legal interval
for cloud spanner dates. A write to a date column is rejected if the value is outside of that
interval.v
- the source of element values. This may be null
to produce a value for which
isNull()
is true
. Individual elements may also be null
.public static Value structArray(Type elementType, @Nullable Iterable<Struct> v)
ARRAY<STRUCT<...>>
value.elementType
- v
- the source of element values. This may be null
to produce a value for which
isNull()
is true
. Individual elements may also be null
.public abstract Type getType()
isNull()
is true.public abstract boolean isNull()
true
if this instance represents a NULL
value.public abstract boolean getBool()
BOOL
-typed instance.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract long getInt64()
INT64
-typed instance.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract double getFloat64()
FLOAT64
-typed instance.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract String getString()
STRING
-typed instance.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract ByteArray getBytes()
BYTES
-typed instance.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract Timestamp getTimestamp()
TIMESTAMP
-typed instance.IllegalStateException
- if isNull()
or the value is not of the expected type or
isCommitTimestamp()
.public abstract boolean isCommitTimestamp()
public abstract Date getDate()
DATE
-typed instance.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract Struct getStruct()
STRUCT
-typed instance.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract List<Boolean> getBoolArray()
ARRAY<BOOL>
-typed instance. While the returned list itself will
never be null
, elements of that list may be null.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract List<Long> getInt64Array()
ARRAY<INT64>
-typed instance. While the returned list itself
will never be null
, elements of that list may be null.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract List<Double> getFloat64Array()
ARRAY<FLOAT64>
-typed instance. While the returned list itself
will never be null
, elements of that list may be null.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract List<String> getStringArray()
ARRAY<STRING>
-typed instance. While the returned list itself
will never be null
, elements of that list may be null.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract List<ByteArray> getBytesArray()
ARRAY<BYTES>
-typed instance. While the returned list itself
will never be null
, elements of that list may be null.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract List<Timestamp> getTimestampArray()
ARRAY<TIMESTAMP>
-typed instance. While the returned list itself
will never be null
, elements of that list may be null.IllegalStateException
- if isNull()
or the value is not of the expected typepublic abstract List<Date> getDateArray()
ARRAY<DATE>
-typed instance. While the returned list itself will
never be null
, elements of that list may be null.IllegalStateException
- if isNull()
or the value is not of the expected typeCopyright © 2019 Google LLC. All rights reserved.