Open the menu

    Source

    A source is the representation of a data repository that has a set of fields. It determines the schema of the data and populates the controls, which are the visual components of the DOUI interfaces.

    The data provider is responsible for obtaining data from a data source (for example, a database table or a text file) and populating a source.

    Therefore, all the data presented in the DOUI interfaces is obtained through sources and data providers.

    A source consists of a class that extends the Source class. Its hierarchy is defined as follows:

    1. The Source class has the implementation of the infrastructure of a source. It is an abstract class, still without definition on how the data is persisted or organized;

    2. The TabularSource class extends Source, adding the logic that the data is organized in a tabular form, in rows and columns, where each row represents one data entry and each field a column. There is a field that is the primary key. The value of this field never repeats and can be used to identify a row.

      The data of this type of source is stored in an instance of TabularData.

      This class is also abstract, as it does not define how the data is persisted.

    3. The TableSource extends TabularSource, adding the functionality to map fields of the source directly with columns of a table in a database. The type attribute must be specified with the value “table” in the definition of the source.

      This type of source has a IDataProvider, which is responsible for providing data to the source. The default implementation of IDataProvider is a TableDataProvider, which reads the data from the table with the name specified in the table node within the source. The columns read are according to the field identifiers, or the optional columnName attribute in the fields.

      It is possible to use a custom DataProvider. To do this, in the definition of the source the dataproviderClassName element must be defined. In this case, if the dataproviderClassName element is defined, it must contain the name of the class that implements IDataProvider. In this way, instead of TableSource using its standard data reading method, the specified IDataProvider will be called when the source needs to read its data.

    The lifecycle of a source is:

    • Its instance is constructed;
    • Its loadData() method is executed, where its data is loaded.