Class OverflowInputStream

All Implemented Interfaces:
Closeable, AutoCloseable, CloneableStream, Resetable

public class OverflowInputStream extends BufferedByteHolderInputStream implements Resetable, CloneableStream
A OverflowInputStream is used by store to turn a long column into an InputStream.

Any time store fetches a long column, the value is returned as a stream. A long column is any column that at some point was longer than a page, so a long column in one table may not be long in another depending on page size.

When the column is fetched a new OverflowInputStream is created and then the datatype's stream is set using: ((StreamStorable)sColumn).setStream(OverflowInputStream);

  • Field Details

    • owner

      protected BaseContainerHandle owner
      Fields of the class
    • overflowPage

      protected long overflowPage
    • overflowId

      protected int overflowId
    • firstOverflowPage

      protected long firstOverflowPage
    • firstOverflowId

      protected int firstOverflowId
    • recordToLock

      protected RecordHandle recordToLock
    • initialized

      private boolean initialized
  • Constructor Details

    • OverflowInputStream

      public OverflowInputStream(ByteHolder bh, BaseContainerHandle owner, long overflowPage, int overflowId, RecordHandle recordToLock)
      Constructor for OverflowInputStream

      It is up to the caller to allocate the ByteHolder for this stream, and pass it in.

      Parameters:
      bh - ByteHolder to hold buffers of bytes as the stream is walked. Expected usage is that a page worth of data is held in memory at a time, filled by a calls to restorePortionLongColumn().
      owner - BaseContainerHandle used to read pages from the container. Note this handle is closed automatically on commit.
      overflowPage - The first overflow page of this long column.
      overflowId - The record id of 1st segment of the long column on overflowPage.
      recordToLock - RecordHandle of the owning record of the long long column, this is the row level lock to get.
  • Method Details

    • fillByteHolder

      public void fillByteHolder() throws IOException
      If bytes remain in stream, insure the current buffer is not empty.

      If there are bytes in current buffer than no more work necessary, else if there are no bytes available in current buffer and there are still more overflow segments then get the next buffer's worth of data.

      Specified by:
      fillByteHolder in class BufferedByteHolderInputStream
      Throws:
      IOException
    • setOverflowPage

      public void setOverflowPage(long overflowPage)
      Set the next overflow page of the long column.

      Used by StorePage.restorePortionLongColumn() as part of the call back process to save the state of the scan of the pieces of the long column. StorePage.restorePortionLongColumn() is called by fillByteHolder() to get the next page worth into a buffer, and in turn after those bytes are read the state of this stream is updated with then next overflow page.

      Parameters:
      overflowPage - Page number containing the next segment of the long column. -1 if there are no more segments.
    • setOverflowId

      public void setOverflowId(int overflowId)
      Set the next overflow page of the long column.

      Used by StorePage.restorePortionLongColumn() as part of the call back process to save the state of the scan of the pieces of the long column. StorePage.restorePortionLongColumn() is called by fillByteHolder() to get the next page worth into a buffer, and in turn after those bytes are read the state of this stream is updated with then next overflow page.

      Parameters:
      overflowId - Page number containing the next segment of the long column. -1 if there are no more segments.
    • getOverflowPage

      public long getOverflowPage()
    • getOverflowId

      public int getOverflowId()
    • initStream

      public void initStream() throws StandardException
      Initialize a Resetable stream.

      InitStream() must be called first before using any other of the Resetable interfaces.

      Reopens the container. This gets a separate intent shared locked on the table and a read lock on the appropriate row. These locks remain until the enclosing blob/clob object is closed, or until the end of the transaction in which initStream() was first called. This locking behavior protects the row while the stream is being accessed. Otherwise for instance in the case of read committed the original row lock on the row would be released when the scan went to the next row, and there would be nothing to stop another transaction from deleting the row while the client read through the stream.

      Specified by:
      initStream in interface Resetable
      Throws:
      StandardException - Standard exception policy.
    • resetStream

      public void resetStream() throws IOException, StandardException
      Reset the stream back to beginning of the long column.

      Also fills in the first buffer from the stream.

      Throws exception if the underlying open container has been closed, for example automatically by a commit().

      Specified by:
      resetStream in interface Resetable
      Throws:
      StandardException - Standard exception policy.
      IOException
    • closeStream

      public void closeStream()
      Close the Resetable stream.

      Close the container associated with this stream. (This will also free the associated IS table lock and the associated S row lock.)

      Specified by:
      closeStream in interface Resetable
    • cloneStream

      public InputStream cloneStream()
      Clone this object.

      Creates a deep copy of this object. The returned stream has its own working buffers and can be initialized, reset and read independently from this stream.

      The cloned stream is set back to the beginning of stream, no matter where the current stream happens to be positioned.

      Specified by:
      cloneStream in interface CloneableStream
      Returns:
      Copy of this stream which can be used independently.