public class TypedValue extends Object
There are 3 representations:
The following table shows the Java type(s) that may represent each SQL type in each representation.
| Type | JDBC | Serial | Local |
|---|---|---|---|
| BOOLEAN | boolean | boolean | boolean |
| BINARY, VARBINARY | byte[] | String (base64) | ByteString |
| DATE | Date |
int | int |
| TIME | Time |
int | int |
| DATE | Timestamp |
long | long |
| CHAR, VARCHAR | String | String | String |
| TINYINT | byte | Number | byte |
| SMALLINT | short | Number | short |
| INTEGER | int | Number | int |
| BIGINT | long | Number | long |
| REAL | float | Number | float |
| FLOAT, DOUBLE | double | Number | double |
| DECIMAL | BigDecimal | Number | BigDecimal |
| ARRAY | Array | List<Object> | List<Object> |
Number in serial format because
JSON numbers are not strongly typed. A float value 3.0 is
transmitted as 3, and is therefore decoded as an int.
Date, Time, Timestamp,
all sub-classes of Date. When they are passed to and
from the server, they are interpreted in terms of a time zone, by default
the current connection's time zone. Their serial and local representations
as int (days since 1970-01-01 for DATE, milliseconds since
00:00:00.000 for TIME), and long (milliseconds since 1970-01-01
00:00:00.000 for TIMESTAMP) are easier to work with, because it is clear
that time zone is not involved.
| Modifier and Type | Field and Description |
|---|---|
private static com.google.protobuf.Descriptors.FieldDescriptor |
BYTES_DESCRIPTOR |
ColumnMetaData.Rep |
componentType
Non-null for ARRAYs, the type of the values stored in the ARRAY.
|
static TypedValue |
EXPLICIT_NULL |
private static com.google.protobuf.Descriptors.FieldDescriptor |
NUMBER_DESCRIPTOR |
static Common.TypedValue |
PROTO_IMPLICIT_NULL |
private static com.google.protobuf.Descriptors.FieldDescriptor |
STRING_DESCRIPTOR |
ColumnMetaData.Rep |
type
Type of the value.
|
Object |
value
Value.
|
| Modifier | Constructor and Description |
|---|---|
private |
TypedValue(ColumnMetaData.Rep rep,
ColumnMetaData.Rep componentType,
Object value) |
private |
TypedValue(ColumnMetaData.Rep rep,
Object value) |
| Modifier and Type | Method and Description |
|---|---|
private static long |
adjust(Number number,
Calendar calendar) |
static TypedValue |
create(String type,
Object value) |
boolean |
equals(Object o) |
static TypedValue |
fromProto(Common.TypedValue proto)
Constructs a
TypedValue from the protocol buffer representation. |
static Object |
getSerialFromProto(Common.TypedValue protoValue)
Converts the serialized value into the appropriate primitive/object.
|
int |
hashCode() |
private boolean |
isSerial(ColumnMetaData.Rep rep,
Object value) |
private static Object |
jdbcToSerial(ColumnMetaData.Rep rep,
Object value,
Calendar calendar) |
private static Object |
jdbcToSerial(ColumnMetaData.Rep rep,
Object value,
Calendar calendar,
SqlType componentType)
Converts a value from JDBC format to a type that can be serialized as
JSON.
|
private static Object |
localToSerial(ColumnMetaData.Rep rep,
Object value)
Converts a value from internal format to a type that can be serialized
as JSON.
|
static TypedValue |
ofJdbc(ColumnMetaData.Rep rep,
Object value,
Calendar calendar)
Creates a TypedValue from a value in JDBC representation.
|
static TypedValue |
ofJdbc(Object value,
Calendar calendar)
Creates a TypedValue from a value in JDBC representation,
deducing its type.
|
static TypedValue |
ofLocal(ColumnMetaData.Rep rep,
Object value)
Creates a TypedValue from a value in local representation.
|
static TypedValue |
ofSerial(ColumnMetaData.Rep rep,
Object value)
Creates a TypedValue from a value in serial representation.
|
static Object |
protoToJdbc(Common.TypedValue protoValue,
Calendar calendar)
Extracts the JDBC value from protobuf-TypedValue representation.
|
(package private) Common.TypedValue |
serializeArray(List<Object> list,
Common.TypedValue.Builder builder,
Common.Rep protoArrayComponentRep) |
private static Object |
serialToJdbc(ColumnMetaData.Rep type,
ColumnMetaData.Rep componentRep,
Object value,
Calendar calendar)
Converts the given value from serial form to JDBC form.
|
private static Object |
serialToLocal(ColumnMetaData.Rep rep,
Object value)
Converts a value to the exact type required for the given
representation.
|
Object |
toJdbc(Calendar calendar)
Converts the value into the JDBC representation.
|
Object |
toLocal()
Converts the value into the local representation.
|
Common.TypedValue |
toProto()
Creates a protocol buffer equivalent object for
this. |
static Common.Rep |
toProto(Common.TypedValue.Builder builder,
Object o)
Writes the given object into the Protobuf representation of a TypedValue.
|
static List<Object> |
values(List<TypedValue> typedValues)
Converts a list of
TypedValue to a list of values. |
private static void |
writeToProtoWithType(Common.TypedValue.Builder builder,
Object o,
Common.Rep type) |
private static final com.google.protobuf.Descriptors.FieldDescriptor NUMBER_DESCRIPTOR
private static final com.google.protobuf.Descriptors.FieldDescriptor STRING_DESCRIPTOR
private static final com.google.protobuf.Descriptors.FieldDescriptor BYTES_DESCRIPTOR
public static final TypedValue EXPLICIT_NULL
public static final Common.TypedValue PROTO_IMPLICIT_NULL
public final ColumnMetaData.Rep type
public final Object value
Always in a form that can be serialized to JSON by Jackson. For example, byte arrays are represented as String.
public final ColumnMetaData.Rep componentType
private TypedValue(ColumnMetaData.Rep rep, Object value)
private TypedValue(ColumnMetaData.Rep rep, ColumnMetaData.Rep componentType, Object value)
private boolean isSerial(ColumnMetaData.Rep rep, Object value)
public static TypedValue create(String type, Object value)
public static TypedValue ofLocal(ColumnMetaData.Rep rep, Object value)
public static TypedValue ofSerial(ColumnMetaData.Rep rep, Object value)
public static TypedValue ofJdbc(ColumnMetaData.Rep rep, Object value, Calendar calendar)
public static TypedValue ofJdbc(Object value, Calendar calendar)
public Object toLocal()
For example, a byte string is represented as a ByteString;
a long is represented as a Long (not just some Number).
private static Object serialToLocal(ColumnMetaData.Rep rep, Object value)
public Object toJdbc(Calendar calendar)
For example, a byte string is represented as a ByteString;
a long is represented as a Long (not just some Number).
private static Object serialToJdbc(ColumnMetaData.Rep type, ColumnMetaData.Rep componentRep, Object value, Calendar calendar)
type - The type of the valuevalue - The valuecalendar - A calendar instanceprivate static Object jdbcToSerial(ColumnMetaData.Rep rep, Object value, Calendar calendar)
private static Object jdbcToSerial(ColumnMetaData.Rep rep, Object value, Calendar calendar, SqlType componentType)
private static Object localToSerial(ColumnMetaData.Rep rep, Object value)
public static List<Object> values(List<TypedValue> typedValues)
TypedValue to a list of values.public Common.TypedValue toProto()
this.thisCommon.TypedValue serializeArray(List<Object> list, Common.TypedValue.Builder builder, Common.Rep protoArrayComponentRep)
private static void writeToProtoWithType(Common.TypedValue.Builder builder, Object o, Common.Rep type)
public static TypedValue fromProto(Common.TypedValue proto)
TypedValue from the protocol buffer representation.proto - The protobuf TypedvalueTypedValue instancepublic static Object getSerialFromProto(Common.TypedValue protoValue)
protoValue - The serialized TypedValue.public static Common.Rep toProto(Common.TypedValue.Builder builder, Object o)
builder - The TypedValue protobuf buildero - The object (value)public static Object protoToJdbc(Common.TypedValue protoValue, Calendar calendar)
protoValue - Protobuf TypedValuecalendar - Instance of a calendarCopyright © 2012–2017 The Apache Software Foundation. All rights reserved.