Accessing database entities from plugins
We have seen how various entities in the JIRA database are defined and how we can introduce new entities. In this recipe, we will see how we can read and write data from the database using these entity definitions.
How to do it...
JIRA exposes the OfBizDelegator (https://docs.atlassian.com/jira/latest/com/atlassian/jira/ofbiz/OfBizDelegator.html) component, which is a wrapper around org.ofbiz.core.entity.DelegatorInterface, to communicate with its database using the Ofbiz layer.
You can get hold of an instance of OfBizDelegator by injecting it in the constructor or from ComponentAccessor, as follows:
OfBizDelegator delegator = ComponentAccessor.getOfBizDelegator();
Reading from a database
We can read from the database using the various methods exposed via the previous delegator class. For example, all the records in the Employee table we defined in the previous recipe can be read as:
List<GenericValue> employees = delegator.findAll("Employee...