org.h2.value

## Class Value

- java.lang.Object
- - org.h2.value.VersionedValue
  - - org.h2.value.Value

Direct Known Subclasses:
  ValueBoolean, ValueByte, ValueBytes, ValueCollectionBase, ValueDate, ValueDecimal, ValueDouble, ValueEnumBase, ValueFloat, ValueGeometry, ValueInt, ValueInterval, ValueLob, ValueLobDb, ValueLong, ValueNull, ValueResultSet, ValueShort, ValueString, ValueTime, ValueTimestamp, ValueTimestampTimeZone, ValueUuid

    public abstract class Value
    extends VersionedValue

This is the base class for all value classes. It provides conversion and comparison methods.

### Field Summary

Fields
`static int` `ARRAY` The value type for ARRAY values.
`static int` `BLOB` The value type for BLOB values.
`static int` `BOOLEAN` The value type for BOOLEAN values.
`static int` `BYTE` The value type for BYTE values.
`static int` `BYTES` The value type for BYTES values.
`static int` `CLOB` The value type for CLOB values.
`static int` `DATE` The value type for DATE values.
`static int` `DECIMAL` The value type for DECIMAL values.
`static int` `DOUBLE` The value type for DOUBLE values.
`static int` `ENUM` The value type for ENUM values.
`static int` `FLOAT` The value type for FLOAT values.
`static int` `GEOMETRY` The value type for string values with a fixed size.
`static int` `INT` The value type for INT values.
`static int` `INTERVAL_DAY` The value type for `INTERVAL DAY` values.
`static int` `INTERVAL_DAY_TO_HOUR` The value type for `INTERVAL DAY TO HOUR` values.
`static int` `INTERVAL_DAY_TO_MINUTE` The value type for `INTERVAL DAY TO MINUTE` values.
`static int` `INTERVAL_DAY_TO_SECOND` The value type for `INTERVAL DAY TO SECOND` values.
`static int` `INTERVAL_HOUR` The value type for `INTERVAL HOUR` values.
`static int` `INTERVAL_HOUR_TO_MINUTE` The value type for `INTERVAL HOUR TO MINUTE` values.
`static int` `INTERVAL_HOUR_TO_SECOND` The value type for `INTERVAL HOUR TO SECOND` values.
`static int` `INTERVAL_MINUTE` The value type for `INTERVAL MINUTE` values.
`static int` `INTERVAL_MINUTE_TO_SECOND` The value type for `INTERVAL MINUTE TO SECOND` values.
`static int` `INTERVAL_MONTH` The value type for `INTERVAL MONTH` values.
`static int` `INTERVAL_SECOND` The value type for `INTERVAL SECOND` values.
`static int` `INTERVAL_YEAR` The value type for `INTERVAL YEAR` values.
`static int` `INTERVAL_YEAR_TO_MONTH` The value type for `INTERVAL YEAR TO MONTH` values.
`static int` `JAVA_OBJECT` The value type for JAVA_OBJECT values.
`static int` `LONG` The value type for LONG values.
`static java.math.BigDecimal` `MIN_LONG_DECIMAL` The smallest Long value, as a BigDecimal.
`static int` `NULL` The value type for NULL.
`static int` `RESULT_SET` The value type for RESULT_SET values.
`static int` `ROW` The value type for ROW values.
`static int` `SHORT` The value type for SHORT values.
`static int` `STRING` The value type for STRING values.
`static int` `STRING_FIXED` The value type for string values with a fixed size.
`static int` `STRING_IGNORECASE` The value type for case insensitive STRING values.
`static int` `TIME` The value type for TIME values.
`static int` `TIMESTAMP` The value type for TIMESTAMP values.
`static int` `TIMESTAMP_TZ` The value type for TIMESTAMP WITH TIME ZONE values.
`static int` `TYPE_COUNT` The number of value types.
`static int` `UNKNOWN` The data type is unknown at this time.
`static int` `UUID` The value type for UUID values.

