Class ClobUpdatableReader

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.lang.Readable

    final class ClobUpdatableReader
    extends java.io.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 EmbedClob clob
      The Clob object we are reading from.
      private boolean closed
      Tells if this reader has been closed.
      private InternalClob iClob
      The current internal representation of the Clob content.
      private long lastUpdateCount
      The last update count seen on the underlying Clob.
      private long maxPos
      Position in Clob where to stop reading unless EOF is reached first.
      private long pos
      Character position of this reader (1-based).
      private java.io.Reader streamReader
      Reader accessing the Clob data and doing the work.
      • Fields inherited from class java.io.Reader

        lock
    • Constructor Summary

      Constructors 
      Constructor Description
      ClobUpdatableReader​(EmbedClob clob)
      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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes this reader.
      int read()  
      int read​(char[] cbuf, int off, int len)  
      long skip​(long len)  
      private void updateReaderIfRequired()
      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 Detail

      • streamReader

        private java.io.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
      • 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 Detail

      • ClobUpdatableReader

        public ClobUpdatableReader​(EmbedClob clob)
                            throws java.io.IOException,
                                   java.sql.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:
        java.io.IOException - if obtaining the underlying reader fails
        java.sql.SQLException - if obtaining the underlying reader fails
      • ClobUpdatableReader

        public ClobUpdatableReader​(EmbedClob clob,
                                   long initialPos,
                                   long length)
                            throws java.io.IOException,
                                   java.sql.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:
        java.io.IOException - if obtaining the underlying reader fails
        java.sql.SQLException - if obtaining the underlying reader fails
    • Method Detail

      • read

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

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

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

        public void close()
                   throws java.io.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 java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in class java.io.Reader
        Throws:
        java.io.IOException - if an error occurs while closing
      • updateReaderIfRequired

        private void updateReaderIfRequired()
                                     throws java.io.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:
        java.io.IOException - if verifying or updating the reader fails