Class ClobUpdatableReader

java.lang.Object
java.io.Reader
org.apache.derby.impl.jdbc.ClobUpdatableReader
All Implemented Interfaces:
Closeable, AutoCloseable, Readable

final class ClobUpdatableReader extends Reader
ClobUpdatableReader is used to create a Reader capable of detecting changes to the underlying source.

This class is aware that the underlying stream can be modified and reinitializes itself if it detects any change in the stream. This invalidates the cache so the changes are reflected immediately.

The task of this class is to detect changes in the underlying Clob. Repositioning is handled by other classes.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final EmbedClob
    The Clob object we are reading from.
    private boolean
    Tells if this reader has been closed.
    private InternalClob
    The current internal representation of the Clob content.
    private long
    The last update count seen on the underlying Clob.
    private final long
    Position in Clob where to stop reading unless EOF is reached first.
    private long
    Character position of this reader (1-based).
    private Reader
    Reader accessing the Clob data and doing the work.

    Fields inherited from class java.io.Reader

    lock
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an updatable reader configured with initial position set to the first character in the Clob and with no imposed length limit.
    ClobUpdatableReader(EmbedClob clob, long initialPos, long length)
    Creates an updatable reader configured with the specified initial position and with an imposed length limit.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes this reader.
    int
     
    int
    read(char[] cbuf, int off, int len)
     
    long
    skip(long len)
     
    private void
    Updates the reader if the underlying data has been modified.

    Methods inherited from class java.io.Reader

    mark, markSupported, nullReader, read, read, ready, reset, transferTo

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • streamReader

      private Reader streamReader
      Reader accessing the Clob data and doing the work.
    • pos

      private long pos
      Character position of this reader (1-based).
    • lastUpdateCount

      private long lastUpdateCount
      The last update count seen on the underlying Clob.
    • clob

      private final EmbedClob clob
      The Clob object we are reading from.

      Note that even though the Clob itself is final, the internal representation of the content may change. The reference to the Clob is needed to get a hold of the new internal representation if it is changed.

      See Also:
    • iClob

      private InternalClob iClob
      The current internal representation of the Clob content.

      If the user starts out with a read-only Clob and then modifies it, the internal representation will change.

    • maxPos

      private final long maxPos
      Position in Clob where to stop reading unless EOF is reached first.
    • closed

      private volatile boolean closed
      Tells if this reader has been closed.
  • Constructor Details

    • ClobUpdatableReader

      public ClobUpdatableReader(EmbedClob clob) throws IOException, SQLException
      Creates an updatable reader configured with initial position set to the first character in the Clob and with no imposed length limit.
      Parameters:
      clob - source data
      Throws:
      IOException - if obtaining the underlying reader fails
      SQLException - if obtaining the underlying reader fails
    • ClobUpdatableReader

      public ClobUpdatableReader(EmbedClob clob, long initialPos, long length) throws IOException, SQLException
      Creates an updatable reader configured with the specified initial position and with an imposed length limit.
      Parameters:
      clob - source data
      initialPos - the first character that will be read
      length - the maximum number of characters that will read
      Throws:
      IOException - if obtaining the underlying reader fails
      SQLException - if obtaining the underlying reader fails
  • Method Details

    • read

      public int read() throws IOException
      Overrides:
      read in class Reader
      Throws:
      IOException
    • read

      public int read(char[] cbuf, int off, int len) throws IOException
      Specified by:
      read in class Reader
      Throws:
      IOException
    • skip

      public long skip(long len) throws IOException
      Overrides:
      skip in class Reader
      Throws:
      IOException
    • close

      public void close() throws IOException
      Closes this reader.

      An IOException will be thrown if any of the read or skip methods are called after the reader has been closed.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Reader
      Throws:
      IOException - if an error occurs while closing
    • updateReaderIfRequired

      private void updateReaderIfRequired() throws IOException
      Updates the reader if the underlying data has been modified.

      There are two cases to deal with:

      1. The underlying data of the internal Clob representation has been modified.
      2. The internal Clob representation has changed.
      The latter case happens when a read-only Clob, represented as a stream into store, is modified by the user and a new temporary internal representation is created.
      Throws:
      IOException - if verifying or updating the reader fails