数据库模型设计
数据库建表语句
Mysql建表语句
- 核心引擎 activiti.mysql.create.engine.sql (必选)
- 历史数据 activiti.mysql.create.engine.sql (可选)
- 身份信息 activit.mysql.create.identity.sql(可选)
Mysql删除语句
- 核心引擎 activiti.mysql.drop.engine.sql
- 历史数据 activiti.mysql.drop.history.sql
- 身份信息 activiti.mysql.drop.identity.sql
通用数据库
-
查看数据库基本信息
-
java 代码
private static final Logger LOGGER = LoggerFactory.getLogger(DbConfigTests.class); @Test public void testDbConfig() { ProcessEngineConfiguration resourceDefault = ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault(); ProcessEngine processEngine = resourceDefault.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("tableName = {}", tableName); } LOGGER.info("tableName.size() = {}", tableNames.size()); } -
控制台输出结果为
-
-
删除表结构java代码
@Test public void dropTable() { ProcessEngineConfiguration configuration = ProcessEngineConfiguration .createProcessEngineConfigurationFromResource("activiti-mysql.cfg.xml"); ProcessEngine processEngine = configuration.buildProcessEngine(); ManagementService managementService = processEngine.getManagementService(); Object executeCommand = managementService.executeCommand((CommandContext commandContext) -> { commandContext.getDbSqlSession().dbSchemaDrop(); LOGGER.info("删除表结构"); return null; }); } -
测试部署java代码
public class DbGeTest { @Rule public ActivitiRule activitiRule = new ActivitiRule("activiti-mysql.cfg.xml"); @Test public void testByteArray() { activitiRule.getRepositoryService().createDeployment() .name("测试部署") .addClasspathResource("my-process.bpmn20.xml") .deploy(); } @Test public void testByteArrayInsert() { ManagementService managementService = activitiRule.getManagementService(); managementService.executeCommand((CommandContext commandContext) -> { ByteArrayEntityImpl byteArrayEntity = new ByteArrayEntityImpl(); byteArrayEntity.setName("test"); byteArrayEntity.setBytes("test message".getBytes()); commandContext.getByteArrayEntityManager().insert(byteArrayEntity); return null; }); } }
流程定义存储表
ACT_RE_DEPLOYMENT【DeploymentEntityImpl】
ACT_RE_PROCDEF【ProcessDefinitionEntityImpl】
- 数据库表里面的信息如下
- 部署文件资源代码
@Test
public void testDepoly() {
activitiRule.getRepositoryService()
.createDeployment()
.name("二次审批流程")
.addClasspathResource("second_approve.bpmn20.xml")
.deploy();
}
- 挂起代码如下
@Test
public void testSuspend() {
RepositoryService repositoryService = activitiRule.getRepositoryService();
repositoryService.suspendProcessDefinitionById("second_approve:2:7504");
boolean suspended = repositoryService
.isProcessDefinitionSuspended("second_approve:2:7504");
LOGGER.info("suspended = {}", suspended);
}
-
结果如下
身份数据表设计
身份数据表(identity)
ACT_ID_USER(UserEntityImpl)
ACT_ID_INFO(IdentityInfoEntityImpl)
ACT_ID_GROUP(GroupEntityImpl)
ACT_ID_MEMBERSHIP(MemberShipEntityImpl)
创建用户信息表
- Java代码
public class DbIdentityTest {
@Rule
public ActivitiRule activitiRule = new ActivitiRule("activiti-mysql.cfg.xml");
@Test
public void testIdentity() {
IdentityService identityService = activitiRule.getIdentityService();
User user1 = identityService.newUser("user1");
user1.setFirstName("firstName");
user1.setLastName("lastName");
user1.setEmail("1233@qq.com");
user1.setPassword("pwd");
identityService.saveUser(user1);
User user2 = identityService.newUser("user2");
identityService.saveUser(user2);
Group group1 = identityService.newGroup("group1");
group1.setName("for test");
identityService.saveGroup(group1);
identityService.createMembership(user1.getId(), group1.getId());
identityService.createMembership(user2.getId(), group1.getId());
identityService.setUserInfo(user1.getId(),"age","18");
identityService.setUserInfo(user1.getId(),"address","Bejing");
}
- 执行结果为
运行时流程数据表
数据表分类
ACT_ID_EXECUTUION(ExecutionEntityImpl)
ACT_ID_TASK(TaskEntityImpl)
ACT_RU_VARIABLE(VariableInstanceEntityImpl)
ACT_RU_IDENITYLINK(IdentityLinkedEntityImpl)
ACT_RU_EVENT_SUBSCR(EventSubscriptionEntityImpl)
ACT_RU_JOB(JobEntityImpl)
-
Java执行代码
public class DbRepostitoryTests { private static final Logger LOGGER = LoggerFactory.getLogger(DbRepostitoryTests.class); @Rule public ActivitiRule activitiRule = new ActivitiRule("activiti-mysql.cfg.xml"); @Test public void testDepoly() { activitiRule.getRepositoryService() .createDeployment() .name("二次审批流程") .addClasspathResource("second_approve.bpmn20.xml") .deploy(); } @Test public void testSuspend() { RepositoryService repositoryService = activitiRule.getRepositoryService(); repositoryService.suspendProcessDefinitionById("second_approve:2:7504"); boolean suspended = repositoryService .isProcessDefinitionSuspended("second_approve:2:7504"); LOGGER.info("suspended = {}", suspended); } }
private static final Logger LOGGER = LoggerFactory.getLogger(DbRunTimeTests.class);
@Rule
public ActivitiRule activitiRule = new ActivitiRule("activiti-mysql.cfg.xml");
@Test
public void testDepoly() {
activitiRule.getRepositoryService()
.createDeployment()
.name("二次审批流程")
.addClasspathResource("second_approve.bpmn20.xml")
.deploy();
Map<String, Object> variables = Maps.newHashMap();
variables.put("key1", "values1");
ProcessInstance processInstance = activitiRule.getRuntimeService()
.startProcessInstanceByKey("second_approve", variables);
}
@Test
public void testSetOwner() {
TaskService taskService = activitiRule.getTaskService();
Task task = taskService.createTaskQuery().processDefinitionKey("second_approve")
.singleResult();
taskService.setOwner(task.getId(), "user1");
}
@Test
public void testMessage() {
Deployment deployment = activitiRule.getRepositoryService()
.createDeployment().addClasspathResource("my-process-message.bpmn20.xml")
.deploy();
}
@Test
public void testMessageReceived() throws InterruptedException {
Deployment deployment = activitiRule.getRepositoryService()
.createDeployment().addClasspathResource("my-process-message-received.bpmn20.xml")
.deploy();
ProcessInstance processInstance = activitiRule.getRuntimeService()
.startProcessInstanceByKey("my-process");
Thread.sleep(1000 * 30L);
}