org.apache.derby.impl.jdbc
Class ClobUpdatableReader

java.lang.Object
  extended by java.io.Reader
      extended by org.apache.derby.impl.jdbc.ClobUpdatableReader
All Implemented Interfaces:
java.io.Closeable, 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
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
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
 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, read, read, ready, reset
 
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.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

Built on Thu 2012-03-29 21:53:33+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.