Class TypeDescriptorImpl

java.lang.Object
org.apache.derby.catalog.types.TypeDescriptorImpl
All Implemented Interfaces:
Externalizable, Serializable, TypeDescriptor, Formatable, TypedFormat

public class TypeDescriptorImpl extends Object implements TypeDescriptor, Formatable
See Also:
  • Field Details

    • typeId

      private BaseTypeIdImpl typeId
      This class implements Formatable. That means that it can write itself to and from a formatted stream. If you add more fields to this class, make sure that you also write/read them with the writeExternal()/readExternal() methods. If, inbetween releases, you add more fields to this class, then you should bump the version number emitted by the getTypeFormatId() method.
    • precision

      private int precision
    • scale

      private int scale
    • isNullable

      private boolean isNullable
    • maximumWidth

      private int maximumWidth
    • collationType

      private int collationType
      See Also:
  • Constructor Details

    • TypeDescriptorImpl

      public TypeDescriptorImpl()
      Public niladic constructor. Needed for Formatable interface to work.
    • TypeDescriptorImpl

      public TypeDescriptorImpl(BaseTypeIdImpl typeId, int precision, int scale, boolean isNullable, int maximumWidth)
      Constructor for use with numeric types
      Parameters:
      typeId - The typeId of the type being described
      precision - The number of decimal digits.
      scale - The number of digits after the decimal point.
      isNullable - TRUE means it could contain NULL, FALSE means it definitely cannot contain NULL.
      maximumWidth - The maximum number of bytes for this datatype
    • TypeDescriptorImpl

      public TypeDescriptorImpl(BaseTypeIdImpl typeId, int precision, int scale, boolean isNullable, int maximumWidth, int collationType)
      Constructor to use when the caller doesn't know if it is requesting numeric or no-numeric DTD. For instance, when dealing with MAX/MIN aggregrate operators, AggregateNode.bindExpression could be dealing with a character string operand or a numeric operand. The result of MAX/MIN will depend on the type of it's operand. And hence when this constructor gets called by AggregateNode.bindExpression, we don't know what type we are constructing and hence this constructor supports arguments for both numeric and non-numeric types.
      Parameters:
      typeId - The typeId of the type being described
      precision - The number of decimal digits.
      scale - The number of digits after the decimal point.
      isNullable - TRUE means it could contain NULL, FALSE means it definitely cannot contain NULL.
      maximumWidth - The maximum number of bytes for this datatype
      collationType - The collation type of a string data type
    • TypeDescriptorImpl

      public TypeDescriptorImpl(BaseTypeIdImpl typeId, boolean isNullable, int maximumWidth)
      Constructor for use with non-numeric types
      Parameters:
      typeId - The typeId of the type being described
      isNullable - TRUE means it could contain NULL, FALSE means it definitely cannot contain NULL.
      maximumWidth - The maximum number of bytes for this datatype
    • TypeDescriptorImpl

      public TypeDescriptorImpl(TypeDescriptorImpl source, int precision, int scale, boolean isNullable, int maximumWidth)
      Constructor for internal uses only. (This is useful when the precision and scale are potentially wider than those in the source, like when determining the dominant data type.)
      Parameters:
      source - The DTSI to copy
      precision - The number of decimal digits.
      scale - The number of digits after the decimal point.
      isNullable - TRUE means it could contain NULL, FALSE means it definitely cannot contain NULL.
      maximumWidth - The maximum number of bytes for this datatype
    • TypeDescriptorImpl

      public TypeDescriptorImpl(TypeDescriptorImpl source, int precision, int scale, boolean isNullable, int maximumWidth, int collationType)
    • TypeDescriptorImpl

      public TypeDescriptorImpl(TypeDescriptorImpl source, boolean isNullable, int maximumWidth)
      Constructor for internal uses only
      Parameters:
      source - The DTSI to copy
      isNullable - TRUE means it could contain NULL, FALSE means it definitely cannot contain NULL.
      maximumWidth - The maximum number of bytes for this datatype
  • Method Details

    • copyTypeDescriptors

      public static TypeDescriptor[] copyTypeDescriptors(TypeDescriptor[] original)
      copy an array of type descriptors
    • getMaximumWidth

      public int getMaximumWidth()
      Description copied from interface: TypeDescriptor
      Returns the maximum width of the type. This may have different meanings for different types. For example, with char, it means the maximum number of characters, while with int, it is the number of bytes (i.e. 4).
      Specified by:
      getMaximumWidth in interface TypeDescriptor
      Returns:
      the maximum length of this Type; -1 means "unknown/no max length"
      See Also:
    • getMaximumWidthInBytes

      public int getMaximumWidthInBytes()
      Return the length of this type in bytes. Note that while the JDBC API _does_ define a need for returning length in bytes of a type, it doesn't state clearly what that means for the various types. We assume therefore that the values here are meant to match those specified by the ODBC specification (esp. since ODBC clients are more likely to need this value than a Java client). The ODBC spec that defines the values we use here can be found at the following link: http://msdn.microsoft.com/library/default.asp?url=/library/ en-us/odbc/htm/odbctransfer_octet_length.asp
      Specified by:
      getMaximumWidthInBytes in interface TypeDescriptor
      Returns:
      the maximum length of this Type IN BYTES; -1 means "unknown/no max length"
      See Also:
    • isStringType

      public boolean isStringType()
      Report whether this type is a string type.
    • getJDBCTypeId

      public int getJDBCTypeId()
      Get the jdbc type id for this type. JDBC type can be found in java.sql.Types.
      Specified by:
      getJDBCTypeId in interface TypeDescriptor
      Returns:
      a jdbc type, e.g. java.sql.Types.DECIMAL
      See Also:
    • getTypeName

      public String getTypeName()
      Gets the name of this datatype.
      Specified by:
      getTypeName in interface TypeDescriptor
      Returns:
      the name of this datatype
    • getPrecision

      public int getPrecision()
      Returns the number of decimal digits for the datatype, if applicable.
      Specified by:
      getPrecision in interface TypeDescriptor
      Returns:
      The number of decimal digits for the datatype. Returns zero for non-numeric datatypes.
    • getScale

      public int getScale()
      Returns the number of digits to the right of the decimal for the datatype, if applicable.
      Specified by:
      getScale in interface TypeDescriptor
      Returns:
      The number of digits to the right of the decimal for the datatype. Returns zero for non-numeric datatypes.
    • isNullable

      public boolean isNullable()
      Returns TRUE if the datatype can contain NULL, FALSE if not. JDBC supports a return value meaning "nullability unknown" - I assume we will never have columns where the nullability is unknown.
      Specified by:
      isNullable in interface TypeDescriptor
      Returns:
      TRUE if the datatype can contain NULL, FALSE if not.
    • isRowMultiSet

      public boolean isRowMultiSet()
      Description copied from interface: TypeDescriptor
      Return true if this is a Row Multiset type
      Specified by:
      isRowMultiSet in interface TypeDescriptor
      See Also:
    • isUserDefinedType

      public boolean isUserDefinedType()
      Description copied from interface: TypeDescriptor
      Return true if this is a user defined type
      Specified by:
      isUserDefinedType in interface TypeDescriptor
      See Also:
    • getCollationType

      public int getCollationType()
      Description copied from interface: TypeDescriptor
      Get the collation type for this type. This api applies only to character string types. And its return value is valid only if the collation derivation of this type is "implicit" or "explicit". (In Derby 10.3, collation derivation can't be "explicit". Hence in Derby 10.3, this api should be used only if the collation derivation is "implicit".
      Specified by:
      getCollationType in interface TypeDescriptor
      Returns:
      collation type which applies to character string types with collation derivation of "implicit" or "explicit". The possible return values in Derby 10.3 will be COLLATION_TYPE_UCS_BASIC and COLLATION_TYPE_TERRITORY_BASED.
      See Also:
    • setCollationType

      public void setCollationType(int collationTypeValue)
    • getSQLstring

      public String getSQLstring()
      Converts this data type descriptor (including length/precision) to a string. E.g. VARCHAR(30) or java.util.Hashtable
      Specified by:
      getSQLstring in interface TypeDescriptor
      Returns:
      String version of datatype, suitable for running through the Parser.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getTypeId

      public BaseTypeIdImpl getTypeId()
      Get the type Id stored within this type descriptor.
    • equals

      public boolean equals(Object object)
      Compare if two TypeDescriptors are exactly the same
      Overrides:
      equals in class Object
      Parameters:
      object - the dataTypeDescriptor to compare to.
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Read this object from a stream of stored objects.
      Specified by:
      readExternal in interface Externalizable
      Parameters:
      in - read this.
      Throws:
      IOException - thrown on error
      ClassNotFoundException - thrown on error
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Write this object to a stream of stored objects.
      Specified by:
      writeExternal in interface Externalizable
      Parameters:
      out - write bytes here.
      Throws:
      IOException - thrown on error
    • getTypeFormatId

      public int getTypeFormatId()
      Get the formatID which corresponds to this class.
      Specified by:
      getTypeFormatId in interface TypedFormat
      Returns:
      the formatID of this class
    • getRowColumnNames

      public String[] getRowColumnNames()
      Description copied from interface: TypeDescriptor
      If this catalog type is a row multi-set type then return its array of column names.
      Specified by:
      getRowColumnNames in interface TypeDescriptor
      Returns:
      Column names comprising the row, null if this is not a row type.
    • getRowTypes

      public TypeDescriptor[] getRowTypes()
      Description copied from interface: TypeDescriptor
      If this catalog type is a row multi-set type then return its array of catalog types.
      Specified by:
      getRowTypes in interface TypeDescriptor
      Returns:
      Catalog ypes comprising the row, null if this is not a row type.