Is it somehow possible to extend processInstanceQueries with custom SQL code? I would use this for a custom where-condition.
Hi Timo!
You can make use of NativeQueries. They allow you to directly use SQL:
runtimeService.createNativeProcessInstanceQuery().sql("SELECT * FROM " + managementService.getTableName(ProcessInstance.class) WHERE <<YOUR CUSTOM WHERE HERE>>).list()
An example can be found here:
@Test
public void testNativeQuery() {
// just test that the query will be constructed and executed, details
// are tested in the TaskQueryTest
assertEquals("ACT_RU_EXECUTION", managementService.getTableName(ProcessInstance.class, false));
long piCount = runtimeService.createProcessInstanceQuery().count();
// There are 2 executions for each process instance
assertEquals(piCount * 2, runtimeService.createNativeProcessInstanceQuery().sql("SELECT * FROM " + managementService.getTableName(ProcessInstance.class)).list().size());
assertEquals(piCount * 2, runtimeService.createNativeProcessInstanceQuery().sql("SELECT count(*) FROM " + managementService.getTableName(ProcessInstance.class)).count());
}
/**
* Test confirming fix for ACT-1731
*/
@Test
@Deployment(resources = { "org/flowable/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testIncludeBinaryVariables() throws Exception {
// Start process with a binary variable
Alternatively, you can execute your own custom SQL by creating a MyBatis mapper. See here for details: https://www.flowable.org/docs/userguide/index.html#advanced.custom.sql.queries
Hope it helped!