Activiti表結構
- ACT_GE_* 通用資料表
- ACT_RE_* 流程定義存儲表
- ACT_ID_* 身份資訊表
- ACT_RU_* 運作時資料庫表
- ACT_HI_* 曆史資料表
表結構目錄
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsICM38FdsYkRGZkRG9lcvx2bjxiNx8VZ6l2cs0TTXVmZ5cVWv50MMBjVtJWd0ckW65UbM5WOHJWa5kHT20ESjBjUIF2X0hXZ0xCMx81dvRWYoNHLrdEZwZ1Rh5WNXp1bwNjW1ZUba9VZwlHdssmch1mclRXY39CXldWYtlWPzNXZj9mcw1ycz9WL49zZuBnLwYTMzMTM0cTM1ADNwAjMwIzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
通用資料表
資料表分類 | 描述 |
ACT_GE_PROPERTY | 屬性表(儲存流程引擎的KV鍵值屬性) |
ACT_GE_BYTEARRAY | 資源表(存儲流程定義相關的資源) |
實際具體運用
檢視資料庫中的所有表\删除表結構
public class DbConfigTest {
private static final Logger LOGGER = LoggerFactory.getLogger(DbConfigTest.class);
@Test
public void testDbConfig(){
ProcessEngine processEngine = ProcessEngineConfiguration
.createProcessEngineConfigurationFromResource("activiti-mysql.cfg.xml").buildProcessEngine();
ManagementService managementService = processEngine.getManagementService();
Map<String, Long> tableCount = managementService.getTableCount();//擷取表的資料量
ArrayList<String> tableNames = Lists.newArrayList(tableCount.keySet());
Collections.sort(tableNames);
for(String tableName : tableNames){
LOGGER.info("table = {}", tableName);
}
LOGGER.info("tableNames.size = {}", tableNames.size());
}
@Test
public void dropTable(){
ProcessEngine processEngine = ProcessEngineConfiguration
.createProcessEngineConfigurationFromResource("activiti-mysql.cfg.xml").buildProcessEngine();
ManagementService managementService = processEngine.getManagementService();
managementService.executeCommand(new Command<Object>(){
@Override
public Object execute(CommandContext commandContext) {
commandContext.getDbSqlSession().dbSchemaDrop();
LOGGER.info("删除表結構");
return null;
}
});
}
}
activiti-mysql.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=utf-8&useSSL=false"/>
<property name="jdbcDriver" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUsername" value="root"/>
<property name="jdbcPassword" value="123456"/>
<property name="databaseSchemaUpdate" value="true"/><!– create-drop指明資料庫必須是空的 –>
<property name="dbHistoryUsed" value="false"/>
<property name="dbIdentityUsed" value="false"/>
</bean>-->
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
<property name="dataSource" ref="dataSource"/>
<property name="databaseSchemaUpdate" value="true"/>
<property name="dbHistoryUsed" value="false"/>
<property name="dbIdentityUsed" value="false"/>
</bean>
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/activiti6unit?useUnicode=true&characterEncoding=utf-8&useSSL=false"/>
<property name="username" value="root"/>
<property name="password" value="123456"/>
<property name="initialSize" value="1"/>
<property name="maxActive" value="20"/>
<property name="filters" value="stat,slf4j"/>
</bean>
</beans>
通過原生的底層的ByteArrayEntity寫入資料庫
public class DbGeTest {
@Rule
public ActivitiRule activitiRule = new ActivitiRule("activiti-mysql.cfg.xml");
@Test
public void testByeArray(){
activitiRule.getRepositoryService().createDeployment()
.name("測試部署")
.addClasspathResource("my-process.bpmn20.xml")
.deploy();
}
//通過原生的底層的ByteArrayEntity寫入資料庫
@Test
public void testByteArrayInsert(){
ManagementService managementService = activitiRule.getManagementService();
Object o = managementService.executeCommand(new Command<Object>() {
@Override
public Object execute(CommandContext commandContext) {
ByteArrayEntityImpl entity = new ByteArrayEntityImpl();
entity.setName("test");
entity.setBytes("test message".getBytes());
commandContext.getByteArrayEntityManager().insert(entity);
return null;
}
});
}
}
流程定義存儲表
流程部署表具體字段
流程定義表具體字段
流程定義存儲表具體運用
public class DbRepositoryTest {
@Rule
public ActivitiRule activitiRule = new ActivitiRule("activiti-mysql.cfg.xml");
@Test
public void testDeploy(){
activitiRule.getRepositoryService().createDeployment()
.name("二級審批流程")
.addClasspathResource("second_approve.bpmn20.xml")
.deploy();
}
@Test
public void testSuspend(){
RepositoryService repositoryService = activitiRule.getRepositoryService();
repositoryService.suspendProcessDefinitionById("second_approve:2:10004");
boolean processDefinitionSuspended = repositoryService.isProcessDefinitionSuspended("second_approve:2:10004");
LOGGER.info("流程挂起:{}",processDefinitionSuspended);
}
}
身份資料表
使用者擴充資訊表ACT_ID_INFO具體字段
設計使用者資訊,組資訊,使用者組關系等運用
@Test
public void testIdentity(){
IdentityService identityService = activitiRule.getIdentityService();
User user1 = identityService.newUser("user1");
user1.setFirstName("zhang");
user1.setLastName("san");
user1.setEmail("[email protected]");
user1.setPassword("pwd");
identityService.saveUser(user1);
Group group1 = identityService.newGroup("group1");
group1.setName("for test");
identityService.saveGroup(group1);
User user2 = identityService.newUser("user2");
identityService.saveUser(user2);
identityService.createMembership(user1.getId(),group1.getId());
identityService.createMembership(user2.getId(),group1.getId());
identityService.setUserInfo(user1.getId(),"age","18");
identityService.setUserInfo(user1.getId(),"address","hangzhou");
LOGGER.info("建立使用者表成功");
}
運作時流程資料表
ACT_RU_EXECUTION流程執行個體執行表具體字段
ACT_RU_TASK使用者任務表具體字段
變量資訊表ACT_RU_VARIABLE(VariableInstanceEntityImpl)具體字段
參與者資訊表ACT_RU_IdentityLink(IdentityLinkEntityImpl)具體字段
事件訂閱表ACT_RU_EVENT_SUBSCR(EventSubscriptionEntityImpl)具體字段
測試
@Test
public void testRuntime(){
activitiRule.getRepositoryService().createDeployment()
.name("二次審批流程")
.addClasspathResource("second_approve.bpmn20.xml")
.deploy();
Map<String,Object>variables=Maps.newHashMap();
variables.put("key1","value1");
activitiRule.getRuntimeService().startProcessInstanceByKey("second_approve",variables);
}
備注:涉及到三張表:流程執行個體執行表,使用者任務表,變量表
曆史流程資料表
測試
@Test
public void testHistory(){
activitiRule.getRepositoryService().createDeployment()
.name("測試部署")
.addClasspathResource("com/syc/activiti/my-process.bpmn20.xml")
.deploy();
RuntimeService runtimeService = activitiRule.getRuntimeService();
Map<String, Object> variables = Maps.newHashMap();
variables.put("key0", "value0");
variables.put("key1", "value1");
variables.put("key2", "value2");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process", variables);
runtimeService.setVariable(processInstance.getId(),"key1","value1_1");
TaskService taskService = activitiRule.getTaskService();
Task task = taskService.createTaskQuery()
.processDefinitionId(processInstance.getId())
.singleResult();
//taskService.setOwner(task.getId(),"user1");
/*taskService.createAttachment("url",
task.getId(),processInstance.getId(),
"name","desc",
"/url/test.png");*/
/* taskService.addComment(task.getId(),task.getProcessInstanceId(),"record note1");
taskService.addComment(task.getId(),task.getProcessInstanceId(),"record note2");*/
Map<String, String> properties = Maps.newHashMap();
properties.put("key2","value2_1");
properties.put("key3","value3_1");
//activitiRule.getFormService().submitTaskFormData(task.getId(),properties);
}