## org.h2.value
Class ValueLob

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

    public class ValueLob

extends Value

Implementation of the BLOB and CLOB data types. Small objects are kept in memory and stored in the data page of the record. Large objects are stored in their own files. When large objects are set in a prepared statement, they are first stored as 'temporary' files. Later, when they are used in a record, and when the record is stored, the lob files are linked: the file is renamed using the file format (tableId).(objectId). There is one exception: large variables are stored in the file (-1).(objectId). When lobs are deleted, they are first renamed to a temp file, and if the delete operation is committed the file is deleted. Data compression is supported.

Field Summary
`static int` `TABLE_ID_SESSION_VARIABLE` The 'table id' to use for session variables.

Fields inherited from class org.h2.value.Value
`ARRAY, BLOB, BOOLEAN, BYTE, BYTES, CLOB, DATE, DECIMAL, DOUBLE, FLOAT, INT, JAVA_OBJECT, LONG, NULL, RESULT_SET, SHORT, STRING, STRING_FIXED, STRING_IGNORECASE, TIME, TIMESTAMP, TYPE_COUNT, UNKNOWN, UUID`

Method Summary
`void` `close()` Close the underlying resource, if any.
`protected int` `compareSecure(Value v, CompareMode mode)` Compare the value with another value of the same type.
`Value` `convertTo(int t)` Convert a lob to another data type.
`void` `convertToFileIfRequired(DataHandler handler)` Store the lob data to a file if the size of the buffer it larger than the maximum size for an in-place lob.
`ValueLob` `copyToTemp()` Create an independent copy of this temporary value.
`static ValueLob` `createBlob(java.io.InputStream in, long length, DataHandler handler)` Create a BLOB value from a stream.
`static ValueLob` `createClob(java.io.Reader in, long length, DataHandler handler)` Create a CLOB value from a stream.
`static ValueLob` `createSmallLob(int type, byte[] small)` Create a small lob using the given byte array.
`boolean` `equals(java.lang.Object other)` Check if the two values are equal.
`static boolean` `existsLobFile(java.lang.String prefix)` Check if a lob file exists for this database.
`byte[]` `getBytes()`
`byte[]` `getBytesNoCopy()`
`int` `getDisplaySize()` Get the display size in characters.
`java.lang.String` `getFileName()` Get the current file name where the lob is saved.
`java.io.InputStream` `getInputStream()`
`int` `getMemory()` Get the memory used by this object.
`java.lang.Object` `getObject()` Get the value as an object.
`int` `getObjectId()` Get the current object id of this lob.
`long` `getPrecision()` Get the precision.
`java.io.Reader` `getReader()`
`byte[]` `getSmall()` Get the data if this a small lob value.
`java.lang.String` `getSQL()` Get the SQL expression for this value.
`java.lang.String` `getString()` Get the value as a string.
`int` `getTableId()` Get the current table id of this lob.
`java.lang.String` `getTraceSQL()` Get a medium size SQL expression for debugging or tracing.
`int` `getType()` Get the value type.
`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 tabId)` Link a large value to a given table.
`static ValueLob` `open(int type, DataHandler handler, int tableId, int objectId, long precision, boolean compression)` Create a LOB value with the given parameters.
`static void` `removeAllForTable(DataHandler handler, int tableId)` Remove all lobs for a given table id.
`static void` `resetDirCounter()` Reset the directory counter as if the process was stopped.
`void` `set(java.sql.PreparedStatement prep, int parameterIndex)` Set the value as a parameter in a prepared statement.
`void` `setFileName(java.lang.String fileName, boolean linked)` Set the file name of this lob value.
`void` `unlink()` Mark any underlying resource as 'not linked to any table'.
`boolean` `useCompression()` Check if this lob value is compressed.

Methods inherited from class org.h2.value.Value
`add, checkPrecision, compareEqual, compareTo, compareTypeSave, convertPrecision, convertScale, divide, getBigDecimal, getBoolean, getByte, getDate, getDateNoCopy, getDouble, getFloat, getHigherOrder, getInt, getLong, getScale, getShort, getSignum, getTime, getTimeNoCopy, getTimestamp, getTimestampNoCopy, multiply, negate, subtract, throwUnsupportedExceptionForType, toString`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Field Detail

### TABLE_ID_SESSION_VARIABLE

    public static final int TABLE_ID_SESSION_VARIABLE

  The 'table id' to use for session variables.

  See Also:
    Constant Field Values

