Class ColumnDescription

java.lang.Object
com.mckoi.database.global.ColumnDescription

public class ColumnDescription extends 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
  • Constructor Details

    • ColumnDescription

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

      public ColumnDescription(String name, int type, boolean not_null)
    • ColumnDescription

      public ColumnDescription(ColumnDescription cd)
    • ColumnDescription

      public ColumnDescription(String name, ColumnDescription cd)
  • Method Details

    • 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 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 String getSQLTypeName()
      Returns the name (as a string) of the SQL type or null if the type is not understood.
    • classType

      public 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(Object ob)
      The 'equals' method, used to determine equality between column descriptions.
      Overrides:
      equals in class Object
    • writeTo

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

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