https://blog.csdn.net/evan_leung/article/details/51589870

http://www.jianshu.com/p/e6971e8a8dad

下面本人介绍一些activiti这款开源流程设计引擎的数据库表结构,首先阐述:我们刚开始接触或者使用一个新的东西(技术)时我们首先多问一下自己几个为什么?为什么activiti在工作流程领域这么流行呢?仅仅是因为开源么?实现如此强大的流程引擎,activiti底层设计是如何进行的?activiti中依赖哪些技术等?这些可能应该是那些刚接触这个开源流程引擎产品的人应该有的疑问。我们在用开源产品的都是其实应该多问自己为什么?这样才能有所进步,不是么?兴许你一时兴起,“起笔”就把一款属于你自己的开源作品给做出来了!

了解一个开源作品,它的底层很重要。在使用它之前,你是否尝试过了解它的底层。那么这些尝试是否对你有必要呢?个人解决有必要,首先这个东西确实在你看来是个有用的东西,你对它感兴趣。兴许将来你在应用它的时候可能会发现它的BUG,其实大牛写的东西也未必是完美的,兴许你在使用时候就发现其中不满意的东西,那么你就可以向开元社区提交的你的BUG!就比如说我们在了解activiti的底层数据结构之后,在我们使用activiti的时候发现一些数据查询过程中出现性能瓶颈时,我们可以尝试分析activiti的数据查询规则,activiti的数据访问层依赖于mybatis,那么我可以分析打包在jar包里的关于mybatis的sql配置部分,看看那些所谓大牛们写的sql是否存在问题。当你发现问题时,你可以对它进行修改,然后重新打包。从而满足自己在项目有中的需要。这些都是一些关于进阶了解一个开源作品的方式。在这样过程中你会发现你在某方面会有所进步。以上内容抛砖引玉,希望对你有所帮助!

好吧,请允许我废话了这么久,下面开始解析activiti的数据库底层的模型截图:

以上就activiti底层数据库23张表结构,个人觉得了解底层数据库模型是有必要的,让我们直观的了解一个开源作品的底层设计结构,对日后大伙使用的时候能有很大的帮助,特别是activiti的高级应用。大致看一下这些模型你们就知道activiti的23张表直接约束关系了!那么大家在使用activiti提供的servcies API查询activiti流程控制数据时就更清晰一些了!比如如下说明:

  1. activiti的历史任务是单独的表来储存,表之间没有任何外间关联,从以上模型就可以看出
  2.  
  3. ACT_HI_ACTINST 流程活动历史记录信息
  4. ACT_HI_ATTACHMENT
  5. ACT_HI_COMMENT 流程评论信息
  6. ACT_HI_DETAIL 流程明细信息
  7. ACT_HI_IDENTITYLINK 流程身份关系信息
  8. ACT_HI_PROCINST 流程历史信息
  9. ACT_HI_TASKINST 任务历史信息
  10. ACT_HI_VARINST 历史流程中的参数
  11.  
  12. historyService可查询历史数据表(可查询以上这些表,与流程历史相关数据的查询都可以通过<span style="font-family: Arial, Helvetica, sans-serif;">historyService来查询</span>)
  13. historyService.createHistoricActivityInstanceQuery(); //查询ACT_HI_ACTINST表
  14. historyService.createHistoricDetailQuery(); //查询ACT_HI_DETAIL表
  15. historyService.createHistoricProcessInstanceQuery(); //查询ACT_HI_PROCINST表
  16. historyService.createHistoricTaskInstanceQuery(); //查询ACT_HI_TASKINST表
  17. historyService.createHistoricVariableInstanceQuery(); //查询ACT_HI_VARINST表

activiti其中数据的查询和判断都是类似的!在这里就不过多介绍了。

下面是actviti中mybatis的映射配置:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
  4.  
  5. <configuration>
  6. <settings>
  7. <setting name="lazyLoadingEnabled" value="false" />
  8. </settings>
  9. <typeAliases>
  10. <typeAlias type="org.activiti.engine.impl.persistence.ByteArrayRefTypeHandler" alias="ByteArrayRefTypeHandler"/>
  11. </typeAliases>
  12. <typeHandlers>
  13. <typeHandler handler="ByteArrayRefTypeHandler"
  14. javaType="org.activiti.engine.impl.persistence.entity.ByteArrayRef"
  15. jdbcType="VARCHAR"/>
  16. </typeHandlers>
  17. <mappers>
  18. <mapper resource="org/activiti/db/mapping/entity/Attachment.xml" />
  19. <mapper resource="org/activiti/db/mapping/entity/ByteArray.xml" />
  20. <mapper resource="org/activiti/db/mapping/entity/Comment.xml" />
  21. <mapper resource="org/activiti/db/mapping/entity/Deployment.xml" />
  22. <mapper resource="org/activiti/db/mapping/entity/Execution.xml" />
  23. <mapper resource="org/activiti/db/mapping/entity/Group.xml" />
  24. <mapper resource="org/activiti/db/mapping/entity/HistoricActivityInstance.xml" />
  25. <mapper resource="org/activiti/db/mapping/entity/HistoricDetail.xml" />
  26. <mapper resource="org/activiti/db/mapping/entity/HistoricProcessInstance.xml" />
  27. <mapper resource="org/activiti/db/mapping/entity/HistoricVariableInstance.xml" />
  28. <mapper resource="org/activiti/db/mapping/entity/HistoricTaskInstance.xml" />
  29. <mapper resource="org/activiti/db/mapping/entity/HistoricIdentityLink.xml" />
  30. <mapper resource="org/activiti/db/mapping/entity/IdentityInfo.xml" />
  31. <mapper resource="org/activiti/db/mapping/entity/IdentityLink.xml" />
  32. <mapper resource="org/activiti/db/mapping/entity/Job.xml" />
  33. <mapper resource="org/activiti/db/mapping/entity/Membership.xml" />
  34. <mapper resource="org/activiti/db/mapping/entity/Model.xml" />
  35. <mapper resource="org/activiti/db/mapping/entity/ProcessDefinition.xml" />
  36. <mapper resource="org/activiti/db/mapping/entity/Property.xml" />
  37. <mapper resource="org/activiti/db/mapping/entity/Resource.xml" />
  38. <mapper resource="org/activiti/db/mapping/entity/TableData.xml" />
  39. <mapper resource="org/activiti/db/mapping/entity/Task.xml" />
  40. <mapper resource="org/activiti/db/mapping/entity/User.xml" />
  41. <mapper resource="org/activiti/db/mapping/entity/VariableInstance.xml" />
  42. <mapper resource="org/activiti/db/mapping/entity/EventSubscription.xml" />
  43. </mappers>
  44. </configuration>

