溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

activiti原表怎么增加新字段

發(fā)布時間:2022-03-21 16:58:39 來源:億速云 閱讀:432 作者:iii 欄目:云計算

這篇文章主要介紹“activiti原表怎么增加新字段”,在日常操作中,相信很多人在activiti原表怎么增加新字段問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”activiti原表怎么增加新字段”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!

activiti自帶了很多表,如圖:

activiti原表怎么增加新字段

Activiti工作流引擎的數(shù)據(jù)庫表中的表名稱都是以 ACT_.第二部分兩個字母表示表的類型。使用模糊匹配的方式說明表的類型匹配activiti的服務(wù)API.

·         ACT_RE_*: RE代表倉儲(Repository).這種表前綴以“static”表示流程定義信息或者流程資源信息(如流程的圖表和規(guī)則等).

·         ACT_RU_*: RU標(biāo)識為運行(Runtime)時表。包含流程實例,用戶任務(wù)和變量任務(wù)等在運行時的數(shù)據(jù)信息。這些表只存儲Activiti在流程實例運行執(zhí)行的數(shù)據(jù),在流程結(jié)束的時候從表中去除數(shù)據(jù)。從而保持運行時候數(shù)據(jù)的表的快速和小數(shù)據(jù)量.

·         ACT_ID_*:ID標(biāo)識為唯一(Identity)的。包含一些唯一的信息如用戶,用戶做等信息。

·         ACT_HI_*:HI表示歷史數(shù)據(jù)(History)表,包括過期的流程實例,過期的變量和過期的任務(wù)等。

·         ACT_GE_*:GE表示公用(General data)的數(shù)據(jù)庫表類型。

        ACT_GE_BYTEARRAY 表保存了開發(fā)時候的文件,在工作流部署的時候需要上傳相關(guān)的工作流文件到相關(guān)的項目中。其中如果是文件采用方式如下,將圖片和或者文件轉(zhuǎn)換為二進制字節(jié)流存儲。

activiti原表怎么增加新字段

    bytes_字段保存了文件內(nèi)容,如果是圖片,則是保存了二進制。

    由于各個項目的業(yè)務(wù)特殊性,想擴展ACT_GE_BYTEARRAY 的字段,增加2個新字段SYS_,SWITCHBOARD_字段。

怎么把數(shù)據(jù)保存到表中,這里采用的是修改源碼的辦法:

步驟1:修改ACT_GE_BYTEARRAY 表對應(yīng)實體org.activiti.engine.impl.persistence.entity.ResourceEntity,添加SYS_,SWITCHBOARD_字段:

public class ResourceEntity implements Serializable, PersistentObject {

  private static final long serialVersionUID = 1L;

  protected String id;
  protected String name;
  protected byte[] bytes;
  protected String deploymentId;
  protected boolean generated = false;
  
  //-------------------------------
  private String switchboard;
  private boolean sys;
  ...
}

步驟2:修改相應(yīng)的sql的配置,添加SYS_,SWITCHBOARD_字段。

文件org.activiti.db.mapping.entity.Resource.xml:


<?xml version="1.0" encoding="UTF-8" ?> 

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 
  
