Top Description Fields Constructors Methods
org.apache.derby.impl.jdbc

pack-priv final Class StoreStreamClob

extends Object
implements InternalClob
Class Inheritance
All Implemented Interfaces
org.apache.derby.impl.jdbc.InternalClob
Imports
java.io.BufferedInputStream, .EOFException, .FilterReader, .IOException, .InputStream, .Reader, .Writer, java.sql.SQLException, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.jdbc.CharacterStreamDescriptor, org.apache.derby.shared.common.reference.SQLState, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.types.Resetable, org.apache.derby.iapi.util.UTF8Util

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:

  1. The first few bytes are used for length encoding. Currently the number of bytes is either 2 or 5.
  2. 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

Modifier and TypeField and Description
private final 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 final PositionedStoreStream
positionedStoreStream

The stream from store, used to read bytes from the database.

private volatile boolean
released

Tells whether this Clob has been released or not.

private final Object
synchronizationObject

Object used for synchronizing access to the store stream.

private FilterReader
unclosableInternalReader

The internal reader wrapped so that it cannot be closed.

Constructor Summary

AccessConstructor and Description
public
StoreStreamClob(CharacterStreamDescriptor
descriptor for the source stream, including a reference to it
csd
,
ConnectionChild
the connection (child) this Clob belongs to
conChild
)

Creates a new Clob based on a stream from store.

Method Summary

Modifier and TypeMethod and Description
private void
checkIfValid()

Makes sure the Clob has not been released.

public long

Returns:

Number of characters in the Clob.
getCharLength
()

Implements org.apache.derby.impl.jdbc.InternalClob.getCharLength.

Returns the number of characters in the Clob.

public long

Returns:

The number of characters in the Clob, or -1 if unknown.
getCharLengthIfKnown
()

Implements org.apache.derby.impl.jdbc.InternalClob.getCharLengthIfKnown.

Returns the cached character count for the Clob, if any.

public Reader

Returns:

A reader initialized at the specified position.
getInternalReader
(long
1-based character position.
characterPosition
)

Implements org.apache.derby.impl.jdbc.InternalClob.getInternalReader.

Returns an internal reader for the Clob, initialized at the specified character position.

public InputStream

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.
getRawByteStream
()

Implements org.apache.derby.impl.jdbc.InternalClob.getRawByteStream.

Returns a stream serving the raw bytes of this Clob.

public Reader

Returns:

A reader initialized at the specified position.
getReader
(long
character position. The first character is at position 1.
pos
)

Implements org.apache.derby.impl.jdbc.InternalClob.getReader.

Returns a reader for the Clob, initialized at the specified character position.

public long

Returns:

Zero (read-only Clob).
getUpdateCount
()

Implements org.apache.derby.impl.jdbc.InternalClob.getUpdateCount.

Returns the update count of this Clob.

public Writer
getWriter(long
the starting character position. The first character is at position 1.
pos
)

Implements org.apache.derby.impl.jdbc.InternalClob.getWriter.

Not supported.

public long
insertString(String
the string to insert
str
,
long
the character position the string will be inserted at. Must be between 1 and clob.length() +1, inclusive.
pos
)

Implements org.apache.derby.impl.jdbc.InternalClob.insertString.

Not supported.

public boolean

Returns:

true if released, false if not.
isReleased
()

Implements org.apache.derby.impl.jdbc.InternalClob.isReleased.

Tells if this Clob has been released.

public boolean

Returns:

false, this Clob is read-only.
isWritable
()

Implements org.apache.derby.impl.jdbc.InternalClob.isWritable.

Tells if this Clob can be modified.

private static SQLException

Returns:

A SQLException wrapped around the real cause of the error
noStateChangeLOB
(Throwable
real cause of error that we want to "ignore" with respect to transaction context cleanup
t
)

Wrap real exception in a SQLException to avoid changing the state of the connection child by cleaning it up.

public void
release()

Implements org.apache.derby.impl.jdbc.InternalClob.release.

Releases resources associated with this Clob.

public void
truncate(long
the length in characters to truncate to
newLength
)

Implements org.apache.derby.impl.jdbc.InternalClob.truncate.

Not supported.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

conChildback to summary
private final ConnectionChild conChild

The connection (child) this Clob belongs to.

csdback to summary
private CharacterStreamDescriptor csd

The descriptor used to describe the underlying source stream.

internalReaderback to summary
private UTF8Reader 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 instance 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.

positionedStoreStreamback to summary
private final PositionedStoreStream positionedStoreStream

The stream from store, used to read bytes from the database.

To be able to support the requirements, the stream must implement Resetable.

releasedback to summary
private volatile boolean released

Tells whether this Clob has been released or not.

synchronizationObjectback to summary
private final Object synchronizationObject

Object used for synchronizing access to the store stream.

unclosableInternalReaderback to summary
private FilterReader unclosableInternalReader

