org.apache.derby.impl.jdbc
Class EmbedClob

java.lang.Object
  extended byorg.apache.derby.impl.jdbc.ConnectionChild
      extended byorg.apache.derby.impl.jdbc.EmbedClob
All Implemented Interfaces:
java.sql.Clob

final class EmbedClob
extends ConnectionChild
implements java.sql.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
protected static boolean CLOSE
           
protected  InternalDriver factory
          Factory for JDBC objects to be created.
private  boolean isString
           
protected  EmbedConnection localConn
           
private  java.io.InputStream myStream
           
private  java.lang.String myString
           
protected static boolean NOCLOSE
           
 
Constructor Summary
protected EmbedClob(DataValueDescriptor dvd, EmbedConnection con)
           
 
Method Summary
protected  void commitIfAutoCommit()
          Perform a commit if autocommit is enabled.
protected  void commitIfNeeded()
          Perform a commit if one is needed.
protected  void finalize()
           
 java.io.InputStream getAsciiStream()
          Gets the CLOB value designated by this Clob object as a stream of Ascii bytes.
protected  java.util.Calendar getCal()
          Get and save a unique calendar object for this JDBC object.
 java.io.Reader getCharacterStream()
          Gets the Clob contents as a Unicode stream.
private  UTF8Reader getCharacterStreamAtPos(long position, java.lang.Object synchronization)
           
protected  java.lang.Object getConnectionSynchronization()
          Return an object to be used for connection synchronization.
 ContextManager getContextManager()
           
 Database getDatabase()
           
protected  EmbedConnection getEmbedConnection()
          Return a reference to the EmbedConnection
 java.lang.String getSubString(long pos, int length)
          Returns a copy of the specified substring in the CLOB value designated by this Clob object.
protected  java.sql.SQLException handleException(java.lang.Throwable t)
          Handle any exception.
protected  java.sql.SQLException handleException(java.lang.Throwable t, boolean close)
          Handle any exception.
 long length()
          Returns the number of characters in the CLOB value designated by this Clob object.
protected  void needCommit()
          If Autocommit is on, note that a commit is needed.
protected  java.sql.SQLException newSQLException(java.lang.String messageId)
           
protected  java.sql.SQLException newSQLException(java.lang.String messageId, java.lang.Object arg1)
           
protected  java.sql.SQLException newSQLException(java.lang.String messageId, java.lang.Object arg1, java.lang.Object arg2)
           
(package private) static java.sql.SQLException noStateChangeLOB(java.lang.Throwable t)
           
 long position(java.sql.Clob searchClob, long start)
          Determines the character position at which the specified Clob object searchstr appears in this Clob object.
 long position(java.lang.String searchStr, long start)
          Determines the character position at which the specified substring searchstr appears in the CLOB.
protected  void restoreContextStack()
          Setup the context stack (a.k.a. context manager) for this connection.
 java.io.OutputStream 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.
 java.io.Writer setCharacterStream(long pos)
          JDBC 3.0 Retrieves a stream to be used to write a stream of Unicode characters to the CLOB value that this Clob object represents, starting at position pos.
 int setString(long pos, java.lang.String parameterName)
          JDBC 3.0 Writes the given Java String to the CLOB value that this Clob object designates at the position pos.
 int setString(long pos, java.lang.String str, int offset, int len)
          JDBC 3.0 Writes len characters of str, starting at character offset, to the CLOB value that this Clob represents.
protected  void setupContextStack()
          Setup the context stack (a.k.a. context manager) for this connection.
 void truncate(long len)
          JDBC 3.0 Truncates the CLOB value that this Clob designates to have a length of len characters
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isString

private boolean isString

myStream

private java.io.InputStream myStream

myString

private java.lang.String myString

CLOSE

protected static final boolean CLOSE
See Also:
Constant Field Values

NOCLOSE

protected static final boolean NOCLOSE
See Also:
Constant Field Values

localConn

protected EmbedConnection localConn

factory

protected final InternalDriver factory
Factory for JDBC objects to be created.

Constructor Detail

EmbedClob

protected EmbedClob(DataValueDescriptor dvd,
                    EmbedConnection con)
             throws StandardException
Method Detail

length

public long length()
            throws java.sql.SQLException
Returns the number of characters in the CLOB value designated by this Clob object.

Specified by:
length in interface java.sql.Clob
Returns:
length of the CLOB in characters
Throws:
java.sql.SQLException - if there is an error accessing the length of the CLOB

getSubString

public java.lang.String getSubString(long pos,
                                     int length)
                              throws java.sql.SQLException
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.

Specified by:
getSubString in interface java.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 the CLOB value designated by this Clob object
Throws:
java.sql.SQLException - if there is an error accessing the CLOB NOTE: return the empty string if pos is too large

getCharacterStream

public java.io.Reader getCharacterStream()
                                  throws java.sql.SQLException
Gets the Clob contents as a Unicode stream.

Specified by:
getCharacterStream in interface java.sql.Clob
Returns:
a Unicode stream containing the CLOB data
Throws:
java.sql.SQLException - if there is an error accessing the CLOB

getAsciiStream

public java.io.InputStream getAsciiStream()
                                   throws java.sql.SQLException
Gets the CLOB value designated by this Clob object as a stream of Ascii bytes.

Specified by:
getAsciiStream in interface java.sql.Clob
Returns:
an ascii stream containing the CLOB data
Throws:
java.sql.SQLException - if there is an error accessing the CLOB value

getCharacterStreamAtPos

private UTF8Reader getCharacterStreamAtPos(long position,
                                           java.lang.Object synchronization)
                                    throws java.io.IOException,
                                           StandardException
Throws:
java.io.IOException
StandardException

