当前位置: 首页 > news >正文

Activiti源码跟踪之模型Model操作

Activiti源码跟踪之模型Model操作

模型model设计到的表ACT_RE_MODEL、ACT_GE_BYTEARRAY

ACT_RE_MODEL表结构:

CREATE TABLE `ACT_RE_MODEL` (`ID_` varchar(64) COLLATE utf8_bin NOT NULL,`REV_` int(11) DEFAULT NULL,`NAME_` varchar(255) COLLATE utf8_bin DEFAULT NULL,`KEY_` varchar(255) COLLATE utf8_bin DEFAULT NULL,`CATEGORY_` varchar(255) COLLATE utf8_bin DEFAULT NULL,`CREATE_TIME_` timestamp NULL DEFAULT NULL,`LAST_UPDATE_TIME_` timestamp NULL DEFAULT NULL,`VERSION_` int(11) DEFAULT NULL,`META_INFO_` varchar(4000) COLLATE utf8_bin DEFAULT NULL,`DEPLOYMENT_ID_` varchar(64) COLLATE utf8_bin DEFAULT NULL,`EDITOR_SOURCE_VALUE_ID_` varchar(64) COLLATE utf8_bin DEFAULT NULL,`EDITOR_SOURCE_EXTRA_VALUE_ID_` varchar(64) COLLATE utf8_bin DEFAULT NULL,`TENANT_ID_` varchar(255) COLLATE utf8_bin DEFAULT '',PRIMARY KEY (`ID_`),KEY `ACT_FK_MODEL_SOURCE` (`EDITOR_SOURCE_VALUE_ID_`),KEY `ACT_FK_MODEL_SOURCE_EXTRA` (`EDITOR_SOURCE_EXTRA_VALUE_ID_`),KEY `ACT_FK_MODEL_DEPLOYMENT` (`DEPLOYMENT_ID_`),CONSTRAINT `ACT_FK_MODEL_DEPLOYMENT` FOREIGN KEY (`DEPLOYMENT_ID_`) REFERENCES `ACT_RE_DEPLOYMENT` (`ID_`),CONSTRAINT `ACT_FK_MODEL_SOURCE` FOREIGN KEY (`EDITOR_SOURCE_VALUE_ID_`) REFERENCES `ACT_GE_BYTEARRAY` (`ID_`),CONSTRAINT `ACT_FK_MODEL_SOURCE_EXTRA` FOREIGN KEY (`EDITOR_SOURCE_EXTRA_VALUE_ID_`) REFERENCES `ACT_GE_BYTEARRAY` (`ID_`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

其中ACT_RE_MODEL有三个外键,对应ACT_GE_BYTEARRAY的有两个。

CREATE TABLE `ACT_GE_BYTEARRAY`  (`ID_` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,`REV_` int NULL DEFAULT NULL,`NAME_` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,`DEPLOYMENT_ID_` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,`BYTES_` longblob NULL,`GENERATED_` tinyint NULL DEFAULT NULL,PRIMARY KEY (`ID_`) USING BTREE,INDEX `ACT_FK_BYTEARR_DEPL`(`DEPLOYMENT_ID_`) USING BTREE,CONSTRAINT `ACT_FK_BYTEARR_DEPL` FOREIGN KEY (`DEPLOYMENT_ID_`) REFERENCES `ACT_RE_DEPLOYMENT` (`ID_`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_bin ROW_FORMAT = Dynamic;

EDITOR_SOURCE_VALUE_ID_对应ACT_GE_BYTEARRAY的ID_,表示该模型对应的模型文件(json格式数据)。repositoryService.addModelEditorSource方法实现。

EDITOR_SOURCE_EXTRA_VALUE_ID_对应ACT_GE_BYTEARRAY的ID_,表示该模型生成的图片文件。repositoryService.addModelEditorSourceExtra方法实现。

1、保存模型:

Model modelData = repositoryService.newModel();
repositoryService.saveModel(modelData);

执行对应的SaveModelCmd。会插入或更新ACT_RE_MODEL的数据。

SaveModelCmd对应的execute方法:

public Void execute(CommandContext commandContext) {if(model == null) {throw new ActivitiIllegalArgumentException("model is null");}if (model.getId() == null) {commandContext.getModelEntityManager().insertModel(model);} else {commandContext.getModelEntityManager().updateModel(model);}return null;}

执行对应的insert或update方法:
insert方法分发ENTITY_CREATED和ENTITY_INITIALIZED事件:

  public void insertModel(Model model) {((ModelEntity) model).setCreateTime(Context.getProcessEngineConfiguration().getClock().getCurrentTime());((ModelEntity) model).setLastUpdateTime(Context.getProcessEngineConfiguration().getClock().getCurrentTime());getDbSqlSession().insert((PersistentObject) model);if(Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, model));Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, model));}}

