Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.derby.impl.jdbc
Class EmbedClob  view EmbedClob download EmbedClob.java

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  org.apache.derby.jdbc.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(org.apache.derby.iapi.types.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()
          Called on an object by the Virtual Machine at most once, at some point after the Object is determined unreachable but before it is destroyed.
 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.
 org.apache.derby.iapi.services.context.ContextManager getContextManager()
           
 org.apache.derby.iapi.db.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.
 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.
 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 org.apache.derby.jdbc.InternalDriver factory
Factory for JDBC objects to be created.

Constructor Detail

EmbedClob

protected EmbedClob(org.apache.derby.iapi.types.DataValueDescriptor dvd,
                    EmbedConnection con)
             throws org.apache.derby.iapi.error.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

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

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

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

getCharacterStreamAtPos

private UTF8Reader getCharacterStreamAtPos(long position,
                                           java.lang.Object synchronization)
                                    throws java.io.IOException,
                                           org.apache.derby.iapi.error.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

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

finalize

protected void finalize()
Description copied from class: java.lang.Object
Called on an object by the Virtual Machine at most once, at some point after the Object is determined unreachable but before it is destroyed. You would think that this means it eventually is called on every Object, but this is not necessarily the case. If execution terminates abnormally, garbage collection does not always happen. Thus you cannot rely on this method to always work. For finer control over garbage collection, use references from the java.lang.ref package.

Virtual Machines are free to not call this method if they can determine that it does nothing important; for example, if your class extends Object and overrides finalize to do simply super.finalize().

finalize() will be called by a java.lang.Thread that has no locks on any Objects, and may be called concurrently. There are no guarantees on the order in which multiple objects are finalized. This means that finalize() is usually unsuited for performing actions that must be thread-safe, and that your implementation must be use defensive programming if it is to always work.

If an Exception is thrown from finalize() during garbage collection, it will be patently ignored and the Object will still be destroyed.

It is allowed, although not typical, for user code to call finalize() directly. User invocation does not affect whether automatic invocation will occur. It is also permitted, although not recommended, for a finalize() method to "revive" an object by making it reachable from normal code again.

Unlike constructors, finalize() does not get called for an object's superclass unless the implementation specifically calls super.finalize().

The default implementation does nothing.


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

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

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

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

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

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.


handleException

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


needCommit

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


commitIfNeeded

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


commitIfAutoCommit

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


setupContextStack

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


restoreContextStack

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


getContextManager

public org.apache.derby.iapi.services.context.ContextManager getContextManager()

getDatabase

public org.apache.derby.iapi.db.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)