Class EmbedClob
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
- JSR169 - no subsetting for java.sql.Clob
- JDBC 2.0
- JDBC 3.0 - no new dependencies on new JDBC 3.0 or JDK 1.4 classes, new update methods can safely be added into implementation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate InternalClobThe underlying Clob object, which may change depending on what the user does with the Clob.private booleanTells whether the Clob has been freed or not.private intFields inherited from class ConnectionChild
factory, localConn -
Constructor Summary
ConstructorsModifierConstructorDescription(package private)EmbedClob(EmbedConnection con) Creates an empty Clob object.protectedEmbedClob(EmbedConnection con, StringDataValue dvd) Creates a Clob on top of a data value descriptor. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidvoidfree()Frees theCloband releases the resources that it holds.Gets theCLOBvalue designated by thisClobobject as a stream of Ascii bytes.Gets theClobcontents as a stream of characters.getCharacterStream(long pos, long length) Returns aReaderobject that contains a partialClobvalue, starting with the character specified by pos, which is length characters in length.(package private) InternalClobReturns the current internal Clob representation.intReturns LOB locator key.getSubString(long pos, int length) Returns a copy of the specified substring in theCLOBvalue designated by thisClobobject.longlength()Returns the number of characters in theCLOBvalue designated by thisClobobject.private voidMakes a writable clone of the current Clob.private voidmakeWritableClobClone(long len) Makes a writable clone of the current Clob.longDetermines the character position at which the specified substringsearchStrappears in theCLOBvalue.longDetermines the character position at which the specifiedClobobjectsearchstrappears in thisClobobject.setAsciiStream(long pos) 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.setCharacterStream(long pos) 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.intJDBC 3.0 Writes the given Java String to the CLOB value that this Clob object designates at the position pos.intJDBC 3.0 Writes len characters of str, starting at character offset, to the CLOB value that this Clob represents.voidtruncate(long len) JDBC 3.0 Truncates the CLOB value that this Clob designates to have a length of len characters
-
Field Details
-
clob
The underlying Clob object, which may change depending on what the user does with the Clob. -
isValid
private boolean isValidTells whether the Clob has been freed or not. -
locator
private int locator
-
-
Constructor Details
-
EmbedClob
EmbedClob(EmbedConnection con) throws SQLException Creates an empty Clob object.- Parameters:
con- The Connection object associated with this EmbedClob object.- Throws:
SQLException
-
EmbedClob
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(int). The data value descriptor may provide aStringor a stream as the source of the Clob.- Parameters:
con- associated connection for the Clobdvd- string data value descriptor providing the Clob source- Throws:
StandardExceptionSQLException
-
-
Method Details
-
length
Returns the number of characters in theCLOBvalue designated by thisClobobject.- Specified by:
lengthin interfaceClob- Returns:
- The length of the
CLOBin number of characters. - Throws:
SQLException- if obtaining the length fails
-
getSubString
Returns a copy of the specified substring in theCLOBvalue designated by thisClobobject.The substring begins at position
posand has up to *lengthconsecutive 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.
- Specified by:
getSubStringin interfaceClob- Parameters:
pos- the first character of the substring to be extracted. The first character is at position 1.length- the number of consecutive characters to be copied- Returns:
- A
Stringthat is the specified substring in theCLOBvalue designated by thisClobobject - Throws:
SQLException- if there is an error accessing theCLOB
-
getCharacterStream
Gets theClobcontents as a stream of characters.- Specified by:
getCharacterStreamin interfaceClob- Returns:
- A character stream containing the
CLOBdata. - Throws:
SQLException- if there is an error accessing theCLOB
-
getAsciiStream
Gets theCLOBvalue designated by thisClobobject as a stream of Ascii bytes.- Specified by:
getAsciiStreamin interfaceClob- Returns:
- An Ascii stream containing the
CLOBdata. Valid values in the stream are 0 - 255. - Throws:
SQLException- if there is an error accessing theCLOBvalue
-
position
Determines the character position at which the specified substringsearchStrappears in theCLOBvalue.The search begins at position
start. The method uses the following algorithm for the search:If the
CLOBvalue is materialized as a string, useString.indexOf.If the
CLOBvalue is represented as a stream, read a block of chars from the start position and compare the chars withsearchStr. Then:- If a matching char is found, increment
matchCount. - If
matchCountis equal to the length ofsearchStr, 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
searchStrwill 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.- Specified by:
positionin interfaceClob- Parameters:
searchStr- the substring for which to searchstart- the position at which to begin searching; the first position is1- Returns:
- The position at which the substring appears,
-1if it does not appear in theCLOBvalue. The first position is1. - Throws:
SQLException- if there is an error accessing theCLOBvalue
- If a matching char is found, increment
-
position
Determines the character position at which the specifiedClobobjectsearchstrappears in thisClobobject. The search begins at positionstart.- Specified by:
positionin interfaceClob- Parameters:
searchClob- theClobobject for which to searchstart- the position at which to begin searching; the first position is 1- Returns:
- the position at which the
Clobobject appears, else -1; the first position is 1 - Throws:
SQLException- if there is an error accessing theCLOBvalue
-
setString
JDBC 3.0 Writes the given Java String to the CLOB value that this Clob object designates at the position pos.- Specified by:
setStringin interfaceClob- Parameters:
pos- the position at which to start writing to the CLOB value that this Clob object represents- Returns:
- the number of characters written
- Throws:
SQLException- if writing the string fails
-
setString
JDBC 3.0 Writes len characters of str, starting at character offset, to the CLOB value that this Clob represents.- Specified by:
setStringin interfaceClob- Parameters:
pos- the position at which to start writing to this Clob objectstr- the string to be written to the CLOB value that this Clob designatesoffset- the offset into str to start reading the characters to be writtenlen- the number of characters to be written- Returns:
- the number of characters written
- Throws:
SQLException- if writing the string fails
-
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.- Specified by:
setAsciiStreamin interfaceClob- Parameters:
pos- the position at which to start writing to this Clob object- Returns:
- the stream to which ASCII encoded characters can be written
- Throws:
SQLException- if obtaining the stream fails
-
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.- Specified by:
setCharacterStreamin interfaceClob- Parameters:
pos- the position at which to start writing to this Clob object- Returns:
- the stream to which Unicode encoded characters can be written
- Throws:
SQLException- if obtaining the stream fails
-
truncate
JDBC 3.0 Truncates the CLOB value that this Clob designates to have a length of len characters- Specified by:
truncatein interfaceClob- Parameters:
len- the length, in characters, to which the CLOB value should be truncated, 0 is accepted- Throws:
SQLException- if truncating the CLOB value fails
-
free
Frees theCloband releases the resources that it holds.The object is invalid once the
freemethod is called. Iffreeis called multiple times, the subsequent calls tofreeare treated as a no-op.- Specified by:
freein interfaceClob- Specified by:
freein interfaceEngineLOB- Throws:
SQLException- if an error occurs releasing the Clobs resources
-
getCharacterStream
Returns aReaderobject that contains a partialClobvalue, starting with the character specified by pos, which is length characters in length.- Specified by:
getCharacterStreamin interfaceClob- Parameters:
pos- the offset to the first character of the partial value to be retrieved. The first character in the Clob is at position 1.length- the length in characters of the partial value to be retrieved.- Returns:
Readerthrough which the partialClobvalue can be read.- Throws:
SQLException- if pos is less than 1 or if pos is greater than the number of characters in theClobor ifpos + lengthis greater thanClob.length() +1
-
checkValidity
- Throws:
SQLException
-
makeWritableClobClone
Makes a writable clone of the current Clob.This is called when we have a
StoreStreamCloband the user calls a method updating the content of the Clob. A temporary Clob will then be created to hold the updated content.- Throws:
IOException- if accessing underlying I/O resources failSQLException- if accessing underlying resources fail
-
makeWritableClobClone
Makes a writable clone of the current Clob.This is called when we have a
StoreStreamCloband 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- number of characters to be cloned (should be smaller than clob length)- Throws:
IOException- if accessing underlying I/O resources failSQLException- if accessing underlying resources fail
-
getInternalClob
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:
- The current internal Clob representation.
-
getLocator
public int getLocator()Description copied from interface:EngineLOBReturns LOB locator key.The key can be used with
EmbedConnection.getLOBMapping(int)to retrieve this LOB at a later time.- Specified by:
getLocatorin interfaceEngineLOB- Returns:
- locator value for this Clob.
-