update方法分发ENTITY_UPDATED方法:

public void updateModel(ModelEntity updatedModel) {CommandContext commandContext = Context.getCommandContext();updatedModel.setLastUpdateTime(Context.getProcessEngineConfiguration().getClock().getCurrentTime());DbSqlSession dbSqlSession = commandContext.getDbSqlSession();dbSqlSession.update(updatedModel);if(Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, updatedModel));}}

2、保存其他信息(模型文件或图片)

保存模型文件(json格式)。涉及到的表:ACT_RE_MODEL、ACT_GE_BYTEARRAY

repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));

AddEditorSourceForModelCmd:

public Object execute(CommandContext commandContext) {commandContext.getModelEntityManager().insertEditorSourceForModel(modelId, bytes);return null;}
}

insertEditorSourceForModel

public void insertEditorSourceForModel(String modelId, byte[] modelSource) {ModelEntity model = findModelById(modelId);if (model != null) {ByteArrayRef ref = new ByteArrayRef(model.getEditorSourceValueId());ref.setValue("source", modelSource);if (model.getEditorSourceValueId() == null) {model.setEditorSourceValueId(ref.getId());updateModel(model);}}}

其中ref.setValue(“source”, modelSource)方法对

model.getEditorSourceValueId() == null 生成DbSqlSession的inser语句,最后执行updateModel方法
model.getEditorSourceValueId() != null ,ByteArrayRef.ensureInitialized()方法调用DbSqlSession.selectById(),ByteArrayEntity存放在canche。ByteArrayRef.setBytes(bytes); 把新的byte值设进 ByteArrayEntity
DbSqlSession.flush()的getUpdatedObjects()方法,比较persistentObject对象,生成update

http://www.lryc.cn/news/171509.html

相关文章:

  • C#-WinForm-发送邮件
  • Springboot整合jdbc和Mybatis
  • 日常生活中的常用命令及操作
  • 【C++杂货铺】国庆中秋特辑——多态由浅入深详细总结
  • MongoDB基础详解
  • 解锁前端Vue3宝藏级资料 第五章 Vue 组件应用 4 ( provide 和 inject )
  • 【List篇】LinkedList 详解
  • 推动统一供应链“度量衡”,上汽大通突破传统拥抱SaaS生态
  • 蓝牙核心规范(V5.4)10.9-BLE 入门笔记之GAP
  • nginx 配置 ssl
  • 家居设计软件Live Home 3D Pro mac中文版特点介绍
  • OkHttp - 现代应用网络的方式
  • SpringBoot3基础:最简项目示例
  • flex:1详解,以及flex:1和flex:auto的区别
  • 在VMware虚拟机中固定CentOS系统ip(使用桥接模式)
  • 怎样才能让百度搜索到自己的博客?--九五小庞
  • 【学习笔记】多模态综述
  • MLAgents (0) Unity 安装及运行
  • typename关键字详解(消除歧义)
  • 设计模式_解释器模式
  • 【算法基础】数学知识
  • PDCA循环
  • Redis 缓存雪崩、缓存穿透、缓存击穿
  • Android Media3 ExoPlayer 开启缓存功能
  • MyBatis注解开发
  • C# Onnx Yolov8 Cls 分类
  • Fiddler常用的快键键
  • 【Linux】生产消费模型 + 线程池
  • 基于springboot+vue的爱心助农网站(前后端分离)
  • “华为杯”研究生数学建模竞赛2019年-【华为杯】D题:汽车行驶工况构建(附获奖论文和MATLAB代码实现)