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_S服务器托管网OURCE_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, m服务器托管网odel));
}
}
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.fwqtg.net
相关推荐: Unity与Android交互(4)——接入SDK
【前言】 unity接入Android SDK有两种方式,一种是把Unity的工程导出google project的形式进行接入,另一种是通过把Android的工程做成Plugins的形式进行接入。我们接入SDK基本都是将SDK作为插件的形式接入的。 对我们接…