In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to add new fields to the original activiti table". In daily operation, I believe many people have doubts about how to add new fields to the original activiti table. The editor consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about how to add new fields to the original activiti table. Next, please follow the editor to study!
Activiti comes with many tables, as shown in the figure:
The table names in the database tables of the Activiti workflow engine are all named as ACT_. In the second part, two letters denote the type of table. Use fuzzy matching to specify that the type of the table matches the service API of activiti.
ACT_RE_*: RE stands for Repository. This table prefix denotes process definition information or process resource information (such as process charts and rules, etc.) with "static".
The ACT_RU_*: RU is identified as a running (Runtime) time table. Contains data information at run time for process instances, user tasks, variable tasks, and so on. These tables store only the data that Activiti executes when the process instance is running, and removes the data from the table at the end of the process. Thus keep the runtime data table fast and small amount of data.
ACT_ID_*:ID is identified as unique (Identity). Contains some unique information such as user, user do and so on.
ACT_HI_*:HI represents historical data (History) tables, including expired process instances, expired variables, expired tasks, and so on.
ACT_GE_*:GE represents a common (General data) database table type.
The ACT_GE_BYTEARRAY table saves the development files, and the relevant workflow files need to be uploaded to the relevant project when the workflow is deployed. If the file is in the following way, convert the picture and or file into a binary byte stream storage.
The bytes_ field holds the contents of the file, or, in the case of a picture, the binary.
Due to the business particularity of each project, I want to expand the field of ACT_GE_BYTEARRAY and add 2 new fields, SYS_,SWITCHBOARD_ field.
How to save the data to the table? here is the method of modifying the source code:
Step 1: modify the ACT_GE_BYTEARRAY table corresponding entity org.activiti.engine.impl.persistence.entity.ResourceEntity and add the SYS_,SWITCHBOARD_ field:
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;...}
Step 2: modify the configuration of the corresponding sql and add the SYS_,SWITCHBOARD_ field.
File 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} select NAME_ from ${prefix} ACT_GE_BYTEARRAY where DEPLOYMENT_ID_ = # {parameter} order by NAME_ asc select * from ${prefix} ACT_GE_BYTEARRAY where DEPLOYMENT_ID_ = # {deploymentId} AND NAME_ = # { ResourceName} select * from ${prefix} ACT_GE_BYTEARRAY where DEPLOYMENT_ID_ = # {parameter} order by NAME_ asc select * from ${prefix} ACT_GE_BYTEARRAY where DEPLOYMENT_ID_ = # {deploymentId} AND NAME_ = # {resourceName} select * from ${prefix} ACT_GE_BYTEARRAY where DEPLOYMENT_ID_ = # {parameter} order by NAME_ asc
It is mainly about the revised content.
Step 3: when loading the data file, set the value of 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 ()
Note: this is mainly through ResourceEntity resourceEntity = deploymentEntity.getResource ("activiti/leave.bpmn"); get the corresponding entity from the database, and then set the value of our newly added field.
Test results:
When you see the data above, the SYS_,SWITCHBOARD_ field has a value, and activiti/leave.bpmn is correct, but the value corresponding to activiti/leave.leave.png is incorrect. Because the two added values should be the same.
Let's continue to modify:
Step 4:org.activiti.engine.impl.bpmn.deployer.BpmnDeployer, load the picture in 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 (resourceEntityNull) {resource.setSwitchboard (resourceEntity.getSwitchboard ()) Resource.setSys (resourceEntity.isSys ());} / / Mark the resource as' generated' resource.setGenerated (true); Context .getCommandContext () .getDbSqlSession () .insert (resource);}
Some people want to ask, why should be so modified, there is no way, I am step by step debug, step by step look at the source code.
Step 5: file org.activiti.db.mapping.entity.VariableInstance.xml, add the SYS_,SWITCHBOARD_ field:
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})
Then the test results:
At this point, the study on "how to add new fields to the original activiti table" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.