Record Class DataColumn

java.lang.Object
java.lang.Record
de.calamanari.adl.sql.config.DataColumn
Record Components:
tableName - name of the data base table
columnName - name of the column in the table
columnType - type of the column for type alignment with the logical data model
isAlwaysKnown - if true there is always a value for any record existing in the table see DataColumn
isMultiRow - if true there can be multiple rows (values) in the table related to the same id
filters - optional (null = empty list): columns with fixed values to filter the result see FilterColumn
All Implemented Interfaces:
AdlSqlColumn, Serializable

public record DataColumn(String tableName, String columnName, AdlSqlType columnType, boolean isAlwaysKnown, boolean isMultiRow, List<FilterColumn> filters) extends Record implements AdlSqlColumn
A DataColumn describes the characteristics of a table colum in a database.

Remarks:

The flag isAlwaysKnown defines that there is a known value for every record in your database.

E.g., be there a record ID=4711 and a column MODEL, you guarantee that there will be a non-null value in that column for ID-4711.

Important: There is a subtle difference between a column with the SQL-constraint NOT NULL and isAlwaysKnown.
In a database with multiple tables there are two ways a value can be unknown (SQL NULL). First, if a column is nullable, then the value of that column can be SQL NULL. Second, if there is a left join to a table that does not contain a record's id that otherwise matches all query conditions, then this column also appears as SQL NULL value. Be sure, both cannot happen before you set this property. The query builder relies on this setting to decide about the join type. An incorrect setting may lead to wrong query results.

  • If there is exactly one table in your setup, you can safely set this property if there is a NOT NULL SQL-constraint on the related column.
  • If the table is marked with TableNature.containsAllIds() (resp. TableNature.isPrimaryTable()) and there is a NOT NULL SQL-constraint on the related column, then you can safely set this property.
  • If you configure a multi-table setup, please double-check if a particular join path among the configured tables could lead to above mentioned problem.
  • Don't set this property if you are unsure.
The flag isMultiRow defines that the data for a single record can be located on multiple rows.

+------+-------+---------+
|  ID  | ...   | COLOR   |
+------+-------+---------+
| 8231 | ...   | BLUE    |
+------+-------+---------+
| 8231 | ...   | RED     |
+------+-------+---------+
| 8231 | ...   | YELLOW  |
+------+-------+---------+
| 9555 | ...   | ...     |
+------+-------+---------+
In the example above for the same record (8321) there are 3 different values for the attribute COLOR, which must be considered when generating queries.
An SQL-query like COLOR = 'BLUE' AND COLOR = 'RED' would not work because any of these conditions fixes a row set that is incompatible to the other condition. We call this accidental row-pinning.

  • Unnecessarily setting this property may negatively impact the performance (increased query complexity) but queries will be correct.
  • However, if the values sit on multiple rows not setting this property will inevitably lead to incorrect query results.
  • If you see unexpected query results and you are unsure, then try setting this property to compare the generated queries and the outcome.

If you omit providing an explicit logical data model and instead rely on the the physical model, then any argument mapped to a column marked as multi-row will appear as collection. This is not accurate but may help to understand the implications. In other words: there can be valid scenarios where a multi-row mapping does not imply a collection attribute. This is especially the case for key-value onboarding (flat filtered table) with every key assigned to only one value per record.

Each entry in filters defines an extra column filter related to this data column. This is required if this data column stores information effectively qualified or narrowed by values of other column(s).
See also FilterColumn.

Instances are deeply immutable.

Author:
Karl Eilebrecht
See Also:
  • Constructor Details

    • DataColumn

      public DataColumn(String tableName, String columnName, AdlSqlType columnType, boolean isAlwaysKnown, boolean isMultiRow, List<FilterColumn> filters)
      Creates an instance of a DataColumn record class.
      Parameters:
      tableName - the value for the tableName record component
      columnName - the value for the columnName record component
      columnType - the value for the columnType record component
      isAlwaysKnown - the value for the isAlwaysKnown record component
      isMultiRow - the value for the isMultiRow record component
      filters - the value for the filters record component
  • Method Details

    • forTable

      public static ConfigBuilderInterfaces.DataColumnStep1 forTable(String tableName)
      Starts the fluent building process for a data column
      Parameters:
      tableName - target table
      Returns:
      builder
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • tableName

      public String tableName()
      Returns the value of the tableName record component.
      Specified by:
      tableName in interface AdlSqlColumn
      Returns:
      the value of the tableName record component
    • columnName

      public String columnName()
      Returns the value of the columnName record component.
      Specified by:
      columnName in interface AdlSqlColumn
      Returns:
      the value of the columnName record component
    • columnType

      public AdlSqlType columnType()
      Returns the value of the columnType record component.
      Specified by:
      columnType in interface AdlSqlColumn
      Returns:
      the value of the columnType record component
    • isAlwaysKnown

      public boolean isAlwaysKnown()
      Returns the value of the isAlwaysKnown record component.
      Returns:
      the value of the isAlwaysKnown record component
    • isMultiRow

      public boolean isMultiRow()
      Returns the value of the isMultiRow record component.
      Returns:
      the value of the isMultiRow record component
    • filters

      public List<FilterColumn> filters()
      Returns the value of the filters record component.
      Returns:
      the value of the filters record component