### Fields inherited from class org.h2.value.VersionedValue

`DUMMY`

### Constructor Summary

Constructors
Constructor and Description
`Value()`

### Method Summary

Methods
`Value` `add(Value v)` Add a value and return the result.
`boolean` `checkPrecision(long precision)` Check if the precision is smaller or equal than the given precision.
`static void` `clearCache()` Clear the value cache.
`int` `compareTo(Value v, Mode databaseMode, CompareMode compareMode)` Compare this value against another value using the specified compare mode.
`abstract int` `compareTypeSafe(Value v, CompareMode mode)` Compare this value against another value given that the values are of the same data type.
`int` `compareWithNull(Value v, boolean forEquality, Mode databaseMode, CompareMode compareMode)` Compare this value against another value using the specified compare mode.
`boolean` `containsNull()` Returns true if this value is NULL or contains NULL value.
`Value` `convertPrecision(long precision, boolean force)` Convert the precision to the requested value.
`Value` `convertScale(boolean onlyToSmallerScale, int targetScale)` Convert the scale.
`Value` `convertTo(int targetType)` Compare a value to the specified type.
`Value` `convertTo(int targetType, Mode mode)` Convert a value to the specified type.
`protected Value` `convertTo(int targetType, Mode mode, java.lang.Object column, ExtTypeInfo extTypeInfo)` Convert a value to the specified type.
`Value` `convertTo(TypeInfo targetType, Mode mode, java.lang.Object column)` Convert a value to the specified type.
`static int` `convertToInt(long x, java.lang.Object column)` Convert to integer, throwing exception if out of range.
`Value` `copy(DataHandler handler, int tableId)` Copy a large value, to be used in the given table.
`Value` `copyToResult()` Create an independent copy of this value if needed, that will be bound to a result.
`Value` `copyToTemp()` Copy this value to a temporary file if necessary.
`Value` `divide(Value v)` Divide by a value and return the result.
`abstract boolean` `equals(java.lang.Object other)` Check if the two values have the same hash code.
`java.math.BigDecimal` `getBigDecimal()`
`boolean` `getBoolean()`
`byte` `getByte()`
`byte[]` `getBytes()`
`byte[]` `getBytesNoCopy()`
`protected DataHandler` `getDataHandler()` Return the data handler for the values that support it (actually only Java objects).
`java.sql.Date` `getDate()`
`double` `getDouble()`
`float` `getFloat()`
`static int` `getHigherOrder(int t1, int t2)` Get the higher value order type of two value types.
`static TypeInfo` `getHigherType(TypeInfo type1, TypeInfo type2)` Get the higher data type of two data types.
`java.io.InputStream` `getInputStream()`
`java.io.InputStream` `getInputStream(long oneBasedOffset, long length)` Get the input stream
`int` `getInt()`
`long` `getLong()`
`int` `getMemory()` Get the memory used by this object.
`abstract java.lang.Object` `getObject()` Get the value as an object.
`java.io.Reader` `getReader()`
`java.io.Reader` `getReader(long oneBasedOffset, long length)` Get the reader
`ResultInterface` `getResult()` Returns result for result set value, or single-row result with this value in column X for other values.
`short` `getShort()`
`int` `getSignum()`
`byte[]` `getSmall()` Get the byte array.
`java.lang.String` `getSQL()` Get the SQL expression for this value.
`abstract java.lang.StringBuilder` `getSQL(java.lang.StringBuilder builder)` Appends the SQL expression for this value to the specified builder.
`abstract java.lang.String` `getString()` Get the value as a string.
`int` `getTableId()` Get the table (only for LOB object).
`java.sql.Time` `getTime()`
`java.sql.Timestamp` `getTimestamp()`
`java.lang.String` `getTraceSQL()` Get a medium size SQL expression for debugging or tracing.
`abstract TypeInfo` `getType()` Returns the data type.
`protected DbException` `getUnsupportedExceptionForOperation(java.lang.String op)` Create an exception meaning the specified operation is not supported for this data type.
`abstract int` `getValueType()` Get the value type.
`abstract int` `hashCode()`
`boolean` `isLinkedToTable()` Check if this value is linked to a specific table.
`Value` `modulus(Value v)` Take the modulus with a value and return the result.
`Value` `multiply(Value v)` Multiply with a value and return the result.
`Value` `negate()` Return -value if this value support arithmetic operations.
`void` `remove()` Remove the underlying resource, if any.
`abstract void` `set(java.sql.PreparedStatement prep, int parameterIndex)` Set the value as a parameter in a prepared statement.
`Value` `subtract(Value v)` Subtract a value and return the result.
`java.lang.String` `toString()`

