部署涉及到的表:ACT_GE_BYTEARRAY、ACT_RE_MODEL、ACT_RE_PROCDEF
参考:http://www.jianshu.com/p/0aeb725c1c9a
1、流程部署调用:
RepositoryService.createDeployment().deploy();
RepositoryServiceImpl的createDeployment方法返回DeploymentBuilder对象,该对象是一个部署管理接口,含有deploy()等方法。
public DeploymentBuilder createDeployment() {
return commandExecutor.execute(new Command<DeploymentBuilder>() {
@Override
public DeploymentBuilder execute(CommandContext commandContext) {
return new DeploymentBuilderImpl(RepositoryServiceImpl.this);
}
});
}
DeploymentBuilderImpl的deploy方法调用repositoryService的deploy方法:
public Deployment deploy() {
return repositoryService.deploy(this);
}
2、RepositoryServiceImpl的deploy方法通过命令模式调用LogInterceptor
、 SpringTransactionInterceptor
、CommandContextInterceptor
拦截器之后,最后CommandContextInterceptor
会调用DeployCmd.execute()方法
public Deployment deploy(DeploymentBuilderImpl deploymentBuilder) {
return commandExecutor.execute(new DeployCmd<Deployment>(deploymentBuilder));
}
3、DeployCmd.execute():
部署使用DeploymentEntity对象。
public Deployment execute(CommandContext commandContext) {
......
deployment.setNew(true);
// Save the data
commandContext
.getDeploymentEntityManager()
.insertDeployment(deployment);
if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
commandContext.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
commandContext
.getProcessEngineConfiguration()
.getDeploymentManager()
.deploy(deployment, deploymentSettings);
......
}
deployment.setNew(true):第一次部署
insertDeployment(deployment):insert的是DeploymentEntity对象,存入表
deploymentSettings进行设置参数
deploy(deployment, deploymentSettings):部署
重点看下部署的方法:BpmnDeployer.deploy(deployment, deploymentSettings):方法很长,涉及到对Bpmn解析,对ProcessDefinitionEntity对象赋值,生成processDefinitionId并insert入库等一系列操作。其中最后几行代码:
public void deploy(DeploymentEntity deployment, Map<String, Object> deploymentSettings) {
......
// Add to cache
DeploymentManager deploymentManager = processEngineConfiguration.getDeploymentManager();
deploymentManager.getProcessDefinitionCache().add(processDefinition.getId(), processDefinition);
addDefinitionInfoToCache(processDefinition, processEngineConfiguration, commandContext);
......
}
分别将processDefinition放入DeploymentCache和ProcessDefinitionInfoCache
因为流程定义的数据不会改变,为了避免每次使用流程定义时都访问数据库,所以在流程进行部署之后,生成的流程定义会放在缓存中。