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

pack-priv final Class EmbedClob

extends ConnectionChild
implements Clob, EngineLOB
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.jdbc.EngineLOB, java.sql.Clob
Imports
org.apache.derby.shared.common.reference.SQLState, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.jdbc.EngineLOB, .CharacterStreamDescriptor, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.types.Resetable, .StringDataValue, java.io.Reader, .IOException, .EOFException, java.sql.SQLException, .Clob

Implements java.sql.Clob (see the JDBC 2.0 spec). A clob sits on top of a CHAR, VARCHAR or LONG VARCHAR column. If its data is small (less than 1 page) it is a byte array taken from the SQLChar class. If it is large (more than 1 page) it is a long column in the database. The long column is accessed as a stream, and is implemented in store as an OverflowInputStream. The Resetable interface allows sending messages to that stream to initialize itself (reopen its container and lock the corresponding row) and to reset itself to the beginning.

Note

In the case that the data is large, it is represented as a stream. This stream can be returned to the user in the getAsciiStream() method. This means that we have limited control over the state of the stream, since the user can read bytes from it at any time. Thus all methods here reset the stream to the beginning before doing any work.

Caveat

The methods may not behave correctly if a user sets up multiple threads and sucks data from the stream (returned from getAsciiStream()) at the same time as calling the Clob methods.

Supports

Field Summary

Modifier and TypeField and Description
private InternalClob
clob

The underlying Clob object, which may change depending on what the user does with the Clob.

private boolean
isValid

Tells whether the Clob has been freed or not.

private int
Inherited from org.apache.derby.impl.jdbc.ConnectionChild:
factorylocalConn

Constructor Summary

AccessConstructor and Description
pack-priv
EmbedClob(EmbedConnection
The Connection object associated with this EmbedClob object.
con
)

Creates an empty Clob object.

protected
EmbedClob(EmbedConnection
associated connection for the Clob
con
,
StringDataValue
string data value descriptor providing the Clob source
dvd
)

Creates a Clob on top of a data value descriptor.

Method Summary

Modifier and TypeMethod and Description
private void
public void
free()

Implements java.sql.Clob.free, org.apache.derby.iapi.jdbc.EngineLOB.free.

Frees the Clob and releases the resources that it holds.

public InputStream

Returns:

An Ascii stream containing the CLOB data. Valid values in the stream are 0 - 255.
getAsciiStream
()

Implements java.sql.Clob.getAsciiStream.

Gets the CLOB value designated by this Clob object as a stream of Ascii bytes.

public Reader

Returns:

A character stream containing the CLOB data.
getCharacterStream
()

Implements java.sql.Clob.getCharacterStream.

Gets the Clob contents as a stream of characters.

public Reader

Returns:

Reader through which the partial Clob value can be read.
getCharacterStream
(long
the offset to the first character of the partial value to be retrieved. The first character in the Clob is at position 1.
pos
,
long
the length in characters of the partial value to be retrieved.
length
)

Implements java.sql.Clob.getCharacterStream.

Returns a Reader object that contains a partial Clob value, starting with the character specified by pos, which is length characters in length.

pack-priv InternalClob

Returns:

The current internal Clob representation.
getInternalClob
()

Returns the current internal Clob representation.

public int

Returns:

locator value for this Clob.
getLocator
()

Implements org.apache.derby.iapi.jdbc.EngineLOB.getLocator.

Returns LOB locator key.

public String

Returns:

A String that is the specified substring in the CLOB value designated by this Clob object
getSubString
(long
the first character of the substring to be extracted. The first character is at position 1.
pos
,
int
the number of consecutive characters to be copied
length
)

Implements java.sql.Clob.getSubString.

Returns a copy of the specified substring in the CLOB value designated by this Clob object.

public long

Returns:

The length of the CLOB in number of characters.
length
()

Implements java.sql.Clob.length.

Returns the number of characters in the CLOB value designated by this Clob object.

private void
makeWritableClobClone()

Makes a writable clone of the current Clob.

