JDBC Driver - TypedValue

org.polypheny.jdbc.types.TypedValue wraps a Prism value. You get it from PolyRow.getValue or a field of a PolyDocument. Its conversion methods follow the driver’s type conversion rules. Use a conversion that matches the data type you expect.

Inspecting and reading values

  • getValueCase() exposes the value’s Prism type. isNull() distinguishes a Prism null from a non-null value. Check isNull() before converting to a primitive. A primitive conversion can return a default such as zero for a null.
  • asObject() returns the driver’s natural Java type, such as Integer, Long, String, byte[], java.sql.Array, PolyDocument, PolyInterval, or null. The Calendar overload uses the calendar for temporal values.
  • Use asObject(Class<T>) with Array.class, PolyDocument.class, or the Java class of a graph value. Use the type map overload for user-defined type mappings.
  • getLength() returns a string’s length or the number of binary bytes, and returns zero for other types. getTrimmed(int) is a driver utility for taking a prefix of a materialized string or binary value. isUdt() currently returns false.
  • toString() delegates to asString() and wraps a conversion failure in RuntimeException. For database values, call the typed method directly to handle conversion errors as SQL exceptions.

Conversions and factories

Value Read with Construct with
Boolean asBoolean fromBoolean
Integers asByte, asShort, asInt, asLong fromByte, fromShort, fromInteger, fromLong
Floating-point and decimal asFloat, asDouble, asBigDecimal, asBigDecimal(int scale) fromFloat, fromDouble, fromBigDecimal
Text asString, asNString, asCharacterStream, asNCharacterStream fromString, fromNString, fromCharacterStream, fromNCharacterStream
Binary and streams asBytes, asAsciiStream, asBinaryStream, asUnicodeStream fromBytes, fromAsciiStream, fromBinaryStream, fromUnicodeStream
Large objects asBlob, asClob, asNClob fromBlob, fromClob, fromNClob
Date and time asDate, asTime, asTimestamp, with optional Calendar fromDate, fromTime, fromTimestamp, with optional Calendar
Collection and document asArray, asDocument fromArray, fromDocument
Interval asInterval fromInterval
Generic or null asObject, isNull fromObject(Object), fromObject(Object, int targetSqlType), fromNull

The stream and large-object factories have overloads for streams or readers and optional lengths. They can buffer their inputs in memory. Use the length-free overloads unless an API requires a length.

fromRef, fromUrl, fromRowId, fromSQLXML, fromStruct, and fromObject(Object, int, int) are unsupported. The matching asRef, asUrl, asSQLXML, and asStruct readers fail with a type mismatch. asRowId can return null for a Prism null but the driver does not map a result value to a row ID.

Graph values

Use these readers for graph-valued cells returned in a Cypher result.

Prism value Java type Reader
NODE PolyNode asNode()
EDGE PolyEdge asEdge()
PATH PolyPath asPath()
GRAPH PolyGraph asGraph()

asObject() returns the corresponding Java type. You can also supply the matching class to asObject(Class<T>). Graph readers return null for a Prism null and raise a SQL exception for a value of another type.

When a result contains graph values inside a document, call asDocument() and read the fields as typed values. For a list, call asArray() and use Array.getArray() or Array.getResultSet() to read its entries.

Protocol types

TypedValue(ProtoValue) wraps a value from the driver’s bundled Prism classes and serialize() builds a Prism ProtoValue. See the in-memory document example for a round trip.

To represent an interval, PolyInterval(long months, long milliseconds) stores the calendar and elapsed-time components separately. getMonths() and getMilliseconds() return those components, equals(Object) compares both, and toString() formats them for display.

The JDBC driver source repository contains the full TypedValue API.

© Polypheny GmbH. All Rights Reserved.