InternalClob
final class TemporaryClob extends java.lang.Object implements InternalClob
Character positions given as input to methods in this class are always 1-based. Byte positions are always 0-based.
Modifier and Type | Class | Description |
---|---|---|
private static class |
TemporaryClob.CharToBytePositionCache |
A simple class to hold the byte position for a character position.
|
Modifier and Type | Field | Description |
---|---|---|
private LOBStreamControl |
bytes |
Underlying structure holding this Clobs raw bytes.
|
private long |
cachedCharLength |
Cached character length of the Clob.
|
private ConnectionChild |
conChild |
Connection child assoicated with this Clob.
|
private UTF8Reader |
internalReader |
Shared internal reader, closed when the Clob is released.
|
private TemporaryClob.CharToBytePositionCache |
posCache |
Simple one-entry cache for character-byte position.
|
private boolean |
released |
Tells whether this Clob has been released or not.
|
private java.io.FilterReader |
unclosableInternalReader |
The internal reader wrapped so that it cannot be closed.
|
Constructor | Description |
---|---|
TemporaryClob(java.lang.String data,
ConnectionChild conChild) |
Constructs a
TemporaryClob object and
initializes with a initial String. |
TemporaryClob(ConnectionChild conChild) |
Constructs a
TemporaryClob object used to perform
operations on a CLOB value. |
Modifier and Type | Method | Description |
---|---|---|
private void |
checkIfValid() |
Makes sure the Clob has not been released.
|
(package private) static InternalClob |
cloneClobContent(java.lang.String dbName,
ConnectionChild conChild,
InternalClob clob) |
Clones the content of another internal Clob.
|
(package private) static InternalClob |
cloneClobContent(java.lang.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(java.lang.String str) |
Converts a string into the modified UTF-8 byte encoding.
|
long |
getByteLength() |
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 position
startPos . |
long |
getCharLength() |
Returns number of characters in the Clob.
|
long |
getCharLengthIfKnown() |
Returns the cached character count for the Clob, if any.
|
private CharacterStreamDescriptor |
getCSD() |
Returns a character stream descriptor for the stream.
|
java.io.Reader |
getInternalReader(long characterPosition) |
Returns an internal reader for the Clob content, 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) |
Constructs and returns a
Reader . |
long |
getUpdateCount() |
Returns the update count of this Clob.
|
java.io.Writer |
getWriter(long pos) |
Constructs and returns a
Writer for the CLOB value. |
long |
insertString(java.lang.String str,
long insertionPoint) |
Inserts a string at the given position.
|
boolean |
isReleased() |
Tells if this Clob has been released.
|
boolean |
isWritable() |
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 void |
updateInternalState(long charChangePosition) |
Updates the internal state after a modification has been performed on
the Clob content.
|
private ConnectionChild conChild
Currently only used for synchronization in *some* streams associated with the Clob. This suggests something is off wrt. synchronization.
private final LOBStreamControl bytes
private boolean released
private long cachedCharLength
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.
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
private final TemporaryClob.CharToBytePositionCache posCache
TemporaryClob(ConnectionChild conChild)
TemporaryClob
object used to perform
operations on a CLOB value.conChild
- connection object used to obtain synchronization objectjava.lang.NullPointerException
- if conChild
is
null
TemporaryClob(java.lang.String data, ConnectionChild conChild) throws java.io.IOException, StandardException
TemporaryClob
object and
initializes with a initial String.data
- initial value in StringconChild
- connection object used to obtain synchronization objectjava.io.IOException
StandardException
static InternalClob cloneClobContent(java.lang.String dbName, ConnectionChild conChild, InternalClob clob) throws java.io.IOException, java.sql.SQLException
dbName
- name of the assoicated databaseconChild
- assoiated connection childclob
- the Clob whose content to clonejava.io.IOException
- if accessing the I/O resources fail (read or write)java.sql.SQLException
- if accessing underlying resources failstatic InternalClob cloneClobContent(java.lang.String dbName, ConnectionChild conChild, InternalClob clob, long length) throws java.io.IOException, java.sql.SQLException
dbName
- name of the assoicated databaseconChild
- assoiated connection childclob
- the Clob whose content to clonelength
- number of chars in new InternalClobjava.io.IOException
- if accessing the I/O resources fail (read or write)java.sql.SQLException
- if accessing underlying resources failpublic void release() throws java.io.IOException
release
in interface InternalClob
java.io.IOException
- if accessing underlying I/O resources failpublic java.io.InputStream getRawByteStream() throws java.io.IOException
The stream is managed by the underlying byte store, and can serve bytes both from memory and from a file on disk.
getRawByteStream
in interface InternalClob
0
.java.io.IOException
- if obtaining the stream failsprivate long getBytePosition(long charPos) throws java.io.IOException
startPos
.
See comments in SQLChar.readExternal for more notes on
processing the UTF8 format.charPos
- character positionjava.io.EOFException
- if the character position specified is greater than
the Clob length +1java.io.IOException
- if accessing underlying I/O resources failpublic long getUpdateCount()
getUpdateCount
in interface InternalClob
public java.io.Writer getWriter(long pos) throws java.io.IOException, java.sql.SQLException
Writer
for the CLOB value.getWriter
in interface InternalClob
pos
- the initial position in bytes for the Writer
Writer
to write to the CLOB value.java.io.IOException
java.sql.SQLException
- if the specified position is invalidpublic java.io.Reader getReader(long pos) throws java.io.IOException, java.sql.SQLException
Reader
.getReader
in interface InternalClob
pos
- initial position of the returned Reader
in
number of characters. Expected to be non-negative. The first
character is at position 0
.Reader
with the underlying CLOB
value as source.java.io.IOException
java.sql.SQLException
- if the specified position is too bigpublic java.io.Reader getInternalReader(long characterPosition) throws java.io.IOException, java.sql.SQLException
InternalClob
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
.
getInternalReader
in interface InternalClob
characterPosition
- character position. The first character is at
position 1
.Reader
serving the content of the Clob.java.io.IOException
- if accessing underlying I/O resources failjava.sql.SQLException
- if accessing underlying resources failgetReader(long)
public long getCharLength() throws java.io.IOException
getCharLength
in interface InternalClob
java.io.IOException
- if accessing the underlying I/O resources failpublic long getCharLengthIfKnown()
getCharLengthIfKnown
in interface InternalClob
-1
if unknown.public long getByteLength() throws java.io.IOException
CLOB
value.java.io.IOException
- if accessing the underlying I/O resources failpublic long insertString(java.lang.String str, long insertionPoint) throws java.io.IOException, java.sql.SQLException
insertString
in interface InternalClob
str
- the string to insertinsertionPoint
- the character position to insert the string atjava.io.EOFException
- if the position is larger than the Clob length +1java.io.IOException
- if accessing the underlying I/O resources failjava.sql.SQLException
- if accessing the underlying resources failpublic boolean isReleased()
isReleased
in interface InternalClob
true
if released, false
if not.public boolean isWritable()
isWritable
in interface InternalClob
true
public void truncate(long newCharLength) throws java.io.IOException, java.sql.SQLException
truncate
in interface InternalClob
newCharLength
- the new length, in characters, of the Clobjava.io.IOException
- if accessing the underlying I/O resources failsjava.sql.SQLException
- if accessing underlying resources failprivate byte[] getByteFromString(java.lang.String str)
str
- string to represent with modified UTF-8 encodingprivate void copyClobContent(InternalClob clob) throws java.io.IOException, java.sql.SQLException
clob
- the Clob to copy fromjava.io.IOException
- if accessing I/O resources fail (both read and write)java.sql.SQLException
- if accessing underlying resources failprivate void copyClobContent(InternalClob clob, long charLength) throws java.io.IOException, java.sql.SQLException
clob
- the Clob to copy fromcharLength
- number of chars to copyjava.io.EOFException
- if the length of the stream is shorter than the
specified lengthjava.io.IOException
- if accessing I/O resources fail (both read and write)java.sql.SQLException
- if accessing underlying resources failprivate final void checkIfValid()
All operations are invalid on a released Clob.
java.lang.IllegalStateException
- if the Clob has been releasedprivate final void updateInternalState(long charChangePosition)
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.
charChangePosition
- the position where the Clob change startedprivate final CharacterStreamDescriptor getCSD() throws java.io.IOException
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.
java.io.IOException
- if obtaining the length of the stream failsApache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.