Query Active Objects for statistical data or how to escape Active Object restrictions

When using Active Objects in a Jira plugin you have a limited amount of operations you can execute against the database. For example the count(*) - methods only allow to return the result of the first row. More or less the Active Objects API is restricted to entity-specific methods.

Example: Having a table named ‘votes’ with the field ‘weekday’ how could I query for the number of entries like this:

select count(*) from votes group by weekday;

Using Active Objects the following code just brings up the first result as the method only returns an ‘int’ value:

activeObjects.count(Vote.class, Query.select().group("weekday"));

What is the right way to perform such type of database queries in a Jira plugin?

2 Likes

Apparently we’re supposed to be using QueryDSL. The source code for Jira Service Desk shows it’s usage pretty plainly. I’m still figuring it out.

1 Like

Atlassian’s Pocketknife QueryDSL module abstracts the ActiveObjects “features” and helps a lot. We are using AO only to manage the database schema (table creation, migrations), everything else is done with QueryDSL.

You can find the Pocketknife source code here: atlassian-pocketknife-querydsl
The examples should be enough to get started :slight_smile:

1 Like