### Methods inherited from class org.h2.value.VersionedValue

`getCommittedValue, getCurrentValue, getOperationId, isCommitted`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Field Detail

#### UNKNOWN

    public static final int UNKNOWN

The data type is unknown at this time.

See Also:
  Constant Field Values

#### NULL

    public static final int NULL

The value type for NULL.

See Also:
  Constant Field Values

#### BOOLEAN

    public static final int BOOLEAN

The value type for BOOLEAN values.

See Also:
  Constant Field Values

#### BYTE

    public static final int BYTE

The value type for BYTE values.

See Also:
  Constant Field Values

#### SHORT

    public static final int SHORT

The value type for SHORT values.

See Also:
  Constant Field Values

#### INT

    public static final int INT

The value type for INT values.

See Also:
  Constant Field Values

#### LONG

    public static final int LONG

The value type for LONG values.

See Also:
  Constant Field Values

#### DECIMAL

    public static final int DECIMAL

The value type for DECIMAL values.

See Also:
  Constant Field Values

#### DOUBLE

    public static final int DOUBLE

The value type for DOUBLE values.

See Also:
  Constant Field Values

#### FLOAT

    public static final int FLOAT

The value type for FLOAT values.

See Also:
  Constant Field Values

#### TIME

    public static final int TIME

The value type for TIME values.

See Also:
  Constant Field Values

#### DATE

    public static final int DATE

The value type for DATE values.

See Also:
  Constant Field Values

#### TIMESTAMP

    public static final int TIMESTAMP

The value type for TIMESTAMP values.

See Also:
  Constant Field Values

#### BYTES

    public static final int BYTES

The value type for BYTES values.

See Also:
  Constant Field Values

#### STRING

    public static final int STRING

The value type for STRING values.

See Also:
  Constant Field Values

#### STRING_IGNORECASE

    public static final int STRING_IGNORECASE

The value type for case insensitive STRING values.

See Also:
  Constant Field Values

#### BLOB

    public static final int BLOB

The value type for BLOB values.

See Also:
  Constant Field Values

#### CLOB

    public static final int CLOB

The value type for CLOB values.

See Also:
  Constant Field Values

#### ARRAY

    public static final int ARRAY

The value type for ARRAY values.

See Also:
  Constant Field Values

#### RESULT_SET

    public static final int RESULT_SET

The value type for RESULT_SET values.

See Also:
  Constant Field Values

#### JAVA_OBJECT

    public static final int JAVA_OBJECT

The value type for JAVA_OBJECT values.

See Also:
  Constant Field Values

#### UUID

    public static final int UUID

The value type for UUID values.

See Also:
  Constant Field Values

#### STRING_FIXED

    public static final int STRING_FIXED

The value type for string values with a fixed size.

See Also:
  Constant Field Values

#### GEOMETRY

    public static final int GEOMETRY

The value type for string values with a fixed size.

See Also:
  Constant Field Values

#### TIMESTAMP_TZ

    public static final int TIMESTAMP_TZ

The value type for TIMESTAMP WITH TIME ZONE values.

See Also:
  Constant Field Values

#### ENUM

    public static final int ENUM

The value type for ENUM values.

See Also:
  Constant Field Values

