How To Use A JBStrap DataDescriptor
Upon start-up, all files with the extension .ds.xml are loaded from the file path specified in the DATADESCRIPTOR_DIR
parameter and DataDescriptors are automatically created.
Note: The DATADESCRIPTOR_DIR
parameter is the one that stores the file path for all DataDescriptor descriptor files.
You can access the DataDescriptors in any part of the source code or you can register a new DataDescriptor . Use a DataDescriptor for queries, data modification or you can just pass it to a data handling component which in turn automatically handles the DataDescriptor and contained data. Data handling components will be automatically built and set using DataDescriptor s .
Fetch
You can query data from the database using two different methods. A synchronous query means source code execution will wait until the queried data is loaded. An asynchronous query, on the other hand, means program execution will not be interrupted due to data loading and a callback method is used to handle data or exceptions.
Synchronous query using a DataDescriptor :
If you use an asynchronous query to get data from the DataDescriptor , you always have to implement the DataDescriptorCallback
interface. The interface requires the implementation of two methods: onSuccess()
gets the query result in a parameter. The method is called upon successful query execution. The method onError()
gets the exception encountered during query execution. The method is called only if an exception has been thrown during the query.
Asynchronous query using a DataDescriptor :
Getting all records from a DataDescriptor using an asynchronous query where the valid
column has a Y :
Save
Not only can DataDescriptors query data, but records can be saved to a DataDescriptor . The save process can also be performed synchronously and asynchronously. Multiple records can be saved to a DataDescriptor at the same time and DataDescriptors support transaction management.
If the save is done asynchronously, saved records will be retrieved by the onSuccess()
backend if the backup is successful. If an error occurs during save, the onError()
method will be called to handle the error.
Remove
You can also delete records from a DataDescriptor , which can also be done synchronously and asynchronously. It is also possible to delete multiple records from a DataDescriptor at the same time, and DataDescriptors can handle transactions even if they are deleted.
If deletion is performed asynchronously, the deleted records will be retrieved by the onSuccess()
method in case of a successful deletion. If an error occurs during deletion, the onError()
method will be called to handle the error.