Class SQLClob
- All Implemented Interfaces:
Externalizable
,Serializable
,Comparable
,Formatable
,Storable
,StreamStorable
,TypedFormat
,ConcatableDataValue
,DataValueDescriptor
,Orderable
,StringDataValue
,VariableSizeDataValue
- Direct Known Subclasses:
CollatorSQLClob
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Holder class for header information gathered from the raw byte header in the stream. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate CharacterStreamDescriptor
The descriptor for the stream.private Boolean
Tells if the database is being accessed in soft upgrade mode.private static final int
The maximum number of bytes used by the stream header.private static final StreamHeaderGenerator
The header generator used for 10.5 databases.private static final StreamHeaderGenerator
The header generator used for 10.4 (or older) databases.Fields inherited from class org.apache.derby.iapi.types.SQLChar
_clobValue, arg_passer, CHAR_HEADER_GENERATOR, RETURN_SPACE_THRESHOLD, stream
Fields inherited from interface org.apache.derby.iapi.types.DataValueDescriptor
UNKNOWN_LOGICAL_LENGTH
Fields inherited from interface org.apache.derby.iapi.types.Orderable
ORDER_OP_EQUALS, ORDER_OP_GREATEROREQUALS, ORDER_OP_GREATERTHAN, ORDER_OP_LESSOREQUALS, ORDER_OP_LESSTHAN
Fields inherited from interface org.apache.derby.iapi.types.StringDataValue
BOTH, COLLATION_DERIVATION_EXPLICIT, COLLATION_DERIVATION_IMPLICIT, COLLATION_DERIVATION_NONE, COLLATION_TYPE_TERRITORY_BASED, COLLATION_TYPE_TERRITORY_BASED_IDENTICAL, COLLATION_TYPE_TERRITORY_BASED_PRIMARY, COLLATION_TYPE_TERRITORY_BASED_SECONDARY, COLLATION_TYPE_TERRITORY_BASED_TERTIARY, COLLATION_TYPE_UCS_BASIC, LEADING, TRAILING
Fields inherited from interface org.apache.derby.iapi.types.VariableSizeDataValue
IGNORE_PRECISION
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncloneValue
(boolean forceMaterialization) Returns a clone of this CLOB value.boolean
Get Boolean from a SQLChar.byte
getByte()
Get Byte from a SQLChar.byte[]
getBytes()
Gets the value in the data value descriptor as a byte[].Get date from a SQLChar.double
Get double from a SQLChar.float
getFloat()
Get float from a SQLChar.int
getInt()
Get int from a SQLChar.int
Returns the character length of this Clob.long
getLong()
Get long from a SQLChar.Get a new null value of the same type as this data value.Gets the value in the data value descriptor as a int.short
getShort()
Get Short from a SQLChar.Returns a stream header generator for a Clob.Returns a descriptor for the input stream for this CLOB value.Get time from a SQLChar.getTimestamp
(Calendar cal) Get Timestamp from a SQLChar.final String
Gets a trace representation of the CLOB for debugging.int
Return my format identifier.Get the SQL name of the datatypegetValue
(RuleBasedCollator collatorForComparison) Gets either SQLChar/SQLVarchar/SQLLongvarchar/SQLClob(base classes) or CollatorSQLChar/CollatorSQLVarchar/CollatorSQLLongvarch/CollatorSQLClob (subclasses).boolean
Tells if this CLOB value is, or will be, represented by a stream.private SQLClob.HeaderInfo
investigateHeader
(byte[] hdr, int bytesRead) Investigates the header and returns length information.void
normalize
(DataTypeDescriptor desiredType, DataValueDescriptor sourceValue) Normalization method - this method may be called when putting a value into a SQLClob, for example, when inserting into a SQLClob column.void
Reads and materializes the CLOB value from the stream.void
Reads and materializes the CLOB value from the stream.final void
Restore this object to its (SQL)null value.private void
rewindStream
(InputStream in, long offset) Rewinds the stream to the beginning and then skips the specified number of bytes.void
setBigDecimal
(BigDecimal bigDecimal) Only to be called when an application through JDBC is setting a SQLChar to a java.math.BigDecimal.(package private) final void
Set the value from an non-null Java.sql.Clob object.final void
setStream
(InputStream stream) Sets a new stream for this CLOB.void
setStreamHeaderFormat
(Boolean inSoftUpgradeMode) Tells whether the database is being accessed in soft upgrade mode or not.void
setValue
(boolean theValue) Set the value.void
setValue
(byte theValue) Set the value of this DataValueDescriptor to the given byte value At DataType level just throws an error lower classes will overridevoid
setValue
(byte[] theValue) Set the value of this DataValueDescriptor.void
setValue
(double theValue) Set the value of this DataValueDescriptor to the given double value At DataType level just throws an error lower classes will overridevoid
setValue
(float theValue) Set the value of this DataValueDescriptor to the given float value At DataType level just throws an error lower classes will overridevoid
setValue
(int theValue) Set the value of this DataValueDescriptor to the given int value At DataType level just throws an error lower classes will overridevoid
setValue
(long theValue) Set the value of this DataValueDescriptor to the given long value At DataType level just throws an error lower classes will overridevoid
setValue
(short theValue) Set the value of this DataValueDescriptor to the given short value At DataType level just throws an error lower classes will overridevoid
Set the value of this DataValueDescriptor.void
Set the value of this DataValueDescriptor.void
Set the value of this DataValueDescriptor.int
Each built-in type in JSQL has a precedence.int
CHAR/VARCHAR/LONG VARCHAR implementation.void
Writes the CLOB data value to the given destination stream using the modified UTF-8 format.Methods inherited from class org.apache.derby.iapi.types.SQLVarchar
growBy, normalize
Methods inherited from class org.apache.derby.iapi.types.SQLChar
ansiTrim, charLength, cloneHolder, compare, compare, concatenate, copyState, equals, estimateMemoryUsage, getCharArray, getCollationKey, getCollatorForCollation, getDate, getLocaleFinder, getNewVarchar, getRawDataAndZeroIt, getStream, getString, getTime, getTimestamp, greaterOrEquals, greaterThan, hashCode, hashCodeForCollation, hasNonBlankChars, isNull, lessOrEquals, lessThan, like, like, loadStream, locate, lower, notEquals, readExternal, readExternalClobFromArray, returnStream, setFrom, setInto, setLocaleFinder, setObjectForCast, setValue, setValue, setValue, setValueFromResultSet, setWidth, stringCompare, stringCompare, stringCompare, substring, throwStreamingIOException, toString, upper, writeClobUTF, zeroRawData
Methods inherited from class org.apache.derby.iapi.types.DataType
checkHostVariable, coalesce, compare, compare, compareTo, dataTypeConversion, equals, flip, genericSetObject, getTypeName, in, invalidFormat, isNotNull, isNullOp, outOfRange, recycle, setInto, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, throwLangSetMismatch, throwLangSetMismatch
-
Field Details
-
TEN_FOUR_CLOB_HEADER_GENERATOR
The header generator used for 10.4 (or older) databases. -
TEN_FIVE_CLOB_HEADER_GENERATOR
The header generator used for 10.5 databases. -
MAX_STREAM_HEADER_LENGTH
private static final int MAX_STREAM_HEADER_LENGTHThe maximum number of bytes used by the stream header.Use the length specified by the ten five header generator.
-
csd
The descriptor for the stream. If there is no stream this should benull
, which is also true if the descriptor hasen't been constructed yet. Note: Always check ifstream
is non-null before using the information stored in the descriptor internally. -
inSoftUpgradeMode
Tells if the database is being accessed in soft upgrade mode.
-
-
Constructor Details
-
SQLClob
public SQLClob() -
SQLClob
-
SQLClob
-
-
Method Details
-
getTypeName
Description copied from interface:DataValueDescriptor
Get the SQL name of the datatype- Specified by:
getTypeName
in interfaceDataValueDescriptor
- Overrides:
getTypeName
in classSQLVarchar
- Returns:
- The SQL name of the datatype
-
cloneValue
Returns a clone of this CLOB value.Unlike the other binary types, CLOBs can be very large. We try to clone the underlying stream when possible to avoid having to materialize the value into memory.
- Specified by:
cloneValue
in interfaceDataValueDescriptor
- Overrides:
cloneValue
in classSQLVarchar
- Parameters:
forceMaterialization
- any streams representing the data value will be materialized iftrue
, the data value will be kept as a stream if possible iffalse
- Returns:
- A clone of this CLOB value.
- See Also:
-
getNewNull
Description copied from interface:DataValueDescriptor
Get a new null value of the same type as this data value.- Specified by:
getNewNull
in interfaceDataValueDescriptor
- Overrides:
getNewNull
in classSQLVarchar
- See Also:
-
getValue
Description copied from interface:StringDataValue
Gets either SQLChar/SQLVarchar/SQLLongvarchar/SQLClob(base classes) or CollatorSQLChar/CollatorSQLVarchar/CollatorSQLLongvarch/CollatorSQLClob (subclasses). Whether this method returns the base class or the subclass depends on the value of the RuleBasedCollator. If RuleBasedCollator is null, then the object returned would be baseclass otherwise it would be subcalss.- Specified by:
getValue
in interfaceStringDataValue
- Overrides:
getValue
in classSQLVarchar
- See Also:
-
getTypeFormatId
public int getTypeFormatId()Return my format identifier.- Specified by:
getTypeFormatId
in interfaceTypedFormat
- Overrides:
getTypeFormatId
in classSQLVarchar
- Returns:
- The identifier. (A UUID stuffed in an array of 16 bytes).
- See Also:
-
typePrecedence
public int typePrecedence()Description copied from class:DataType
Each built-in type in JSQL has a precedence. This precedence determines how to do type promotion when using binary operators. For example, float has a higher precedence than int, so when adding an int to a float, the result type is float. The precedence for some types is arbitrary. For example, it doesn't matter what the precedence of the boolean type is, since it can't be mixed with other types. But the precedence for the number types is critical. The SQL standard requires that exact numeric types be promoted to approximate numeric when one operator uses both. Also, the precedence is arranged so that one will not lose precision when promoting a type.- Specified by:
typePrecedence
in interfaceDataValueDescriptor
- Overrides:
typePrecedence
in classSQLVarchar
- Returns:
- The precedence of this type.
- See Also:
-
getBoolean
Description copied from class:SQLChar
Get Boolean from a SQLChar.Return false for only "0" or "false" for false. No case insensitivity. Everything else is true.
The above matches JCC and the client driver.
- Specified by:
getBoolean
in interfaceDataValueDescriptor
- Overrides:
getBoolean
in classSQLChar
- Returns:
- The data value as a boolean.
- Throws:
StandardException
- Thrown on error- See Also:
-
getByte
Description copied from class:SQLChar
Get Byte from a SQLChar.Uses java standard Byte.parseByte() to perform coercion.
- Specified by:
getByte
in interfaceDataValueDescriptor
- Overrides:
getByte
in classSQLChar
- Returns:
- The data value as a byte.
- Throws:
StandardException
- thrown on failure to convert- See Also:
-
getShort
Description copied from class:SQLChar
Get Short from a SQLChar.Uses java standard Short.parseShort() to perform coercion.
- Specified by:
getShort
in interfaceDataValueDescriptor
- Overrides:
getShort
in classSQLChar
- Returns:
- The data value as a short.
- Throws:
StandardException
- thrown on failure to convert- See Also:
-
getInt
Description copied from class:SQLChar
Get int from a SQLChar.Uses java standard Short.parseInt() to perform coercion.
- Specified by:
getInt
in interfaceDataValueDescriptor
- Overrides:
getInt
in classSQLChar
- Returns:
- The data value as a int.
- Throws:
StandardException
- thrown on failure to convert- See Also:
-
getLength
Returns the character length of this Clob.If the value is stored as a stream, the stream header will be read. If the stream header doesn't contain the stream length, the whole stream will be decoded to determine the length.
- Specified by:
getLength
in interfaceDataValueDescriptor
- Overrides:
getLength
in classSQLChar
- Returns:
- The character length of this Clob.
- Throws:
StandardException
- if obtaining the length fails
-
getLong
Description copied from class:SQLChar
Get long from a SQLChar.Uses java standard Short.parseLong() to perform coercion.
- Specified by:
getLong
in interfaceDataValueDescriptor
- Overrides:
getLong
in classSQLChar
- Returns:
- The data value as a long.
- Throws:
StandardException
- thrown on failure to convert- See Also:
-
getFloat
Description copied from class:SQLChar
Get float from a SQLChar.Uses java standard Float.floatValue() to perform coercion.
- Specified by:
getFloat
in interfaceDataValueDescriptor
- Overrides:
getFloat
in classSQLChar
- Returns:
- The data value as a float.
- Throws:
StandardException
- thrown on failure to convert- See Also:
-
getDouble
Description copied from class:SQLChar
Get double from a SQLChar.Uses java standard Double.doubleValue() to perform coercion.
- Specified by:
getDouble
in interfaceDataValueDescriptor
- Overrides:
getDouble
in classSQLChar
- Returns:
- The data value as a double.
- Throws:
StandardException
- thrown on failure to convert- See Also:
-
typeToBigDecimal
Description copied from class:SQLChar
CHAR/VARCHAR/LONG VARCHAR implementation. Convert to a BigDecimal using getString.- Specified by:
typeToBigDecimal
in interfaceDataValueDescriptor
- Overrides:
typeToBigDecimal
in classSQLChar
- Returns:
- Types.CHAR for String conversion through getString Types.DECIMAL for BigDecimal through getObject or Types.BIGINT for long conversion through getLong
- Throws:
StandardException
- Conversion is not possible
-
getBytes
Description copied from class:DataType
Gets the value in the data value descriptor as a byte[]. Throws an exception if the data value is not receivable as a Binary or Varbinary.- Specified by:
getBytes
in interfaceDataValueDescriptor
- Overrides:
getBytes
in classDataType
- Returns:
- The Binary value as a byte[].
- Throws:
StandardException
- Thrown on error
-
getDate
Description copied from class:SQLChar
Get date from a SQLChar.- Specified by:
getDate
in interfaceDataValueDescriptor
- Overrides:
getDate
in classSQLChar
- Parameters:
cal
- calendar for object creation- Returns:
- The data value as a java.sql.Date.
- Throws:
StandardException
- thrown on failure to convert- See Also:
-
getObject
Description copied from class:DataType
Gets the value in the data value descriptor as a int. Throws an exception if the data value is not receivable as a int.- Specified by:
getObject
in interfaceDataValueDescriptor
- Overrides:
getObject
in classSQLChar
- Returns:
- The data value as a int.
- Throws:
StandardException
- Thrown on error
-
getStreamWithDescriptor
Returns a descriptor for the input stream for this CLOB value.The descriptor contains information about header data, current positions, length, whether the stream should be buffered or not, and if the stream is capable of repositioning itself.
When this method returns, the stream is positioned on the first character position, such that the next read will return the first character in the stream.
- Specified by:
getStreamWithDescriptor
in interfaceStringDataValue
- Overrides:
getStreamWithDescriptor
in classSQLChar
- Returns:
- A descriptor for the stream, which includes a reference to the
stream itself. If the value cannot be represented as a stream,
null
is returned instead of a descriptor. - Throws:
StandardException
- if obtaining the descriptor fails- See Also:
-
hasStream
public boolean hasStream()Tells if this CLOB value is, or will be, represented by a stream.- Specified by:
hasStream
in interfaceDataValueDescriptor
- Overrides:
hasStream
in classDataType
- Returns:
true
if the value is represented by a stream,false
otherwise.- See Also:
-
getTime
Description copied from class:SQLChar
Get time from a SQLChar.- Specified by:
getTime
in interfaceDataValueDescriptor
- Overrides:
getTime
in classSQLChar
- Parameters:
cal
- calendar for object creation- Returns:
- The data value as a java.sql.Time.
- Throws:
StandardException
- thrown on failure to convert- See Also:
-
getTimestamp
Description copied from class:SQLChar
Get Timestamp from a SQLChar.- Specified by:
getTimestamp
in interfaceDataValueDescriptor
- Overrides:
getTimestamp
in classSQLChar
- Parameters:
cal
- calendar for object creation- Returns:
- The data value as a java.sql.Timestamp.
- Throws:
StandardException
- thrown on failure to convert- See Also:
-
getTraceString
Gets a trace representation of the CLOB for debugging.- Specified by:
getTraceString
in interfaceDataValueDescriptor
- Overrides:
getTraceString
in classSQLChar
- Returns:
- a trace representation of the CLOB.
- Throws:
StandardException
- if getting the data value fails.- See Also:
-
normalize
public void normalize(DataTypeDescriptor desiredType, DataValueDescriptor sourceValue) throws StandardException Normalization method - this method may be called when putting a value into a SQLClob, for example, when inserting into a SQLClob column. See NormalizeResultSet in execution. Per the SQL standard ,if the clob column is not big enough to hold the value being inserted,truncation error will result if there are trailing non-blanks. Truncation of trailing blanks is allowed.- Specified by:
normalize
in interfaceDataValueDescriptor
- Overrides:
normalize
in classSQLVarchar
- Parameters:
desiredType
- The type to normalize the source column tosourceValue
- The value to normalize- Throws:
StandardException
- Thrown for null into non-nullable column, and for truncation error
-
setValue
Description copied from class:DataType
Set the value of this DataValueDescriptor. At DataType level just throws an error lower classes will override- Specified by:
setValue
in interfaceDataValueDescriptor
- Overrides:
setValue
in classSQLChar
- Parameters:
theValue
- The Time value to set this DataValueDescriptor tocal
- The time zone from the calendar is used to construct the database time value- Throws:
StandardException
- Thrown on error
-
setValue
Description copied from class:DataType
Set the value of this DataValueDescriptor. At DataType level just throws an error lower classes will override- Specified by:
setValue
in interfaceDataValueDescriptor
- Overrides:
setValue
in classSQLChar
- Parameters:
theValue
- The Timestamp value to set this DataValueDescriptor tocal
- The time zone from the calendar is used to construct the database timestamp value- Throws:
StandardException
- Thrown on error
-
setValue
Description copied from class:DataType
Set the value of this DataValueDescriptor. At DataType level just throws an error lower classes will override- Specified by:
setValue
in interfaceDataValueDescriptor
- Overrides:
setValue
in classSQLChar
- Parameters:
theValue
- The Date value to set this DataValueDescriptor tocal
- The time zone from the calendar is used to construct the database date value- Throws:
StandardException
- Thrown on error
-
setBigDecimal
Description copied from class:SQLChar
Only to be called when an application through JDBC is setting a SQLChar to a java.math.BigDecimal.- Specified by:
setBigDecimal
in interfaceDataValueDescriptor
- Overrides:
setBigDecimal
in classSQLChar
- Parameters:
bigDecimal
- required to be a BigDecimal or null.- Throws:
StandardException
-
setStream
Sets a new stream for this CLOB.- Specified by:
setStream
in interfaceStreamStorable
- Overrides:
setStream
in classSQLChar
- Parameters:
stream
- the new stream
-
restoreToNull
public final void restoreToNull()Description copied from interface:Storable
Restore this object to its (SQL)null value.- Specified by:
restoreToNull
in interfaceStorable
- Overrides:
restoreToNull
in classSQLChar
- See Also:
-
setValue
Description copied from class:DataType
Set the value of this DataValueDescriptor to the given int value At DataType level just throws an error lower classes will override- Specified by:
setValue
in interfaceDataValueDescriptor
- Overrides:
setValue
in classSQLChar
- Parameters:
theValue
- The value to set this DataValueDescriptor to- Throws:
StandardException
- Thrown on error
-
setValue
Description copied from class:DataType
Set the value of this DataValueDescriptor to the given double value At DataType level just throws an error lower classes will override- Specified by:
setValue
in interfaceDataValueDescriptor
- Overrides:
setValue
in classSQLChar
- Parameters:
theValue
- The value to set this DataValueDescriptor to- Throws:
StandardException
- Thrown on error
-
setValue
Description copied from class:DataType
Set the value of this DataValueDescriptor to the given float value At DataType level just throws an error lower classes will override- Specified by:
setValue
in interfaceDataValueDescriptor
- Overrides:
setValue
in classSQLChar
- Parameters:
theValue
- The value to set this DataValueDescriptor to- Throws:
StandardException
- Thrown on error
-
setValue
Description copied from class:DataType
Set the value of this DataValueDescriptor to the given short value At DataType level just throws an error lower classes will override- Specified by:
setValue
in interfaceDataValueDescriptor
- Overrides:
setValue
in classSQLChar
- Parameters:
theValue
- The value to set this DataValueDescriptor to- Throws:
StandardException
- Thrown on error
-
setValue
Description copied from class:DataType
Set the value of this DataValueDescriptor to the given long value At DataType level just throws an error lower classes will override- Specified by:
setValue
in interfaceDataValueDescriptor
- Overrides:
setValue
in classSQLChar
- Parameters:
theValue
- The value to set this DataValueDescriptor to- Throws:
StandardException
- Thrown on error
-
setValue
Description copied from class:DataType
Set the value of this DataValueDescriptor to the given byte value At DataType level just throws an error lower classes will override- Specified by:
setValue
in interfaceDataValueDescriptor
- Overrides:
setValue
in classSQLChar
- Parameters:
theValue
- The value to set this DataValueDescriptor to- Throws:
StandardException
- Thrown on error
-
setValue
Description copied from class:DataType
Set the value. At DataType level just throws an error lower classes will override- Specified by:
setValue
in interfaceDataValueDescriptor
- Overrides:
setValue
in classSQLChar
- Parameters:
theValue
- Contains the boolean value to set this to- Throws:
StandardException
-
setValue
Description copied from class:DataType
Set the value of this DataValueDescriptor. At DataType level just throws an error lower classes will override- Specified by:
setValue
in interfaceDataValueDescriptor
- Overrides:
setValue
in classSQLChar
- Parameters:
theValue
- The byte value to set this DataValueDescriptor to- Throws:
StandardException
-
setObject
Set the value from an non-null Java.sql.Clob object.- Overrides:
setObject
in classDataType
- Throws:
StandardException
-
writeExternal
Writes the CLOB data value to the given destination stream using the modified UTF-8 format.- Specified by:
writeExternal
in interfaceExternalizable
- Overrides:
writeExternal
in classSQLChar
- Parameters:
out
- destination stream- Throws:
IOException
- if writing to the destination stream fails- See Also:
-
getStreamHeaderGenerator
Returns a stream header generator for a Clob.NOTE: To guarantee a successful generation, one of the following two conditions must be met at header or EOF generation time:
setStreamHeaderFormat
has been invoked before the header generator was obtained.- There is context at generation time, such that the mode can be determined by obtaining the database context and by consulting the data dictionary.
- Specified by:
getStreamHeaderGenerator
in interfaceStringDataValue
- Overrides:
getStreamHeaderGenerator
in classSQLChar
- Returns:
- A stream header generator.
- See Also:
-
setStreamHeaderFormat
Tells whether the database is being accessed in soft upgrade mode or not.- Specified by:
setStreamHeaderFormat
in interfaceStringDataValue
- Overrides:
setStreamHeaderFormat
in classSQLChar
- Parameters:
inSoftUpgradeMode
-TRUE
if the database is accessed in soft upgrade mode,FALSE
is not, ornull
if unknown
-
investigateHeader
Investigates the header and returns length information.- Parameters:
hdr
- the raw header bytesbytesRead
- number of bytes written into the raw header bytes array- Returns:
- The information obtained from the header.
- Throws:
IOException
- if the header format is invalid, or the stream seems to have been corrupted
-
readExternal
Reads and materializes the CLOB value from the stream.- Specified by:
readExternal
in interfaceExternalizable
- Overrides:
readExternal
in classSQLChar
- Parameters:
in
- source stream- Throws:
UTFDataFormatException
- if an encoding error is detectedIOException
- if reading from the stream fails, or the content of the stream header is invalid
-
readExternalFromArray
Reads and materializes the CLOB value from the stream.- Specified by:
readExternalFromArray
in interfaceDataValueDescriptor
- Overrides:
readExternalFromArray
in classSQLChar
- Parameters:
in
- source stream- Throws:
UTFDataFormatException
- if an encoding error is detectedIOException
- if reading from the stream fails, or the content of the stream header is invalid- See Also:
-
rewindStream
Rewinds the stream to the beginning and then skips the specified number of bytes.- Parameters:
in
- input stream to rewindoffset
- number of bytes to skip- Throws:
IOException
- if resetting or reading from the stream fails
-