JBStrap JPA DAO
In JBStrap, the lowest level of data handling takes place when database data is handled via source code. However, the framework provides higher levels which take this task over from the developer, and automatize data handling. The JPA DAO API offers a simple approach to JPA-based data handling.
JPA DAO API implements all sorts of data handling processes. Every process is compatible with the previously discussed DataRecord and Criteria classes. Query operations can receive the Criteria, and they will return with a DataRecord or a List<DataRecord>. If any error is encountered, developers must implement a handler for it. The JPA DAO is also capable of using DataDescriptor s which means that data structures and data access rights can be easily parameterized. To read more about the JBStrap DataDescriptor, click here .
Databases are made accessible using the JPA layer. The database access can be set in the persistence.xml file, and this is where entities must be listed. The framework uses the EclipseLink 2.6.2. JPA implementation . Please refer to the documentation to see how to create the entities you wish to work with.
Fetch
This functionality is used most often by JPA DAO API to fetch data from the database. This can be done by fetching all data from an entity, or you can use a filter criteria as well as look for something specific using its unique entity ID. The returned data can be further organized. You can specify if you want the full data set or just a part of it.
You can start a fetch based on an entity or DataDescriptor. If a Client object is passed to the fetch method, you can perform this while taking user access rights into account. This means that if the current user has no read rights to the data, the fetch will be unsuccessful, and it will return with an error.
General fetches (through an entity):
General fetches (through a DataDescriptor ):
Fetching using the unique ID:
Counting rows in a data source:
Save
A DataRecord in the memory can be saved to the database by using the JPA DAO API layer. If the primary key is present in the DataRecord and a DataRecord exists also in the database, the existing one will be overwritten with the one being saved. If no primary key value exists in the data record to be saved or the specified value does not exist in the database, a new value will be committed to the database.
If the save operation results in an error, data in the database will be left unchanged and an error message appears. You can also implement access control for a save operation. If a user has no access rights to write the data, the save operation will return with an error and data will be left unchanged.
Remove
JPA DAO API allows you to delete a record from a database. The prerequisite for this is that the data record must have a unique ID. Except for the unique ID, the API does not use any other values from the data record. Therefore, it is sufficient to use the unique ID to reference the record.
You can even use the API to delete a record. If an exception is thrown during the delete operation, the record will not be deleted. It remains unchanged in the database and an error message appears.