Interface InternalClob
-
- All Known Implementing Classes:
StoreStreamClob,TemporaryClob
interface InternalClobA set of operations available on internal Clob content representations.The methods defined by
Clobmust be implemented on top of this interface. In addition, there are some methods to aid internal tasks and organization, like transferring one internal Clob representation to another one.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description longgetCharLength()Gets the number of characters in the Clob.longgetCharLengthIfKnown()Gets the number of characters in the Clob if it is already known.java.io.ReadergetInternalReader(long characterPosition)Returns an internal reader for the Clob content, initialized at the specified character position.java.io.InputStreamgetRawByteStream()Returns a stream serving the raw bytes of the Clob.java.io.ReadergetReader(long characterPosition)Returns a reader for the Clob content, initialized at the specified character position.longgetUpdateCount()Returns the update count of the Clob.java.io.WritergetWriter(long charPos)Returns a writer to write data into the Clob.longinsertString(java.lang.String str, long pos)Inserts the given string at the specified character position.booleanisReleased()Tells if the the Clob has been released.booleanisWritable()Tells if the Clob representation is intended to be writable.voidrelease()Frees the resources held by the internal Clob representation.voidtruncate(long newLength)
-
-
-
Method Detail
-
getCharLength
long getCharLength() throws java.io.IOException, java.sql.SQLExceptionGets the number of characters in the Clob.- Returns:
- Number of characters in the Clob.
- Throws:
java.io.IOException- if accessing underlying I/O resources failjava.sql.SQLException- if accessing underlying resources fail
-
getCharLengthIfKnown
long getCharLengthIfKnown()
Gets the number of characters in the Clob if it is already known.This method will not do any work to obtain the length if it isn't already known. Due to special handling of zero in the code, this method will return
-1if a length of zero is cached internally.If a positive value is returned, it is expected to be equal to the actual length of the Clob (i.e., no stale values must be returned).
- Returns:
- Number of characters in the Clob, or
-1if the length is currently unknown (not cached).
-
getRawByteStream
java.io.InputStream getRawByteStream() throws java.io.IOException, java.sql.SQLExceptionReturns a stream serving the raw bytes of the Clob.Note that it is up to the caller of this method to handle the issue of encoding. There is no predetermined encoding associated with this byte stream, it is up to the Clob representation which one it uses.
This stream may be an internal store stream, and should not be directly published to the end user (returned through the JDBC API). There are three reasons for this:
- the stream may be closed by the end user when it is not supposed to
- operations on the stream might throw exceptions we don't want to present to the end user unwrapped
- the stream may contain a Derby specific end-of-stream marker
The primary use of this method is to clone the Clob contents without going via char (or String). Make sure the clone uses the same encoding as the original Clob representation.
- Returns:
- A stream of bytes representing the content of the Clob, initialized at byte position 0.
- Throws:
java.io.IOException- if accessing underlying I/O resources failjava.sql.SQLException- if accessing underlying resources fail
-
getReader
java.io.Reader getReader(long characterPosition) throws java.io.IOException, java.sql.SQLExceptionReturns a reader for the Clob content, initialized at the specified character position.- Parameters:
characterPosition- character position. The first character is at position1.- Returns:
- A
Readerserving the content of the Clob. - Throws:
EOFException- if the position is larger then the Clobjava.io.IOException- if accessing underlying I/O resources failjava.sql.SQLException- if accessing underlying resources fail
-
getInternalReader
java.io.Reader getInternalReader(long characterPosition) throws java.io.IOException, java.sql.SQLExceptionReturns an internal reader for the Clob content, initialized at the specified character position.This method can return a shared reader object, avoiding instantiation and repositioning costs for internal operations where the stream itself is not published to the end-user. One such example is
Clob.getSubString.- Parameters:
characterPosition- character position. The first character is at position1.- Returns:
- A
Readerserving the content of the Clob. - Throws:
EOFException- if the position is larger then the Clobjava.io.IOException- if accessing underlying I/O resources failjava.sql.SQLException- if accessing underlying resources fail
-
getUpdateCount
long getUpdateCount()
Returns the update count of the Clob.The update count is increased each time a modification of the Clob content is made.
- Returns:
- Update count, starting at zero.
-
getWriter
java.io.Writer getWriter(long charPos) throws java.io.IOException, java.sql.SQLExceptionReturns a writer to write data into the Clob.The semantics of the writer is the same as for
insertString(java.lang.String, long).- Parameters:
charPos- the starting character position. The first character is at position1.- Returns:
- A writer initialized at the specified character position.
- Throws:
java.io.IOException- if writing to the Clob failsjava.sql.SQLException- if accessing underlying resources failjava.lang.UnsupportedOperationException- if the Clob representation is read-only
-
insertString
long insertString(java.lang.String str, long pos) throws java.io.IOException, java.sql.SQLExceptionInserts the given string at the specified character position.The behavior of this method can be defined by the following examples on the Clob
clobwith value"ABCDEFG";clob.setString(2, "XX")- "AXXDEFG"clob.setString(1, "XX")- "XXCDEFG"clob.setString(8, "XX")- "ABCDEFGXX"clob.setString(7, "XX")- "ABCDEFXX"clob.setString(9, "XX")- throws exception
- Parameters:
str- the string to insertpos- the character position the string will be inserted at. Must be between1andclob.length() +1, inclusive.- Returns:
- The number of characters inserted.
- Throws:
java.io.IOException- if writing to the I/O resources failjava.sql.SQLException- it the position is invalidjava.lang.IllegalArgumentException- if the string isnulljava.lang.UnsupportedOperationException- if the Clob representation is read-only
-
isReleased
boolean isReleased()
Tells if the the Clob has been released.Depending on the context, a Clob is released either because the internal representation has been changed, or because the Clob itself has been closed. The former can happen when a user modifies a stream that is currently represented as a store stream. The latter can happen if
Clob.freehas been called, or if Derby implicitly closes the Clob.- Returns:
trueif released,falseif not.
-
isWritable
boolean isWritable()
Tells if the Clob representation is intended to be writable.Note that even if this method returns
true, it might not be possible to write to the Clob. If this happens, it is because the assoicated database is read-only, and the internal Clob representation is unable to obtain the resources it require (could be an area on disk to write temporary data).- Returns:
trueif the Clob is intended to be writable,falseif modifying the Clob is definitely not possible.
-
release
void release() throws java.io.IOException, java.sql.SQLExceptionFrees the resources held by the internal Clob representation.After calling this method, all other operations on the Clob will be invalid and throw an exception.
- Throws:
java.io.IOException- if freeing associated I/O resources failsjava.sql.SQLException- if freeing associated resources fails
-
truncate
void truncate(long newLength) throws java.io.IOException, java.sql.SQLException- Parameters:
newLength- the length in characters to truncate to- Throws:
java.io.IOException- if accessing the underlying I/O resources failsjava.sql.SQLException- if accessing underlying resources failjava.lang.UnsupportedOperationException- if the Clob representation is read-only
-
-