private void
makeWritableClobClone(long
number of characters to be cloned (should be smaller than clob length)
len
)

Makes a writable clone of the current Clob.

public long

Returns:

The position at which the substring appears, -1 if it does not appear in the CLOB value. The first position is 1.
position
(String
the substring for which to search
searchStr
,
long
the position at which to begin searching; the first position is 1
start
)

Implements java.sql.Clob.position.

Determines the character position at which the specified substring searchStr appears in the CLOB value.

public long

Returns:

the position at which the Clob object appears, else -1; the first position is 1
position
(Clob
the Clob object for which to search
searchClob
,
long
the position at which to begin searching; the first position is 1
start
)

Implements java.sql.Clob.position.

Determines the character position at which the specified Clob object searchstr appears in this Clob object.

public OutputStream

Returns:

the stream to which ASCII encoded characters can be written
setAsciiStream
(long
the position at which to start writing to this Clob object
pos
)

Implements java.sql.Clob.setAsciiStream.

JDBC 3.0 Retrieves a stream to be used to write Ascii characters to the CLOB value that this Clob object represents, starting at position pos.

public Writer

Returns:

the stream to which Unicode encoded characters can be written
setCharacterStream
(long
the position at which to start writing to this Clob object
pos
)

Implements java.sql.Clob.setCharacterStream.

JDBC 3.0 Retrieves a stream to be used to write a stream of characters to the CLOB value that this Clob object represents, starting at position pos.

public int

Returns:

the number of characters written
setString
(long
the position at which to start writing to the CLOB value that this Clob object represents
pos
,
String
the string to be written to the CLOB value that this Clob designates
str
)

Implements java.sql.Clob.setString.

JDBC 3.0 Writes the given Java String to the CLOB value that this Clob object designates at the position pos.

public int

Returns:

the number of characters written
setString
(long
the position at which to start writing to this Clob object
pos
,
String
the string to be written to the CLOB value that this Clob designates
str
,
int
the offset into str to start reading the characters to be written
offset
,
int
the number of characters to be written
len
)

Implements java.sql.Clob.setString.

JDBC 3.0 Writes len characters of str, starting at character offset, to the CLOB value that this Clob represents.

public void
truncate(long
the length, in characters, to which the CLOB value should be truncated, 0 is accepted
len
)

Implements java.sql.Clob.truncate.

JDBC 3.0 Truncates the CLOB value that this Clob designates to have a length of len characters

Inherited from org.apache.derby.impl.jdbc.ConnectionChild:
commitIfAutoCommitcommitIfNeededgetCalgetConnectionSynchronizationgetEmbedConnectiongetLanguageConnectionContextgetLCChandleExceptionneedCommitnewSQLExceptionrestoreContextStackrestoreIntrFlagIfSeensetupContextStack

Field Detail

clobback to summary
private InternalClob clob

The underlying Clob object, which may change depending on what the user does with the Clob.

isValidback to summary
private boolean isValid

Tells whether the Clob has been freed or not.

locatorback to summary
private int locator

Constructor Detail

EmbedClobback to summary
pack-priv EmbedClob(EmbedConnection con) throws SQLException

Creates an empty Clob object.

Parameters
con:EmbedConnection

The Connection object associated with this EmbedClob object.

EmbedClobback to summary
protected EmbedClob(EmbedConnection con, StringDataValue dvd) throws StandardException, SQLException

Creates a Clob on top of a data value descriptor.

This constructor should only be called by EmbedResultSet#getClob. The data value descriptor may provide a String or a stream as the source of the Clob.

Parameters
con:EmbedConnection

associated connection for the Clob

dvd:StringDataValue

string data value descriptor providing the Clob source

Method Detail

checkValidityback to summary
private void checkValidity() throws SQLException
freeback to summary
public void free() throws SQLException

Implements java.sql.Clob.free, org.apache.derby.iapi.jdbc.EngineLOB.free.

Frees the Clob and releases the resources that it holds.

The object is invalid once the free method is called. If free is called multiple times, the subsequent calls to free are treated as a no-op.

