本人博客開始遷移,博客整個架構本身搭建及編碼 http://www.cookqq.com/listBlog.action java
activiti自帶了不少表,如圖:sql
Activiti工做流引擎的數據庫表中的表名稱都是以 ACT_.第二部分兩個字母表示表的類型。使用模糊匹配的方式說明表的類型匹配activiti的服務API.數據庫
· ACT_RE_*: RE表明倉儲(Repository).這種表前綴以「static」表示流程定義信息或者流程資源信息(如流程的圖表和規則等).mybatis
· ACT_RU_*: RU標識爲運行(Runtime)時表。包含流程實例,用戶任務和變量任務等在運行時的數據信息。這些表只存儲Activiti在流程實例運行執行的數據,在流程結束的時候從表中去除數據。從而保持運行時候數據的表的快速和小數據量.架構
· ACT_ID_*:ID標識爲惟一(Identity)的。包含一些惟一的信息如用戶,用戶作等信息。app
· ACT_HI_*:HI表示歷史數據(History)表,包括過時的流程實例,過時的變量和過時的任務等。post
· ACT_GE_*:GE表示公用(General data)的數據庫表類型。測試
ACT_GE_BYTEARRAY 表保存了開發時候的文件,在工做流部署的時候須要上傳相關的工做流文件到相關的項目中。其中若是是文件採用方式以下,將圖片和或者文件轉換爲二進制字節流存儲。ui
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>
...
而後測試結果: