Class SQLClob

    • Field Detail

      • TEN_FOUR_CLOB_HEADER_GENERATOR

        private static final StreamHeaderGenerator TEN_FOUR_CLOB_HEADER_GENERATOR
        The header generator used for 10.4 (or older) databases.
      • TEN_FIVE_CLOB_HEADER_GENERATOR

        private static final StreamHeaderGenerator TEN_FIVE_CLOB_HEADER_GENERATOR
        The header generator used for 10.5 databases.
      • MAX_STREAM_HEADER_LENGTH

        private static final int MAX_STREAM_HEADER_LENGTH
        The maximum number of bytes used by the stream header.

        Use the length specified by the ten five header generator.

      • csd

        private CharacterStreamDescriptor csd
        The descriptor for the stream. If there is no stream this should be null, which is also true if the descriptor hasen't been constructed yet. Note: Always check if stream is non-null before using the information stored in the descriptor internally.
      • inSoftUpgradeMode

        private java.lang.Boolean inSoftUpgradeMode
        Tells if the database is being accessed in soft upgrade mode.
    • Constructor Detail

      • SQLClob

        public SQLClob()
      • SQLClob

        public SQLClob​(java.lang.String val)
      • SQLClob

        public SQLClob​(java.sql.Clob val)
    • Method Detail

      • cloneValue

        public DataValueDescriptor cloneValue​(boolean forceMaterialization)
        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 interface DataValueDescriptor
        Overrides:
        cloneValue in class SQLVarchar
        Parameters:
        forceMaterialization - any streams representing the data value will be materialized if true, the data value will be kept as a stream if possible if false
        Returns:
        A clone of this CLOB value.
        See Also:
        DataValueDescriptor.cloneValue(boolean)
      • getValue

        public StringDataValue getValue​(java.text.RuleBasedCollator collatorForComparison)
        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 interface StringDataValue
        Overrides:
        getValue in class SQLVarchar
        See Also:
        StringDataValue.getValue(RuleBasedCollator)
      • 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 interface DataValueDescriptor
        Overrides:
        typePrecedence in class SQLVarchar
        Returns:
        The precedence of this type.
        See Also:
        DataValueDescriptor.typePrecedence()
      • getLength

        public int getLength()
                      throws StandardException
        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 interface DataValueDescriptor
        Overrides:
        getLength in class SQLChar
        Returns:
        The character length of this Clob.
        Throws:
        StandardException - if obtaining the length fails
      • typeToBigDecimal

        public int typeToBigDecimal()
                             throws StandardException
        Description copied from class: SQLChar
        CHAR/VARCHAR/LONG VARCHAR implementation. Convert to a BigDecimal using getString.
        Specified by:
        typeToBigDecimal in interface DataValueDescriptor
        Overrides:
        typeToBigDecimal in class SQLChar
        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
      • getStreamWithDescriptor

        public CharacterStreamDescriptor getStreamWithDescriptor()
                                                          throws StandardException
        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 interface StringDataValue
        Overrides:
        getStreamWithDescriptor in class SQLChar
        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:
        getStreamWithDescriptor()
      • 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 interface DataValueDescriptor
        Overrides:
        normalize in class SQLVarchar
        Parameters:
        desiredType - The type to normalize the source column to
        sourceValue - The value to normalize
        Throws:
        StandardException - Thrown for null into non-nullable column, and for truncation error
      • setValue

        public void setValue​(java.sql.Time theValue,
                             java.util.Calendar cal)
                      throws StandardException
        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 interface DataValueDescriptor
        Overrides:
        setValue in class SQLChar
        Parameters:
        theValue - The Time value to set this DataValueDescriptor to
        cal - The time zone from the calendar is used to construct the database time value
        Throws:
        StandardException - Thrown on error
      • setValue

        public void setValue​(java.sql.Timestamp theValue,
                             java.util.Calendar cal)
                      throws StandardException
        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 interface DataValueDescriptor
        Overrides:
        setValue in class SQLChar
        Parameters:
        theValue - The Timestamp value to set this DataValueDescriptor to
        cal - The time zone from the calendar is used to construct the database timestamp value
        Throws:
        StandardException - Thrown on error
      • setValue

        public void setValue​(java.sql.Date theValue,
                             java.util.Calendar cal)
                      throws StandardException
        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 interface DataValueDescriptor
        Overrides:
        setValue in class SQLChar
        Parameters:
        theValue - The Date value to set this DataValueDescriptor to
        cal - The time zone from the calendar is used to construct the database date value
        Throws:
        StandardException - Thrown on error
      • setStream

        public final void setStream​(java.io.InputStream stream)
        Sets a new stream for this CLOB.
        Specified by:
        setStream in interface StreamStorable
        Overrides:
        setStream in class SQLChar
        Parameters:
        stream - the new stream
      • setValue

        public void setValue​(int theValue)
                      throws StandardException
        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 interface DataValueDescriptor
        Overrides:
        setValue in class SQLChar
        Parameters:
        theValue - The value to set this DataValueDescriptor to
        Throws:
        StandardException - Thrown on error
      • setValue

        public void setValue​(double theValue)
                      throws StandardException
        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 interface DataValueDescriptor
        Overrides:
        setValue in class SQLChar
        Parameters:
        theValue - The value to set this DataValueDescriptor to
        Throws:
        StandardException - Thrown on error
      • setValue

        public void setValue​(float theValue)
                      throws StandardException
        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 interface DataValueDescriptor
        Overrides:
        setValue in class SQLChar
        Parameters:
        theValue - The value to set this DataValueDescriptor to
        Throws:
        StandardException - Thrown on error
      • setValue

        public void setValue​(short theValue)
                      throws StandardException
        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 interface DataValueDescriptor
        Overrides:
        setValue in class SQLChar
        Parameters:
        theValue - The value to set this DataValueDescriptor to
        Throws:
        StandardException - Thrown on error
      • setValue

        public void setValue​(long theValue)
                      throws StandardException
        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 interface DataValueDescriptor
        Overrides:
        setValue in class SQLChar
        Parameters:
        theValue - The value to set this DataValueDescriptor to
        Throws:
        StandardException - Thrown on error
      • setValue

        public void setValue​(byte theValue)
                      throws StandardException
        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 interface DataValueDescriptor
        Overrides:
        setValue in class SQLChar
        Parameters:
        theValue - The value to set this DataValueDescriptor to
        Throws:
        StandardException - Thrown on error
      • setValue

        public void setValue​(byte[] theValue)
                      throws StandardException
        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 interface DataValueDescriptor
        Overrides:
        setValue in class SQLChar
        Parameters:
        theValue - The byte value to set this DataValueDescriptor to
        Throws:
        StandardException
      • writeExternal

        public void writeExternal​(java.io.ObjectOutput out)
                           throws java.io.IOException
        Writes the CLOB data value to the given destination stream using the modified UTF-8 format.
        Specified by:
        writeExternal in interface java.io.Externalizable
        Overrides:
        writeExternal in class SQLChar
        Parameters:
        out - destination stream
        Throws:
        java.io.IOException - if writing to the destination stream fails
        See Also:
        DataInputStream
      • setStreamHeaderFormat

        public void setStreamHeaderFormat​(java.lang.Boolean inSoftUpgradeMode)
        Tells whether the database is being accessed in soft upgrade mode or not.
        Specified by:
        setStreamHeaderFormat in interface StringDataValue
        Overrides:
        setStreamHeaderFormat in class SQLChar
        Parameters:
        inSoftUpgradeMode - TRUE if the database is accessed in soft upgrade mode, FALSE is not, or null if unknown
      • investigateHeader

        private SQLClob.HeaderInfo investigateHeader​(byte[] hdr,
                                                     int bytesRead)
                                              throws java.io.IOException
        Investigates the header and returns length information.
        Parameters:
        hdr - the raw header bytes
        bytesRead - number of bytes written into the raw header bytes array
        Returns:
        The information obtained from the header.
        Throws:
        java.io.IOException - if the header format is invalid, or the stream seems to have been corrupted
      • readExternal

        public void readExternal​(java.io.ObjectInput in)
                          throws java.io.IOException
        Reads and materializes the CLOB value from the stream.
        Specified by:
        readExternal in interface java.io.Externalizable
        Overrides:
        readExternal in class SQLChar
        Parameters:
        in - source stream
        Throws:
        java.io.UTFDataFormatException - if an encoding error is detected
        java.io.IOException - if reading from the stream fails, or the content of the stream header is invalid
      • readExternalFromArray

        public void readExternalFromArray​(ArrayInputStream in)
                                   throws java.io.IOException
        Reads and materializes the CLOB value from the stream.
        Specified by:
        readExternalFromArray in interface DataValueDescriptor
        Overrides:
        readExternalFromArray in class SQLChar
        Parameters:
        in - source stream
        Throws:
        java.io.UTFDataFormatException - if an encoding error is detected
        java.io.IOException - if reading from the stream fails, or the content of the stream header is invalid
        See Also:
        DataInputStream.readUnsignedShort(), Externalizable.readExternal(java.io.ObjectInput)
      • rewindStream

        private void rewindStream​(java.io.InputStream in,
                                  long offset)
                           throws java.io.IOException
        Rewinds the stream to the beginning and then skips the specified number of bytes.
        Parameters:
        in - input stream to rewind
        offset - number of bytes to skip
        Throws:
        java.io.IOException - if resetting or reading from the stream fails