Data Management Entities

JBStrap uses three important data management entities:

  • DataRecord
  • Criteria
  • Order

If have already read through the data management concept , you are familiar with them. This article will give more details about them.

DataRecord

Data handled by the data handling layer will be returned in a DataRecord class, regardless of how it was queried from the database. If you want to save or delete data, pass it to the layer in a DataRecord class. A data record represents a data row (e.g. a row in a data table or view). The data in the DataRecord class will be stored using a key-value pair, in which the key is the attribute name (e.g. the table column name) and the value is the value in the table. The DataRecord class is completely generic and independent of the data descriptor. As data values may come from any database or data structure, they will be handled in the same way, without additional hassle.

If the DataRecord was created by the data handling layer, the attributes' original value will also be saved. After reading from the DataRecord, both values will be present, as a current value and an original value. If you modify the DataRecord afterwards (e.g. a user modifies it using a form), the current value will be modified accordingly, however, the original value will remain in the DataRecord. This allows you to easily check how the data record was modified.

Functions

The main function of the DataRecord class is to store data and to read data from it. The current and original values can be read from the data record, but you can change the current value as well. During the reading process, the data can also be converted.

Reading a value from the data record:
Setting a value in the data record:
Querying the original value of a data record attribute:
Querying the original value of a data record attribute, as a String:

Your program logic may receive a Record with an unknown structure. To handle this, the Record class comes with multiple methods that allow you to use the Record data without knowing the attribute names. You can query the names of every attribute, or you can get the values in a Map class.

Querying the names of every attribute in the data record:
Querying every data from the data record into a Map, The map key is the attribute name, and the value will be the attribute value, in the correct type:

Related pages

Criteria

Filter criteria in JBStrap must be created using the Criteria object. There are two types of Criteria objects: a simple and a complex one. A simple Criteria object contains only a single condition, whereas a complex Criteria consists of multiple conditions. Conditions can be nested, allowing you to create a Criteria to any degree of complexity.

The Criteria class is designed to define filter criteria but it is also capable of deciding whether a DataRecord satisfies the criteria or not. You can filter a DataRecord list, or you can branch the program logic based on a user-defined Criteria.

Functions

Simple Criteria are conditions evaluating some input data based on an operator. Such conditions do not contain logic operators (AND, OR) and therefore have only one condition – themselves.

Creating a simple Criteria (equivalent expression in SQL: columnName = 25):
Creating a NULL value using a simple Criteria (equivelent expression in SQL: columnName is NULL):
Filtering for multiple values (equivalent expression in SQL: columnName in (’one’,’two’,’three’):
Negation Criteria (equivalent expression in SQL: columnName != 32):

You can also define complex Criteria – a list of conditions connected with logic operators.

Creating all filter Criteria (equivalent expression in SQL: column1 = 25 AND column2 < 100):
Criteria consisting of multiple complex criteria (equivalent expression in SQL: (column1 is NULL AND column2 <= 100) OR (column1 is NOT NULL AND column2 > 500 AND COLUMN3 = ’valid’ ):

Criteria can be defined by using a value that comes from an other DataRecord. This enables you to define non-specific conditions reserved for later use. An example for this is when you want a list component to depend on the values of a form data record. Creating a filter Criteria using a value from a DataRecord. In this example we suppose to have a Form object which contains a „Type” field and a Grid. The user is able to edit the contents of the form. You want to display data in the Grid independently of the „Type” field’s value. Do this by inserting the following source code into the form change handler:

The Criteria is not just for filtering values. A Criteria can decide whether a DataRecord corresponds to the given Criteria or not. Let’s take an example of a list containing only DataRecords. Such a list contains the results of a query or the contents of a Grid. Our goal is to select DataRecords from this list based on a given Criteria. This can be done either programmatically (possibly a daunting task requiring you to write an extensive chunk of source code) or via Criteria. The following source code selects DataRecord s from a list (of data records) which have a valid „Y” attribute and a column1 attribute greater than 50 or a column3 attribute equal to 300:

Order

The Order class defines the order in which records are returned. Classes enable you to arrange the records into a specific order by a column (in ascending or descending order).

The easiest way to order data is to specify the column name. In the below code sample, we're putting the customerName column into an ascending order:

You can put data values into a descending order, too. You'll have to specify "DESCENDING" here:

In this case, data values in the customerName column are returned in a reverse order. You may need to order your data values based on multiple columns. To do that, specify the Order classes in a list:

To filter and order the results at the same time, do the following:

Related pages