下面是就那其中一个映射配置来说明,如HistoricProcessInstance.xml:

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2.  
  3. <!--
  4. ~ Licensed under the Apache License, Version 2.0 (the "License");
  5. ~ you may not use this file except in compliance with the License.
  6. ~ You may obtain a copy of the License at
  7. ~
  8. ~ http://www.apache.org/licenses/LICENSE-2.0
  9. ~
  10. ~ Unless required by applicable law or agreed to in writing, software
  11. ~ distributed under the License is distributed on an "AS IS" BASIS,
  12. ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. ~ See the License for the specific language governing permissions and
  14. ~ limitations under the License.
  15. -->
  16.  
  17. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  18.  
  19. <mapper namespace="org.activiti.engine.impl.persistence.entity.HistoricTaskInstanceEntity">
  20.  
  21. <!-- HISTORIC TASK INSTANCE INSERT -->
  22.  
  23. <insert id="insertHistoricTaskInstance" parameterType="org.activiti.engine.impl.persistence.entity.HistoricTaskInstanceEntity">
  24. insert into ${prefix}ACT_HI_TASKINST (
  25. ID_,
  26. PROC_DEF_ID_,
  27. PROC_INST_ID_,
  28. EXECUTION_ID_,
  29. NAME_,
  30. PARENT_TASK_ID_,
  31. DESCRIPTION_,
  32. OWNER_,
  33. ASSIGNEE_,
  34. START_TIME_,
  35. CLAIM_TIME_,
  36. END_TIME_,
  37. DURATION_,
  38. DELETE_REASON_,
  39. TASK_DEF_KEY_,
  40. FORM_KEY_,
  41. PRIORITY_,
  42. DUE_DATE_,
  43. CATEGORY_,
  44. TENANT_ID_
  45. ) values (
  46. #{id ,jdbcType=VARCHAR},
  47. #{processDefinitionId, jdbcType=VARCHAR},
  48. #{processInstanceId, jdbcType=VARCHAR},
  49. #{executionId, jdbcType=VARCHAR},
  50. #{name ,jdbcType=VARCHAR},
  51. #{parentTaskId ,jdbcType=VARCHAR},
  52. #{description ,jdbcType=VARCHAR},
  53. #{owner ,jdbcType=VARCHAR},
  54. #{assignee ,jdbcType=VARCHAR},
  55. #{startTime, jdbcType=TIMESTAMP},
  56. #{claimTime, jdbcType=TIMESTAMP},
  57. #{endTime, jdbcType=TIMESTAMP},
  58. #{durationInMillis ,jdbcType=BIGINT},
  59. #{deleteReason ,jdbcType=VARCHAR},
  60. #{taskDefinitionKey ,jdbcType=VARCHAR},
  61. #{formKey ,jdbcType=VARCHAR},
  62. #{priority, jdbcType=INTEGER},
  63. #{dueDate, jdbcType=TIMESTAMP},
  64. #{category, jdbcType=VARCHAR},
  65. #{tenantId, jdbcType=VARCHAR}
  66. )
  67. </insert>
  68.  
  69. <!-- HISTORIC TASK INSTANCE UPDATE -->
  70.  
  71. <update id="updateHistoricTaskInstance" parameterType="org.activiti.engine.impl.persistence.entity.HistoricTaskInstanceEntity">
  72. update ${prefix}ACT_HI_TASKINST set
  73. EXECUTION_ID_ = #{executionId, jdbcType=VARCHAR},
  74. NAME_ = #{name, jdbcType=VARCHAR},
  75. PARENT_TASK_ID_ = #{parentTaskId, jdbcType=VARCHAR},
  76. DESCRIPTION_ = #{description, jdbcType=VARCHAR},
  77. OWNER_ = #{owner, jdbcType=VARCHAR},
  78. ASSIGNEE_ = #{assignee, jdbcType=VARCHAR},
  79. CLAIM_TIME_ = #{claimTime, jdbcType=TIMESTAMP},
  80. END_TIME_ = #{endTime, jdbcType=TIMESTAMP},
  81. DURATION_ = #{durationInMillis ,jdbcType=BIGINT},
  82. DELETE_REASON_ = #{deleteReason ,jdbcType=VARCHAR},
  83. TASK_DEF_KEY_ = #{taskDefinitionKey ,jdbcType=VARCHAR},
  84. FORM_KEY_ = #{formKey ,jdbcType=VARCHAR},
  85. PRIORITY_ = #{priority, jdbcType=INTEGER},
  86. DUE_DATE_ = #{dueDate, jdbcType=TIMESTAMP},
  87. CATEGORY_ = #{category, jdbcType=VARCHAR}
  88. where ID_ = #{id}
  89. </update>
  90.  
  91. <!-- HISTORIC TASK INSTANCE DELETE -->
  92.  
  93. <delete id="deleteHistoricTaskInstance" parameterType="org.activiti.engine.impl.persistence.entity.HistoricTaskInstanceEntity">
  94. delete from ${prefix}ACT_HI_TASKINST where ID_ = #{id}
  95. </delete>
  96.  
  97. <!-- HISTORIC TASK INSTANCE RESULT MAP -->
  98.  
  99. <resultMap id="historicTaskInstanceResultMap" type="org.activiti.engine.impl.persistence.entity.HistoricTaskInstanceEntity">
  100. <id property="id" column="ID_" jdbcType="VARCHAR" />
  101. <result property="processDefinitionId" column="PROC_DEF_ID_" jdbcType="VARCHAR" />
  102. <result property="processInstanceId" column="PROC_INST_ID_" jdbcType="VARCHAR" />
  103. <result property="executionId" column="EXECUTION_ID_" jdbcType="VARCHAR" />
  104. <result property="name" column="NAME_" jdbcType="VARCHAR" />
  105. <result property="parentTaskId" column="PARENT_TASK_ID_" jdbcType="VARCHAR" />
  106. <result property="description" column="DESCRIPTION_" jdbcType="VARCHAR" />
  107. <result property="owner" column="OWNER_" jdbcType="VARCHAR" />
  108. <result property="assignee" column="ASSIGNEE_" jdbcType="VARCHAR" />
  109. <result property="startTime" column="START_TIME_" jdbcType="TIMESTAMP" />
  110. <result property="claimTime" column="CLAIM_TIME_" jdbcType="TIMESTAMP" />
  111. <result property="endTime" column="END_TIME_" jdbcType="TIMESTAMP" />
  112. <result property="durationInMillis" column="DURATION_" jdbcType="BIGINT" />
  113. <result property="deleteReason" column="DELETE_REASON_" jdbcType="VARCHAR" />
  114. <result property="taskDefinitionKey" column="TASK_DEF_KEY_" jdbcType="VARCHAR" />
  115. <result property="formKey" column="FORM_KEY_" jdbcType="VARCHAR" />
  116. <result property="priority" column="PRIORITY_" jdbcType="INTEGER" />
  117. <result property="dueDate" column="DUE_DATE_" jdbcType="TIMESTAMP" />
  118. <result property="category" column="CATEGORY_" jdbcType="VARCHAR" />
  119. <result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR" />
  120. </resultMap>
  121.  
  122. <resultMap id="historicTaskInstanceAndVariablesResultMap" type="org.activiti.engine.impl.persistence.entity.HistoricTaskInstanceEntity">
  123. <id property="id" column="ID_" jdbcType="VARCHAR" />
  124. <result property="processDefinitionId" column="PROC_DEF_ID_" jdbcType="VARCHAR" />
  125. <result property="processInstanceId" column="PROC_INST_ID_" jdbcType="VARCHAR" />
  126. <result property="executionId" column="EXECUTION_ID_" jdbcType="VARCHAR" />
  127. <result property="name" column="NAME_" jdbcType="VARCHAR" />
  128. <result property="parentTaskId" column="PARENT_TASK_ID_" jdbcType="VARCHAR" />
  129. <result property="description" column="DESCRIPTION_" jdbcType="VARCHAR" />
  130. <result property="owner" column="OWNER_" jdbcType="VARCHAR" />
  131. <result property="assignee" column="ASSIGNEE_" jdbcType="VARCHAR" />
  132. <result property="startTime" column="START_TIME_" jdbcType="TIMESTAMP" />
  133. <result property="claimTime" column="CLAIM_TIME_" jdbcType="TIMESTAMP" />
  134. <result property="endTime" column="END_TIME_" jdbcType="TIMESTAMP" />
  135. <result property="durationInMillis" column="DURATION_" jdbcType="BIGINT" />
  136. <result property="deleteReason" column="DELETE_REASON_" jdbcType="VARCHAR" />
  137. <result property="taskDefinitionKey" column="TASK_DEF_KEY_" jdbcType="VARCHAR" />
  138. <result property="formKey" column="FORM_KEY_" jdbcType="VARCHAR" />
  139. <result property="priority" column="PRIORITY_" jdbcType="INTEGER" />
  140. <result property="dueDate" column="DUE_DATE_" jdbcType="TIMESTAMP" />
  141. <result property="category" column="CATEGORY_" jdbcType="VARCHAR" />
  142. <result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR" />
  143. <collection property="queryVariables" column="TASK_ID_" javaType="ArrayList" ofType="org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity">
  144. <id property="id" column="VAR_ID_"/>
  145. <result property="name" column="VAR_NAME_" javaType="String" jdbcType="VARCHAR" />
  146. <result property="variableType" column="VAR_TYPE_" javaType="org.activiti.engine.impl.variable.VariableType" jdbcType="VARCHAR" />
  147. <result property="revision" column="VAR_REV_" jdbcType="INTEGER" />
  148. <result property="processInstanceId" column="VAR_PROC_INST_ID_" jdbcType="VARCHAR" />
  149. <result property="executionId" column="VAR_EXECUTION_ID_" jdbcType="VARCHAR" />
  150. <result property="taskId" column="VAR_TASK_ID_" jdbcType="VARCHAR" />
  151. <result property="byteArrayRef" column="VAR_BYTEARRAY_ID_" typeHandler="ByteArrayRefTypeHandler"/>
  152. <result property="doubleValue" column="VAR_DOUBLE_" jdbcType="DOUBLE" />
  153. <result property="textValue" column="VAR_TEXT_" jdbcType="VARCHAR" />
  154. <result property="textValue2" column="VAR_TEXT2_" jdbcType="VARCHAR" />
  155. <result property="longValue" column="VAR_LONG_" jdbcType="BIGINT" />
  156. </collection>
  157. </resultMap>
  158.  
  159. <!-- HISTORIC TASK INSTANCE SELECT -->
  160.  
  161. <select id="selectHistoricTaskInstance" resultMap="historicTaskInstanceResultMap">
  162. select * from ${prefix}ACT_HI_TASKINST where ID_ = #{historicTaskInstanceId}
  163. </select>
  164.  
  165. <select id="selectHistoricTaskInstanceIdsByProcessInstanceId" resultType="string" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" >
  166. select ID_
  167. from ${prefix}ACT_HI_TASKINST
  168. where PROC_INST_ID_ = #{parameter}
  169. </select>
  170.  
  171. <select id="selectHistoricTaskInstancesByQueryCriteria" parameterType="org.activiti.engine.impl.HistoricTaskInstanceQueryImpl" resultMap="historicTaskInstanceResultMap">
  172. ${limitBefore}
  173. select distinct RES.* ${limitBetween}
  174. <include refid="selectHistoricTaskInstancesByQueryCriteriaSql"/>
  175. ${orderBy}
  176. ${limitAfter}
  177. </select>
  178.  
  179. <select id="selectHistoricTaskInstanceCountByQueryCriteria" parameterType="org.activiti.engine.impl.HistoricTaskInstanceQueryImpl" resultType="long">
  180. select count(RES.ID_)
  181. <include refid="selectHistoricTaskInstancesByQueryCriteriaSql"/>
  182. </select>
  183.  
  184. <sql id="selectHistoricTaskInstancesByQueryCriteriaSql">
  185. from ${prefix}ACT_HI_TASKINST RES
  186. <include refid="commonSelectHistoricTaskInstancesByQueryCriteriaSql"/>
  187. </sql>
  188.  
  189. <select id="selectHistoricTaskInstancesWithVariablesByQueryCriteria" parameterType="org.activiti.engine.impl.HistoricTaskInstanceQueryImpl" resultMap="historicTaskInstanceAndVariablesResultMap">
  190. ${limitBefore}
  191. select distinct RES.*,
  192. VAR.ID_ as VAR_ID_, VAR.NAME_ as VAR_NAME_, VAR.VAR_TYPE_ as VAR_TYPE_, VAR.REV_ as VAR_REV_,
  193. VAR.PROC_INST_ID_ as VAR_PROC_INST_ID_, VAR.EXECUTION_ID_ as VAR_EXECUTION_ID_, VAR.TASK_ID_ as VAR_TASK_ID_,
  194. VAR.BYTEARRAY_ID_ as VAR_BYTEARRAY_ID_, VAR.DOUBLE_ as VAR_DOUBLE_,
  195. VAR.TEXT_ as VAR_TEXT_, VAR.TEXT2_ as VAR_TEXT2_, VAR.LAST_UPDATED_TIME_ as VAR_LAST_UPDATED_TIME_, VAR.LONG_ as VAR_LONG_
  196. ${limitBetween}
  197. <include refid="selectHistoricTaskInstancesWithVariablesByQueryCriteriaSql"/>
  198. ${orderBy}
  199. ${limitAfter}
  200. </select>
  201.  
  202. <select id="selectHistoricTaskInstancesWithVariablesByQueryCriteria_mssql_or_db2" parameterType="org.activiti.engine.impl.HistoricTaskInstanceQueryImpl" resultMap="historicTaskInstanceAndVariablesResultMap">
  203. ${limitBefore}
  204. select distinct TEMPRES_ID_ as ID_,
  205. TEMPRES_PROC_DEF_ID_ as PROC_DEF_ID_, TEMPRES_PROC_INST_ID_ as PROC_INST_ID_, TEMPRES_EXECUTION_ID_ as EXECUTION_ID_,
  206. TEMPRES_NAME_ as NAME_, TEMPRES_PARENT_TASK_ID_ as PARENT_TASK_ID_,
  207. TEMPRES_DESCRIPTION_ as DESCRIPTION_, TEMPRES_OWNER_ as OWNER_, TEMPRES_ASSIGNEE_ as ASSIGNEE_,
  208. TEMPRES_START_TIME_ as START_TIME_, TEMPRES_CLAIM_TIME_ as CLAIM_TIME_, TEMPRES_END_TIME_ as END_TIME_,
  209. TEMPRES_DURATION_ as DURATION_, TEMPRES_TASK_DEF_KEY_ as TASK_DEF_KEY_, TEMPRES_FORM_KEY_ as FORM_KEY_,
  210. TEMPRES_PRIORITY_ as PRIORITY_, TEMPRES_DUE_DATE_ as DUE_DATE_,
  211. TEMPRES_DELETE_REASON_ as DELETE_REASON_,
  212. TEMPVAR_ID_ as VAR_ID_, TEMPVAR_NAME_ as VAR_NAME_, TEMPVAR_TYPE_ as VAR_TYPE_, TEMPVAR_REV_ as VAR_REV_,
  213. TEMPVAR_PROC_INST_ID_ as VAR_PROC_INST_ID_, TEMPVAR_EXECUTION_ID_ as VAR_EXECUTION_ID_, TEMPVAR_TASK_ID_ as VAR_TASK_ID_,
  214. TEMPVAR_BYTEARRAY_ID_ as VAR_BYTEARRAY_ID_, TEMPVAR_DOUBLE_ as VAR_DOUBLE_,
  215. TEMPVAR_TEXT_ as VAR_TEXT_, TEMPVAR_LAST_UPDATED_TIME_ as VAR_LAST_UPDATED_TIME_, TEMPVAR_TEXT2_ as VAR_TEXT2_, TEMPVAR_LONG_ as VAR_LONG_
  216. ${limitOuterJoinBetween}
  217. RES.ID_ as TEMPRES_ID_, RES.PROC_DEF_ID_ as TEMPRES_PROC_DEF_ID_, RES.PROC_INST_ID_ as TEMPRES_PROC_INST_ID_,
  218. RES.EXECUTION_ID_ as TEMPRES_EXECUTION_ID_, RES.NAME_ as TEMPRES_NAME_ , RES.PARENT_TASK_ID_ as TEMPRES_PARENT_TASK_ID_,
  219. RES.DESCRIPTION_ as TEMPRES_DESCRIPTION_, RES.OWNER_ as TEMPRES_OWNER_, RES.ASSIGNEE_ as TEMPRES_ASSIGNEE_,
  220. RES.START_TIME_ as TEMPRES_START_TIME_, RES.END_TIME_ as TEMPRES_END_TIME_, RES.CLAIM_TIME_ as TEMPRES_CLAIM_TIME_,
  221. RES.DURATION_ as TEMPRES_DURATION_, RES.TASK_DEF_KEY_ as TEMPRES_TASK_DEF_KEY_,
  222. RES.FORM_KEY_ as TEMPRES_FORM_KEY_, RES.PRIORITY_ as TEMPRES_PRIORITY_,
  223. RES.DUE_DATE_ as TEMPRES_DUE_DATE_, RES.DELETE_REASON_ as TEMPRES_DELETE_REASON_,
  224. VAR.ID_ as TEMPVAR_ID_, VAR.NAME_ as TEMPVAR_NAME_, VAR.VAR_TYPE_ as TEMPVAR_TYPE_, VAR.REV_ as TEMPVAR_REV_,
  225. VAR.PROC_INST_ID_ as TEMPVAR_PROC_INST_ID_, VAR.EXECUTION_ID_ as TEMPVAR_EXECUTION_ID_, VAR.TASK_ID_ as TEMPVAR_TASK_ID_,
  226. VAR.BYTEARRAY_ID_ as TEMPVAR_BYTEARRAY_ID_, VAR.DOUBLE_ as TEMPVAR_DOUBLE_,
  227. VAR.TEXT_ as TEMPVAR_TEXT_, VAR.TEXT2_ as TEMPVAR_TEXT2_, VAR.LAST_UPDATED_TIME_ as TEMPVAR_LAST_UPDATED_TIME_, VAR.LONG_ as TEMPVAR_LONG_
  228. <include refid="selectHistoricTaskInstancesWithVariablesByQueryCriteriaSql"/>
  229. ${orderBy}
  230. ${limitAfter}
  231. </select>
  232.  
  233. <sql id="selectHistoricTaskInstancesWithVariablesByQueryCriteriaSql">
  234. from ${prefix}ACT_HI_TASKINST RES
  235. <choose>
  236. <when test="includeTaskLocalVariables && includeProcessVariables">
  237. left outer join ${prefix}ACT_HI_VARINST VAR ON RES.ID_ = VAR.TASK_ID_ or RES.PROC_INST_ID_ = VAR.EXECUTION_ID_
  238. </when>
  239. <otherwise>
  240. <if test="includeTaskLocalVariables">
  241. left outer join ${prefix}ACT_HI_VARINST VAR ON RES.ID_ = VAR.TASK_ID_
  242. </if>
  243. <if test="includeProcessVariables">
  244. left outer join ${prefix}ACT_HI_VARINST VAR ON RES.PROC_INST_ID_ = VAR.EXECUTION_ID_ and VAR.TASK_ID_ is null
  245. </if>
  246. </otherwise>
  247. </choose>
  248. <include refid="commonSelectHistoricTaskInstancesByQueryCriteriaSql"/>
  249. </sql>
  250.  
  251. <sql id="commonSelectHistoricTaskInstancesByQueryCriteriaSql">
  252. <if test="candidateUser != null || candidateGroups != null">
  253. inner join ${prefix}ACT_HI_IDENTITYLINK HI on HI.TASK_ID_ = RES.ID_
  254. </if>
  255. <if test="processFinished || processUnfinished || processInstanceBusinessKey != null || processInstanceBusinessKeyLike != null">
  256. inner join ${prefix}ACT_HI_PROCINST HPI ON RES.PROC_INST_ID_ = HPI.ID_
  257. </if>
  258. <if test="processDefinitionKey != null || processDefinitionKeyLike != null || processDefinitionName != null || processDefinitionNameLike != null">
  259. inner join ${prefix}ACT_RE_PROCDEF D on RES.PROC_DEF_ID_ = D.ID_
  260. </if>
  261. <foreach collection="queryVariableValues" index="index" item="var">
  262. <choose>
  263. <when test="var.local">
  264. inner join ${prefix}ACT_HI_VARINST A${index} on RES.ID_ = A${index}.TASK_ID_
  265. </when>
  266. <otherwise>
  267. inner join ${prefix}ACT_HI_VARINST A${index} on RES.PROC_INST_ID_ = A${index}.PROC_INST_ID_
  268. </otherwise>
  269. </choose>
  270. </foreach>
  271. <where>
  272. <if test="taskId != null">
  273. RES.ID_ = #{taskId}
  274. </if>
  275. <if test="processDefinitionId != null">
  276. and RES.PROC_DEF_ID_ = #{processDefinitionId}
  277. </if>
  278. <if test="processDefinitionKey != null">
  279. and D.KEY_ = #{processDefinitionKey}
  280. </if>
  281. <if test="processDefinitionKeyLike != null">
  282. and D.KEY_ like #{processDefinitionKeyLike}
  283. </if>
  284. <if test="processDefinitionName != null">
  285. and D.NAME_ = #{processDefinitionName}
  286. </if>
  287. <if test="processDefinitionNameLike != null">
  288. and D.NAME_ like #{processDefinitionNameLike}
  289. </if>
  290. <if test="processInstanceId != null">
  291. and RES.PROC_INST_ID_ = #{processInstanceId}
  292. </if>
  293. <if test="processInstanceBusinessKey != null">
  294. and HPI.BUSINESS_KEY_ = #{processInstanceBusinessKey}
  295. </if>
  296. <if test="processInstanceBusinessKeyLike != null">
  297. and HPI.BUSINESS_KEY_ like #{processInstanceBusinessKeyLike}
  298. </if>
  299. <if test="taskDefinitionKey != null">
  300. and RES.TASK_DEF_KEY_ = #{taskDefinitionKey}
  301. </if>
  302. <if test="taskDefinitionKeyLike != null">
  303. and RES.TASK_DEF_KEY_ like #{taskDefinitionKeyLike}
  304. </if>
  305. <if test="executionId != null">
  306. and RES.EXECUTION_ID_ = #{executionId}
  307. </if>
  308. <if test="taskName != null">
  309. and RES.NAME_ = #{taskName}
  310. </if>
  311. <if test="taskNameLike != null">
  312. and RES.NAME_ like #{taskNameLike}
  313. </if>
  314. <if test="taskParentTaskId != null">
  315. and RES.PARENT_TASK_ID_ = #{taskParentTaskId}
  316. </if>
  317. <if test="taskDescription != null">
  318. and RES.DESCRIPTION_ = #{taskDescription}
  319. </if>
  320. <if test="taskDescriptionLike != null">
  321. and RES.DESCRIPTION_ like #{taskDescriptionLike}
  322. </if>
  323. <if test="taskDeleteReason != null">
  324. and RES.DELETE_REASON_ = #{taskDeleteReason}
  325. </if>
  326. <if test="taskDeleteReasonLike != null">
  327. and RES.DELETE_REASON_ like #{taskDeleteReasonLike}
  328. </if>
  329. <if test="taskOwner != null">
  330. and RES.OWNER_ = #{taskOwner}
  331. </if>
  332. <if test="taskOwnerLike != null">
  333. and RES.OWNER_ like #{taskOwnerLike}
  334. </if>
  335. <if test="taskAssignee != null">
  336. and RES.ASSIGNEE_ = #{taskAssignee}
  337. </if>
  338. <if test="taskAssigneeLike != null">
  339. and RES.ASSIGNEE_ like #{taskAssigneeLike}
  340. </if>
  341. <if test="taskPriority != null">
  342. and RES.PRIORITY_ = #{taskPriority}
  343. </if>
  344. <if test="taskMinPriority != null">
  345. and RES.PRIORITY_ >= #{taskMinPriority}
  346. </if>
  347. <if test="taskMaxPriority != null">
  348. and RES.PRIORITY_ <= #{taskMaxPriority}
  349. </if>
  350. <if test="unfinished">
  351. and RES.END_TIME_ is null
  352. </if>
  353. <if test="finished">
  354. and RES.END_TIME_ is not null
  355. </if>
  356. <if test="processFinished">
  357. and HPI.END_TIME_ is not null
  358. </if>
  359. <if test="processUnfinished">
  360. and HPI.END_TIME_ is null
  361. </if>
  362. <if test="dueDate != null">
  363. and RES.DUE_DATE_ = #{dueDate}
  364. </if>
  365. <if test="dueBefore != null">
  366. and RES.DUE_DATE_ < #{dueBefore}
  367. </if>
  368. <if test="dueAfter != null">
  369. and RES.DUE_DATE_ > #{dueAfter}
  370. </if>
  371. <if test="withoutDueDate">
  372. and RES.DUE_DATE_ is null
  373. </if>
  374. <if test="creationDate != null">
  375. and RES.START_TIME_ = #{creationDate}
  376. </if>
  377. <if test="creationBeforeDate != null">
  378. and RES.START_TIME_ < #{creationBeforeDate}
  379. </if>
  380. <if test="creationAfterDate != null">
  381. and RES.START_TIME_ > #{creationAfterDate}
  382. </if>
  383. <if test="completedDate != null">
  384. and RES.END_TIME_ = #{completedDate}
  385. </if>
  386. <if test="completedBeforeDate != null">
  387. and RES.END_TIME_ < #{completedBeforeDate}
  388. </if>
  389. <if test="completedAfterDate != null">
  390. and RES.END_TIME_ > #{completedAfterDate}
  391. </if>
  392. <if test="category != null">
  393. and RES.CATEGORY_ = #{category}
  394. </if>
  395. <if test="tenantId != null">
  396. and RES.TENANT_ID_ = #{tenantId}
  397. </if>
  398. <if test="tenantIdLike != null">
  399. and RES.TENANT_ID_ like #{tenantIdLike}
  400. </if>
  401. <if test="withoutTenantId">
  402. and (RES.TENANT_ID_ = '' or RES.TENANT_ID_ is null)
  403. </if>
  404. <if test="candidateUser != null || candidateGroups != null">
  405. and RES.ASSIGNEE_ is null
  406. and HI.TYPE_ = 'candidate'
  407. and
  408. (
  409. <if test="candidateUser != null">
  410. HI.USER_ID_ = #{candidateUser}
  411. </if>
  412. <if test="candidateUser != null && candidateGroups != null && candidateGroups.size() > 0">
  413. or
  414. </if>
  415. <if test="candidateGroups != null && candidateGroups.size() > 0">
  416. HI.GROUP_ID_ IN
  417. <foreach item="group" index="index" collection="candidateGroups"
  418. open="(" separator="," close=")">
  419. #{group}
  420. </foreach>
  421. </if>
  422. )
  423. </if>
  424. <if test="involvedUser != null">
  425. and (
  426. exists(select LINK.USER_ID_ from ${prefix}ACT_HI_IDENTITYLINK LINK where USER_ID_ = #{involvedUser} and LINK.TASK_ID_ = RES.ID_)
  427. or RES.ASSIGNEE_ = #{involvedUser}
  428. or RES.OWNER_ = #{involvedUser}
  429. )
  430. </if>
  431. <foreach item="queryVar" collection="queryVariableValues" index="index">
  432. <if test="!queryVar.local">
  433. <!-- When process instance variable is queried for, taskId should be null -->
  434. and A${index}.TASK_ID_ is null
  435. </if>
  436. <if test="queryVar.name != null">
  437. <!-- Match-all variable-names when name is null -->
  438. and A${index}.NAME_= #{queryVar.name}
  439. </if>
  440. <if test="!queryVar.type.equals('null')">
  441. and A${index}.VAR_TYPE_ = #{queryVar.type}
  442. </if>
  443. <!-- Variable value -->
  444. <if test="queryVar.textValue != null && queryVar.longValue == null && queryVar.doubleValue == null">
  445. <choose>
  446. <when test="queryVar.operator.equals('EQUALS_IGNORE_CASE') || queryVar.operator.equals('NOT_EQUALS_IGNORE_CASE')">
  447. and lower(A${index}.TEXT_)
  448. </when>
  449. <otherwise>
  450. and A${index}.TEXT_
  451. </otherwise>
  452. </choose>
  453. <choose>
  454. <when test="queryVar.operator.equals('LIKE')">LIKE</when>
  455. <otherwise><include refid="executionVariableOperator" /></otherwise>
  456. </choose>
  457. #{queryVar.textValue}
  458. </if>
  459. <if test="queryVar.textValue2 != null">
  460. and A${index}.TEXT2_
  461. <choose>
  462. <when test="queryVar.operator.equals('LIKE')">LIKE</when>
  463. <otherwise><include refid="executionVariableOperator" /></otherwise>
  464. </choose>
  465. #{queryVar.textValue2}
  466. </if>
  467. <if test="queryVar.longValue != null">
  468. and A${index}.LONG_
  469. <include refid="executionVariableOperator" />
  470. #{queryVar.longValue}
  471. </if>
  472. <if test="queryVar.doubleValue != null">
  473. and A${index}.DOUBLE_
  474. <include refid="executionVariableOperator" />
  475. #{queryVar.doubleValue}
  476. </if>
  477. <!-- Null variable type -->
  478. <if test="queryVar.textValue == null && queryVar.textValue2 == null && queryVar.longValue == null && queryVar.doubleValue == null">
  479. <choose>
  480. <when test="queryVar.operator.equals('NOT_EQUALS')">
  481. and (A${index}.TEXT_ is not null or A${index}.TEXT2_ is not null or A${index}.LONG_ is not null or A${index}.DOUBLE_ is not null or A${index}.BYTEARRAY_ID_ is not null)
  482. </when>
  483. <otherwise>
  484. and A${index}.TEXT_ is null and A${index}.TEXT2_ is null and A${index}.LONG_ is null and A${index}.DOUBLE_ is null and A${index}.BYTEARRAY_ID_ is null
  485. </otherwise>
  486. </choose>
  487. </if>
  488. </foreach>
  489. </where>
  490. </sql>
  491.  
  492. <sql id="executionVariableOperator">
  493. <choose>
  494. <when test="queryVar.operator.equals('EQUALS')">=</when>
  495. <when test="queryVar.operator.equals('EQUALS_IGNORE_CASE')">=</when>
  496. <when test="queryVar.operator.equals('NOT_EQUALS')"><></when>
  497. <when test="queryVar.operator.equals('NOT_EQUALS_IGNORE_CASE')"><></when>
  498. <when test="queryVar.operator.equals('GREATER_THAN')">></when>
  499. <when test="queryVar.operator.equals('GREATER_THAN_OR_EQUAL')">>=</when>
  500. <when test="queryVar.operator.equals('LESS_THAN')"><</when>
  501. <when test="queryVar.operator.equals('LESS_THAN_OR_EQUAL')"><=</when>
  502. </choose>
  503. </sql>
  504.  
  505. <select id="selectHistoricTaskInstanceByNativeQuery" parameterType="java.util.Map" resultMap="historicTaskInstanceResultMap">
  506. <if test="resultType == 'LIST_PAGE'">
  507. ${limitBefore}
  508. </if>
  509. ${sql}
  510. <if test="resultType == 'LIST_PAGE'">
  511. ${limitAfter}
  512. </if>
  513. </select>
  514.  
  515. <select id="selectHistoricTaskInstanceByNativeQuery_mssql_or_db2" parameterType="java.util.Map" resultMap="historicTaskInstanceResultMap">
  516. <if test="resultType == 'LIST_PAGE'">
  517. ${limitBeforeNativeQuery}
  518. </if>
  519. ${sql}
  520. <if test="resultType == 'LIST_PAGE'">
  521. ${limitAfter}
  522. </if>
  523. </select>
  524.  
  525. <select id="selectHistoricTaskInstanceCountByNativeQuery" parameterType="java.util.Map" resultType="long">
  526. ${sql}
  527. </select>
  528. </mapper>

看了这些,如果你觉得你对activiti的底层有足够的了解,你可以完全重写或者扩展actviti中的service API。activiti就是通过这些sql映射配置来完成数据查询,当然如果你在使用过程中如果发现其中一些sql查询效率很低的话,大伙可以由针对的进行修改达到自己的要求。   现在网络上一些关于activiti也有类似的问题出现。大伙使用过程相信也会遇到。在这里就这样抛砖引玉,希望对初学的你有所帮助.......

http://blog.csdn.net/romantichjwhjwhjw/article/details/40650671

activiti数据库表结构全貌解析的更多相关文章

  1. Activiti数据库表结构(表详细版)

    http://blog.csdn.net/hj7jay/article/details/51302829 1  Activiti数据库表结构 1.1      数据库表名说明 Activiti工作流总 ...

  2. Activiti数据库表结构(23张表5.*版本)

    1  Activiti数据库表结构 1.1      数据库表名说明 Activiti工作流总共包含23张数据表,所有的表名默认以“ACT_”开头. 并且表名的第二部分用两个字母表明表的用例,而这个用 ...

  3. 15.5 自学Zabbix之路15.5 Zabbix数据库表结构简单解析-其他 表

    点击返回:自学Zabbix之路 自学Zabbix之路15.5 Zabbix数据库表结构简单解析-其他 表  1. Actions表 actions表记录了当触发器触发时,需要采用的动作. 2.Aler ...

  4. 自学Zabbix之路15.1 Zabbix数据库表结构简单解析-Hosts表、Hosts_groups表、Interface表

    点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 自学Zabbix之路15.1 Zabbix数据库表结构简单解析-Hosts表.Hosts_grou ...

  5. 自学Zabbix之路15.2 Zabbix数据库表结构简单解析-Items表

    点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 自学Zabbix之路15.2 Zabbix数据库表结构简单解析-Items表 Items表记录了i ...

  6. 自学Zabbix之路15.3 Zabbix数据库表结构简单解析-Triggers表、Applications表、 Mapplings表

    点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 自学Zabbix之路15.3 Zabbix数据库表结构简单解析-Triggers表.Applica ...

  7. 自学Zabbix之路15.4 Zabbix数据库表结构简单解析-Expressions表、Media表、 Events表

    点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 自学Zabbix之路15.4 Zabbix数据库表结构简单解析-Expressions表.Medi ...

  8. 自学Zabbix之路15.5 Zabbix数据库表结构简单解析-其他 表

    点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 自学Zabbix之路15.5 Zabbix数据库表结构简单解析-其他 表  1. Actions表 ...

  9. activiti数据库表结构剖析

    1.结构设计 1.1.    逻辑结构设计 Activiti使用到的表都是ACT_开头的. ACT_RE_*: ’RE’表示repository(存储),RepositoryService接口所操作的 ...

随机推荐

  1. 开个帖,开始学习shell编程

    恩,就这么开始了 首先说一下这个小小的插曲...写着写着,它就崩溃了,然后我也崩溃了...崩溃的我到处找一个不会让我崩溃的工具,然后找来找去就找到了scribefire. 1. 关于从Command ...

  2. JavaScript碰到的几个方法

    =>isNaN() 函数用于检查其参数|是否|是|非数字值. 绕吧,我给它断个句,别一不小心看叉了 百度百科告诉我们,NaN,是Not a Number的缩写 所以, alert(isNaN(1 ...

  3. C#获取文件的Md5值

            private string GetMd5(Stream fileStream)         {             MD5CryptoServiceProvider md5P ...

  4. ( 译、持续更新 ) JavaScript 上分小技巧(二)

    考虑到文章过长,不便于阅读,这里分出第二篇,如有后续,每15个知识点分为一篇... 第一篇地址:( 译.持续更新 ) JavaScript 上分小技巧(一) 第三篇地址:( 译.持续更新 ) Java ...

  5. 《JavaScript权威指南》学习笔记 第七天 DOM操作

    由衷的觉得,随着IT技术的广泛的运用,个人电脑以及智能手机的使用,信息的获取与传播更为简单.但是我们获取有用信息的难度相反是越来越大了,想要保持住自己的注意力越来越难了.除了吃饭睡觉,我的精力都在电脑 ...

  6. MongoDb学习1

    目标框架必须是 4.5以上,最新MongoDb.Driver 是 2.2.4(与MongoDb.Driver 的1.x版本差别较大) 官方文档 http://mongodb.github.io/mon ...

  7. html img src base64

    网页上有些图片的src或css背景图片的url后面跟了一大串字符,比如:data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAEAAAAkCAYAAABId ...

  8. git config --global core.autocrlf false

    git config --global core.autocrlf  false warning: LF will be replaced by CRLF in .idea/vcs.xml.The f ...

  9. UDP SOCKET网络通信 C#

    接收端 using System; using System.Net; using System.Net.Sockets; using System.Text; using System.Thread ...

  10. linux curl 命令详解,以及实例

    linux curl是一个利用URL规则在命令行下工作的文件传输工具.它支持文件的上传和下载,所以是综合传输工具,但按传统,习惯称url为下载工具. 一,curl命令参数,有好多我没有用过,也不知道翻 ...