Class ColumnType

  • All Implemented Interfaces:
    java.io.Serializable

    public class ColumnType
    extends java.lang.Object
    implements java.io.Serializable
    The type of a single column in a relation. The type is composed of two parts. The first part is present in all attribute-types, and is the "base type" of the attribute, such as INTEGER, TIMESTAMP, or CHARACTER. These values are represented by the SQLDataType enumeration. However, some of these types also require additional information about their length, precision, or other details. This second part is included as values in this class. The two parts together represent the type of a particular attribute.
    See Also:
    Serialized Form
    • Field Detail

      • SMALLINT

        public static final ColumnType SMALLINT
      • DATETIME

        public static final ColumnType DATETIME
      • TIMESTAMP

        public static final ColumnType TIMESTAMP
      • FILE_POINTER

        public static final ColumnType FILE_POINTER
      • baseType

        private SQLDataType baseType
        The base SQL data-type for the attribute.
      • length

        private int length
        For CHAR and VARCHAR attributes, this contains the length (or maximum length) of the character-sequence. This value must be at least 1; zero and negative values are invalid.

        This value is required in CHAR and VARCHAR attribute-declarations, but we default to a length of 1 here.

      • precision

        private int precision
        For NUMERIC attributes, this contains the precision of the number, or the total number of significant digits in the number.

        The default precision value used is DEFAULT_PRECISION.

      • scale

        private int scale
        For NUMERIC attributes, this contains the scale of the number, or the number of significant digits that are to the right of the decimal place.

        The SQL Standard says that the default scale should be zero, which although this seems a bit useless, that's what we do.

    • Constructor Detail

      • ColumnType

        public ColumnType​(SQLDataType baseType)
        Construct a new attribute-type instance, with the specified base SQL datatype. Note that more information may be needed to complete the attribute-type information, depending on the SQL datatype that is being used.
        Parameters:
        baseType - the base SQL datatype for this column type
    • Method Detail

      • VARCHAR

        public static ColumnType VARCHAR​(int length)
      • CHAR

        public static ColumnType CHAR​(int length)
      • NUMERIC

        public static ColumnType NUMERIC​(int precision)
      • NUMERIC

        public static ColumnType NUMERIC​(int precision,
                                         int scale)
      • equals

        public boolean equals​(java.lang.Object obj)
        Returns true if obj is another ColumnType object with the same type information, including both base type and any relevant size information.
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • getBaseType

        public SQLDataType getBaseType()
        Returns the base datatype for the attribute.
        Returns:
        the base SQL datatype for the attribute
      • hasLength

        public boolean hasLength()
        Returns true if this column type supports/requires a length, or false if the type does not.
        Returns:
        true if this column type supports/requires a length, or false if the type does not
      • setLength

        public void setLength​(int val)
        Specify the length of the data for CHAR and VARCHAR attributes.
        Parameters:
        val - the length of the data-type
        Throws:
        java.lang.IllegalStateException - if the attribute's base-type is not CHAR or VARCHAR.
        java.lang.IllegalArgumentException - if the specified length is zero or negative.
      • getLength

        public int getLength()
        Returns the length of the data for CHAR and VARCHAR attributes.
        Returns:
        the length of the data-type
        Throws:
        java.lang.IllegalStateException - if the attribute's base-type is not CHAR or VARCHAR.
      • setPrecision

        public void setPrecision​(int val)
        Specify the precision of the data for NUMERIC attributes.
        Parameters:
        val - the precision of the data-type
        Throws:
        java.lang.IllegalStateException - if the attribute's base-type is not NUMERIC.
        java.lang.IllegalArgumentException - if the specified precision is zero or negative, or if the specified precision is less than the scale.
      • getPrecision

        public int getPrecision()
        Returns the precision of the data for NUMERIC attributes.
        Returns:
        the precision of the data-type
        Throws:
        java.lang.IllegalStateException - if the attribute's base-type is not NUMERIC.
      • setScale

        public void setScale​(int val)
        Specify the scale of the data for NUMERIC attributes.
        Parameters:
        val - the scale of the data-type
        Throws:
        java.lang.IllegalStateException - if the attribute's base-type is not NUMERIC.
        java.lang.IllegalArgumentException - if the specified scale is negative, or if the specified scale is greater than the precision.
      • getScale

        public int getScale()
        Returns the scale of the data for NUMERIC attributes.
        Returns:
        the scale of the data-type
        Throws:
        java.lang.IllegalStateException - if the attribute's base-type is not NUMERIC.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object