首页 > 代码库 > Activiti 5.17 --从Activiti的业务对象到MyBatis SQL Mapping ID的映射规则
Activiti 5.17 --从Activiti的业务对象到MyBatis SQL Mapping ID的映射规则
Activiti 的业务实体层使用 PersistentObject 向数据层传递数据;
MyBatis 使用Mapping中的 id 执行SQL 逻辑;
本文讲述了从Activiti PersistentObject 到 MyBatis SQL id 的映射规则。
一、数据层和数据的关系
二、PersistentObject 对象
三、MyBatis 对应的SQL ID
1、insert
<insert id="insertProcessDefinition" parameterType="org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity"> ... </insert>
<insert id="insertAttachment" parameterType="org.activiti.engine.impl.persistence.entity.AttachmentEntity"> ... </insert>2、update
<update id="updateAttachment" parameterType="org.activiti.engine.impl.persistence.entity.AttachmentEntity"> ... </update>
<update id="updateProcessDefinition" parameterType="org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity"> ... </update>
3、delete
<delete id="deleteProcessDefinitionsByDeploymentId" parameterType="string"> ... </delete>
<delete id="deleteAttachment" parameterType="org.activiti.engine.impl.persistence.entity.AttachmentEntity"> ... </delete>
四、映射规则
1、 String prefix = "insert";
2、Class persistentObjectClass = org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity.class
3、String statement = prefix + persistentObjectClass.getSimpleName(); // 值为 : insertProcessDefinitionEntity
4、statement = statement.substring(0, statement.length()-6); // 值为 : insertProcessDefinition
5、statement = “insertProcessDefinition” 与 上面第1项 insert 中的id 对应起来了。
所以,只要知道了操作的方法和操作对象,就可以找到MyBatis的SQL ID,并执行该SQL了。
相关的代码如下:
public String getInsertStatement(PersistentObject object) { return getStatement(object.getClass(), insertStatements, "insert"); } public String getUpdateStatement(PersistentObject object) { return getStatement(object.getClass(), updateStatements, "update"); } public String getDeleteStatement(Class<?> persistentObjectClass) { return getStatement(persistentObjectClass, deleteStatements, "delete"); } public String getSelectStatement(Class<?> persistentObjectClass) { return getStatement(persistentObjectClass, selectStatements, "select"); } private String getStatement(Class<?> persistentObjectClass, Map<Class<?>,String> cachedStatements, String prefix) { String statement = cachedStatements.get(persistentObjectClass); if (statement!=null) { return statement; } statement = prefix + persistentObjectClass.getSimpleName(); statement = statement.substring(0, statement.length()-6); cachedStatements.put(persistentObjectClass, statement); return statement; }
Activiti 5.17 --从Activiti的业务对象到MyBatis SQL Mapping ID的映射规则