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 (http://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 ComponentManager
, as follows:
OfBizDelegator delegator = ComponentAccessor.getComponent(OfBizDelegator.class);
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...