Class ColumnDescription


  • public class ColumnDescription
    extends java.lang.Object
    This is a description of a column and the data it stores. Specifically it stores the 'type' as defined in the Types class, the 'size' if the column cells may be different lengths (eg, string), the name of the column, whether the column set must contain unique elements, and whether a cell may be added that is null.
    Author:
    Tobias Downer
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Class classType()
      Returns the class of Java object for this field.
      boolean equals​(java.lang.Object ob)
      The 'equals' method, used to determine equality between column descriptions.
      java.lang.String getName()
      Returns the name of the field.
      int getScale()
      If this is a number, returns the scale of the field.
      int getSize()
      Returns the size of the given field.
      int getSQLType()
      Returns a value from java.sql.Type that is the SQL type defined for this column.
      java.lang.String getSQLTypeName()
      Returns the name (as a string) of the SQL type or null if the type is not understood.
      int getType()
      Returns an integer representing the type of the field.
      int getUniqueGroup()
      Returns the unique group that this column is in.
      boolean isNotNull()
      Determines whether the field can contain a null value or not.
      boolean isNumericType()
      Returns true if this column is a numeric type.
      boolean isQuantifiable()
      Returns true if the type of the field is searchable.
      boolean isUnique()
      Determines whether the field can contain two items that are identical.
      static ColumnDescription readFrom​(java.io.DataInputStream in)
      Reads a ColumnDescription from the given DataInputStream and returns a new instance of it.
      void setScale​(int scale)
      Sets the scale of the numerical values stored.
      void setSQLType​(int sql_type)
      Sets the SQL type for this ColumnDescription object.
      void setUnique()
      Sets this column to unique.
      void setUniqueGroup​(int group)
      Sets the column to belong to the specified unique group in the table.
      void writeTo​(java.io.DataOutputStream out)
      Writes this ColumnDescription to the given DataOutputStream.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ColumnDescription

        public ColumnDescription​(java.lang.String name,
                                 int type,
                                 int size,
                                 boolean not_null)
        The Constructors if the type does require a size.
      • ColumnDescription

        public ColumnDescription​(java.lang.String name,
                                 int type,
                                 boolean not_null)
      • ColumnDescription

        public ColumnDescription​(java.lang.String name,
                                 ColumnDescription cd)
    • Method Detail

      • setUnique

        public void setUnique()
        Sets this column to unique. NOTE: This can only happen during the setup of the object. Unpredictable results will occur otherwise.
      • setUniqueGroup

        public void setUniqueGroup​(int group)
        Sets the column to belong to the specified unique group in the table. Setting to -1 sets the column to no unique group. NOTE: This can only happen during the setup of the object. Unpredictable results will occur otherwise.
      • setSQLType

        public void setSQLType​(int sql_type)
        Sets the SQL type for this ColumnDescription object. This is only used to emulate SQL types in the database. They are mapped to the simpler internal types as follows:

            DB_STRING := CHAR, VARCHAR, LONGVARCHAR
           DB_NUMERIC := TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, REAL,
                         DOUBLE, NUMERIC, DECIMAL
              DB_DATE := DATE, TIME, TIMESTAMP
           DB_BOOLEAN := BIT
              DB_BLOB := BINARY, VARBINARY, LONGVARBINARY
            DB_OBJECT := JAVA_OBJECT
         
      • setScale

        public void setScale​(int scale)
        Sets the scale of the numerical values stored.
      • getName

        public java.lang.String getName()
        Returns the name of the field. The field type returned should be 'ZIP' or 'Address1'. To resolve to the tables type, we must append an additional 'Company.' or 'Customer.' string to the front.
      • getType

        public int getType()
        Returns an integer representing the type of the field. The types are outlined in com.mckoi.database.global.Types.
      • isNumericType

        public boolean isNumericType()
        Returns true if this column is a numeric type.
      • getSQLType

        public int getSQLType()
        Returns a value from java.sql.Type that is the SQL type defined for this column. It's possible that the column may not have had the SQL type set in which case we map from the internal db type ( DB_??? ) to the most logical sql type.
      • getSQLTypeName

        public java.lang.String getSQLTypeName()
        Returns the name (as a string) of the SQL type or null if the type is not understood.
      • classType

        public java.lang.Class classType()
        Returns the class of Java object for this field.
      • getSize

        public int getSize()
        Returns the size of the given field. This is only applicable to a few of the types, ie VARCHAR.
      • getScale

        public int getScale()
        If this is a number, returns the scale of the field.
      • isNotNull

        public boolean isNotNull()
        Determines whether the field can contain a null value or not. Returns true if it is required for the column to contain data.
      • isUnique

        public boolean isUnique()
        Determines whether the field can contain two items that are identical. Returns true if each element must be unique.
      • getUniqueGroup

        public int getUniqueGroup()
        Returns the unique group that this column is in. If it does not belong to a unique group then the value -1 is returned.
      • isQuantifiable

        public boolean isQuantifiable()
        Returns true if the type of the field is searchable. Searchable means that the database driver can quantify it, as in determine if a given object of the same type is greater, equal or less. We can not quantify BLOB types.
      • equals

        public boolean equals​(java.lang.Object ob)
        The 'equals' method, used to determine equality between column descriptions.
        Overrides:
        equals in class java.lang.Object
      • writeTo

        public void writeTo​(java.io.DataOutputStream out)
                     throws java.io.IOException
        Writes this ColumnDescription to the given DataOutputStream. ( Remember to flush output stream )
        Throws:
        java.io.IOException
      • readFrom

        public static ColumnDescription readFrom​(java.io.DataInputStream in)
                                          throws java.io.IOException
        Reads a ColumnDescription from the given DataInputStream and returns a new instance of it.
        Throws:
        java.io.IOException