<mapper namespace="org.activiti.engine.impl.persistence.entity.ResourceEntity">
  
  <!-- RESOURCE INSERT -->

  <insert id="insertResource" parameterType="org.activiti.engine.impl.persistence.entity.ResourceEntity">
    insert into ${prefix}ACT_GE_BYTEARRAY(ID_, REV_, NAME_, BYTES_, DEPLOYMENT_ID_, GENERATED_,SWITCHBOARD_,SYS_)  values (#{id, jdbcType=VARCHAR}, 1, #{name, jdbcType=VARCHAR}, #{bytes, jdbcType=BLOB}, #{deploymentId, jdbcType=VARCHAR}, #{generated, jdbcType=BOOLEAN}, #{switchboard, jdbcType=VARCHAR},#{sys, jdbcType=BOOLEAN})  </insert>
  
  <!-- RESOURCE UPDATE -->

  <!-- RESOURCE DELETE -->

  <delete id="deleteResourcesByDeploymentId" parameterType="string">
    delete from ${prefix}ACT_GE_BYTEARRAY where DEPLOYMENT_ID_ = #{id}
  </delete>
  
  <!-- RESOURCE RESULTMAP -->

  <resultMap id="resourceResultMap" type="org.activiti.engine.impl.persistence.entity.ResourceEntity">
    <id property="id" column="ID_" jdbcType="VARCHAR" />
    <result property="name" column="NAME_" jdbcType="VARCHAR"/>
    <result property="bytes" column="BYTES_" jdbcType="BLOB"/>
    <result property="generated" column="GENERATED_" jdbcType="BOOLEAN"/>
    <result property="switchboard" column="SWITCHBOARD_" jdbcType="VARCHAR"/>
    <result property="sys" column="SYS_" jdbcType="BOOLEAN"/>
  </resultMap>
  
  <!-- RESOURCE SELECT -->

  <select id="selectResourceNamesByDeploymentId" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultType="string">
    select NAME_ from ${prefix}ACT_GE_BYTEARRAY where DEPLOYMENT_ID_ = #{parameter} order by NAME_ asc
  </select>
  
  <select id="selectResourceByDeploymentIdAndResourceName" parameterType="map" resultMap="resourceResultMap">
    select * from ${prefix}ACT_GE_BYTEARRAY 
    where DEPLOYMENT_ID_ = #{deploymentId}
          AND NAME_ = #{resourceName}
  </select>

  <select id="selectResourcesByDeploymentId" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="resourceResultMap">
    select * from ${prefix}ACT_GE_BYTEARRAY where DEPLOYMENT_ID_ = #{parameter} order by NAME_ asc
  </select>  

  <!-- postgresql specific -->
  <resultMap id="resourceResultMap_postgres" type="org.activiti.engine.impl.persistence.entity.ResourceEntity">
    <id property="id" column="ID_" jdbcType="VARCHAR" />
    <result property="name" column="NAME_" jdbcType="VARCHAR"/>
    <result property="bytes" column="BYTES_" jdbcType="BINARY"/>
    <result property="generated" column="GENERATED_" jdbcType="BOOLEAN"/>
    <result property="switchboard" column="SWITCHBOARD_" jdbcType="VARCHAR"/>
    <result property="sys" column="SYS_" jdbcType="BOOLEAN"/>
  </resultMap>
    
  <!-- postgresql specific -->
  <select id="selectResourceByDeploymentIdAndResourceName_postgres" parameterType="map" resultMap="resourceResultMap_postgres">
    select * from ${prefix}ACT_GE_BYTEARRAY 
    where DEPLOYMENT_ID_ = #{deploymentId}
          AND NAME_ = #{resourceName}
  </select>
  
  <!-- postgresql specific -->
  <select id="selectResourcesByDeploymentId_postgres" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="resourceResultMap_postgres">
    select * from ${prefix}ACT_GE_BYTEARRAY where DEPLOYMENT_ID_ = #{parameter} order by NAME_ asc
  </select>  
  
</mapper>


主要就是修改<insert><resultMap>的內(nèi)容

步驟3:加載數(shù)據(jù)文件時候,設(shè)置SYS_,SWITCHBOARD_的值

ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
 RepositoryService repositoryService = processEngine.getRepositoryService();
 DeploymentBuilderImpl deploymentBuilder =(DeploymentBuilderImpl) repositoryService.createDeployment()
 .addClasspathResource("activiti/leave.bpmn");
 DeploymentEntity deploymentEntity = deploymentBuilder.getDeployment();
 ResourceEntity resourceEntity = deploymentEntity.getResource("activiti/leave.bpmn");
 resourceEntity.setSwitchboard(getSwitchboard());
 resourceEntity.setSys(true);
 deploymentEntity.addResource(resourceEntity);
 deploymentBuilder.deploy();

注:這里主要是通過ResourceEntity resourceEntity = deploymentEntity.getResource("activiti/leave.bpmn");獲得數(shù)據(jù)庫獲得對應(yīng)的實體,然后設(shè)置我們新添加的字段的值。

測試結(jié)果:

activiti原表怎么增加新字段

看到上面的數(shù)據(jù),SYS_,SWITCHBOARD_字段都有值了,activiti/leave.bpmn是正確的,但是activiti/leave.leave.png對應(yīng)的值是不正確的。因為這2個添加的值因該是一樣的。

下面繼續(xù)修改:

步驟4:org.activiti.engine.impl.bpmn.deployer.BpmnDeployer,加載activiti/leave.bpmn中的圖片

    public void deploy(DeploymentEntity deployment) {
...
  createResource(resourceName,diagramResourceName, diagramBytes, deployment);
...
}

protected void createResource(String resourceName ,String name, byte[] bytes, DeploymentEntity deploymentEntity) {
    ResourceEntity resource = new ResourceEntity();
    resource.setName(name);
    resource.setBytes(bytes);
    resource.setDeploymentId(deploymentEntity.getId());
    
    ResourceEntity resourceEntity = deploymentEntity.getResource(resourceName);
    if(resourceEntity!=null){
    	resource.setSwitchboard(resourceEntity.getSwitchboard());
    	resource.setSys(resourceEntity.isSys());
    }
    // Mark the resource as 'generated'
    resource.setGenerated(true);
    
    Context
      .getCommandContext()
      .getDbSqlSession()
      .insert(resource);
  }

有人要問,問什么要這么修改,沒辦法,我是一步一步debug,一步一步看源碼。

步驟5:文件org.activiti.db.mapping.entity.VariableInstance.xml,添加SYS_,SWITCHBOARD_字段:

  <!-- BYTE ARRAY INSERT -->

  <insert id="insertByteArray" parameterType="org.activiti.engine.impl.persistence.entity.ByteArrayEntity">
    insert into ${prefix}ACT_GE_BYTEARRAY(ID_, REV_, NAME_, BYTES_, DEPLOYMENT_ID_,SWITCHBOARD_,SYS_)
    values (
      #{id, jdbcType=VARCHAR},
      1, 
      #{name, jdbcType=VARCHAR}, 
      #{bytes, jdbcType=BLOB}, 
      #{deploymentId, jdbcType=VARCHAR},
      #{switchboard, jdbcType=VARCHAR},
      #{sys, jdbcType=BOOLEAN}
    )  
  </insert>

然后測試結(jié)果:

  activiti原表怎么增加新字段

到此,關(guān)于“activiti原表怎么增加新字段”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI