Class OverflowInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.derby.impl.store.raw.data.ByteHolderInputStream
-
- org.apache.derby.impl.store.raw.data.BufferedByteHolderInputStream
-
- org.apache.derby.impl.store.raw.data.OverflowInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.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 Summary
Fields Modifier and Type Field Description protected int
firstOverflowId
protected long
firstOverflowPage
private boolean
initialized
protected int
overflowId
protected long
overflowPage
protected BaseContainerHandle
owner
Fields of the classprotected RecordHandle
recordToLock
-
Fields inherited from class org.apache.derby.impl.store.raw.data.ByteHolderInputStream
bh
-
-
Constructor Summary
Constructors Constructor Description OverflowInputStream(ByteHolder bh, BaseContainerHandle owner, long overflowPage, int overflowId, RecordHandle recordToLock)
Constructor for OverflowInputStream
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.InputStream
cloneStream()
Clone this object.void
closeStream()
Close the Resetable stream.void
fillByteHolder()
If bytes remain in stream, insure the current buffer is not empty.int
getOverflowId()
long
getOverflowPage()
void
initStream()
Initialize a Resetable stream.void
resetStream()
Reset the stream back to beginning of the long column.void
setOverflowId(int overflowId)
Set the next overflow page of the long column.void
setOverflowPage(long overflowPage)
Set the next overflow page of the long column.-
Methods inherited from class org.apache.derby.impl.store.raw.data.BufferedByteHolderInputStream
available, read, read, skip
-
Methods inherited from class org.apache.derby.impl.store.raw.data.ByteHolderInputStream
getByteHolder, setByteHolder
-
-
-
-
Field Detail
-
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 Detail
-
OverflowInputStream
public OverflowInputStream(ByteHolder bh, BaseContainerHandle owner, long overflowPage, int overflowId, RecordHandle recordToLock)
Constructor for OverflowInputStreamIt 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 Detail
-
fillByteHolder
public void fillByteHolder() throws java.io.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 classBufferedByteHolderInputStream
- Throws:
java.io.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 interfaceResetable
- Throws:
StandardException
- Standard exception policy.
-
resetStream
public void resetStream() throws java.io.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 interfaceResetable
- Throws:
StandardException
- Standard exception policy.java.io.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 interfaceResetable
-
cloneStream
public java.io.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 interfaceCloneableStream
- Returns:
- Copy of this stream which can be used independently.
-
-