#### INTERVAL_YEAR

    public static final int INTERVAL_YEAR

The value type for `INTERVAL YEAR` values.

See Also:
  Constant Field Values

#### INTERVAL_MONTH

    public static final int INTERVAL_MONTH

The value type for `INTERVAL MONTH` values.

See Also:
  Constant Field Values

#### INTERVAL_DAY

    public static final int INTERVAL_DAY

The value type for `INTERVAL DAY` values.

See Also:
  Constant Field Values

#### INTERVAL_HOUR

    public static final int INTERVAL_HOUR

The value type for `INTERVAL HOUR` values.

See Also:
  Constant Field Values

#### INTERVAL_MINUTE

    public static final int INTERVAL_MINUTE

The value type for `INTERVAL MINUTE` values.

See Also:
  Constant Field Values

#### INTERVAL_SECOND

    public static final int INTERVAL_SECOND

The value type for `INTERVAL SECOND` values.

See Also:
  Constant Field Values

#### INTERVAL_YEAR_TO_MONTH

    public static final int INTERVAL_YEAR_TO_MONTH

The value type for `INTERVAL YEAR TO MONTH` values.

See Also:
  Constant Field Values

#### INTERVAL_DAY_TO_HOUR

    public static final int INTERVAL_DAY_TO_HOUR

The value type for `INTERVAL DAY TO HOUR` values.

See Also:
  Constant Field Values

#### INTERVAL_DAY_TO_MINUTE

    public static final int INTERVAL_DAY_TO_MINUTE

The value type for `INTERVAL DAY TO MINUTE` values.

See Also:
  Constant Field Values

#### INTERVAL_DAY_TO_SECOND

    public static final int INTERVAL_DAY_TO_SECOND

The value type for `INTERVAL DAY TO SECOND` values.

See Also:
  Constant Field Values

#### INTERVAL_HOUR_TO_MINUTE

    public static final int INTERVAL_HOUR_TO_MINUTE

The value type for `INTERVAL HOUR TO MINUTE` values.

See Also:
  Constant Field Values

#### INTERVAL_HOUR_TO_SECOND

    public static final int INTERVAL_HOUR_TO_SECOND

The value type for `INTERVAL HOUR TO SECOND` values.

See Also:
  Constant Field Values

#### INTERVAL_MINUTE_TO_SECOND

    public static final int INTERVAL_MINUTE_TO_SECOND

The value type for `INTERVAL MINUTE TO SECOND` values.

See Also:
  Constant Field Values

#### ROW

    public static final int ROW

The value type for ROW values.

See Also:
  Constant Field Values

#### TYPE_COUNT

    public static final int TYPE_COUNT

The number of value types.

See Also:
  Constant Field Values

#### MIN_LONG_DECIMAL

    public static final java.math.BigDecimal MIN_LONG_DECIMAL

The smallest Long value, as a BigDecimal.

### Constructor Detail

#### Value

    public Value()

### Method Detail

#### getSQL

    public java.lang.String getSQL()

Get the SQL expression for this value.

Returns:
  the SQL expression

#### getSQL

    public abstract java.lang.StringBuilder getSQL(java.lang.StringBuilder builder)

Appends the SQL expression for this value to the specified builder.

Parameters:
  `builder` - string builder
Returns:
  the specified string builder

#### getType

    public abstract TypeInfo getType()

Returns the data type.

Returns:
  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

#### getString

    public abstract java.lang.String getString()

Get the value as a string.

Returns:
  the string

#### getObject

    public abstract java.lang.Object getObject()

Get the value as an object.

Returns:
  the object

#### set

    public abstract void set(java.sql.PreparedStatement prep,
           int parameterIndex)
                      throws java.sql.SQLException

Set the value as a parameter in a prepared statement.

Parameters:
  `prep` - the prepared statement
  `parameterIndex` - the parameter index
Throws:
  `java.sql.SQLException`

#### hashCode

    public abstract int hashCode()

