Package org.apache.derby.client.am
Class ClientClob
- java.lang.Object
-
- org.apache.derby.client.am.Lob
-
- org.apache.derby.client.am.ClientClob
-
- All Implemented Interfaces:
java.sql.Clob
,UnitOfWorkListener
public class ClientClob extends Lob implements java.sql.Clob
This class implements the JDBCjava.sql.Clob
interface.
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.InputStream
asciiStream_
private java.io.Reader
characterStream_
protected java.lang.String
string_
private java.io.InputStream
unicodeStream_
private byte[]
utf8String_
-
Fields inherited from class org.apache.derby.client.am.Lob
agent_, ASCII_STREAM, BINARY_STREAM, BINARY_STRING, CHARACTER_STREAM, dataType_, INVALID_LOCATOR, isValid_, LOCATOR, locator_, STRING, UNICODE_STREAM
-
-
Constructor Summary
Constructors Modifier Constructor Description private
ClientClob(Agent agent, boolean willBeLayerBStreamed)
ClientClob(Agent agent, byte[] unconvertedBytes, java.nio.charset.Charset charset, int dataOffset)
ClientClob(Agent agent, int locator)
Create aClientClob
object for a Clob value stored on the server and indentified bylocator
.(package private)
ClientClob(Agent agent, java.io.InputStream inputStream, java.nio.charset.Charset encoding)
Create aClientClob
of unknown length with the specified encoding.ClientClob(Agent agent, java.io.InputStream inputStream, java.nio.charset.Charset encoding, int length)
(package private)
ClientClob(Agent agent, java.io.Reader reader)
Create aClientClob
of unknown length.(package private)
ClientClob(Agent agent, java.io.Reader reader, int length)
ClientClob(Agent agent, java.lang.String string)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
free()
This method frees theClob
object and releases the resources the resources that it holds.java.io.InputStream
getAsciiStream()
(package private) java.io.InputStream
getAsciiStreamX()
java.io.Reader
getCharacterStream()
java.io.Reader
getCharacterStream(long pos, long length)
Returns aReader
object that contains a partialClob
value, starting with the character specified by pos, which is length characters in length.(package private) java.io.Reader
getCharacterStreamX()
(package private) long
getLocatorLength()
Get the length in bytes of theClob
value represented by this locator basedClob
object.java.lang.String
getString()
java.lang.String
getSubString(long pos, int length)
Returns a copy of the specified substring in theCLOB
value designated by thisClientClob
object.private java.lang.String
getSubStringX(long pos, int length)
java.io.InputStream
getUnicodeStream()
int
getUTF8Length()
byte[]
getUtf8String()
boolean
isAsciiStream()
boolean
isCharacterStream()
boolean
isString()
boolean
isUnicodeStream()
long
length()
protected void
materializeStream()
Materialize the stream used for input to the database.long
position(java.lang.String searchstr, long start)
long
position(java.sql.Clob searchstr, long start)
private long
positionX(java.lang.String searchstr, long start)
private long
positionX(java.sql.Clob searchstr, long start)
(package private) void
reInitForNonLocator(java.lang.String newString)
Reinitialize the value of this CLOB.java.io.OutputStream
setAsciiStream(long pos)
java.io.Writer
setCharacterStream(long pos)
int
setString(long pos, java.lang.String str)
int
setString(long pos, java.lang.String str, int offset, int len)
(package private) int
setStringX(long pos, java.lang.String str, int offset, int len)
void
truncate(long len)
-
Methods inherited from class org.apache.derby.client.am.Lob
checkForClosedConnection, checkForLocatorValidity, checkPosAndLength, checkValidity, completeLocalCommit, completeLocalRollback, getAgent, getLocator, getUpdateCount, incrementUpdateCount, isLayerBStreamingPossible, isLocator, listenToUnitOfWork, materializeStream, setSqlLength, sqlLength, willBeLayerBStreamed
-
-
-
-
Constructor Detail
-
ClientClob
public ClientClob(Agent agent, java.lang.String string)
-
ClientClob
public ClientClob(Agent agent, byte[] unconvertedBytes, java.nio.charset.Charset charset, int dataOffset) throws SqlException
- Throws:
SqlException
-
ClientClob
public ClientClob(Agent agent, java.io.InputStream inputStream, java.nio.charset.Charset encoding, int length)
-
ClientClob
ClientClob(Agent agent, java.io.InputStream inputStream, java.nio.charset.Charset encoding) throws SqlException
Create aClientClob
of unknown length with the specified encoding. This constructor was added to support the JDBC 4 length less overloads. Note that aClientClob
created with this constructor is made for input to the database only. Do not pass it out to the user!- Parameters:
agent
-inputStream
- the data to insertencoding
- encoding to use for characters. Only "ISO-8859-1" is allowed.- Throws:
SqlException
-
ClientClob
ClientClob(Agent agent, java.io.Reader reader, int length)
-
ClientClob
public ClientClob(Agent agent, int locator)
Create aClientClob
object for a Clob value stored on the server and indentified bylocator
.- Parameters:
agent
- context for thisClob
object (incl. connection).locator
- reference id toClob
value on server.
-
ClientClob
ClientClob(Agent agent, java.io.Reader reader)
Create aClientClob
of unknown length. This constructor was added to support the JDBC 4 length less overloads. Note that aClientClob
created with this constructor is made for input to the database only. Do not pass it out to the user!- Parameters:
agent
-reader
- the data to insert
-
ClientClob
private ClientClob(Agent agent, boolean willBeLayerBStreamed)
-
-
Method Detail
-
length
public long length() throws java.sql.SQLException
-
getSubString
public java.lang.String getSubString(long pos, int length) throws java.sql.SQLException
Returns a copy of the specified substring in theCLOB
value designated by thisClientClob
object. The substring begins at positionpos
and has up tolength
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 to the end of the CLOB are returned.- Specified by:
getSubString
in interfacejava.sql.Clob
- 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
String
that is the specified substring in theCLOB
value designated by thisClientClob
object - Throws:
java.sql.SQLException
- if there is an error accessing theCLOB
NOTE: If the starting position is the length of the CLOB plus 1, zero characters are returned regardless of the length requested.
-
getSubStringX
private java.lang.String getSubStringX(long pos, int length) throws SqlException
- Throws:
SqlException
-
getCharacterStream
public java.io.Reader getCharacterStream() throws java.sql.SQLException
- Specified by:
getCharacterStream
in interfacejava.sql.Clob
- Throws:
java.sql.SQLException
-
getCharacterStreamX
java.io.Reader getCharacterStreamX() throws SqlException
- Throws:
SqlException
-
getAsciiStream
public java.io.InputStream getAsciiStream() throws java.sql.SQLException
- Specified by:
getAsciiStream
in interfacejava.sql.Clob
- Throws:
java.sql.SQLException
-
getAsciiStreamX
java.io.InputStream getAsciiStreamX() throws SqlException
- Throws:
SqlException
-
position
public long position(java.lang.String searchstr, long start) throws java.sql.SQLException
- Specified by:
position
in interfacejava.sql.Clob
- Throws:
java.sql.SQLException
-
positionX
private long positionX(java.lang.String searchstr, long start) throws SqlException
- Throws:
SqlException
-
position
public long position(java.sql.Clob searchstr, long start) throws java.sql.SQLException
- Specified by:
position
in interfacejava.sql.Clob
- Throws:
java.sql.SQLException
-
positionX
private long positionX(java.sql.Clob searchstr, long start) throws SqlException
- Throws:
SqlException
-
setString
public int setString(long pos, java.lang.String str) throws java.sql.SQLException
- Specified by:
setString
in interfacejava.sql.Clob
- Throws:
java.sql.SQLException
-
setString
public int setString(long pos, java.lang.String str, int offset, int len) throws java.sql.SQLException
- Specified by:
setString
in interfacejava.sql.Clob
- Throws:
java.sql.SQLException
-
setStringX
int setStringX(long pos, java.lang.String str, int offset, int len) throws SqlException
- Throws:
SqlException
-
setAsciiStream
public java.io.OutputStream setAsciiStream(long pos) throws java.sql.SQLException
- Specified by:
setAsciiStream
in interfacejava.sql.Clob
- Throws:
java.sql.SQLException
-
setCharacterStream
public java.io.Writer setCharacterStream(long pos) throws java.sql.SQLException
- Specified by:
setCharacterStream
in interfacejava.sql.Clob
- Throws:
java.sql.SQLException
-
truncate
public void truncate(long len) throws java.sql.SQLException
- Specified by:
truncate
in interfacejava.sql.Clob
- Throws:
java.sql.SQLException
-
free
public void free() throws java.sql.SQLException
This method frees theClob
object and releases the resources the resources that it holds. The object is invalid once thefree
method is called. Iffree
is called multiple times, the subsequent calls tofree
are treated as a no-op.- Specified by:
free
in interfacejava.sql.Clob
- Throws:
java.sql.SQLException
- if an error occurs releasing the Clob's resources
-
getCharacterStream
public java.io.Reader getCharacterStream(long pos, long length) throws java.sql.SQLException
Returns aReader
object that contains a partialClob
value, starting with the character specified by pos, which is length characters in length.- Specified by:
getCharacterStream
in interfacejava.sql.Clob
- 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:
Reader
through which the partialClob
value can be read.- Throws:
java.sql.SQLException
- if pos is less than 1 or if pos is greater than the number of characters in theClob
or ifpos + length
is greater thanClob.length() +1
-
isString
public boolean isString()
-
isAsciiStream
public boolean isAsciiStream()
-
isCharacterStream
public boolean isCharacterStream()
-
isUnicodeStream
public boolean isUnicodeStream()
-
getUnicodeStream
public java.io.InputStream getUnicodeStream()
-
getString
public java.lang.String getString()
-
getUtf8String
public byte[] getUtf8String()
-
getUTF8Length
public int getUTF8Length()
-
reInitForNonLocator
void reInitForNonLocator(java.lang.String newString)
Reinitialize the value of this CLOB. This is legacy code, only used when talking to servers that don't support locators.- Parameters:
newString
- the new value
-
materializeStream
protected void materializeStream() throws SqlException
Materialize the stream used for input to the database.- Specified by:
materializeStream
in classLob
- Throws:
SqlException
-
getLocatorLength
long getLocatorLength() throws SqlException
Get the length in bytes of theClob
value represented by this locator basedClob
object. A stored procedure call will be made to get it from the server.- Overrides:
getLocatorLength
in classLob
- Returns:
- length of
Clob
in bytes - Throws:
SqlException
-
-