activiti学习笔记(四)managementService

managementService

  • Job任务管理
  • 数据库相关通用操作
  • 执行流程引擎命令(Command)

Job任务查询

activiti学习笔记(四)managementService_第1张图片
Job任务查询

从上述表可以看出主要还是Job相关的查询。

数据库相关操作

  • 查询表结构元数据(TableMetaData)
  • 通用表查询(TablePageQuery)
  • 执行自定义的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> rowsList = tablePage.getRows();
for (Map 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> findAll();
}

接口的方法定义中添加select注解来实现自定义sql语句。
然后配置下流程配置文件:


        
        
        
        
        
        
            
                com.activiti.MyCustomMapper
            
        
    

最后后台代码调用这个自定义接口:

List> mapList = managementService
                .executeCustomSql(
                        new AbstractCustomSqlExecution>>(MyCustomMapper.class){
public List> execute(MyCustomMapper myCustomMapper) {
        return myCustomMapper.findAll();
}
});
for(Map map: mapList){
     logger.info("map={}",map);
 }

结果正常输出act_ru_task表的数据。

下面接着看managementService执行自定义命令:

ProcessEngineConfiguration cfg = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
ProcessEngine processEngine = cfg.buildProcessEngine();
ManagementService managementService = processEngine.getManagementService();
managementService.executeCommand(new Command() {
   public Object execute(CommandContext commandContext) {
       // 自定义命令实现
       return null;
   }
});

你可能感兴趣的:(activiti学习笔记(四)managementService)