Overrides:
  `hashCode` in class `java.lang.Object`

#### equals

    public abstract boolean equals(java.lang.Object other)

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.

Overrides:
  `equals` in class `java.lang.Object`
Parameters:
  `other` - the other value
Returns:
  true if they are equal

#### 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 type
  `t2` - the second value type
Returns:
  the higher value type of the two

#### getHigherType

    public static TypeInfo getHigherType(TypeInfo type1,
                         TypeInfo type2)

Get the higher data type of two data types. If values need to be converted to match the other operands data type, the value with the lower order is converted to the value with the higher order.

Parameters:
  `type1` - the first data type
  `type2` - the second data type
Returns:
  the higher data type of the two

#### clearCache

    public static void clearCache()

Clear the value cache. Used for testing.

#### getBoolean

    public boolean getBoolean()

#### getDate

    public java.sql.Date getDate()

#### getTime

    public java.sql.Time getTime()

#### getTimestamp

    public java.sql.Timestamp getTimestamp()

#### getBytes

    public byte[] getBytes()

#### getBytesNoCopy

    public byte[] getBytesNoCopy()

#### getByte

    public byte getByte()

#### getShort

    public short getShort()

#### getBigDecimal

    public java.math.BigDecimal getBigDecimal()

#### getDouble

    public double getDouble()

#### getFloat

    public float getFloat()

#### getInt

    public int getInt()

#### getLong

    public long getLong()

#### getInputStream

    public java.io.InputStream getInputStream()

#### getInputStream

    public java.io.InputStream getInputStream(long oneBasedOffset,
                                     long length)

Get the input stream

Parameters:
  `oneBasedOffset` - the offset (1 means no offset)
  `length` - the requested length
Returns:
  the new input stream

#### getReader

    public java.io.Reader getReader()

#### getReader

    public java.io.Reader getReader(long oneBasedOffset,
                           long length)

Get the reader

Parameters:
  `oneBasedOffset` - the offset (1 means no offset)
  `length` - the requested length
Returns:
  the new reader

#### add

    public Value add(Value v)

Add a value and return the result.

Parameters:
  `v` - the value to add
Returns:
  the result

#### getSignum

    public int getSignum()

#### negate

    public Value negate()

Return -value if this value support arithmetic operations.

Returns:
  the negative

#### subtract

    public Value subtract(Value v)

Subtract a value and return the result.

Parameters:
  `v` - the value to subtract
Returns:
  the result

#### divide

    public Value divide(Value v)

Divide by a value and return the result.

Parameters:
  `v` - the value to divide by
Returns:
  the result

#### multiply

    public Value multiply(Value v)

Multiply with a value and return the result.

Parameters:
  `v` - the value to multiply with
Returns:
  the result

#### modulus

    public Value modulus(Value v)

Take the modulus with a value and return the result.

Parameters:
  `v` - the value to take the modulus with
Returns:
  the result

#### convertTo

    public final Value convertTo(int targetType)

Compare a value to the specified type.

Parameters:
  `targetType` - the type of the returned value
Returns:
  the converted value

#### convertTo

    public final Value convertTo(int targetType,
                  Mode mode)

Convert a value to the specified type.

Parameters:
  `targetType` - the type of the returned value
  `mode` - the mode
Returns:
  the converted value

#### convertTo

    public final Value convertTo(TypeInfo targetType,
                  Mode mode,
                  java.lang.Object column)

Convert a value to the specified type.

Parameters:
  `targetType` - the type of the returned value
  `mode` - the conversion mode
  `column` - the column (if any), used for to improve the error message if conversion fails
Returns:
  the converted value

#### convertTo

    protected Value convertTo(int targetType,
                  Mode mode,
                  java.lang.Object column,
                  ExtTypeInfo extTypeInfo)

Convert a value to the specified type.

Parameters:
  `targetType` - the type of the returned value
  `mode` - the conversion mode
  `column` - the column (if any), used for to improve the error message if conversion fails
  `extTypeInfo` - the extended data type information, or null
