Class SQLChar

java.lang.Object
org.apache.derby.iapi.types.DataType
org.apache.derby.iapi.types.SQLChar
All Implemented Interfaces:
Externalizable, Serializable, Comparable, Formatable, Storable, StreamStorable, TypedFormat, ConcatableDataValue, DataValueDescriptor, Orderable, StringDataValue, VariableSizeDataValue
Direct Known Subclasses:
CollatorSQLChar, SQLVarchar

public class SQLChar extends DataType implements StringDataValue, StreamStorable
The SQLChar represents a CHAR value with UCS_BASIC collation. SQLChar may be used directly by any code when it is guaranteed that the required collation is UCS_BASIC, e.g. system columns.

The state may be in char[], a String, a Clob, or an unread stream, depending on how the datatype was created.

Stream notes:

When the datatype comes from the database layer and the length of the bytes necessary to store the datatype on disk exceeds the size of a page of the container holding the data then the store returns a stream rather than reading all the bytes into a char[] or String. The hope is that the usual usage case is that data never need be expanded in the derby layer, and that client can just be given a stream that can be read a char at a time through the jdbc layer. Even though SQLchar's can't ever be this big, this code is shared by all the various character datatypes including SQLClob which is expected to usually larger than a page.

The state can also be a stream in the case of insert/update where the client has used a jdbc interface to set the value as a stream rather than char[]. In this case the hope is that the usual usage case is that stream never need be read until it is passed to store, read once, and inserted into the database.

See Also:
  • Field Details

    • PAD

      private static final char PAD
      The pad character (space).
      See Also:
    • RETURN_SPACE_THRESHOLD

      protected static final int RETURN_SPACE_THRESHOLD
      threshold, that decides when we return space back to the VM see getString() where it is used
      See Also:
    • GROWBY_FOR_CHAR

      private static final int GROWBY_FOR_CHAR
      when we know that the array needs to grow by at least one byte, it is not performant to grow by just one byte instead this amount is used to provide a reasonable growby size.
      See Also:
    • BASE_MEMORY_USAGE

      private static final int BASE_MEMORY_USAGE
    • BLANKS

      private static final char[] BLANKS
      Static array that can be used for blank padding.
    • CHAR_HEADER_GENERATOR

      protected static final StreamHeaderGenerator CHAR_HEADER_GENERATOR
      Stream header generator for CHAR, VARCHAR and LONG VARCHAR. Currently, only one header format is used for these data types.
    • value

      private String value
      Fields of the class
    • rawData

      private char[] rawData
    • rawLength

      private int rawLength
    • cKey

      private CollationKey cKey
    • _clobValue

      protected Clob _clobValue
      The value as a user-created Clob
    • stream

      InputStream stream
      The value as a stream in the on-disk format.
    • localeFinder

      private LocaleFinder localeFinder
    • arg_passer

      char[][] arg_passer
  • Constructor Details

    • SQLChar

      public SQLChar()
      no-arg constructor, required by Formattable.
    • SQLChar

      public SQLChar(String val)
    • SQLChar

      public SQLChar(Clob val)
    • SQLChar

      public SQLChar(char[] val)

      This is a special constructor used when we need to represent a password as a VARCHAR (see DERBY-866). If you need a general-purpose constructor for char[] values and you want to re-use this constructor, make sure to keep track of the following:

      • A password should never be turned into a String. This is because Java garbage collection makes it easy to sniff memory for String passwords. For more information, see this blog.
      • It must be possible to 0 out the char[] array wrapped inside this SQLChar. This reduces the vulnerability that someone could sniff the char[] password after Derby has processed it.
  • Method Details