Class DBTableColumn

All Implemented Interfaces:
Column, ColumnExpr

public class DBTableColumn extends DBColumn
This class represent one column of a table. It contains all properties of this columns (e.g. the column width).
  • Field Details

    • DBCOLATTR_SINGLEBYTECHARS

      public static final String DBCOLATTR_SINGLEBYTECHARS
      See Also:
    • type

      protected DataType type
    • size

      protected double size
    • required

      protected boolean required
    • autoGenerated

      protected boolean autoGenerated
    • readOnly

      protected boolean readOnly
    • defaultValue

      protected Object defaultValue
    • decimalScale

      protected int decimalScale
  • Constructor Details

    • DBTableColumn

      public DBTableColumn(DBTable table, DataType type, String name, double size, boolean required, boolean autoGenerated, Object defValue)
      Constructs a DBTableColumn object set the specified parameters to this object.
      Parameters:
      table - the table object to add the column to, set to null if you don't want it added to a table
      type - the type of the column e.g. integer, text, date
      name - the column name
      size - the column width
      required - flag whether the column is required
      autoGenerated - flag whether the column is auto generated
      defValue - the object value
    • DBTableColumn

      protected DBTableColumn(DBTable newTable, DBTableColumn other)
      Clone Constructor
      Parameters:
      newTable - the cloned table
      other - the column to clone
  • Method Details

    • getDefaultValue

      public Object getDefaultValue()
      Returns the default column value. For columns of type DBDataType.AUTOINC this is assumed to be the name of a sequence
      Returns:
      the default column value
    • setDefaultValue

      public void setDefaultValue(Object defValue)
      Sets the default column value.
      Parameters:
      defValue - the default column value
    • getRecordDefaultValue

      public Object getRecordDefaultValue(Record record, Connection conn)
      Returns the default column value. Unlike getDefaultValue this function is used when creating or adding records. If the column value is DBDataType AUTOIN this function will return a new sequence value for this record
      Parameters:
      record - the record
      conn - a valid database connection
      Returns:
      the default column value
    • getDataType

      public DataType getDataType()
      Returns the data type.
      Specified by:
      getDataType in interface ColumnExpr
      Specified by:
      getDataType in class DBColumnExpr
      Returns:
      the data type
      See Also:
    • getSize

      public double getSize()
      Gets the the column width.
      Specified by:
      getSize in interface Column
      Specified by:
      getSize in class DBColumn
      Returns:
      the column width
    • setSize

      public void setSize(double size)
      Changes the size of the table column
      Use for dynamic data model changes only.
      Parameters:
      size - the new column size
    • getDecimalScale

      public int getDecimalScale()
      Returns the scale of the Decimal or 0 if the DataType is not DataType.DECIMAL.
      Returns:
      the decimal scale
    • setDecimalScale

      public void setDecimalScale(int scale)
      Sets the scale of a decimal. The DataType must be set to DataType.DECIMAL otherwise an exception is thrown.
      Parameters:
      scale - the number of fraction digits
    • isRequired

      public boolean isRequired()
      Returns true if column is mandatory. Only for the graphic presentation.
      Specified by:
      isRequired in interface Column
      Specified by:
      isRequired in class DBColumn
      Returns:
      true if column is mandatory
    • isAutoGenerated

      public boolean isAutoGenerated()
      Returns true if column is a numeric sequence or otherwise generated value
      Specified by:
      isAutoGenerated in interface Column
      Specified by:
      isAutoGenerated in class DBColumn
      Returns:
      true if column is auto increment
    • isSingleByteChars

      public boolean isSingleByteChars()
      Returns true if column the column is a single byte text or character column or false otherwise
      Returns:
      true if column is a single byte character based column
    • setSingleByteChars

      public void setSingleByteChars(boolean singleByteChars)
      sets whether this column is a single byte character or text column
      Parameters:
      singleByteChars - flag whether single byte chars should be used
    • setRequired

      public void setRequired(boolean required)
      Changes the required property of the table column
      Use for dynamic data model changes only.
      Parameters:
      required - true if the column is required or false otherwise
    • isReadOnly

      public boolean isReadOnly()
      Checks whether the column is read only.
      Specified by:
      isReadOnly in interface Column
      Specified by:
      isReadOnly in class DBColumn
      Returns:
      true if the column is read only
    • setReadOnly

      public void setReadOnly(boolean readOnly)
      Sets the read only attribute of the column.
      Parameters:
      readOnly - true if the column should be read only or false otherwise
    • setEnumOptions

      public void setEnumOptions(Class<? extends Enum<?>> enumType)
      sets the options from an enum class
      Parameters:
      enumType - the enum type
    • validateValue

      public Object validateValue(Object value)
      Checks whether the supplied value is valid for this column. If the type of the value supplied does not match the columns data type the value will be checked for compatibility.
      Specified by:
      validateValue in interface Column
      Specified by:
      validateValue in class DBColumn
      Parameters:
      value - the checked to check for validity
      Returns:
      true if the value is valid or false otherwise.
    • referenceOn

      public DBRelation.DBReference referenceOn(DBTableColumn target)
      Creates a foreign key relation for this column.
      Parameters:
      target - the referenced primary key column
      Returns:
      the reference object
    • addXml

      public Element addXml(Element parent, long flags)
      Sets field elements, default attributes and all options to the specified Element object (XML tag).
      Specified by:
      addXml in class DBColumn
      Parameters:
      parent - the parent object
      flags - a long value
      Returns:
      the work up Element object