Package org.h2.value
Class Value
- Direct Known Subclasses:
SearchRow,SpatialKey,ValueBigint,ValueBinary,ValueBoolean,ValueChar,ValueCollectionBase,ValueDate,ValueDecfloat,ValueDouble,ValueEnumBase,ValueGeometry,ValueInteger,ValueInterval,ValueJavaObject,ValueJson,ValueLob,ValueNull,ValueNumeric,ValueReal,ValueSmallint,ValueTime,ValueTimestamp,ValueTimestampTimeZone,ValueTimeTimeZone,ValueTinyint,ValueUuid,ValueVarbinary,ValueVarchar,ValueVarcharIgnoreCase
This is the base class for all value classes.
It provides conversion and comparison methods.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe value type for ARRAY values.static final intCast a value to the specified type for assignment.static final intThe value type for BIGINT values.static final intThe value type for BINARY values.static final intThe value type for BINARY LARGE OBJECT values.static final intThe value type for BOOLEAN values.static final intCast a value to the specified type.static final intThe value type for CHARACTER values.static final intThe value type for CHARACTER LARGE OBJECT values.static final intConvert a value to the specified type without taking scale and precision into account.static final intThe value type for DATE values.static final intThe value type for DECFLOAT values.static final intThe value type for DOUBLE PRECISION values.static final Value[]Empty array of values.static final intThe value type for ENUM values.static final intThe value type for string values with a fixed size.static final intThe value type for INTEGER values.static final intThe value type forINTERVAL DAYvalues.static final intThe value type forINTERVAL DAY TO HOURvalues.static final intThe value type forINTERVAL DAY TO MINUTEvalues.static final intThe value type forINTERVAL DAY TO SECONDvalues.static final intThe value type forINTERVAL HOURvalues.static final intThe value type forINTERVAL HOUR TO MINUTEvalues.static final intThe value type forINTERVAL HOUR TO SECONDvalues.static final intThe value type forINTERVAL MINUTEvalues.static final intThe value type forINTERVAL MINUTE TO SECONDvalues.static final intThe value type forINTERVAL MONTHvalues.static final intThe value type forINTERVAL SECONDvalues.static final intThe value type forINTERVAL YEARvalues.static final intThe value type forINTERVAL YEAR TO MONTHvalues.static final intThe value type for JAVA_OBJECT values.static final intThe value type for JSON values.static final BigDecimalThe largest BIGINT value, as a BigDecimal.static final BigDecimalThe smallest BIGINT value, as a BigDecimal.static final intThe value type for NULL.static final intThe value type for NUMERIC values.static final intThe value type for REAL values.static final intThe value type for ROW values.static final intThe value type for SMALLINT values.static final intThe value type for TIME values.static final intThe value type for TIME WITH TIME ZONE values.static final intThe value type for TIMESTAMP values.static final intThe value type for TIMESTAMP WITH TIME ZONE values.static final intThe value type for TINYINT values.static final intThe number of value types.static final intThe data type is unknown at this time.static final intThe value type for UUID values.static final intThe value type for BINARY VARYING values.static final intThe value type for CHARACTER VARYING values.static final intThe value type for VARCHAR_IGNORECASE values.Fields inherited from interface org.h2.util.HasSQL
ADD_PLAN_INFORMATION, DEFAULT_SQL_FLAGS, NO_CASTS, QUOTE_ONLY_WHEN_REQUIRED, REPLACE_LOBS_FOR_TRACE, TRACE_SQL_FLAGS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd a value and return the result.final ValuecastTo(TypeInfo targetType, CastDataProvider provider) Cast a value to the specified type.longReturns length of this value in characters.static voidClear the value cache.final intcompareTo(Value v, CastDataProvider provider, CompareMode compareMode) Compare this value against another value using the specified compare mode.abstract intcompareTypeSafe(Value v, CompareMode mode, CastDataProvider provider) Compare this value against another value given that the values are of the same data type.intcompareWithNull(Value v, boolean forEquality, CastDataProvider provider, CompareMode compareMode) Compare this value against another value using the specified compare mode.booleanReturns true if this value is NULL or contains NULL value.final ValueconvertForAssignTo(TypeInfo targetType, CastDataProvider provider, Object column) Cast a value to the specified type for assignment.final ValueconvertTo(int targetType) Convert a value to the specified type without taking scale and precision into account.final ValueconvertTo(int targetType, CastDataProvider provider) Convert a value to the specified type without taking scale and precision into account.final ValueConvert a value to the specified type without taking scale and precision into account.final ValueconvertTo(TypeInfo targetType, CastDataProvider provider) Convert a value to the specified type without taking scale and precision into account.final ValueconvertTo(TypeInfo targetType, CastDataProvider provider, Object column) Convert a value to the specified type without taking scale and precision into account.final ValueArrayconvertToAnyArray(CastDataProvider provider) Convert this value to any ARRAY data type.final ValueJsonConvert this value to JSON data type.final ValueRowConvert this value to any ROW data type.final ValueBigintconvertToBigint(Object column) Converts this value to a BIGINT value.final ValueBooleanConverts this value to a BOOLEAN value.Converts this value to a CHAR value.final ValueDateconvertToDate(CastDataProvider provider) Converts this value to a DATE value.final ValueDoubleConverts this value to a DOUBLE value.final ValueEnumconvertToEnum(ExtTypeInfoEnum extTypeInfo, CastDataProvider provider) Converts this value to an ENUM value.final ValueGeometryconvertToGeometry(ExtTypeInfoGeometry extTypeInfo) Converts this value to a GEOMETRY value.static intconvertToInt(long x, Object column) Convert to integer, throwing exception if out of range.final ValueIntegerconvertToInt(Object column) Converts this value to INT value.final ValueJavaObjectconvertToJavaObject(TypeInfo targetType, int conversionMode, Object column) Converts this value to a JAVA_OBJECT value.convertToJson(TypeInfo targetType, int conversionMode, Object column) Converts this value to a JSON value.static longconvertToLong(BigDecimal x, Object column) Convert to long, throwing exception if out of range.final ValueRealConverts this value to a REAL value.final ValueSmallintconvertToSmallint(Object column) Converts this value to a SMALLINT value.final ValueTinyintconvertToTinyint(Object column) Converts this value to a TINYINT value.final ValueUuidConverts this value to a UUID value.Divide by a value and return the result.abstract booleanCheck if the two values have the same hash code.booleanReturns this value as a Javabooleanvalue.bytegetByte()Returns this value as a Javabytevalue.byte[]getBytes()byte[]doubleReturns this value as a Javadoublevalue.floatgetFloat()Returns this value as a Javafloatvalue.static intgetHigherOrder(int t1, int t2) Get the higher value order type of two value types.getInputStream(long oneBasedOffset, long length) Get the input streamintgetInt()Returns this value as a Javaintvalue.longgetLong()Returns this value as a Javalongvalue.intGet the memory used by this object.getReader(long oneBasedOffset, long length) Get the readershortgetShort()Returns this value as a Javashortvalue.intabstract StringGet the value as a string.abstract TypeInfogetType()Returns the data type.static StringgetTypeName(int valueType) Returns name of the specified data type.protected final DbExceptionCreate an exception meaning the specified operation is not supported for this data type.abstract intGet the value type.Scans this and specified values until a first NULL occurrence and returns a value where NULL appears earlier, ornullif these two values have first NULL on the same position.abstract inthashCode()final booleanisFalse()Returns whether this valueIS FALSE.final booleanisTrue()Returns whether this valueIS TRUE.Take the modulus with a value and return the result.Multiply with a value and return the result.negate()Return -value if this value support arithmetic operations.longReturns length of this value in bytes.Subtract a value and return the result.toString()Methods inherited from class org.h2.value.VersionedValue
getCommittedValue, getCurrentValue, getOperationId, isCommittedMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.h2.util.HasSQL
getSQL, getSQL, getTraceSQL
-
Field Details
-
UNKNOWN
public static final int UNKNOWNThe data type is unknown at this time.- See Also:
-
NULL
public static final int NULLThe value type for NULL.- See Also:
-
CHAR
public static final int CHARThe value type for CHARACTER values.- See Also:
-
VARCHAR
public static final int VARCHARThe value type for CHARACTER VARYING values.- See Also:
-
CLOB
public static final int CLOBThe value type for CHARACTER LARGE OBJECT values.- See Also:
-
VARCHAR_IGNORECASE
public static final int VARCHAR_IGNORECASEThe value type for VARCHAR_IGNORECASE values.- See Also:
-
BINARY
public static final int BINARYThe value type for BINARY values.- See Also:
-
VARBINARY
public static final int VARBINARYThe value type for BINARY VARYING values.- See Also:
-
BLOB
public static final int BLOBThe value type for BINARY LARGE OBJECT values.- See Also:
-
BOOLEAN
public static final int BOOLEANThe value type for BOOLEAN values.- See Also:
-
TINYINT
public static final int TINYINTThe value type for TINYINT values.- See Also:
-
SMALLINT
public static final int SMALLINTThe value type for SMALLINT values.- See Also:
-
INTEGER
public static final int INTEGERThe value type for INTEGER values.- See Also:
-
BIGINT
public static final int BIGINTThe value type for BIGINT values.- See Also:
-
NUMERIC
public static final int NUMERICThe value type for NUMERIC values.- See Also:
-
REAL
public static final int REALThe value type for REAL values.- See Also:
-
DOUBLE
public static final int DOUBLEThe value type for DOUBLE PRECISION values.- See Also:
-
DECFLOAT
public static final int DECFLOATThe value type for DECFLOAT values.- See Also:
-
DATE
public static final int DATEThe value type for DATE values.- See Also:
-
TIME
public static final int TIMEThe value type for TIME values.- See Also:
-
TIME_TZ
public static final int TIME_TZThe value type for TIME WITH TIME ZONE values.- See Also:
-
TIMESTAMP
public static final int TIMESTAMPThe value type for TIMESTAMP values.- See Also:
-
TIMESTAMP_TZ
public static final int TIMESTAMP_TZThe value type for TIMESTAMP WITH TIME ZONE values.- See Also:
-
INTERVAL_YEAR
public static final int INTERVAL_YEARThe value type forINTERVAL YEARvalues.- See Also:
-
INTERVAL_MONTH
public static final int INTERVAL_MONTHThe value type forINTERVAL MONTHvalues.- See Also:
-
INTERVAL_DAY
public static final int INTERVAL_DAYThe value type forINTERVAL DAYvalues.- See Also:
-
INTERVAL_HOUR
public static final int INTERVAL_HOURThe value type forINTERVAL HOURvalues.- See Also:
-
INTERVAL_MINUTE
public static final int INTERVAL_MINUTEThe value type forINTERVAL MINUTEvalues.- See Also:
-
INTERVAL_SECOND
public static final int INTERVAL_SECONDThe value type forINTERVAL SECONDvalues.- See Also:
-
INTERVAL_YEAR_TO_MONTH
public static final int INTERVAL_YEAR_TO_MONTHThe value type forINTERVAL YEAR TO MONTHvalues.- See Also:
-
INTERVAL_DAY_TO_HOUR
public static final int INTERVAL_DAY_TO_HOURThe value type forINTERVAL DAY TO HOURvalues.- See Also:
-
INTERVAL_DAY_TO_MINUTE
public static final int INTERVAL_DAY_TO_MINUTEThe value type forINTERVAL DAY TO MINUTEvalues.- See Also:
-
INTERVAL_DAY_TO_SECOND
public static final int INTERVAL_DAY_TO_SECONDThe value type forINTERVAL DAY TO SECONDvalues.- See Also:
-
INTERVAL_HOUR_TO_MINUTE
public static final int INTERVAL_HOUR_TO_MINUTEThe value type forINTERVAL HOUR TO MINUTEvalues.- See Also:
-
INTERVAL_HOUR_TO_SECOND
public static final int INTERVAL_HOUR_TO_SECONDThe value type forINTERVAL HOUR TO SECONDvalues.- See Also:
-
INTERVAL_MINUTE_TO_SECOND
public static final int INTERVAL_MINUTE_TO_SECONDThe value type forINTERVAL MINUTE TO SECONDvalues.- See Also:
-
JAVA_OBJECT
public static final int JAVA_OBJECTThe value type for JAVA_OBJECT values.- See Also:
-
ENUM
public static final int ENUMThe value type for ENUM values.- See Also:
-
GEOMETRY
public static final int GEOMETRYThe value type for string values with a fixed size.- See Also:
-
JSON
public static final int JSONThe value type for JSON values.- See Also:
-
UUID
public static final int UUIDThe value type for UUID values.- See Also:
-
ARRAY
public static final int ARRAYThe value type for ARRAY values.- See Also:
-
ROW
public static final int ROWThe value type for ROW values.- See Also:
-
TYPE_COUNT
public static final int TYPE_COUNTThe number of value types.- See Also:
-
EMPTY_VALUES
Empty array of values. -
MAX_LONG_DECIMAL
The largest BIGINT value, as a BigDecimal. -
MIN_LONG_DECIMAL
The smallest BIGINT value, as a BigDecimal. -
CONVERT_TO
public static final int CONVERT_TOConvert a value to the specified type without taking scale and precision into account.- See Also:
-
CAST_TO
public static final int CAST_TOCast a value to the specified type. The scale is set if applicable. The value is truncated to a required precision.- See Also:
-
ASSIGN_TO
public static final int ASSIGN_TOCast a value to the specified type for assignment. The scale is set if applicable. If precision is too large an exception is thrown.- See Also:
-
-
Constructor Details
-
Value
public Value()
-
-
Method Details
-
getTypeName
Returns name of the specified data type.- Parameters:
valueType- the value type- Returns:
- the name
-
getType
Description copied from interface:TypedReturns the data type. -
getValueType
public abstract int getValueType()Get the value type.- Returns:
- the value type
-
getMemory
public int getMemory()Get the memory used by this object.- Returns:
- the memory used in bytes
-
hashCode
public abstract int hashCode() -
equals
Check if the two values have the same hash code. No data conversion is made; this method returns false if the other object is not of the same class. For some values, compareTo may return 0 even if equals return false. Example: ValueDecimal 0.0 and 0.00. -
getHigherOrder
public static int getHigherOrder(int t1, int t2) Get the higher value order type of two value types. If values need to be converted to match the other operands value type, the value with the lower order is converted to the value with the higher order.- Parameters:
t1- the first value typet2- the second value type- Returns:
- the higher value type of the two
-
clearCache
public static void clearCache()Clear the value cache. Used for testing. -
getString
Get the value as a string.- Returns:
- the string
-
getReader
-
getReader
Get the reader- Parameters:
oneBasedOffset- the offset (1 means no offset)length- the requested length- Returns:
- the new reader
-
getBytes
public byte[] getBytes() -
getBytesNoCopy
public byte[] getBytesNoCopy() -
getInputStream
-
getInputStream
Get the input stream- Parameters:
oneBasedOffset- the offset (1 means no offset)length- the requested length- Returns:
- the new input stream
-
getBoolean
public boolean getBoolean()Returns this value as a Javabooleanvalue.- Returns:
- value
- Throws:
DbException- if this value isNULLor cannot be cast toBOOLEAN- See Also:
-
getByte
public byte getByte()Returns this value as a Javabytevalue.- Returns:
- value
- Throws:
DbException- if this value isNULLor cannot be cast toTINYINT
-
getShort
public short getShort()Returns this value as a Javashortvalue.- Returns:
- value
- Throws:
DbException- if this value isNULLor cannot be cast toSMALLINT
-
getInt
public int getInt()Returns this value as a Javaintvalue.- Returns:
- value
- Throws:
DbException- if this value isNULLor cannot be cast toINTEGER
-
getLong
public long getLong()Returns this value as a Javalongvalue.- Returns:
- value
- Throws:
DbException- if this value isNULLor cannot be cast toBIGINT
-
getBigInteger
-
getBigDecimal
-
getFloat
public float getFloat()Returns this value as a Javafloatvalue.- Returns:
- value
- Throws:
DbException- if this value isNULLor cannot be cast toREAL
-
getDouble
public double getDouble()Returns this value as a Javadoublevalue.- Returns:
- value
- Throws:
DbException- if this value isNULLor cannot be cast toDOUBLE PRECISION
-
add
Add a value and return the result.- Parameters:
v- the value to add- Returns:
- the result
-
getSignum
public int getSignum() -
negate
Return -value if this value support arithmetic operations.- Returns:
- the negative
-
subtract
Subtract a value and return the result.- Parameters:
v- the value to subtract- Returns:
- the result
-
divide
Divide by a value and return the result.- Parameters:
v- the divisorquotientType- the type of quotient (used only to read precision and scale when applicable)- Returns:
- the result
-
multiply
Multiply with a value and return the result.- Parameters:
v- the value to multiply with- Returns:
- the result
-
modulus
Take the modulus with a value and return the result.- Parameters:
v- the value to take the modulus with- Returns:
- the result
-
convertTo
Convert a value to the specified type without taking scale and precision into account.- Parameters:
targetType- the type of the returned value- Returns:
- the converted value
-
convertTo
Convert a value to the specified type without taking scale and precision into account.- Parameters:
targetType- the type of the returned value- Returns:
- the converted value
-
convertTo
Convert a value to the specified type without taking scale and precision into account.- Parameters:
targetType- the type of the returned valueprovider- the cast information provider- Returns:
- the converted value
-
convertTo
Convert a value to the specified type without taking scale and precision into account.- Parameters:
targetType- the type of the returned valueprovider- the cast information provider- Returns:
- the converted value
-
convertTo
Convert a value to the specified type without taking scale and precision into account.- Parameters:
targetType- the type of the returned valueprovider- the cast information providercolumn- the column, used to improve the error message if conversion fails- Returns:
- the converted value
-
convertToAnyJson
Convert this value to JSON data type.- Returns:
- a JSON value
-
convertToAnyArray
Convert this value to any ARRAY data type.- Parameters:
provider- the cast information provider- Returns:
- a row value
-
convertToAnyRow
Convert this value to any ROW data type.- Returns:
- a row value
-
castTo
Cast a value to the specified type. The scale is set if applicable. The value is truncated to the required precision.- Parameters:
targetType- the type of the returned valueprovider- the cast information provider- Returns:
- the converted value
-
convertForAssignTo
public final Value convertForAssignTo(TypeInfo targetType, CastDataProvider provider, Object column) Cast a value to the specified type for assignment. The scale is set if applicable. If precision is too large an exception is thrown.- Parameters:
targetType- the type of the returned valueprovider- the cast information providercolumn- the column, used to improve the error message if conversion fails- Returns:
- the converted value
-
convertToChar
Converts this value to a CHAR value. May not be called on a NULL value.- Returns:
- a CHAR value.
-
convertToBoolean
Converts this value to a BOOLEAN value. May not be called on a NULL value.- Returns:
- the BOOLEAN value
-
convertToTinyint
Converts this value to a TINYINT value. May not be called on a NULL value.- Parameters:
column- the column, used for to improve the error message if conversion fails- Returns:
- the TINYINT value
-
convertToSmallint
Converts this value to a SMALLINT value. May not be called on a NULL value.- Parameters:
column- the column, used for to improve the error message if conversion fails- Returns:
- the SMALLINT value
-
convertToInt
Converts this value to INT value. May not be called on a NULL value.- Parameters:
column- the column, used for to improve the error message if conversion fails- Returns:
- the INT value
-
convertToBigint
Converts this value to a BIGINT value. May not be called on a NULL value.- Parameters:
column- the column, used for to improve the error message if conversion fails- Returns:
- the BIGINT value
-
convertToReal
Converts this value to a REAL value. May not be called on a NULL value.- Returns:
- the REAL value
-
convertToDouble
Converts this value to a DOUBLE value. May not be called on a NULL value.- Returns:
- the DOUBLE value
-
convertToDate
Converts this value to a DATE value. May not be called on a NULL value.- Parameters:
provider- the cast information provider- Returns:
- the DATE value
-
convertToJavaObject
public final ValueJavaObject convertToJavaObject(TypeInfo targetType, int conversionMode, Object column) Converts this value to a JAVA_OBJECT value. May not be called on a NULL value.- Parameters:
targetType- the type of the returned valueconversionMode- conversion modecolumn- the column (if any), used to improve the error message if conversion fails- Returns:
- the JAVA_OBJECT value
-
convertToEnum
Converts this value to an ENUM value. May not be called on a NULL value.- Parameters:
extTypeInfo- the extended data type informationprovider- the cast information provider- Returns:
- the ENUM value
-
convertToGeometry
Converts this value to a GEOMETRY value. May not be called on a NULL value.- Parameters:
extTypeInfo- the extended data type information, or null- Returns:
- the GEOMETRY value
-
convertToJson
Converts this value to a JSON value. May not be called on a NULL value.- Parameters:
targetType- the type of the returned valueconversionMode- conversion modecolumn- the column (if any), used to improve the error message if conversion fails- Returns:
- the JSON value
-
convertToUuid
Converts this value to a UUID value. May not be called on a NULL value.- Returns:
- the UUID value
-
compareTypeSafe
Compare this value against another value given that the values are of the same data type.- Parameters:
v- the other valuemode- the compare modeprovider- the cast information provider- Returns:
- 0 if both values are equal, -1 if the other value is smaller, and 1 otherwise
-
compareTo
Compare this value against another value using the specified compare mode.- Parameters:
v- the other valueprovider- the cast information providercompareMode- the compare mode- Returns:
- 0 if both values are equal, -1 if this value is smaller, and 1 otherwise
-
compareWithNull
public int compareWithNull(Value v, boolean forEquality, CastDataProvider provider, CompareMode compareMode) Compare this value against another value using the specified compare mode.- Parameters:
v- the other valueforEquality- perform only check for equalityprovider- the cast information providercompareMode- the compare mode- Returns:
- 0 if both values are equal, -1 if this value is smaller, 1
if other value is larger,
Integer.MIN_VALUEif order is not defined due to NULL comparison
-
containsNull
public boolean containsNull()Returns true if this value is NULL or contains NULL value.- Returns:
- true if this value is NULL or contains NULL value
-
getValueWithFirstNull
Scans this and specified values until a first NULL occurrence and returns a value where NULL appears earlier, ornullif these two values have first NULL on the same position.- Parameters:
v- a value of the same data type as this value, must be neither equal to nor smaller than nor greater than this value- Returns:
- this value, the specified value, or
null
-
convertToInt
Convert to integer, throwing exception if out of range.- Parameters:
x- integer value.column- Column info.- Returns:
- x
-
convertToLong
Convert to long, throwing exception if out of range.- Parameters:
x- long value.column- Column info.- Returns:
- x
-
toString
-
getUnsupportedExceptionForOperation
Create an exception meaning the specified operation is not supported for this data type.- Parameters:
op- the operation- Returns:
- the exception
-
charLength
public long charLength()Returns length of this value in characters.- Returns:
- length of this value in characters
- Throws:
NullPointerException- if this value isNULL
-
octetLength
public long octetLength()Returns length of this value in bytes.- Returns:
- length of this value in bytes
- Throws:
NullPointerException- if this value isNULL
-
isTrue
public final boolean isTrue()Returns whether this valueIS TRUE.- Returns:
trueif it is. ForBOOLEANvalues returnstrueforTRUEandfalseforFALSEandUNKNOWN(NULL).- See Also:
-
isFalse
public final boolean isFalse()Returns whether this valueIS FALSE.- Returns:
trueif it is. ForBOOLEANvalues returnstrueforFALSEandfalseforTRUEandUNKNOWN(NULL).- See Also:
-