position

public long position(java.lang.String searchStr,
                     long start)
              throws java.sql.SQLException
Determines the character position at which the specified substring searchstr appears in the CLOB. The search begins at position start.

Specified by:
position in interface java.sql.Clob
Parameters:
start - the position at which to begin searching; the first position is 1
Returns:
the position at which the substring appears, else -1; the first position is 1
Throws:
java.sql.SQLException - if there is an error accessing the CLOB value

position

public long position(java.sql.Clob searchClob,
                     long start)
              throws java.sql.SQLException
Determines the character position at which the specified Clob object searchstr appears in this Clob object. The search begins at position start.

Specified by:
position in interface java.sql.Clob
Parameters:
start - the position at which to begin searching; the first position is 1
Returns:
the position at which the Clob object appears, else -1; the first position is 1
Throws:
java.sql.SQLException - if there is an error accessing the CLOB value

finalize

protected void finalize()

setString

public int setString(long pos,
                     java.lang.String parameterName)
              throws java.sql.SQLException
JDBC 3.0 Writes the given Java String to the CLOB value that this Clob object designates at the position pos.

Specified by:
setString in interface java.sql.Clob
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:
java.sql.SQLException - Feature not implemented for now.

setString

public int setString(long pos,
                     java.lang.String str,
                     int offset,
                     int len)
              throws java.sql.SQLException
JDBC 3.0 Writes len characters of str, starting at character offset, to the CLOB value that this Clob represents.

Specified by:
setString in interface java.sql.Clob
Parameters:
pos - - the position at which to start writing to this Clob object
str - - the string to be written to the CLOB value that this Clob designates
offset - - the offset into str to start reading the characters to be written
len - - the number of characters to be written
Returns:
the number of characters written
Throws:
java.sql.SQLException - Feature not implemented for now.

setAsciiStream

public java.io.OutputStream setAsciiStream(long pos)
                                    throws java.sql.SQLException
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:
setAsciiStream in interface java.sql.Clob
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:
java.sql.SQLException - Feature not implemented for now.

setCharacterStream

public java.io.Writer setCharacterStream(long pos)
                                  throws java.sql.SQLException
JDBC 3.0 Retrieves a stream to be used to write a stream of Unicode characters to the CLOB value that this Clob object represents, starting at position pos.

Specified by:
setCharacterStream in interface java.sql.Clob
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:
java.sql.SQLException - Feature not implemented for now.

truncate

public void truncate(long len)
              throws java.sql.SQLException
JDBC 3.0 Truncates the CLOB value that this Clob designates to have a length of len characters

Specified by:
truncate in interface java.sql.Clob
Parameters:
len - - the length, in bytes, to which the CLOB value that this Blob value should be truncated
Throws:
java.sql.SQLException - Feature not implemented for now.

noStateChangeLOB

static java.sql.SQLException noStateChangeLOB(java.lang.Throwable t)

getEmbedConnection

protected final EmbedConnection getEmbedConnection()
Return a reference to the EmbedConnection


getConnectionSynchronization

protected final java.lang.Object getConnectionSynchronization()
Return an object to be used for connection synchronization.


handleException

protected final java.sql.SQLException handleException(java.lang.Throwable t)
                                               throws java.sql.SQLException
Handle any exception.

Throws:
java.sql.SQLException - thrown if can't handle
See Also:
EmbedConnection.handleException(java.lang.Throwable)

handleException

protected final java.sql.SQLException handleException(java.lang.Throwable t,
                                                      boolean close)
                                               throws java.sql.SQLException
Handle any exception.

Throws:
java.sql.SQLException - thrown if can't handle
See Also:
EmbedConnection.handleException(java.lang.Throwable)

needCommit

protected final void needCommit()
If Autocommit is on, note that a commit is needed.

See Also:
EmbedConnection.needCommit

commitIfNeeded

protected final void commitIfNeeded()
                             throws java.sql.SQLException
Perform a commit if one is needed.

Throws:
java.sql.SQLException - thrown on failure
See Also:
EmbedConnection.commitIfNeeded()

commitIfAutoCommit

protected final void commitIfAutoCommit()
                                 throws java.sql.SQLException
Perform a commit if autocommit is enabled.

Throws:
java.sql.SQLException - thrown on failure
See Also:
EmbedConnection.commitIfNeeded()

setupContextStack

protected final void setupContextStack()
                                throws java.sql.SQLException
Setup the context stack (a.k.a. context manager) for this connection.

Throws:
java.sql.SQLException - thrown on failure
See Also:
EmbedConnection.setupContextStack()

restoreContextStack

protected final void restoreContextStack()
                                  throws java.sql.SQLException
Setup the context stack (a.k.a. context manager) for this connection.

Throws:
java.sql.SQLException - thrown on failure
See Also:
EmbedConnection.restoreContextStack()

getContextManager

public ContextManager getContextManager()

getDatabase

public Database getDatabase()

getCal

protected java.util.Calendar getCal()
Get and save a unique calendar object for this JDBC object. No need to synchronize because multiple threads should not be using a single JDBC object. Even if they do there is only a small window where each would get its own Calendar for a single call.


newSQLException

protected java.sql.SQLException newSQLException(java.lang.String messageId)

newSQLException

protected java.sql.SQLException newSQLException(java.lang.String messageId,
                                                java.lang.Object arg1)

newSQLException

protected java.sql.SQLException newSQLException(java.lang.String messageId,
                                                java.lang.Object arg1,
                                                java.lang.Object arg2)

Built on Tue 2006-10-10 19:23:47+0200, from revision exported

Apache Derby V10.1 Engine Documentation - Copyright © 1997,2005 The Apache Software Foundation or its licensors, as applicable.