以下是流程部署的实现过程,看了一天源码了解了activiti源码是如何实现的,包括数据数据,了解activiti的架构
//根据bpmn文件部署流程
Deployment deployment = repositoryService.createDeployment().addClasspathResource("diagrams/demo2.bpmn").deploy();
调用顺序
//RepositoryServiceImpl类的方法
public Deployment deploy(DeploymentBuilderImpl deploymentBuilder) {
return (Deployment)this.commandExecutor.execute(new DeployCmd(deploymentBuilder));
}
//CommandExecutorImpl类的方法
public <T> T execute(Command<T> command) {
return this.execute(this.defaultConfig, command);
}
public <T> T execute(CommandConfig config, Command<T> command) {
return this.first.execute(config, command);
}
这里的命令执行器CommandExecutorImpl属性first是接口CommandInterceptor,执行顺序是LogInterceptor、SpringTransactionInterceptor、XX、CommandInvoker。
LogInterceptor只是输出日志
SpringTransactionInterceptor是控制事务的,因为部署的时候会往表ACT_RE_PROCDEF、ACT_RE_DEPLOYMENT、ACT_GE_BYTEARRAY同时插入数据,保证事务完整性。
CommandContextInterceptor
CommandInvoker是执行传入的command的excute方法,这里传入的是DeployCmd,所以去看DeployCmd的excute方法
public Deployment execute(CommandContext commandContext) {
DeploymentEntity deployment = deploymentBuilder.getDeployment();
deployment.setDeploymentTime(Context.getProcessEngineConfiguration().getClock().getCurrentTime());
if ( deploymentBuilder.isDuplicateFilterEnabled() ) {
DeploymentEntity existingDeployment = Context
.getCommandContext()
.getDeploymentEntityManager()
.findLatestDeploymentByName(deployment.getName());
if ( (existingDeployment!=null)
&& !deploymentsDiffer(deployment, existingDeployment)) {
return existingDeployment;
}
}
deployment.setNew(true);
// Save the data
Context
.getCommandContext()
.getDeploymentEntityManager()
.insertDeployment(deployment);
if(Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, deployment));
}
// Deployment settings
Map<String, Object> deploymentSettings = new HashMap<String, Object>();
deploymentSettings.put(DeploymentSettings.IS_BPMN20_XSD_VALIDATION_ENABLED, deploymentBuilder.isBpmn20XsdValidationEnabled());
deploymentSettings.put(DeploymentSettings.IS_PROCESS_VALIDATION_ENABLED, deploymentBuilder.isProcessValidationEnabled());
// Actually deploy
Context
.getProcessEngineConfiguration()
.getDeploymentManager()
.deploy(deployment, deploymentSettings);
if (deploymentBuilder.getProcessDefinitionsActivationDate() != null) {
scheduleProcessDefinitionActivation(commandContext, deployment);
}
if(Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, deployment));
}
return deployment;
}
这里保存DeploymentEntity
Context.getCommandContext().getDeploymentEntityManager().insertDeployment(deployment);
再来看DbSqlSession里的insert方法,这里会把实体存入Map insertedObjec