The internal reader wrapped so that it cannot be closed.

Constructor Detail

StoreStreamClobback to summary
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:CharacterStreamDescriptor

descriptor for the source stream, including a reference to it

conChild:ConnectionChild

the connection (child) this Clob belongs to

Method Detail

checkIfValidback to summary
private void checkIfValid()

Makes sure the Clob has not been released.

All operations are invalid on a released Clob.

Exceptions
IllegalStateException:
if the Clob has been released
getCharLengthback to summary
public long getCharLength() throws SQLException

Implements org.apache.derby.impl.jdbc.InternalClob.getCharLength.

Returns the number of characters in the Clob.

Returns:long

Number of characters in the Clob.

Exceptions
SQLException:
if any kind of error is encountered, be it related to I/O or something else
getCharLengthIfKnownback to summary
public long getCharLengthIfKnown()

Implements org.apache.derby.impl.jdbc.InternalClob.getCharLengthIfKnown.

Returns the cached character count for the Clob, if any.

Returns:long

The number of characters in the Clob, or -1 if unknown.

getInternalReaderback to summary
public Reader getInternalReader(long characterPosition) throws IOException, SQLException

Implements org.apache.derby.impl.jdbc.InternalClob.getInternalReader.

Returns an internal reader for the Clob, initialized at the specified character position.

Parameters
characterPosition:long

1-based character position.

Returns:Reader

A reader initialized at the specified position.

Exceptions
IOException:
if accessing the I/O resources fail
SQLException:
if accessing the store resources fail
EOFException:
if the positions is larger than the Clob
getRawByteStreamback to summary
public InputStream getRawByteStream() throws IOException, SQLException

Implements org.apache.derby.impl.jdbc.InternalClob.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.

Returns:InputStream

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.

Exceptions
IOException:
if accessing the I/O resources fail
SQLException:
if accessing the store resources fail
getReaderback to summary
public Reader getReader(long pos) throws IOException, SQLException

Implements org.apache.derby.impl.jdbc.InternalClob.getReader.

Returns a reader for the Clob, initialized at the specified character position.

Parameters
pos:long

character position. The first character is at position 1.

Returns:Reader

A reader initialized at the specified position.

Exceptions
IOException:
if accessing the I/O resources fail
SQLException:
if accessing the store resources fail
EOFException:
if the positions is larger than the Clob
getUpdateCountback to summary
public long getUpdateCount()

Implements org.apache.derby.impl.jdbc.InternalClob.getUpdateCount.

Returns the update count of this Clob.

Always returns zero, as this Clob cannot be updated.

Returns:long

Zero (read-only Clob).

getWriterback to summary
public Writer getWriter(long pos)

Implements org.apache.derby.impl.jdbc.InternalClob.getWriter.

Not supported.

Parameters
pos:long

Doc from org.apache.derby.impl.jdbc.InternalClob.getWriter.

the starting character position. The first character is at position 1.

Returns:Writer

Doc from org.apache.derby.impl.jdbc.InternalClob.getWriter.

A writer initialized at the specified character position.

See Also
InternalClob#getWriter
insertStringback to summary
public long insertString(String str, long pos)

Implements org.apache.derby.impl.jdbc.InternalClob.insertString.

Not supported.

Parameters
str:String

Doc from org.apache.derby.impl.jdbc.InternalClob.insertString.

the string to insert

pos:long

Doc from org.apache.derby.impl.jdbc.InternalClob.insertString.

the character position the string will be inserted at. Must be between 1 and clob.length() +1, inclusive.

Returns:long

Doc from org.apache.derby.impl.jdbc.InternalClob.insertString.

The number of characters inserted.

See Also
InternalClob#insertString
isReleasedback to summary
public boolean isReleased()

Implements org.apache.derby.impl.jdbc.InternalClob.isReleased.

Tells if this Clob has been released.

Returns:boolean

true if released, false if not.

isWritableback to summary
public boolean isWritable()

Implements org.apache.derby.impl.jdbc.InternalClob.isWritable.

Tells if this Clob can be modified.

Returns:boolean

false, this Clob is read-only.

noStateChangeLOBback to summary
private static SQLException noStateChangeLOB(Throwable t)

Wrap real exception in a SQLException to avoid changing the state of the connection child by cleaning it up.

Parameters
t:Throwable

real cause of error that we want to "ignore" with respect to transaction context cleanup

Returns:SQLException

A SQLException wrapped around the real cause of the error

releaseback to summary
public void release()

Implements org.apache.derby.impl.jdbc.InternalClob.release.

Releases resources associated with this Clob.

truncateback to summary
public void truncate(long newLength)

Implements org.apache.derby.impl.jdbc.InternalClob.truncate.

Not supported.

Parameters
newLength:long

Doc from org.apache.derby.impl.jdbc.InternalClob.truncate.

the length in characters to truncate to

See Also
InternalClob#truncate