Class DBColumn

All Implemented Interfaces:
Column, ColumnExpr
Direct Known Subclasses:
DBCommandExpr.DBCmdColumn, DBQueryColumn, DBTableColumn, DBView.DBViewColumn

public abstract class DBColumn extends DBColumnExpr implements Column
This is the base class for all database columns that have a physical representation. i.e. either table or view columns (DBTableColumn oder DBViewColumn)

The column object describes a database column and thus provides metadata. Other non data model specific metadata may be added through attributes.

See Also:
  • Field Details

    • rowset

      protected final DBRowSet rowset
    • name

      protected final String name
    • comment

      protected String comment
    • quoteName

      protected Boolean quoteName
  • Constructor Details

    • DBColumn

      protected DBColumn(DBRowSet rowset, String name)
      Constructs a DBColumn object and set the specified parameters to this object.
      Parameters:
      rowset - the rowset (i.e. Table or View) that this column belongs to
      name - the column name
  • Method Details

    • getIdentifier

      public String getIdentifier()
      Gets an identifier for this RowSet Object
      Returns:
      the rowset identifier
    • equals

      public boolean equals(Object other)
      Custom serialization for transient rowset. private void writeObject(ObjectOutputStream strm) throws IOException { // RowSet strm.writeObject(rowset.getDatabase().getIdentifier()); strm.writeObject(rowset.getName()); // write default strm.defaultWriteObject(); } private void readObject(ObjectInputStream strm) throws IOException, ClassNotFoundException { String dbid = String.valueOf(strm.readObject()); String rsid = String.valueOf(strm.readObject()); // find database DBDatabase dbo = DBDatabase.findByIdentifier(dbid); if (dbo==null) throw new ClassNotFoundException(dbid); // find rowset DBRowSet rso = dbo.getRowSet(rsid); if (rso==null) throw new ClassNotFoundException(dbid+"."+rsid); // set final field ClassUtils.setPrivateFieldValue(DBColumn.class, this, "rowset", rso); // read the rest strm.defaultReadObject(); }
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getSize

      public abstract double getSize()
      Returns the size of the column.
      Specified by:
      getSize in interface Column
      Returns:
      Returns the size of the column
    • isRequired

      public abstract boolean isRequired()
      Returns true if the column is required.
      Specified by:
      isRequired in interface Column
      Returns:
      Returns true if the column is required
    • isAutoGenerated

      public abstract boolean isAutoGenerated()
      Returns true if column is a columns value is an automatically generated value
      Specified by:
      isAutoGenerated in interface Column
      Returns:
      true if column is auto-generated
    • isReadOnly

      public abstract boolean isReadOnly()
      Returns true if the column is read-only.
      Specified by:
      isReadOnly in interface Column
      Returns:
      Returns true if the column is read-only
    • validateValue

      public abstract Object validateValue(Object value)
      Checks if the given value is a valid value for this column If not, an exception is thrown
      Specified by:
      validateValue in interface Column
      Parameters:
      value - the value to validate
      Returns:
      the value the validated and possibly converted value
    • addXml

      public abstract Element addXml(Element parent, long flags)
      Appends column meta information to the parent element
      Specified by:
      addXml in class DBColumnExpr
      Parameters:
      parent - the parent element to which to append the column description
      flags - currently not used
      Returns:
      the newly created child element
    • getDatabase

      public final DBDatabase getDatabase()
      Description copied from class: DBObject
      Returns the database object to which this object belongs to. For the database object itself this function will return the this pointer.
      Specified by:
      getDatabase in class DBObject
      Returns:
      the current DBDatabase object
    • addReferencedColumns

      public void addReferencedColumns(Set<DBColumn> list)
      Description copied from class: DBExpr
      Internal function to obtain all DBColumnExpr-objects used by this expression.
      Specified by:
      addReferencedColumns in class DBExpr
      Parameters:
      list - list to which all used column expressions must be added
      See Also:
    • addSQL

      public void addSQL(DBSQLBuilder sql, long context)
      Adds the colunm name to the SQL-Command.
      This can be either a qualified or unqualified name depending on the context.
      Specified by:
      addSQL in class DBExpr
      Parameters:
      sql - the SQL statment
      context - the current SQL-Command context
    • getName

      public String getName()
      Returns the column name.
      Specified by:
      getName in interface ColumnExpr
      Specified by:
      getName in class DBColumnExpr
      Returns:
      the column name
    • getRowSet

      public DBRowSet getRowSet()
      Returns DBTable, DBQuery or DBView object.
      Specified by:
      getRowSet in class DBColumnExpr
      Returns:
      the DBTable, DBQuery or DBView object
    • getEntity

      public Entity getEntity()
      Returns the Entity Type Same as getRowSet()
      Specified by:
      getEntity in interface Column
      Returns:
      the EntityType if any
    • getUpdateColumn

      public DBColumn getUpdateColumn()
      Returns itself as the underlying column.
      Specified by:
      getUpdateColumn in interface ColumnExpr
      Specified by:
      getUpdateColumn in class DBColumnExpr
      Returns:
      the underlying column
    • isAggregate

      public boolean isAggregate()
      Always returns false since DBColumns cannot be aggregates.
      Specified by:
      isAggregate in class DBColumnExpr
      Returns:
      false
    • reference

      public DBColumnExpr reference()
      Returns a reference expression for this column This can be used to reference a parent column in a subquery
      Returns:
      the column value expression
    • getFullName

      public String getFullName()
      Returns the full qualified column name.
      Returns:
      the full qualified column name
    • getAlias

      public String getAlias()
      returns the qualified alias name for this column
      Returns:
      the alias
    • qualified

      public DBAliasExpr qualified()
      returns an expression that renames the column with its alias name
      Overrides:
      qualified in class DBColumnExpr
      Returns:
      a qualified expression for this column
    • coalesceColumn

      public DBAliasExpr coalesceColumn(Object nullValue)
      Creates a column expression with coalesce and renames it to this column
      Parameters:
      nullValue - the alternative value when this column is null
      Returns:
      the coalesce and alias expression
    • getAttribute

      public Object getAttribute(String name)
      Description copied from class: DBColumnExpr
      Returns the value of a column attribute. Column attributes are used to provide metadata for a column.
      Specified by:
      getAttribute in interface ColumnExpr
      Overrides:
      getAttribute in class DBColumnExpr
      Parameters:
      name - the attribute name
      Returns:
      value of the attribute if it exists or null otherwise
      See Also:
    • getAttributes

      public Set<Attributes.Attribute> getAttributes()
      Returns all metadata attributes.
      Specified by:
      getAttributes in interface Column
      Returns:
      set of metadata attributes
    • getOptions

      public Options getOptions()
      Description copied from class: DBColumnExpr
      Returns the list of options for this column containing all possible field values.
      Specified by:
      getOptions in interface ColumnExpr
      Overrides:
      getOptions in class DBColumnExpr
      Returns:
      the list of options
    • isEnum

      public final boolean isEnum()
      Returns true if an enum type has been set for this column
      Returns:
      true if an enum type has been set for this column or false otherwise
    • getEnumType

      public Class<Enum<?>> getEnumType()
      Returns the enum type for this column
      Specified by:
      getEnumType in interface ColumnExpr
      Returns:
      the enum type
    • getJavaType

      public Class<?> getJavaType()
      Returns the java type for this column
      Overrides:
      getJavaType in class DBColumnExpr
      Returns:
      the java type
    • setCaseSensitive

      public <T extends DBColumn> T setCaseSensitive(Boolean caseSensitiv)
      Sets the case sensitivity of the columnExpr
      Parameters:
      caseSensitiv - the character casing. This may be true, false or null (default)
      Returns:
      self (this)
    • setCaseInsensitive

      public final <T extends DBColumn> T setCaseInsensitive()
      Sets the case sensitivity of the column to insensitive Text columns are case sensitive by default
      Returns:
      self (this)
    • setNumberType

      public final <T extends DBColumn> T setNumberType(String numberType)
      Sets the number type to a given value
      Parameters:
      numberType - the number type. See Column.NUMTYPE_... constants
      Returns:
      self (this)
    • getRegExPattern

      public Pattern getRegExPattern()
      Returns the maximum allowed value
      Returns:
      the minimum length
    • setRegExPattern

      public <T extends DBColumn> T setRegExPattern(String regex)
      Set the regular expression to validate the columnExpr value
      Parameters:
      regex - the regular expression
      Returns:
      self (this)
    • getNormalizedColumn

      public DBColumnExpr getNormalizedColumn()
      Returns the normalized column for the columnExpr (if any)
      Returns:
      the normalized column or null
    • setNormalizedColumn

      public <T extends Column> T setNormalizedColumn(DBColumnExpr normalizedColumn)
      Sets a normalized columnExpr for this columnExpr
      Parameters:
      normalizedColumn - the normalized columnExpr
      Returns:
      self (this)
    • getSortExpr

      public DBColumnExpr getSortExpr()
      Returns the sort expression for a given column If no sort expression is explicitly set then the column itself is returned The returned expression should be assigned to an DBCommand.orderBy() function.
      Returns:
      the sort expression or the column itself if not sort expression is set
    • setSortExpr

      public <T extends DBColumn> T setSortExpr(DBColumnExpr sortExpression)
      Sets a sort function expression for a given column
      Parameters:
      sortExpression - the expression which to use for sorting
      Returns:
      self (this)
    • decodeEnum

      public DBColumnExpr decodeEnum()
      Creates and returns a sql-expression that maps enum values by name or ordinal to their string representation
      Returns:
      a DBDecodeExpr object
    • decodeSort

      public DBColumnExpr decodeSort(boolean defaultToEnd)
      Creates and returns a sql-expression that maps enum values from name to ordinal
      Parameters:
      defaultToEnd - flag whether to put the default item to the end
      Returns:
      a DBDecodeExpr object
    • setSortExpr

      public <T extends DBColumn> T setSortExpr(String sortFunctionTemplate)
      Sets a sort function template for a given column
      Parameters:
      sortFunctionTemplate - the template which must contain a ? which will be replaced with the column name
      Returns:
      return the column
    • to

      public DBSetExpr to(Object value)
      Creates and returns a new DBSetExpr object.
      Parameters:
      value - the Object value
      Returns:
      the new DBSetExpr object
      See Also:
    • toString

      public String toString()
      Override the toString method.
      Overrides:
      toString in class DBColumnExpr
      Returns:
      the table name and the column name (e.g. CUSTOMER.ID)
    • getComment

      public String getComment()
      Returns a comment describing the column in the data scheme.
      Returns:
      Returns the comment.
    • setComment

      public void setComment(String comment)
      Sets a comment describing the current column.
      Parameters:
      comment - the column comment