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

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      long getCharLength()
      Gets the number of characters in the Clob.
      long getCharLengthIfKnown()
      Gets the number of characters in the Clob if it is already known.
      java.io.Reader getInternalReader​(long characterPosition)
      Returns an internal reader for the Clob content, initialized at the specified character position.
      java.io.InputStream getRawByteStream()
      Returns a stream serving the raw bytes of the Clob.
      java.io.Reader getReader​(long characterPosition)
      Returns a reader for the Clob content, initialized at the specified character position.
      long getUpdateCount()
      Returns the update count of the Clob.
      java.io.Writer getWriter​(long charPos)
      Returns a writer to write data into the Clob.
      long insertString​(java.lang.String str, long pos)
      Inserts the given string at the specified character position.
      boolean isReleased()
      Tells if the the Clob has been released.
      boolean isWritable()
      Tells if the Clob representation is intended to be writable.
      void release()
      Frees the resources held by the internal Clob representation.
      void truncate​(long newLength)  
    • Method Detail

      • getCharLength

        long getCharLength()
                    throws java.io.IOException,
                           java.sql.SQLException
        Gets the number of characters in the Clob.
        Returns:
        Number of characters in the Clob.
        Throws:
        java.io.IOException - if accessing underlying I/O resources fail
        java.sql.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

        java.io.InputStream getRawByteStream()
                                      throws java.io.IOException,
                                             java.sql.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:
        java.io.IOException - if accessing underlying I/O resources fail
        java.sql.SQLException - if accessing underlying resources fail
      • getReader

        java.io.Reader getReader​(long characterPosition)
                          throws java.io.IOException,
                                 java.sql.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.
        Throws:
        EOFException - if the position is larger then the Clob
        java.io.IOException - if accessing underlying I/O resources fail
        java.sql.SQLException - if accessing underlying resources fail
      • getInternalReader

        java.io.Reader getInternalReader​(long characterPosition)
                                  throws java.io.IOException,
                                         java.sql.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.
        Throws:
        EOFException - if the position is larger then the Clob
        java.io.IOException - if accessing underlying I/O resources fail
        java.sql.SQLException - if accessing underlying resources fail
      • 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

        java.io.Writer getWriter​(long charPos)
                          throws java.io.IOException,
                                 java.sql.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:
        java.io.IOException - if writing to the Clob fails
        java.sql.SQLException - if accessing underlying resources fail
        java.lang.UnsupportedOperationException - if the Clob representation is read-only
      • insertString

        long insertString​(java.lang.String str,
                          long pos)
                   throws java.io.IOException,
                          java.sql.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:
        java.io.IOException - if writing to the I/O resources fail
        java.sql.SQLException - it the position is invalid
        java.lang.IllegalArgumentException - if the string is null
        java.lang.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 java.io.IOException,
                     java.sql.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:
        java.io.IOException - if freeing associated I/O resources fails
        java.sql.SQLException - if freeing associated resources fails
      • truncate

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