Class ClobUpdatableReader
- java.lang.Object
-
- java.io.Reader
-
- org.apache.derby.impl.jdbc.ClobUpdatableReader
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.lang.Readable
final class ClobUpdatableReader extends java.io.ReaderClobUpdatableReaderis used to create aReadercapable 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 EmbedClobclobThe Clob object we are reading from.private booleanclosedTells if this reader has been closed.private InternalClobiClobThe current internal representation of the Clob content.private longlastUpdateCountThe last update count seen on the underlying Clob.private longmaxPosPosition in Clob where to stop reading unless EOF is reached first.private longposCharacter position of this reader (1-based).private java.io.ReaderstreamReaderReader accessing the Clob data and doing the work.
-
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 voidclose()Closes this reader.intread()intread(char[] cbuf, int off, int len)longskip(long len)private voidupdateReaderIfRequired()Updates the reader if the underlying data has been modified.
-
-
-
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 failsjava.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 datainitialPos- the first character that will be readlength- the maximum number of characters that will read- Throws:
java.io.IOException- if obtaining the underlying reader failsjava.sql.SQLException- if obtaining the underlying reader fails
-
-
Method Detail
-
read
public int read() throws java.io.IOException- Overrides:
readin classjava.io.Reader- Throws:
java.io.IOException
-
read
public int read(char[] cbuf, int off, int len) throws java.io.IOException- Specified by:
readin classjava.io.Reader- Throws:
java.io.IOException
-
skip
public long skip(long len) throws java.io.IOException- Overrides:
skipin classjava.io.Reader- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOExceptionCloses this reader.An
IOExceptionwill be thrown if any of the read or skip methods are called after the reader has been closed.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classjava.io.Reader- Throws:
java.io.IOException- if an error occurs while closing
-
updateReaderIfRequired
private void updateReaderIfRequired() throws java.io.IOExceptionUpdates the reader if the underlying data has been modified.There are two cases to deal with:
- The underlying data of the internal Clob representation has been modified.
- The internal Clob representation has changed.
- Throws:
java.io.IOException- if verifying or updating the reader fails
-
-