【Activiti系列学习】--20.Activiti表结构设计

Activiti表结构

  • ACT_GE_* 通用数据表
  • ACT_RE_* 流程定义存储表
  • ACT_ID_* 身份信息表
  • ACT_RU_* 运行时数据库表
  • ACT_HI_* 历史数据表

表结构目录

通用数据表

数据表分类描述
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&amp;characterEncoding=utf-8&amp;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"/>&lt;!&ndash; create-drop指明数据库必须是空的 &ndash;&gt;
    <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&amp;characterEncoding=utf-8&amp;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("123456789@qq.com");
        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);
    }
 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值