表结构介绍
Activiti的表都以ACT_
开头,第二部分是表示表的用途的两个字母标识。用途也和服务的 API 对应。
-
ACT_RE:RE表示repository。 这个前缀的表包含了流程定义和流程静态资源(图片、规则等)。
-
ACT_RU:RU表示runtime。 这些运行时的表,包含流程实例,任务,变量,异步任务,等运行中的数据。 Activiti只在流程实例执行过程中保存这些数据,在流程结束时就会删除这些记录。这样运行时表可以一直很小速度很快。
-
ACT_HI:HI表示history。这些表包含历史数据,比如历史流程实例,变量,任务等。
-
ACT_GE:GE表示general。通用数据,用于不同场景下 。
表分类 | 表名 | 解释 |
---|---|---|
一般数据 | act_ge_bytearray | 通用的流程定义和流程资源 |
act_ge_property | 系统相关属性 | |
流程历史记录 | act_hi_actinst | 历史的流程实例 |
act_hi_attachment | 历史的流程附件 | |
act_hi_comment | 历史的说明性信息 | |
act_hi_detail | 历史的流程运行中的细节信息 | |
act_hi_identitylink | 历史的流程运行过程中用户关系 | |
act_hi_procinst | 历史的流程实例 | |
act_hi_taskinst | 历史的任务实例 | |
act_hi_varinst | 历史的流程运行中的变量信息 | |
流程定义 | act_re_deployment | 部署单元信息 |
act_re_model | 模型信息 | |
act_re_procdef | 已部署的流程定义 | |
运行实例 | act_ru_event_subscr | 运行时事件 |
act_ru_execution | 运行时流程执行实例 | |
act_ru_identitylink | 运行时用户关系信息,存储任务节点与参与者相关信息 | |
act_ru_job | 运行时作业 | |
act_ru_task | 运行时任务 | |
act_ru_variable | 运行时变量表 |
Activiti类关系
类关系图
在新版本中,IdentityService,FormService这两个Serivce都已经删除了。
流程引擎的配置类
activiti.cfg.xml:Activiti的引擎配置文件。包括ProcessEngineConfiguration的定义、数据源定义、事务管理器等,此文件其实就是一个Spring配置文件。
流程引擎的配置类(ProcessEngineConfiguration):通过ProcessEngineConfiguration可以创建工作流引擎ProceccEngine,常用的两种方法如下:
1、StandaloneProcessEngineConfiguration
-
使用StandaloneProcessEngineConfigurationActiviti可以单独运行,来创建ProcessEngine,Activiti会自己处理事务。
-
配置文件方式:通常在activiti.cfg.xml配置文件中定义一个id为 processEngineConfiguration的bean。
2、SpringProcessEngineConfiguration
-
通过org.activiti.spring.SpringProcessEngineConfiguration与Spring整合。
-
创建Spring与Activiti的整合配置文件:activity-spring.cfg.xml(名称可修改)
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd ">
<!-- 工作流引擎配置bean -->
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<!-- 数据源 -->
<property name="dataSource" ref="dataSource" />
<!-- 使用spring事务管理器 -->
<property name="transactionManager" ref="transactionManager" />
<!-- 数据库策略 -->
<property name="databaseSchemaUpdate" value="drop-create" />
<!-- activiti的定时任务关闭 -->
<property name="jobExecutorActivate" value="false" />
</bean>
<!-- 流程引擎 -->
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>
<!-- 资源服务service -->
<bean id="repositoryService" factory-bean="processEngine"
factory-method="getRepositoryService" />
<!-- 流程运行service -->
<bean id="runtimeService" factory-bean="processEngine"
factory-method="getRuntimeService" />
<!-- 任务管理service -->
<bean id="taskService" factory-bean="processEngine"
factory-method="getTaskService" />
<!-- 历史管理service -->
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
<!-- 用户管理service -->
<bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />
<!-- 引擎管理service -->
<bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
<!-- 数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/activiti" />
<property name="username" value="root" />
<property name="password" value="root123" />
<property name="maxActive" value="3" />
<property name="maxIdle" value="1" />
</bean>
<!-- 事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes></tx:attributes>
<!-- 传播行为 -->
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="find*" propagation="SUPPORTS" read-only="true" />
<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 切面,根据具体项目修改切点配置 -->
<aop:config proxy-target-class="true">
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.itheima.ihrm.service.impl.*.(..))"* />
</aop:config>
</beans>
创建processEngineConfiguration
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml")
上边的代码要求activiti.cfg.xml中必须有一个processEngineConfiguration的bean。也可以使用下边的方法,可以更改bean的名字。
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(String resource, String beanName);
如:
ProcessEngineConfiguration configuration2 = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml","processEngineConfiguration");
工作流引擎创建
工作流引擎(ProcessEngine),相当于一个门面接口,通过ProcessEngineConfiguration创建processEngine,通过ProcessEngine创建各个service接口。
1、默认创建方式:将activiti.cfg.xml文件名及路径固定,且activiti.cfg.xml文件中有 processEngineConfiguration的配置。
// 直接使用工具类 ProcessEngines,使用classpath下的activiti.cfg.xml中的配置创建processEngine
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
2、一般创建方式
// 先构建ProcessEngineConfiguration
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
// 通过ProcessEngineConfiguration创建ProcessEngine,此时会创建数据库
ProcessEngine processEngine = configuration.buildProcessEngine();
Servcie服务接口
Service是工作流引擎提供用于进行工作流部署、执行、管理的服务接口,我们使用这些接口可以操作服务对应的数据表。
Service创建方式
通过ProcessEngine创建Service。
RuntimeService runtimeService = processEngine.getRuntimeService();
RepositoryService repositoryService = processEngine.getRepositoryService();
TaskService taskService = processEngine.getTaskService();
Service总览
Service名称 | Service作用 |
---|---|
RepositoryService | Activiti的资源管理类 |
RuntimeService | Activiti的流程运行管理类 |
TaskService | Activiti的任务管理类 |
HistoryService | Activiti的历史管理类 |
ManagerService | Activiti的引擎管理类 |
1、RepositoryService
Activiti的资源管理类,提供了管理和控制流程发布包和流程定义的操作。使用工作流建模工具设计的业务流程图需要使用此Service将流程定义文件的内容部署到计算机。
除了部署流程定义以外还可以查询引擎中的发布包和流程定义。
暂停或激活发布包,对应全部和特定流程定义。 暂停意味着它们不能再执行任何操作了,激活是对应的反向操作。获得多种资源,像是包含在发布包里的文件, 或引擎自动生成的流程图。
获得流程定义的pojo版本, 可以用来通过Java解析流程,而不必通过xml。
2、RuntimeService:Activiti的流程运行管理类。可以从这个服务类中获取很多关于流程执行相关的信息
3、TaskService:Activiti的任务管理类。可以从这个类中获取任务的信息。
4、HistoryService:Activiti的历史管理类,可以查询历史信息,执行流程时,引擎会保存很多数据(根据配置),比如流程实例启动时间,任务的参与者, 完成任务的时间,每个流程实例的执行路径,等等。 这个服务主要通过查询功能来获得这些数据。
5、ManagementService:Activiti的引擎管理类,提供了对Activiti流程引擎的管理和维护功能,这些功能不在工作流驱动的应用程序中使用,主要用于Activiti系统的日常维护。
评论区