Interface InternalClob

All Known Implementing Classes:
StoreStreamClob, TemporaryClob

interface InternalClob
A set of operations available on internal Clob content representations.

The methods defined by Clob must be implemented on top of this interface. In addition, there are some methods to aid internal tasks and organization, like transferring one internal Clob representation to another one.

  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Gets the number of characters in the Clob.
    long
    Gets the number of characters in the Clob if it is already known.
    getInternalReader(long characterPosition)
    Returns an internal reader for the Clob content, initialized at the specified character position.
    Returns a stream serving the raw bytes of the Clob.
    getReader(long characterPosition)
    Returns a reader for the Clob content, initialized at the specified character position.
    long
    Returns the update count of the Clob.
    getWriter(long charPos)
    Returns a writer to write data into the Clob.
    long
    insertString(String str, long pos)
    Inserts the given string at the specified character position.
    boolean
    Tells if the the Clob has been released.
    boolean
    Tells if the Clob representation is intended to be writable.
    void
    Frees the resources held by the internal Clob representation.
    void
    truncate(long newLength)
     
  • Method Details

    • getCharLength

      long getCharLength() throws IOException, SQLException
      Gets the number of characters in the Clob.
      Returns:
      Number of characters in the Clob.
      Throws:
      IOException - if accessing underlying I/O resources fail
      SQLException - if accessing underlying resources fail
    • getCharLengthIfKnown

      long getCharLengthIfKnown()
      Gets the number of characters in the Clob if it is already known.

      This method will not do any work to obtain the length if it isn't already known. Due to special handling of zero in the code, this method will return -1 if a length of zero is cached internally.

      If a positive value is returned, it is expected to be equal to the actual length of the Clob (i.e., no stale values must be returned).

      Returns:
      Number of characters in the Clob, or -1 if the length is currently unknown (not cached).
    • getRawByteStream

      InputStream getRawByteStream() throws IOException, SQLException
      Returns a stream serving the raw bytes of the Clob.

      Note that it is up to the caller of this method to handle the issue of encoding. There is no predetermined encoding associated with this byte stream, it is up to the Clob representation which one it uses.

      This stream may be an internal store stream, and should not be directly published to the end user (returned through the JDBC API). There are three reasons for this:

      • the stream may be closed by the end user when it is not supposed to
      • operations on the stream might throw exceptions we don't want to present to the end user unwrapped
      • the stream may contain a Derby specific end-of-stream marker

      The primary use of this method is to clone the Clob contents without going via char (or String). Make sure the clone uses the same encoding as the original Clob representation.

      Returns:
      A stream of bytes representing the content of the Clob, initialized at byte position 0.
      Throws:
      IOException - if accessing underlying I/O resources fail
      SQLException - if accessing underlying resources fail
    • getReader

      Reader getReader(long characterPosition) throws IOException, SQLException
      Returns a reader for the Clob content, initialized at the specified character position.
      Parameters:
      characterPosition - character position. The first character is at position 1.
      Returns:
      A Reader serving the content of the Clob.
    • getInternalReader

      Reader getInternalReader(long characterPosition) throws IOException, SQLException
      Returns an internal reader for the Clob content, initialized at the specified character position.

      This method can return a shared reader object, avoiding instantiation and repositioning costs for internal operations where the stream itself is not published to the end-user. One such example is Clob.getSubString.

      Parameters:
      characterPosition - character position. The first character is at position 1.
      Returns:
      A Reader serving the content of the Clob.
    • getUpdateCount

      long getUpdateCount()
      Returns the update count of the Clob.

      The update count is increased each time a modification of the Clob content is made.

      Returns:
      Update count, starting at zero.
    • getWriter

      Writer getWriter(long charPos) throws IOException, SQLException
      Returns a writer to write data into the Clob.

      The semantics of the writer is the same as for insertString(java.lang.String, long).

      Parameters:
      charPos - the starting character position. The first character is at position 1.
      Returns:
      A writer initialized at the specified character position.
      Throws:
      IOException - if writing to the Clob fails
      SQLException - if accessing underlying resources fail
      UnsupportedOperationException - if the Clob representation is read-only
    • insertString

      long insertString(String str, long pos) throws IOException, SQLException
      Inserts the given string at the specified character position.

      The behavior of this method can be defined by the following examples on the Clob clob with value "ABCDEFG";

      • clob.setString(2, "XX") - "AXXDEFG"
      • clob.setString(1, "XX") - "XXCDEFG"
      • clob.setString(8, "XX") - "ABCDEFGXX"
      • clob.setString(7, "XX") - "ABCDEFXX"
      • clob.setString(9, "XX") - throws exception
      Parameters:
      str - the string to insert
      pos - the character position the string will be inserted at. Must be between 1 and clob.length() +1, inclusive.
      Returns:
      The number of characters inserted.
      Throws:
      IOException - if writing to the I/O resources fail
      SQLException - it the position is invalid
      IllegalArgumentException - if the string is null
      UnsupportedOperationException - if the Clob representation is read-only
    • isReleased

      boolean isReleased()
      Tells if the the Clob has been released.

      Depending on the context, a Clob is released either because the internal representation has been changed, or because the Clob itself has been closed. The former can happen when a user modifies a stream that is currently represented as a store stream. The latter can happen if Clob.free has been called, or if Derby implicitly closes the Clob.

      Returns:
      true if released, false if not.
    • isWritable

      boolean isWritable()
      Tells if the Clob representation is intended to be writable.

      Note that even if this method returns true, it might not be possible to write to the Clob. If this happens, it is because the assoicated database is read-only, and the internal Clob representation is unable to obtain the resources it require (could be an area on disk to write temporary data).

      Returns:
      true if the Clob is intended to be writable, false if modifying the Clob is definitely not possible.
    • release

      void release() throws IOException, SQLException
      Frees the resources held by the internal Clob representation.

      After calling this method, all other operations on the Clob will be invalid and throw an exception.

      Throws:
      IOException - if freeing associated I/O resources fails
      SQLException - if freeing associated resources fails
    • truncate

      void truncate(long newLength) throws IOException, SQLException
      Parameters:
      newLength - the length in characters to truncate to
      Throws:
      IOException - if accessing the underlying I/O resources fails
      SQLException - if accessing underlying resources fail
      UnsupportedOperationException - if the Clob representation is read-only