您好,登錄后才能下訂單哦!
這篇文章主要介紹“activiti原表怎么增加新字段”,在日常操作中,相信很多人在activiti原表怎么增加新字段問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”activiti原表怎么增加新字段”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
activiti自帶了很多表,如圖:
Activiti工作流引擎的數據庫表中的表名稱都是以 ACT_.第二部分兩個字母表示表的類型。使用模糊匹配的方式說明表的類型匹配activiti的服務API.
· ACT_RE_*: RE代表倉儲(Repository).這種表前綴以“static”表示流程定義信息或者流程資源信息(如流程的圖表和規則等).
· ACT_RU_*: RU標識為運行(Runtime)時表。包含流程實例,用戶任務和變量任務等在運行時的數據信息。這些表只存儲Activiti在流程實例運行執行的數據,在流程結束的時候從表中去除數據。從而保持運行時候數據的表的快速和小數據量.
· ACT_ID_*:ID標識為唯一(Identity)的。包含一些唯一的信息如用戶,用戶做等信息。
· ACT_HI_*:HI表示歷史數據(History)表,包括過期的流程實例,過期的變量和過期的任務等。
· ACT_GE_*:GE表示公用(General data)的數據庫表類型。
ACT_GE_BYTEARRAY 表保存了開發時候的文件,在工作流部署的時候需要上傳相關的工作流文件到相關的項目中。其中如果是文件采用方式如下,將圖片和或者文件轉換為二進制字節流存儲。
bytes_字段保存了文件內容,如果是圖片,則是保存了二進制。
由于各個項目的業務特殊性,想擴展ACT_GE_BYTEARRAY 的字段,增加2個新字段SYS_,SWITCHBOARD_字段。
怎么把數據保存到表中,這里采用的是修改源碼的辦法:
步驟1:修改ACT_GE_BYTEARRAY 表對應實體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:修改相應的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>的內容
步驟3:加載數據文件時候,設置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");獲得數據庫獲得對應的實體,然后設置我們新添加的字段的值。
測試結果:
看到上面的數據,SYS_,SWITCHBOARD_字段都有值了,activiti/leave.bpmn是正確的,但是activiti/leave.leave.png對應的值是不正確的。因為這2個添加的值因該是一樣的。
下面繼續修改:
步驟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>
然后測試結果:
到此,關于“activiti原表怎么增加新字段”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。