Package org.h2.value

Class ValueLob

All Implemented Interfaces:
HasSQL, Typed
Direct Known Subclasses:
ValueBlob, ValueClob

public abstract class ValueLob extends Value
A implementation of the BINARY LARGE OBJECT and CHARACTER LARGE OBJECT data types. Small objects are kept in memory and stored in the record. Large objects are either stored in the database, or in temporary files.
  • Field Details

    • BLOCK_COMPARISON_SIZE

      static final int BLOCK_COMPARISON_SIZE
      See Also:
    • type

      private TypeInfo type
    • lobData

      final LobData lobData
    • octetLength

      long octetLength
      Length in bytes.
    • charLength

      long charLength
      Length in characters.
    • hash

      private int hash
      Cache the hashCode because it can be expensive to compute.
  • Constructor Details

    • ValueLob

      ValueLob(LobData lobData, long octetLength, long charLength)
  • Method Details

    • rangeCheckUnknown

      private static void rangeCheckUnknown(long zeroBasedOffset, long length)
    • rangeInputStream

      protected static InputStream rangeInputStream(InputStream inputStream, long oneBasedOffset, long length, long dataSize)
      Create an input stream that is s subset of the given stream.
      Parameters:
      inputStream - the source input stream
      oneBasedOffset - the offset (1 means no offset)
      length - the length of the result, in bytes
      dataSize - the length of the input, in bytes
      Returns:
      the smaller input stream
    • rangeReader

      static Reader rangeReader(Reader reader, long oneBasedOffset, long length, long dataSize)
      Create a reader that is s subset of the given reader.
      Parameters:
      reader - the input reader
      oneBasedOffset - the offset (1 means no offset)
      length - the length of the result, in bytes
      dataSize - the length of the input, in bytes
      Returns:
      the smaller input stream
    • createTempLobFileName

      static String createTempLobFileName(DataHandler handler) throws IOException
      Create file name for temporary LOB storage
      Parameters:
      handler - to get path from
      Returns:
      full path and name of the created file
      Throws:
      IOException - if file creation fails
    • getBufferSize

      static int getBufferSize(DataHandler handler, long remaining)
    • 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.
    • copy

      public abstract ValueLob copy(DataHandler database, 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:
      database - the data handler
      tableId - the table where this object is used
      Returns:
      the new value or itself
    • getType

      public TypeInfo getType()
      Description copied from interface: Typed
      Returns the data type.
      Specified by:
      getType in interface Typed
      Specified by:
      getType in class Value
      Returns:
      the data type
    • getStringTooLong

      DbException getStringTooLong(long precision)
    • readString

      String readString(int len)
    • getReader

      public Reader getReader()
      Overrides:
      getReader in class Value
    • getBytes

      public byte[] getBytes()
      Overrides:
      getBytes in class Value
    • getBytesNoCopy

      public byte[] getBytesNoCopy()
      Overrides:
      getBytesNoCopy in class Value
    • getSmall

      private byte[] getSmall()
    • getBytesInternal

      abstract byte[] getBytesInternal()
    • getBinaryTooLong

      DbException getBinaryTooLong(long precision)
    • readBytes

      byte[] readBytes(int len)
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in class Value
    • equals

      public boolean equals(Object other)
      Description copied from class: Value
      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.
      Specified by:
      equals in class Value
      Parameters:
      other - the other value
      Returns:
      true if they are equal
    • 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
    • getLobData

      public LobData getLobData()
    • copyToResult

      public ValueLob copyToResult()
      Create an independent copy of this value, that will be bound to a result.
      Returns:
      the value (this for small objects)