Adding custom find method for Comments

Hi,

In our application, we need to fetch all the comments related to a process/processes. These need to be further filtered by date range and user. In TaskService, we have found following methods for it -
@Override
public List getProcessInstanceComments(String processInstanceId) {
return commandExecutor.execute(new GetProcessInstanceCommentsCmd(processInstanceId));
}

@Override
public List<Comment> getProcessInstanceComments(String processInstanceId, String type) {
    return commandExecutor.execute(new GetProcessInstanceCommentsCmd(processInstanceId, type));
}

None of these serve our purpose. Digging deeper we found following method in MyBatisCommentDataManager -

@Override
@SuppressWarnings("unchecked")
public List<Comment> findCommentsByProcessInstanceId(String processInstanceId, String type) {
    Map<String, Object> params = new HashMap<>();
    params.put("processInstanceId", processInstanceId);
    params.put("type", type);
    return getDbSqlSession().selectListWithRawParameter("selectCommentsByProcessInstanceIdAndType", params);
}

Where is this list maintained and can we add our custom statements to it?
Something on the line of-
selectCommentsByProcessInstanceIdAndTypeAndtimeAndUserId where timestamp is greater/lesser than certain value and userId is equal to some username string.

Regards,

The easiest would be to use a custom query, see http://www.flowable.org/docs/userguide/index.html#advanced.custom.sql.queries

1 Like

Thanks @joram

I ended up using a similar approach on Spring JPA side using nativeSqlQuery method provided by it. I tried using JPQL too but I believe the entities in flowable aren’t JPA’s entities, so it wasn’t recognizing it. My only concern is the dependency of the code on the hardcoded table and column names (in case the underlying table/columns changes). I hope these (column names/table names) are automatically generated by the ORM being used by flowable and won’t change in future unless the entity changes.

Regards,

Correct, they are not jpa entities (MyBatis is used).

Generally, table or column names don’t change, unless there is a serious bug related to it. But that is the very rare exception.