## org.h2.value
Class Value

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

Direct Known Subclasses:
  ValueArray, ValueBoolean, ValueByte, ValueBytes, ValueDate, ValueDecimal, ValueDouble, ValueFloat, ValueInt, ValueLob, ValueLobDb, ValueLong, ValueNull, ValueResultSet, ValueShort, ValueString, ValueTime, ValueTimestamp, ValueUuid

    public abstract class Value

extends java.lang.Object

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

Nested Class Summary
`static interface` `Value.ValueBlob` A "character large object".
`static interface` `Value.ValueClob` A "binary large object".

Field Summary
`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` `FLOAT` The value type for FLOAT values.
`static int` `INT` The value type for INT values.
`static int` `JAVA_OBJECT` The value type for JAVA_OBJECT values.
`static int` `LONG` The value type for LONG values.
`static int` `NULL` The value type for NULL.
`static int` `RESULT_SET` The value type for RESULT_SET 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 INT values.
`static int` `TIMESTAMP` The value type for TIMESTAMP 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.

Constructor Summary
`Value()`

Method Summary
`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.
`void` `close()` Close the underlying resource, if any.
`protected abstract int` `compareSecure(Value v, CompareMode mode)` Compare the value with another value of the same type.
`int` `compareTo(Value v, CompareMode mode)` Compare this value against another value using the specified compare mode.
`int` `compareTypeSave(Value v, CompareMode mode)` Compare this value against another value given that the values are of the same data type.
`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` `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()`
`java.lang.Boolean` `getBoolean()`
`byte` `getByte()`
`byte[]` `getBytes()`
`byte[]` `getBytesNoCopy()`
`java.sql.Date` `getDate()`
`java.sql.Date` `getDateNoCopy()`
`abstract int` `getDisplaySize()` Get the display size in characters.
`double` `getDouble()`
`float` `getFloat()`
`static int` `getHigherOrder(int t1, int t2)` Get the higher value order type of two value types.
`java.io.InputStream` `getInputStream()`
`int` `getInt()`
`long` `getLong()`
`int` `getMemory()` Get the memory used by this object.
`abstract java.lang.Object` `getObject()` Get the value as an object.
`abstract long` `getPrecision()` Get the precision.
`java.io.Reader` `getReader()`
`java.sql.ResultSet` `getResultSet()`
`int` `getScale()`
`short` `getShort()`
`int` `getSignum()`
`byte[]` `getSmall()` Get the byte array.
`abstract java.lang.String` `getSQL()` Get the SQL expression for this value.
`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.Time` `getTimeNoCopy()`
`java.sql.Timestamp` `getTimestamp()`
`java.sql.Timestamp` `getTimestampNoCopy()`
`java.lang.String` `getTraceSQL()` Get a medium size SQL expression for debugging or tracing.
`abstract int` `getType()` Get the value type.
`abstract int` `hashCode()`
`boolean` `isFileBased()` Check if this value is stored in it's own file.
`boolean` `isLinked()` Check if this value is linked to a specific table.
`Value` `link(DataHandler handler, int tableId)` Link a large value to a given 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.
`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.
`protected DbException` `throwUnsupportedExceptionForType(java.lang.String op)` Throw the exception that the feature is not support for the given data type.
`java.lang.String` `toString()`
`void` `unlink()` Mark any underlying resource as 'not linked to any table'.

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 INT 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

### TYPE_COUNT

    public static final int TYPE_COUNT

  The number of value types.

  See Also:
    Constant Field Values

Constructor Detail

### Value

    public Value()

Method Detail

### getSQL

    public abstract java.lang.String getSQL()

  Get the SQL expression for this value.

  Returns:
    the SQL expression

### getType

    public abstract int getType()

  Get the value type.

  Returns:
    the type

### getPrecision

    public abstract long getPrecision()

  Get the precision.

  Returns:
    the precision

### getDisplaySize

    public abstract int getDisplaySize()

  Get the display size in characters.

  Returns:
    the display size

### 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`

### compareSecure

    protected abstract int compareSecure(Value v,
                                         CompareMode mode)

  Compare the value with another value of the same 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

### 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

### clearCache

    public static void clearCache()

  Clear the value cache. Used for testing.

### getBoolean

    public java.lang.Boolean getBoolean()

### getDate

    public java.sql.Date getDate()

### getDateNoCopy

    public java.sql.Date getDateNoCopy()

### getTime

    public java.sql.Time getTime()

### getTimeNoCopy

    public java.sql.Time getTimeNoCopy()

### getTimestamp

    public java.sql.Timestamp getTimestamp()

### getTimestampNoCopy

    public java.sql.Timestamp getTimestampNoCopy()

### 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()

### getReader

    public java.io.Reader getReader()

### 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 Value convertTo(int targetType)

  Compare a value to the specified type.

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

### compareTypeSave

    public final int compareTypeSave(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,
                               CompareMode mode)

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

  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

### getScale

    public int getScale()

### 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

### link

    public Value link(DataHandler handler,
                      int tableId)

  Link a large value to a given table. For values that are kept fully in memory this method has no effect.

  Parameters:
    `handler` - the data handler
    `tableId` - the table to link to
  Returns:
    the new value or itself

### isLinked

    public boolean isLinked()

  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

### unlink

    public void unlink()

  Mark any underlying resource as 'not linked to any table'. For values that are kept fully in memory this method has no effect.

### isFileBased

    public boolean isFileBased()

  Check if this value is stored in it's own file. For values that are kept fully in memory, this method returns false.

  Returns:
    true if it is

### close

    public void close()

  Close 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`

### throwUnsupportedExceptionForType

    protected DbException throwUnsupportedExceptionForType(java.lang.String op)

  Throw the exception that the feature is not support for the given data type.

  Parameters:
    `op` - the operation
  Returns:
    never returns normally
  Throws:
    `DbException` - 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

### getResultSet

    public java.sql.ResultSet getResultSet()