Exceptions
SQLException:
if an error occurs releasing the Clobs resources
getAsciiStreamback to summary
public InputStream getAsciiStream() throws SQLException

Implements java.sql.Clob.getAsciiStream.

Gets the CLOB value designated by this Clob object as a stream of Ascii bytes.

Returns:InputStream

An Ascii stream containing the CLOB data. Valid values in the stream are 0 - 255.

Exceptions
SQLException:
if there is an error accessing the CLOB value
getCharacterStreamback to summary
public Reader getCharacterStream() throws SQLException

Implements java.sql.Clob.getCharacterStream.

Gets the Clob contents as a stream of characters.

Returns:Reader

A character stream containing the CLOB data.

Exceptions
SQLException:
if there is an error accessing the CLOB
getCharacterStreamback to summary
public Reader getCharacterStream(long pos, long length) throws SQLException

Implements java.sql.Clob.getCharacterStream.

Returns a Reader object that contains a partial Clob value, starting with the character specified by pos, which is length characters in length.

Parameters
pos:long

the offset to the first character of the partial value to be retrieved. The first character in the Clob is at position 1.

length:long

the length in characters of the partial value to be retrieved.

Returns:Reader

Reader through which the partial Clob value can be read.

Exceptions
SQLException:
if pos is less than 1 or if pos is greater than the number of characters in the Clob or if pos + length is greater than Clob.length() +1
getInternalClobback to summary
pack-priv InternalClob getInternalClob()

Returns the current internal Clob representation.

Care should be taken, as the representation can change when the user performs operations on the Clob. An example is if the Clob content is served from a store stream and the user updates the content. The internal representation will then be changed to a temporary Clob copy that allows updates.

Returns:InternalClob

The current internal Clob representation.

getLocatorback to summary
public int getLocator()

Implements org.apache.derby.iapi.jdbc.EngineLOB.getLocator.

Doc from org.apache.derby.iapi.jdbc.EngineLOB.getLocator.

Returns LOB locator key.

The key can be used with org.apache.derby.impl.jdbc.EmbedConnection#getLOBMapping to retrieve this LOB at a later time.

Returns:int

locator value for this Clob.

getSubStringback to summary
public String getSubString(long pos, int length) throws SQLException

Implements java.sql.Clob.getSubString.

Returns a copy of the specified substring in the CLOB value designated by this Clob object.

The substring begins at position pos and has up to * length consecutive characters. The starting position must be between 1 and the length of the CLOB plus 1. This allows for zero-length CLOB values, from which only zero-length substrings can be returned.

If a larger length is requested than there are characters available, characters from the start position to the end of the CLOB are returned.

Note

If the starting position is the length of the CLOB plus 1, zero characters are returned regardless of the length requested.

Parameters
pos:long

the first character of the substring to be extracted. The first character is at position 1.

length:int

the number of consecutive characters to be copied

Returns:String

A String that is the specified substring in the CLOB value designated by this Clob object

Exceptions
SQLException:
if there is an error accessing the CLOB
lengthback to summary
public long length() throws SQLException

Implements java.sql.Clob.length.

Returns the number of characters in the CLOB value designated by this Clob object.

Returns:long

The length of the CLOB in number of characters.

Exceptions
SQLException:
if obtaining the length fails
makeWritableClobCloneback to summary
private void makeWritableClobClone() throws IOException, SQLException

Makes a writable clone of the current Clob.

This is called when we have a StoreStreamClob and the user calls a method updating the content of the Clob. A temporary Clob will then be created to hold the updated content.

Exceptions
IOException:
if accessing underlying I/O resources fail
SQLException:
if accessing underlying resources fail
makeWritableClobCloneback to summary
private void makeWritableClobClone(long len) throws IOException, SQLException

Makes a writable clone of the current Clob.

This is called when we have a StoreStreamClob and the user calls a method updating the content of the Clob. A temporary Clob will then be created to hold the updated content.

Parameters
len:long

