Class TemporaryClob
- All Implemented Interfaces:
InternalClob
Character positions given as input to methods in this class are always 1-based. Byte positions are always 0-based.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
A simple class to hold the byte position for a character position. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final LOBStreamControl
Underlying structure holding this Clobs raw bytes.private long
Cached character length of the Clob.private ConnectionChild
Connection child assoicated with this Clob.private UTF8Reader
Shared internal reader, closed when the Clob is released.private final TemporaryClob.CharToBytePositionCache
Simple one-entry cache for character-byte position.private boolean
Tells whether this Clob has been released or not.private FilterReader
The internal reader wrapped so that it cannot be closed. -
Constructor Summary
ConstructorsConstructorDescriptionTemporaryClob
(String data, ConnectionChild conChild) Constructs aTemporaryClob
object and initializes with a initial String.TemporaryClob
(ConnectionChild conChild) Constructs aTemporaryClob
object used to perform operations on a CLOB value. -
Method Summary
Modifier and TypeMethodDescriptionprivate final void
Makes sure the Clob has not been released.(package private) static InternalClob
cloneClobContent
(String dbName, ConnectionChild conChild, InternalClob clob) Clones the content of another internal Clob.(package private) static InternalClob
cloneClobContent
(String dbName, ConnectionChild conChild, InternalClob clob, long length) Clones the content of another internal Clob.private void
copyClobContent
(InternalClob clob) Copies the content of another Clob into this one.private void
copyClobContent
(InternalClob clob, long charLength) Copies the content of another Clob into this one.private byte[]
getByteFromString
(String str) Converts a string into the modified UTF-8 byte encoding.long
Returns the size of the Clob in bytes.private long
getBytePosition
(long charPos) Finds the corresponding byte position for the given UTF-8 character position, starting from the byte positionstartPos
.long
Returns number of characters in the Clob.long
Returns the cached character count for the Clob, if any.private final CharacterStreamDescriptor
getCSD()
Returns a character stream descriptor for the stream.getInternalReader
(long characterPosition) Returns an internal reader for the Clob content, initialized at the specified character position.Returns a stream serving the raw bytes of this Clob.getReader
(long pos) Constructs and returns aReader
.long
Returns the update count of this Clob.getWriter
(long pos) Constructs and returns aWriter
for the CLOB value.long
insertString
(String str, long insertionPoint) Inserts a string at the given position.boolean
Tells if this Clob has been released.boolean
Tells if this Clob is intended to be writable.void
release()
Releases this Clob by freeing assoicated resources.void
truncate
(long newCharLength) Truncate the Clob to the specifiec size.private final void
updateInternalState
(long charChangePosition) Updates the internal state after a modification has been performed on the Clob content.
-
Field Details
-
conChild
Connection child assoicated with this Clob.Currently only used for synchronization in *some* streams associated with the Clob. This suggests something is off wrt. synchronization.
-
bytes
Underlying structure holding this Clobs raw bytes. -
released
private boolean releasedTells whether this Clob has been released or not. -
cachedCharLength
private long cachedCharLengthCached character length of the Clob.A value of
0
is interpreted as unknown length, even though it is a valid value. If the length is requested and the value is zero, an attempt to obtain the length is made by draining the source. -
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 instancegetSubString
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. -
unclosableInternalReader
The internal reader wrapped so that it cannot be closed. -
posCache
Simple one-entry cache for character-byte position.
-
-
Constructor Details
-
TemporaryClob
TemporaryClob(ConnectionChild conChild) Constructs aTemporaryClob
object used to perform operations on a CLOB value.- Parameters:
conChild
- connection object used to obtain synchronization object- Throws:
NullPointerException
- ifconChild
isnull
-
TemporaryClob
TemporaryClob(String data, ConnectionChild conChild) throws IOException, StandardException Constructs aTemporaryClob
object and initializes with a initial String.- Parameters:
data
- initial value in StringconChild
- connection object used to obtain synchronization object- Throws:
IOException
StandardException
-
-
Method Details
-
cloneClobContent
static InternalClob cloneClobContent(String dbName, ConnectionChild conChild, InternalClob clob) throws IOException, SQLException Clones the content of another internal Clob.- Parameters:
dbName
- name of the assoicated databaseconChild
- assoiated connection childclob
- the Clob whose content to clone- Returns:
- A read-write Clob.
- Throws:
IOException
- if accessing the I/O resources fail (read or write)SQLException
- if accessing underlying resources fail
-
cloneClobContent
static InternalClob cloneClobContent(String dbName, ConnectionChild conChild, InternalClob clob, long length) throws IOException, SQLException Clones the content of another internal Clob.- Parameters:
dbName
- name of the assoicated databaseconChild
- assoiated connection childclob
- the Clob whose content to clonelength
- number of chars in new InternalClob- Returns:
- A read-write Clob.
- Throws:
IOException
- if accessing the I/O resources fail (read or write)SQLException
- if accessing underlying resources fail
-
release
Releases this Clob by freeing assoicated resources.- Specified by:
release
in interfaceInternalClob
- Throws:
IOException
- if accessing underlying I/O resources fail
-
getRawByteStream
Returns a stream serving the raw bytes of this Clob.The stream is managed by the underlying byte store, and can serve bytes both from memory and from a file on disk.
- Specified by:
getRawByteStream
in interfaceInternalClob
- Returns:
- A stream serving the raw bytes of the stream, initialized at
byte position
0
. - Throws:
IOException
- if obtaining the stream fails
-
getBytePosition
Finds the corresponding byte position for the given UTF-8 character position, starting from the byte positionstartPos
. See comments in SQLChar.readExternal for more notes on processing the UTF8 format.- Parameters:
charPos
- character position- Returns:
- Stream position in bytes for the given character position.
- Throws:
EOFException
- if the character position specified is greater than the Clob length +1IOException
- if accessing underlying I/O resources fail
-
getUpdateCount
public long getUpdateCount()Returns the update count of this Clob.- Specified by:
getUpdateCount
in interfaceInternalClob
- Returns:
- Update count.
-
getWriter
Constructs and returns aWriter
for the CLOB value.- Specified by:
getWriter
in interfaceInternalClob
- Parameters:
pos
- the initial position in bytes for theWriter
- Returns:
- A
Writer
to write to the CLOB value. - Throws:
IOException
SQLException
- if the specified position is invalid
-
getReader
Constructs and returns aReader
.- Specified by:
getReader
in interfaceInternalClob
- Parameters:
pos
- initial position of the returnedReader
in number of characters. Expected to be non-negative. The first character is at position0
.- Returns:
- A
Reader
with the underlyingCLOB
value as source. - Throws:
IOException
SQLException
- if the specified position is too big
-
getInternalReader
Description copied from interface:InternalClob
Returns an internal reader for the Clob content, initialized at the specified character position.This method can return a shared reader object, avoiding instantiation and repositioning costs for internal operations where the stream itself is not published to the end-user. One such example is
Clob.getSubString
.- Specified by:
getInternalReader
in interfaceInternalClob
- Parameters:
characterPosition
- character position. The first character is at position1
.- Returns:
- A
Reader
serving the content of the Clob. - Throws:
IOException
SQLException
- See Also:
-
getCharLength
Returns number of characters in the Clob.- Specified by:
getCharLength
in interfaceInternalClob
- Returns:
- The length of the Clob in number of characters.
- Throws:
IOException
- if accessing the underlying I/O resources fail
-
getCharLengthIfKnown
public long getCharLengthIfKnown()Returns the cached character count for the Clob, if any.- Specified by:
getCharLengthIfKnown
in interfaceInternalClob
- Returns:
- The number of characters in the Clob, or
-1
if unknown.
-
getByteLength
Returns the size of the Clob in bytes.- Returns:
- Number of bytes in the
CLOB
value. - Throws:
IOException
- if accessing the underlying I/O resources fail
-
insertString
Inserts a string at the given position.- Specified by:
insertString
in interfaceInternalClob
- Parameters:
str
- the string to insertinsertionPoint
- the character position to insert the string at- Returns:
- Number of characters inserted.
- Throws:
EOFException
- if the position is larger than the Clob length +1IOException
- if accessing the underlying I/O resources failSQLException
- if accessing the underlying resources fail
-
isReleased
public boolean isReleased()Tells if this Clob has been released.- Specified by:
isReleased
in interfaceInternalClob
- Returns:
true
if released,false
if not.
-
isWritable
public boolean isWritable()Tells if this Clob is intended to be writable.- Specified by:
isWritable
in interfaceInternalClob
- Returns:
true
-
truncate
Truncate the Clob to the specifiec size.- Specified by:
truncate
in interfaceInternalClob
- Parameters:
newCharLength
- the new length, in characters, of the Clob- Throws:
IOException
- if accessing the underlying I/O resources failsSQLException
- if accessing underlying resources fail
-
getByteFromString
Converts a string into the modified UTF-8 byte encoding.- Parameters:
str
- string to represent with modified UTF-8 encoding- Returns:
- Byte array representing the string in modified UTF-8 encoding.
-
copyClobContent
Copies the content of another Clob into this one.- Parameters:
clob
- the Clob to copy from- Throws:
IOException
- if accessing I/O resources fail (both read and write)SQLException
- if accessing underlying resources fail
-
copyClobContent
Copies the content of another Clob into this one.- Parameters:
clob
- the Clob to copy fromcharLength
- number of chars to copy- Throws:
EOFException
- if the length of the stream is shorter than the specified lengthIOException
- if accessing I/O resources fail (both read and write)SQLException
- if accessing underlying resources fail
-
checkIfValid
private final 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
-
updateInternalState
private final void updateInternalState(long charChangePosition) Updates the internal state after a modification has been performed on the Clob content.Currently the state update consists of dicarding the internal reader to stop it from delivering stale data, to reset the byte/char position cache if necessary, and to reset the cached length.
- Parameters:
charChangePosition
- the position where the Clob change started
-
getCSD
Returns a character stream descriptor for the stream.All streams from the underlying source (
LOBStreamControl
) are position aware and can be moved to a specific byte position cheaply. The maximum length is not really needed, nor known, at the moment, so the maximum allowed Clob length in Derby is used.- Returns:
- A character stream descriptor.
- Throws:
IOException
- if obtaining the length of the stream fails
-