Returns:
  the converted value

#### compareTypeSafe

    public abstract int compareTypeSafe(Value v,
                      CompareMode mode)

Compare this value against another value given that the values are of the same data type.

Parameters:
  `v` - the other value
  `mode` - the compare mode
Returns:
  0 if both values are equal, -1 if the other value is smaller, and 1 otherwise

#### compareTo

    public final int compareTo(Value v,
                Mode databaseMode,
                CompareMode compareMode)

Compare this value against another value using the specified compare mode.

Parameters:
  `v` - the other value
  `databaseMode` - the database mode
  `compareMode` - 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,
                      Mode databaseMode,
                      CompareMode compareMode)

Compare this value against another value using the specified compare mode.

Parameters:
  `v` - the other value
  `forEquality` - perform only check for equality
  `databaseMode` - the database mode
  `compareMode` - the compare mode
Returns:
  0 if both values are equal, -1 if this value is smaller, 1 if other value is larger, `Integer.MIN_VALUE` if 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

#### convertScale

    public Value convertScale(boolean onlyToSmallerScale,
                     int targetScale)

Convert the scale.

Parameters:
  `onlyToSmallerScale` - if the scale should not reduced
  `targetScale` - the requested scale
Returns:
  the value

#### convertPrecision

    public Value convertPrecision(long precision,
                         boolean force)

Convert the precision to the requested value. The precision of the returned value may be somewhat larger than requested, because values with a fixed precision are not truncated.

Parameters:
  `precision` - the new precision
  `force` - true if losing numeric precision is allowed
Returns:
  the new value

#### convertToInt

    public static int convertToInt(long x,
                   java.lang.Object column)

Convert to integer, throwing exception if out of range.

Parameters:
  `x` - integer value.
  `column` - Column info.
Returns:
  x

#### copy

    public Value copy(DataHandler handler,
             int tableId)

Copy a large value, to be used in the given table. For values that are kept fully in memory this method has no effect.

Parameters:
  `handler` - the data handler
  `tableId` - the table where this object is used
Returns:
  the new value or itself

#### isLinkedToTable

    public boolean isLinkedToTable()

Check if this value is linked to a specific table. For values that are kept fully in memory, this method returns false.

Returns:
  true if it is

#### remove

    public void remove()

Remove the underlying resource, if any. For values that are kept fully in memory this method has no effect.

#### checkPrecision

    public boolean checkPrecision(long precision)

Check if the precision is smaller or equal than the given precision.

Parameters:
  `precision` - the maximum precision
Returns:
  true if the precision of this value is smaller or equal to the given precision

#### getTraceSQL

    public java.lang.String getTraceSQL()

Get a medium size SQL expression for debugging or tracing. If the precision is too large, only a subset of the value is returned.

Returns:
  the SQL expression

#### toString

    public java.lang.String toString()

Overrides:
  `toString` in class `java.lang.Object`

#### getUnsupportedExceptionForOperation

    protected final DbException getUnsupportedExceptionForOperation(java.lang.String op)

Create an exception meaning the specified operation is not supported for this data type.

Parameters:
  `op` - the operation
Returns:
  the exception

#### getTableId

    public int getTableId()

Get the table (only for LOB object).

Returns:
  the table id

#### getSmall

    public byte[] getSmall()

Get the byte array.

Returns:
  the byte array

#### copyToTemp

    public Value copyToTemp()

Copy this value to a temporary file if necessary.

Returns:
  the new value

#### copyToResult

    public Value copyToResult()

Create an independent copy of this value if needed, that will be bound to a result. If the original row is removed, this copy is still readable.

Returns:
  the value (this for small objects)

#### getResult

    public ResultInterface getResult()

Returns result for result set value, or single-row result with this value in column X for other values.

Returns:
  result

#### getDataHandler

    protected DataHandler getDataHandler()

Return the data handler for the values that support it (actually only Java objects).

Returns:
  the data handler