final class StoreStreamClob extends java.lang.Object implements InternalClob
Note that the streams from the store are expected to have the following properties:
0xe0 0x00 0x00
Modifier and Type | Field and Description |
---|---|
private ConnectionChild |
conChild
The connection (child) this Clob belongs to.
|
private CharacterStreamDescriptor |
csd
The descriptor used to describe the underlying source stream.
|
private UTF8Reader |
internalReader
Shared internal reader, closed when the Clob is released.
|
private PositionedStoreStream |
positionedStoreStream
The stream from store, used to read bytes from the database.
|
private boolean |
released
Tells whether this Clob has been released or not.
|
private java.lang.Object |
synchronizationObject
Object used for synchronizing access to the store stream.
|
private java.io.FilterReader |
unclosableInternalReader
The internal reader wrapped so that it cannot be closed.
|
Constructor and Description |
---|
StoreStreamClob(CharacterStreamDescriptor csd,
ConnectionChild conChild)
Creates a new Clob based on a stream from store.
|
Modifier and Type | Method and Description |
---|---|
private void |
checkIfValid()
Makes sure the Clob has not been released.
|
long |
getCharLength()
Returns the number of characters in the Clob.
|
long |
getCharLengthIfKnown()
Returns the cached character count for the Clob, if any.
|
java.io.Reader |
getInternalReader(long characterPosition)
Returns an internal reader for the Clob, initialized at the specified
character position.
|
java.io.InputStream |
getRawByteStream()
Returns a stream serving the raw bytes of this Clob.
|
java.io.Reader |
getReader(long pos)
Returns a reader for the Clob, initialized at the specified character
position.
|
long |
getUpdateCount()
Returns the update count of this Clob.
|
java.io.Writer |
getWriter(long pos)
Not supported.
|
long |
insertString(java.lang.String str,
long pos)
Not supported.
|
boolean |
isReleased()
Tells if this Clob has been released.
|
boolean |
isWritable()
Tells if this Clob can be modified.
|
private static java.sql.SQLException |
noStateChangeLOB(java.lang.Throwable t)
Wrap real exception in a
SQLException to avoid changing the state
of the connection child by cleaning it up. |
void |
release()
Releases resources associated with this Clob.
|
void |
truncate(long newLength)
Not supported.
|
private volatile boolean released
private final PositionedStoreStream positionedStoreStream
To be able to support the requirements, the stream must implement
Resetable
.
private CharacterStreamDescriptor csd
private final ConnectionChild conChild
private final java.lang.Object synchronizationObject
private UTF8Reader internalReader
getSubString
calls. Often a
subset, or the whole, of the Clob is read subsequently and then this
optimization avoids repositioning costs (the store does not support
random access for LOBs).
NOTE: Do not publish this reader to the end-user.private java.io.FilterReader unclosableInternalReader
public StoreStreamClob(CharacterStreamDescriptor csd, ConnectionChild conChild) throws StandardException
The stream used as a source for this Clob has to implement the interface
Resetable
, as the stream interface from store only allows for
movement forwards. If the stream has been advanced too far with regards
to the user request, the stream must be reset and we start from the
beginning.
csd
- descriptor for the source stream, including a reference to itconChild
- the connection (child) this Clob belongs toStandardException
public void release()
release
in interface InternalClob
public long getCharLength() throws java.sql.SQLException
getCharLength
in interface InternalClob
java.sql.SQLException
- if any kind of error is encountered, be it related
to I/O or something elsepublic long getCharLengthIfKnown()
getCharLengthIfKnown
in interface InternalClob
-1
if unknown.public java.io.InputStream getRawByteStream() throws java.io.IOException, java.sql.SQLException
Note that the stream returned is an internal stream, and it should not be pulished to end users.
getRawByteStream
in interface InternalClob
java.io.IOException
- if accessing the I/O resources failjava.sql.SQLException
- if accessing the store resources failpublic java.io.Reader getReader(long pos) throws java.io.IOException, java.sql.SQLException
getReader
in interface InternalClob
pos
- character position. The first character is at position 1.java.io.EOFException
- if the positions is larger than the Clobjava.io.IOException
- if accessing the I/O resources failjava.sql.SQLException
- if accessing the store resources failpublic java.io.Reader getInternalReader(long characterPosition) throws java.io.IOException, java.sql.SQLException
getInternalReader
in interface InternalClob
characterPosition
- 1-based character position.java.io.EOFException
- if the positions is larger than the Clobjava.io.IOException
- if accessing the I/O resources failjava.sql.SQLException
- if accessing the store resources failpublic long getUpdateCount()
Always returns zero, as this Clob cannot be updated.
getUpdateCount
in interface InternalClob
public java.io.Writer getWriter(long pos)
getWriter
in interface InternalClob
pos
- the starting character position. The first character is
at position 1
.InternalClob.getWriter(long)
public long insertString(java.lang.String str, long pos)
insertString
in interface InternalClob
str
- the string to insertpos
- the character position the string will be inserted at. Must be
between 1
and clob.length() +1
, inclusive.InternalClob.insertString(java.lang.String, long)
public boolean isReleased()
isReleased
in interface InternalClob
true
if released, false
if not.public boolean isWritable()
isWritable
in interface InternalClob
false
, this Clob is read-only.public void truncate(long newLength)
truncate
in interface InternalClob
newLength
- the length in characters to truncate toInternalClob.truncate(long)
private static java.sql.SQLException noStateChangeLOB(java.lang.Throwable t)
SQLException
to avoid changing the state
of the connection child by cleaning it up.t
- real cause of error that we want to "ignore" with respect to
transaction context cleanupSQLException
wrapped around the real cause of the errorprivate void checkIfValid()
All operations are invalid on a released Clob.
java.lang.IllegalStateException
- if the Clob has been releasedApache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.