Record Class DataColumn
- Record Components:
tableName- name of the data base tablecolumnName- name of the column in the tablecolumnType- type of the column for type alignment with the logical data modelisAlwaysKnown- if true there is always a value for any record existing in the table seeDataColumnisMultiRow- if true there can be multiple rows (values) in the table related to the same idfilters- optional (null = empty list): columns with fixed values to filter the result seeFilterColumn
- All Implemented Interfaces:
AdlSqlColumn, Serializable
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.
+------+-------+---------+ | 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 Summary
ConstructorsConstructorDescriptionDataColumn(String tableName, String columnName, AdlSqlType columnType, boolean isAlwaysKnown, boolean isMultiRow, List<FilterColumn> filters) Creates an instance of aDataColumnrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thecolumnNamerecord component.Returns the value of thecolumnTyperecord component.final booleanIndicates whether some other object is "equal to" this one.filters()Returns the value of thefiltersrecord component.Starts the fluent building process for a data columnfinal inthashCode()Returns a hash code value for this object.booleanReturns the value of theisAlwaysKnownrecord component.booleanReturns the value of theisMultiRowrecord component.Returns the value of thetableNamerecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
DataColumn
public DataColumn(String tableName, String columnName, AdlSqlType columnType, boolean isAlwaysKnown, boolean isMultiRow, List<FilterColumn> filters) Creates an instance of aDataColumnrecord class.- Parameters:
tableName- the value for thetableNamerecord componentcolumnName- the value for thecolumnNamerecord componentcolumnType- the value for thecolumnTyperecord componentisAlwaysKnown- the value for theisAlwaysKnownrecord componentisMultiRow- the value for theisMultiRowrecord componentfilters- the value for thefiltersrecord component
-
-
Method Details
-
forTable
Starts the fluent building process for a data column- Parameters:
tableName- target table- Returns:
- builder
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
tableName
Returns the value of thetableNamerecord component.- Specified by:
tableNamein interfaceAdlSqlColumn- Returns:
- the value of the
tableNamerecord component
-
columnName
Returns the value of thecolumnNamerecord component.- Specified by:
columnNamein interfaceAdlSqlColumn- Returns:
- the value of the
columnNamerecord component
-
columnType
Returns the value of thecolumnTyperecord component.- Specified by:
columnTypein interfaceAdlSqlColumn- Returns:
- the value of the
columnTyperecord component
-
isAlwaysKnown
public boolean isAlwaysKnown()Returns the value of theisAlwaysKnownrecord component.- Returns:
- the value of the
isAlwaysKnownrecord component
-
isMultiRow
public boolean isMultiRow()Returns the value of theisMultiRowrecord component.- Returns:
- the value of the
isMultiRowrecord component
-
filters
-