Class StoreStreamClob
java.lang.Object
org.apache.derby.impl.jdbc.StoreStreamClob
- All Implemented Interfaces:
InternalClob
A read-only Clob representation operating on streams out of the Derby store
module.
Note that the streams from the store are expected to have the following properties:
- The first few bytes are used for length encoding. Currently the number of bytes is either 2 or 5.
- A Derby-specific end-of-stream marker at the end of the stream can
be present. The marker is expected to be
0xe0 0x00 0x00
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConnectionChildThe connection (child) this Clob belongs to.private CharacterStreamDescriptorThe descriptor used to describe the underlying source stream.private UTF8ReaderShared internal reader, closed when the Clob is released.private final PositionedStoreStreamThe stream from store, used to read bytes from the database.private booleanTells whether this Clob has been released or not.private final ObjectObject used for synchronizing access to the store stream.private FilterReaderThe internal reader wrapped so that it cannot be closed. -
Constructor Summary
ConstructorsConstructorDescriptionStoreStreamClob(CharacterStreamDescriptor csd, ConnectionChild conChild) Creates a new Clob based on a stream from store. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidMakes sure the Clob has not been released.longReturns the number of characters in the Clob.longReturns the cached character count for the Clob, if any.getInternalReader(long characterPosition) Returns an internal reader for the Clob, initialized at the specified character position.Returns a stream serving the raw bytes of this Clob.getReader(long pos) Returns a reader for the Clob, initialized at the specified character position.longReturns the update count of this Clob.getWriter(long pos) Not supported.longinsertString(String str, long pos) Not supported.booleanTells if this Clob has been released.booleanTells if this Clob can be modified.private static SQLExceptionWrap real exception in aSQLExceptionto avoid changing the state of the connection child by cleaning it up.voidrelease()Releases resources associated with this Clob.voidtruncate(long newLength) Not supported.
-
Field Details
-
released
private volatile boolean releasedTells whether this Clob has been released or not. -
positionedStoreStream
The stream from store, used to read bytes from the database.To be able to support the requirements, the stream must implement
Resetable. -
csd
The descriptor used to describe the underlying source stream. -
conChild
The connection (child) this Clob belongs to. -
synchronizationObject
Object used for synchronizing access to the store stream. -
internalReader
Shared internal reader, closed when the Clob is released. This is a performance optimization, and the stream is shared between "one time" operations, for instancegetSubStringcalls. 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. -
unclosableInternalReader
The internal reader wrapped so that it cannot be closed.
-
-
Constructor Details
-
StoreStreamClob
public StoreStreamClob(CharacterStreamDescriptor csd, ConnectionChild conChild) throws StandardException Creates a new Clob based on a stream from store.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.- Parameters:
csd- descriptor for the source stream, including a reference to itconChild- the connection (child) this Clob belongs to- Throws:
StandardException
-
-
Method Details
-
release
public void release()Releases resources associated with this Clob.- Specified by:
releasein interfaceInternalClob
-
getCharLength
Returns the number of characters in the Clob.- Specified by:
getCharLengthin interfaceInternalClob- Returns:
- Number of characters in the Clob.
- Throws:
SQLException- if any kind of error is encountered, be it related to I/O or something else
-
getCharLengthIfKnown
public long getCharLengthIfKnown()Returns the cached character count for the Clob, if any.- Specified by:
getCharLengthIfKnownin interfaceInternalClob- Returns:
- The number of characters in the Clob, or
-1if unknown.
-
getRawByteStream
Returns a stream serving the raw bytes of this Clob.Note that the stream returned is an internal stream, and it should not be pulished to end users.
- Specified by:
getRawByteStreamin interfaceInternalClob- Returns:
- A stream serving the bytes of this Clob, initialized at byte 0 of the data. The buffer must be assumed to be unbuffered, but no such guarantee is made.
- Throws:
IOException- if accessing the I/O resources failSQLException- if accessing the store resources fail
-
getReader
Returns a reader for the Clob, initialized at the specified character position.- Specified by:
getReaderin interfaceInternalClob- Parameters:
pos- character position. The first character is at position 1.- Returns:
- A reader initialized at the specified position.
- Throws:
EOFException- if the positions is larger than the ClobIOException- if accessing the I/O resources failSQLException- if accessing the store resources fail
-
getInternalReader
Returns an internal reader for the Clob, initialized at the specified character position.- Specified by:
getInternalReaderin interfaceInternalClob- Parameters:
characterPosition- 1-based character position.- Returns:
- A reader initialized at the specified position.
- Throws:
EOFException- if the positions is larger than the ClobIOException- if accessing the I/O resources failSQLException- if accessing the store resources fail
-
getUpdateCount
public long getUpdateCount()Returns the update count of this Clob.Always returns zero, as this Clob cannot be updated.
- Specified by:
getUpdateCountin interfaceInternalClob- Returns:
- Zero (read-only Clob).
-
getWriter
Not supported.- Specified by:
getWriterin interfaceInternalClob- Parameters:
pos- the starting character position. The first character is at position1.- Returns:
- A writer initialized at the specified character position.
- See Also:
-
insertString
Not supported.- Specified by:
insertStringin interfaceInternalClob- Parameters:
str- the string to insertpos- the character position the string will be inserted at. Must be between1andclob.length() +1, inclusive.- Returns:
- The number of characters inserted.
- See Also:
-
isReleased
public boolean isReleased()Tells if this Clob has been released.- Specified by:
isReleasedin interfaceInternalClob- Returns:
trueif released,falseif not.
-
isWritable
public boolean isWritable()Tells if this Clob can be modified.- Specified by:
isWritablein interfaceInternalClob- Returns:
false, this Clob is read-only.
-
truncate
public void truncate(long newLength) Not supported.- Specified by:
truncatein interfaceInternalClob- Parameters:
newLength- the length in characters to truncate to- See Also:
-
noStateChangeLOB
Wrap real exception in aSQLExceptionto avoid changing the state of the connection child by cleaning it up.- Parameters:
t- real cause of error that we want to "ignore" with respect to transaction context cleanup- Returns:
- A
SQLExceptionwrapped around the real cause of the error
-
checkIfValid
private void checkIfValid()Makes sure the Clob has not been released.All operations are invalid on a released Clob.
- Throws:
IllegalStateException- if the Clob has been released
-