managementService
- Job任務管理
- 數據庫相關通用操作
- 執(zhí)行流程引擎命令(Command)
Job任務查詢

Job任務查詢
從上述表可以看出主要還是Job相關的查詢。
數據庫相關操作
- 查詢表結構元數據(TableMetaData)
- 通用表查詢(TablePageQuery)
- 執(zhí)行自定義的sql查詢(executeCustomSql)
示例
ProcessEngineConfiguration cfg = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
ProcessEngine processEngine = cfg.buildProcessEngine();
ManagementService managementService = processEngine.getManagementService();
// 獲取指定表的數據
TablePage tablePage = managementService.createTablePageQuery()
.tableName(managementService.getTableName(ProcessDefinitionEntity.class))
.listPage(0,100);
List<Map<String,Object>> rowsList = tablePage.getRows();
for (Map<String,Object> row : rowsList){
logger.info("row={}",row);
}
上述示例中通過調用tableName方法來指定要查詢的表,除了直接傳入表名如"act_ru_task"這種形式外,還可以使用上述managementService.getTableName(ProcessDefinitionEntity.class)方法通過實體類來獲取表名。
接下來再看下如何自定義查詢方法:
首先修改配置文件如下:
public interface MyCustomMapper {
@Select("select * from act_ru_task")
public List<Map<String,Object>> findAll();
}
接口的方法定義中添加select注解來實現(xiàn)自定義sql語句。
然后配置下流程配置文件:
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/db_activiti" />
<property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
<property name="jdbcUsername" value="root" />
<property name="jdbcPassword" value="abc123" />
<property name="databaseSchemaUpdate" value="true" />
<property name="customMybatisMappers">
<set>
<value>com.activiti.MyCustomMapper</value>
</set>
</property>
</bean>
最后后臺代碼調用這個自定義接口:
List<Map<String, Object>> mapList = managementService
.executeCustomSql(
new AbstractCustomSqlExecution<MyCustomMapper,List<Map<String,Object>>>(MyCustomMapper.class){
public List<Map<String, Object>> execute(MyCustomMapper myCustomMapper) {
return myCustomMapper.findAll();
}
});
for(Map<String,Object> map: mapList){
logger.info("map={}",map);
}
結果正常輸出act_ru_task表的數據。
下面接著看managementService執(zhí)行自定義命令:
ProcessEngineConfiguration cfg = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
ProcessEngine processEngine = cfg.buildProcessEngine();
ManagementService managementService = processEngine.getManagementService();
managementService.executeCommand(new Command() {
public Object execute(CommandContext commandContext) {
// 自定義命令實現(xiàn)
return null;
}
});