activiti原表怎么增加新字段
这篇文章主要介绍“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原表怎么增加新字段”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注蜗牛博客网站,小编会继续努力为大家带来更多实用的文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:niceseo99@gmail.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
评论