十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
這篇文章主要介紹“activiti原表怎么增加新字段”,在日常操作中,相信很多人在activiti原表怎么增加新字段問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”activiti原表怎么增加新字段”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
創(chuàng)新互聯(lián)專業(yè)IDC數(shù)據(jù)服務(wù)器托管提供商,專業(yè)提供成都服務(wù)器托管,服務(wù)器租用,成都服務(wù)器托管,成都服務(wù)器托管,成都多線服務(wù)器托管等服務(wù)器托管服務(wù)。
activiti自帶了很多表,如圖:
Activiti工作流引擎的數(shù)據(jù)庫表中的表名稱都是以 ACT_.第二部分兩個字母表示表的類型。使用模糊匹配的方式說明表的類型匹配activiti的服務(wù)API.
· ACT_RE_*: RE代表倉儲(Repository).這種表前綴以“static”表示流程定義信息或者流程資源信息(如流程的圖表和規(guī)則等).
· ACT_RU_*: RU標(biāo)識為運(yùn)行(Runtime)時表。包含流程實(shí)例,用戶任務(wù)和變量任務(wù)等在運(yùn)行時的數(shù)據(jù)信息。這些表只存儲Activiti在流程實(shí)例運(yùn)行執(zhí)行的數(shù)據(jù),在流程結(jié)束的時候從表中去除數(shù)據(jù)。從而保持運(yùn)行時候數(shù)據(jù)的表的快速和小數(shù)據(jù)量.
· ACT_ID_*:ID標(biāo)識為唯一(Identity)的。包含一些唯一的信息如用戶,用戶做等信息。
· ACT_HI_*:HI表示歷史數(shù)據(jù)(History)表,包括過期的流程實(shí)例,過期的變量和過期的任務(wù)等。
· ACT_GE_*:GE表示公用(General data)的數(shù)據(jù)庫表類型。
ACT_GE_BYTEARRAY 表保存了開發(fā)時候的文件,在工作流部署的時候需要上傳相關(guān)的工作流文件到相關(guān)的項(xiàng)目中。其中如果是文件采用方式如下,將圖片和或者文件轉(zhuǎn)換為二進(jìn)制字節(jié)流存儲。
bytes_字段保存了文件內(nèi)容,如果是圖片,則是保存了二進(jìn)制。
由于各個項(xiàng)目的業(yè)務(wù)特殊性,想擴(kuò)展ACT_GE_BYTEARRAY 的字段,增加2個新字段SYS_,SWITCHBOARD_字段。
怎么把數(shù)據(jù)保存到表中,這里采用的是修改源碼的辦法:
步驟1:修改ACT_GE_BYTEARRAY 表對應(yīng)實(shí)體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:
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}) delete from ${prefix}ACT_GE_BYTEARRAY where DEPLOYMENT_ID_ = #{id}
主要就是修改
步驟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í)體,然后設(shè)置我們新添加的字段的值。
測試結(jié)果:
看到上面的數(shù)據(jù),SYS_,SWITCHBOARD_字段都有值了,activiti/leave.bpmn是正確的,但是activiti/leave.leave.png對應(yīng)的值是不正確的。因?yàn)檫@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_字段:
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} )
然后測試結(jié)果:
到此,關(guān)于“activiti原表怎么增加新字段”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!