Method Detail

### createSmallLob

    public static ValueLob createSmallLob(int type,
                                          byte[] small)

  Create a small lob using the given byte array.

  Parameters:
    `type` - the type (Value.BLOB or CLOB)
    `small` - the byte array
  Returns:
    the lob value

### open

    public static ValueLob open(int type,
                                DataHandler handler,
                                int tableId,
                                int objectId,
                                long precision,
                                boolean compression)
                         throws java.sql.SQLException

  Create a LOB value with the given parameters.

  Parameters:
    `type` - the data type
    `handler` - the file handler
    `tableId` - the table object id
    `objectId` - the object id
    `precision` - the precision (length in elements)
    `compression` - if compression is used
  Returns:
    the value object
  Throws:
    `java.sql.SQLException`

### createClob

    public static ValueLob createClob(java.io.Reader in,
                                      long length,
                                      DataHandler handler)
                               throws java.sql.SQLException

  Create a CLOB value from a stream.

  Parameters:
    `in` - the reader
    `length` - the number of characters to read, or -1 for no limit
    `handler` - the data handler
  Returns:
    the lob value
  Throws:
    `java.sql.SQLException`

### resetDirCounter

    public static void resetDirCounter()

  Reset the directory counter as if the process was stopped. This method is for debugging only (to simulate stopping a process).

### createBlob

    public static ValueLob createBlob(java.io.InputStream in,
                                      long length,
                                      DataHandler handler)
                               throws java.sql.SQLException

  Create a BLOB value from a stream.

  Parameters:
    `in` - the input stream
    `length` - the number of characters to read, or -1 for no limit
    `handler` - the data handler
  Returns:
    the lob value
  Throws:
    `java.sql.SQLException`

### convertTo

    public Value convertTo(int t)
                    throws java.sql.SQLException

  Convert a lob to another data type. The data is fully read in memory except when converting to BLOB or CLOB.

  Overrides:
    `convertTo` in class `Value`
  Parameters:
    `t` - the new type
  Returns:
    the converted value
  Throws:
    `java.sql.SQLException`

### isLinked

    public boolean isLinked()

  Description copied from class: `Value`
  Check if this value is linked to a specific table. For values that are kept fully in memory, this method returns false.

  Overrides:
    `isLinked` in class `Value`
  Returns:
    true if it is

### getFileName

    public java.lang.String getFileName()

  Get the current file name where the lob is saved.

  Returns:
    the file name or null

### close

    public void close()
               throws java.sql.SQLException

  Description copied from class: `Value`
  Close the underlying resource, if any. For values that are kept fully in memory this method has no effect.

  Overrides:
    `close` in class `Value`
  Throws:
    `java.sql.SQLException`

### unlink

    public void unlink()
                throws java.sql.SQLException

  Description copied from class: `Value`
  Mark any underlying resource as 'not linked to any table'. For values that are kept fully in memory this method has no effect.

  Overrides:
    `unlink` in class `Value`
  Throws:
    `java.sql.SQLException`

### link

    public Value link(DataHandler handler,
                      int tabId)
               throws java.sql.SQLException

  Description copied from class: `Value`
  Link a large value to a given table. For values that are kept fully in memory this method has no effect.

  Overrides:
    `link` in class `Value`
  Parameters:
    `handler` - the data handler
    `tabId` - the table to link to
  Returns:
    the new value or itself
  Throws:
    `java.sql.SQLException`

### getTableId

    public int getTableId()

  Get the current table id of this lob.

  Returns:
    the table id

### getObjectId

    public int getObjectId()

  Get the current object id of this lob.

  Returns:
    the object id

### getType

    public int getType()

  Description copied from class: `Value`
  Get the value type.

  Specified by:
    `getType` in class `Value`
  Returns:
    the type

### getPrecision

    public long getPrecision()

  Description copied from class: `Value`
  Get the precision.

  Specified by:
    `getPrecision` in class `Value`
  Returns:
    the precision

### getString

    public java.lang.String getString()

  Description copied from class: `Value`
  Get the value as a string.

  Specified by:
    `getString` in class `Value`
  Returns:
    the string

### getBytes

    public byte[] getBytes()
                    throws java.sql.SQLException

  Overrides:
    `getBytes` in class `Value`
  Throws:
    `java.sql.SQLException`

### getBytesNoCopy

    public byte[] getBytesNoCopy()
                          throws java.sql.SQLException

  Overrides:
    `getBytesNoCopy` in class `Value`
  Throws:
    `java.sql.SQLException`

### hashCode

    public int hashCode()

  Specified by:
    `hashCode` in class `Value`

### compareSecure

    protected int compareSecure(Value v,
                                CompareMode mode)
                         throws java.sql.SQLException

  Description copied from class: `Value`
  Compare the value with another value of the same type.

  Specified by:
    `compareSecure` in class `Value`
  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
  Throws:
    `java.sql.SQLException`

### getObject

    public java.lang.Object getObject()

  Description copied from class: `Value`
  Get the value as an object.

  Specified by:
    `getObject` in class `Value`
  Returns:
    the object

### getReader

    public java.io.Reader getReader()

  Overrides:
    `getReader` in class `Value`

### getInputStream

    public java.io.InputStream getInputStream()
                                       throws java.sql.SQLException

  Overrides:
    `getInputStream` in class `Value`
  Throws:
    `java.sql.SQLException`

### set

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

  Description copied from class: `Value`
  Set the value as a parameter in a prepared statement.

  Specified by:
    `set` in class `Value`
  Parameters:
    `prep` - the prepared statement
    `parameterIndex` - the parameter index
  Throws:
    `java.sql.SQLException`

### getSQL

    public java.lang.String getSQL()

  Description copied from class: `Value`
  Get the SQL expression for this value.

  Specified by:
    `getSQL` in class `Value`
  Returns:
    the SQL expression

### getTraceSQL

    public java.lang.String getTraceSQL()

  Description copied from class: `Value`
  Get a medium size SQL expression for debugging or tracing. If the precision is too large, only a subset of the value is returned.

  Overrides:
    `getTraceSQL` in class `Value`
  Returns:
    the SQL expression

### getSmall

    public byte[] getSmall()

  Get the data if this a small lob value.

  Returns:
    the data

### getDisplaySize

    public int getDisplaySize()

  Description copied from class: `Value`
  Get the display size in characters.

  Specified by:
    `getDisplaySize` in class `Value`
  Returns:
    the display size

### equals

    public boolean equals(java.lang.Object other)

  Description copied from class: `Value`
  Check if the two values are equal. No data conversion is made; this method returns false if the other object is not of the same class.

  Specified by:
    `equals` in class `Value`
  Parameters:
    `other` - the other value
  Returns:
    true if they are equal

### convertToFileIfRequired

    public void convertToFileIfRequired(DataHandler handler)
                                 throws java.sql.SQLException

  Store the lob data to a file if the size of the buffer it larger than the maximum size for an in-place lob.

  Parameters:
    `handler` - the data handler
  Throws:
    `java.sql.SQLException`

### removeAllForTable

    public static void removeAllForTable(DataHandler handler,
                                         int tableId)
                                  throws java.sql.SQLException

  Remove all lobs for a given table id.

  Parameters:
    `handler` - the data handler
    `tableId` - the table id
  Throws:
    `java.sql.SQLException`

### existsLobFile

    public static boolean existsLobFile(java.lang.String prefix)
                                 throws java.sql.SQLException

  Check if a lob file exists for this database.

  Parameters:
    `prefix` - the file name prefix
  Returns:
    true if a lob file exists
  Throws:
    `java.sql.SQLException`

### useCompression

    public boolean useCompression()

  Check if this lob value is compressed.

  Returns:
    true if it is

### isFileBased

    public boolean isFileBased()

  Description copied from class: `Value`
  Check if this value is stored in it's own file. For values that are kept fully in memory, this method returns false.

  Overrides:
    `isFileBased` in class `Value`
  Returns:
    true if it is

### setFileName

    public void setFileName(java.lang.String fileName,
                            boolean linked)

  Set the file name of this lob value.

  Parameters:
    `fileName` - the file name
    `linked` - if the lob is linked

### getMemory

    public int getMemory()

  Description copied from class: `Value`
  Get the memory used by this object.

  Overrides:
    `getMemory` in class `Value`
  Returns:
    the memory used in bytes

### copyToTemp

    public ValueLob copyToTemp()
                        throws java.sql.SQLException

  Create an independent copy of this temporary value. The file will not be deleted automatically.

  Returns:
    the value
  Throws:
    `java.sql.SQLException`