number of characters to be cloned (should be smaller than clob length)

Exceptions
IOException:
if accessing underlying I/O resources fail
SQLException:
if accessing underlying resources fail
positionback to summary
public long position(String searchStr, long start) throws SQLException

Implements java.sql.Clob.position.

Determines the character position at which the specified substring searchStr appears in the CLOB value.

The search begins at position start. The method uses the following algorithm for the search:

If the CLOB value is materialized as a string, use String.indexOf.

If the CLOB value is represented as a stream, read a block of chars from the start position and compare the chars with searchStr. Then:

  • If a matching char is found, increment matchCount.
  • If matchCount is equal to the length of searchStr, return with the current start position.
  • If no match is found, and there is more data, restart search (see below).
  • If no match is found, return -1.

The position where the stream has a char equal to the first char of searchStr will be remembered and used as the starting position for the next search-iteration if the current match fails. If a non-matching char is found, start a fresh search from the position remembered. If there is no such position, next search will start at the current position +1.

Parameters
searchStr:String

the substring for which to search

start:long

the position at which to begin searching; the first position is 1

Returns:long

The position at which the substring appears, -1 if it does not appear in the CLOB value. The first position is 1.

Exceptions
SQLException:
if there is an error accessing the CLOB value
positionback to summary
public long position(Clob searchClob, long start) throws SQLException

Implements java.sql.Clob.position.

Determines the character position at which the specified Clob object searchstr appears in this Clob object. The search begins at position start.

Parameters
searchClob:Clob

the Clob object for which to search

start:long

the position at which to begin searching; the first position is 1

Returns:long

the position at which the Clob object appears, else -1; the first position is 1

Exceptions
SQLException:
if there is an error accessing the CLOB value
setAsciiStreamback to summary
public OutputStream setAsciiStream(long pos) throws SQLException

Implements java.sql.Clob.setAsciiStream.

JDBC 3.0 Retrieves a stream to be used to write Ascii characters to the CLOB value that this Clob object represents, starting at position pos.

Parameters
pos:long

the position at which to start writing to this Clob object

Returns:OutputStream

the stream to which ASCII encoded characters can be written

Exceptions
SQLException:
if obtaining the stream fails
setCharacterStreamback to summary
public Writer setCharacterStream(long pos) throws SQLException

Implements java.sql.Clob.setCharacterStream.

JDBC 3.0 Retrieves a stream to be used to write a stream of characters to the CLOB value that this Clob object represents, starting at position pos.

Parameters
pos:long

the position at which to start writing to this Clob object

Returns:Writer

the stream to which Unicode encoded characters can be written

Exceptions
SQLException:
if obtaining the stream fails
setStringback to summary
public int setString(long pos, String str) throws SQLException

Implements java.sql.Clob.setString.

JDBC 3.0 Writes the given Java String to the CLOB value that this Clob object designates at the position pos.

Parameters
pos:long

the position at which to start writing to the CLOB value that this Clob object represents

str:String

Doc from java.sql.Clob.setString.

the string to be written to the CLOB value that this Clob designates

Returns:int

the number of characters written

Exceptions
SQLException:
if writing the string fails
setStringback to summary
public int setString(long pos, String str, int offset, int len) throws SQLException

Implements java.sql.Clob.setString.

JDBC 3.0 Writes len characters of str, starting at character offset, to the CLOB value that this Clob represents.

Parameters
pos:long

the position at which to start writing to this Clob object

str:String

the string to be written to the CLOB value that this Clob designates

offset:int

the offset into str to start reading the characters to be written

len:int

the number of characters to be written

Returns:int

the number of characters written

Exceptions
SQLException:
if writing the string fails
truncateback to summary
public void truncate(long len) throws SQLException

Implements java.sql.Clob.truncate.

JDBC 3.0 Truncates the CLOB value that this Clob designates to have a length of len characters

Parameters
len:long

the length, in characters, to which the CLOB value should be truncated, 0 is accepted

Exceptions
SQLException:
if truncating the CLOB value fails