Data Management

JBStrap is designed to support data intensive applications. Data values are usually stored in an SQL physical data source. However, JBStrap's approach is that you can store data values anywhere, for instance, in non-SQL physical data sources, in ElasticSearch, files or you can access them from REST APIs.

JBStrap offers two approaches:

a) a conventional, DAO-based approach: this approach ensures simple data handling. For write/read operations, you have to call the DAO API corresponding to the data source.

b) DataDescriptor solution: a more advanced solution and also easier for programmers to use it. Besides data handling, it also offers an easy way of visualizing data.

In this chapter, we discuss the DAO-based approach in details. If you are interested in the DataDescriptor solution, read more here .

JPA DAO, ElasticSearch DAO, LDAP DAO. Additionally, you can create a custom DAO.

To access physical data, you need a DAO layer that corresponds to the physical data source. The DAO layer communicates with the data connection and can execute data CRUD read/write operations. The DAO implements the program logic behind data read/write/delete operations for the physical data source. If you want to use a custom physical data source, you can implement it by writing your custom DAO.

Physical data sources store data values in different data structures. In case of an SQL physical data source, these structures are data tables. In case of an ElasticSearch, these structures are ElasticSearch indexes. In JBStrap, you have to use entity classes to describe the columns and keys of physical data structures.

The DAO API implements the program logic for write/read/delete operations for other application layers. You can call DAO API methods in you application's program logic. Data values are transmitted in DataRecords and lists of DataRecords. Between the program logic and DAO, data records are transmitted in both directions. A DataRecord is a JBStrap class that describes a data record and contains its data values. You can access a DataRecord in the following way:

Criteria and Order are JBStrap classes that help you organize your search results. Use the Criteria to specify filter criteria. The Order class enables you to set an order for your results. The DAO interprets search Criteria and Order for the corresponding physical data source and sends a request to the physical data connection. Read more on DataRecord, Criteria and Order .

Writing data to the physical data source

To save a record to the physical data source, you simply need to call the method. Data records are a generic data structure in JBStrap, so you need to specify the entity class (data class). Entity classes are associated with physical data structures in your physical data source. This is how the DAO "knows" where exactly to save a data record. Once the data record is saved to the physical data source, the DAO API returns the saved data record to the program logic. If there are trigger-calculated fields, then the resulting new values are returned to the program logic when saving the data record.

To save a data record to the physical data source using JPA DAO, use the following code:

The below sample code shows how to implement a proper save method call in the ElasticSearch API:

Reading data from the physical data source

To read data from the physical data source, we can specify a entity class name and optionally also a DataRecord and Criteria. These three parameters are passed to the DAOAPI.fetch() method. This method of the DAO API forwards the fetch request to the physical data source. The DAO API returns a list of records corresponding to the specified criteria.

To find a list of records using JPA DAO, use the following code:

Let's see how to properly implement a find method call in the ElasticSearch API: