jbpm4.4部署過程詳情

根據ProcessEngine取得RepositoryService加載資源文件; java

String deployId = processEngine.getRepositoryService().createDeployment()
	.addResourceFromClasspath("resources/jbpm/Appropriation.jpdl.xml").deploy();



部署成功回返迴流程id;

該方法的執行流程以下: 數據庫

一、調用DeploymentImpl類的deploy方法; session

public String deploy() {
    return commandService.execute(new DeployCmd(this));
  }



執行部署命令DeployCmd的execute方法;
public String execute(Environment environment) throws Exception {
    RepositorySession repositorySession = environment.get(RepositorySession.class);
    return repositorySession.deploy(deployment);
  }



二、調用RepositorySeession的deploy();參數deployment爲DeployCmd的一個屬性,在構造函數中初始化;

因爲new DeployCmd(this)可知,deployment爲DeploymentImpl的對象; app

public String deploy(NewDeployment deployment) {
    DeploymentImpl deploymentImpl = (DeploymentImpl) deployment;
    
    long dbid = DbidGenerator.getDbidGenerator().getNextId();
    deploymentImpl.setDbid(dbid);
    deploymentImpl.initResourceLobDbids();
    
    session.save(deploymentImpl); // will also save the attached resources
    deployerManager.deploy(deploymentImpl);

    return deploymentImpl.getId();
  }



源碼save註釋有當保存deploymentImpl時同時保持相關的資源;那麼再回頭看DeploymentImpl類的屬性有哪些;
public class DeploymentImpl extends ProblemList implements NewDeployment {

  private static final long serialVersionUID = 1L;

  public static final String KEY_PROCESS_LANGUAGE_ID = "langid";
  public static final String KEY_PROCESS_DEFINITION_ID = "pdid";
  public static final String KEY_PROCESS_DEFINITION_KEY = "pdkey";
  public static final String KEY_PROCESS_DEFINITION_VERSION = "pdversion";

  protected long dbid;
  protected String name;
  protected long timestamp;
  protected String state = Deployment.STATE_ACTIVE;
  protected Map<String, Lob> resources;

  protected CommandService commandService;
  protected Map<String, Object> objects;
  protected Set<DeploymentProperty> objectProperties;



發現一個resources的Map,Value爲Lob類型;再看流程部署調用的加載部署文件方法,這個方法就在DeploymentImple類裏面;
public NewDeployment addResourceFromClasspath(String resourceName) {
    addResourceFromStreamInput(resourceName, new ResourceStreamInput(resourceName));
    return this;
  }



public NewDeployment addResourceFromStreamInput(String name, StreamInput streamInput) {
    if (resources == null) {
      resources = new HashMap<String, Lob>();
    }
    InputStream inputStream = streamInput.openStream();
    try {
      byte[] bytes = IoUtil.readBytes(inputStream);

      // Since this method is probably called outside an environment block, we
      // need to generate the dbid of the Lob later (during the actual deployment).
      Lob lob = new Lob(bytes, false);
      resources.put(name, lob);
    }
    catch (IOException e) {
      throw new JbpmException("couldn't read from " + name, e);
    }
    finally {
      IoUtil.close(inputStream);
    }
    return this;
  }



不難看出資源文件類路徑爲key;

主要再看 protected Set<DeploymentProperty> objectProperties;這個屬性; ide

這個類很簡單; 函數

public class DeploymentProperty implements Serializable {
  
  private static final long serialVersionUID = 1L;

  long dbid;
  protected DeploymentImpl deployment;
  protected String objectName;
  protected String key;
  protected String stringValue;
  protected Long longValue;
  ...



持久化到數據庫,其中的幾條記錄爲

資源文件xml的開頭內容爲 this

<process name="appcardJbpmFlow2" xmlns="http://jbpm.org/4.4/jpdl">



DeploymentProperty對應的數據記錄爲;

相關文章
相關標籤/搜索