Job.xml 14.3 KB
Newer Older
T
tombaeyens 已提交
1 2 3 4
<?xml version="1.0" encoding="UTF-8" ?> 

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 
  
T
tombaeyens 已提交
5
<mapper namespace="org.activiti.engine.impl.persistence.entity.JobEntity">
T
tombaeyens 已提交
6

7
  <!-- JOB DELETE STATEMENTS-->
T
tombaeyens 已提交
8

J
Joram Barrez 已提交
9 10
  <delete id="deleteJob" parameterType="org.activiti.engine.impl.persistence.entity.JobEntity">
    delete from ${prefix}ACT_RU_JOB where ID_ = #{id} and REV_ = #{revision}
T
tombaeyens 已提交
11 12
  </delete>
  
J
Joram Barrez 已提交
13 14
  <delete id="deleteTimer" parameterType="org.activiti.engine.impl.persistence.entity.JobEntity">
    delete from ${prefix}ACT_RU_JOB where ID_ = #{id} and REV_ = #{revision}
15 16
  </delete>
  
J
Joram Barrez 已提交
17 18
  <delete id="deleteMessage" parameterType="org.activiti.engine.impl.persistence.entity.JobEntity">
    delete from ${prefix}ACT_RU_JOB where ID_ = #{id} and REV_ = #{revision}
19 20
  </delete>
  
21 22 23 24 25 26 27 28 29 30 31 32 33
  <!-- JOB UPDATE STATEMENTS -->
  <update id="updateJobTenantIdForDeployment" parameterType="java.util.Map">
    update ${prefix}ACT_RU_JOB set
      TENANT_ID_ = #{tenantId, jdbcType=VARCHAR}
    where
      ID_ in (
        SELECT J.ID_ from ${prefix}ACT_RU_JOB J
        inner join ${prefix}ACT_RE_PROCDEF P on J.PROC_DEF_ID_  = P.ID_
        inner join ${prefix}ACT_RE_DEPLOYMENT D on P.DEPLOYMENT_ID_ = D.ID_ 
        where D.ID_ = #{deploymentId, jdbcType=VARCHAR}
      ) 
  </update>
  
T
tombaeyens 已提交
34
  <!-- JOB RESULTMAP (FOR TIMER AND MESSAGE) -->
T
tombaeyens 已提交
35

T
tombaeyens 已提交
36
  <resultMap id="jobResultMap" type="org.activiti.engine.impl.persistence.entity.JobEntity">
T
tombaeyens 已提交
37
    <id property="id" column="ID_" jdbcType="VARCHAR" />
38
    <result property="revision" column="REV_" jdbcType="INTEGER" />
T
tombaeyens 已提交
39 40 41 42 43
    <result property="lockOwner" column="LOCK_OWNER_" jdbcType="VARCHAR" />
    <result property="lockExpirationTime" column="LOCK_EXP_TIME_" jdbcType="TIMESTAMP" />
    <result property="exclusive" column="EXCLUSIVE_" jdbcType="BOOLEAN" />
    <result property="executionId" column="EXECUTION_ID_" jdbcType="VARCHAR" />
    <result property="processInstanceId" column="PROCESS_INSTANCE_ID_" jdbcType="VARCHAR" />
44
    <result property="processDefinitionId" column="PROC_DEF_ID_" jdbcType="VARCHAR" />
T
tombaeyens 已提交
45
    <result property="retries" column="RETRIES_" jdbcType="INTEGER" />
M
Marcus Klimstra 已提交
46
    <result property="exceptionByteArrayRef" column="EXCEPTION_STACK_ID_" typeHandler="ByteArrayRefTypeHandler" />
47
    <result property="exceptionMessage" column="EXCEPTION_MSG_" jdbcType="VARCHAR" />
T
tombaeyens 已提交
48 49
    <result property="jobHandlerType" column="HANDLER_TYPE_" jdbcType="VARCHAR" />
    <result property="jobHandlerConfiguration" column="HANDLER_CFG_" jdbcType="VARCHAR" />
50
    <result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR" />
T
tombaeyens 已提交
51 52 53 54 55 56
    <discriminator javaType="string" column="TYPE_">
      <case value="message" resultMap="messageResultMap"/> 
      <case value="timer" resultMap="timerResultMap"/> 
    </discriminator>
  </resultMap>

T
tombaeyens 已提交
57
  <resultMap id="messageResultMap" type="org.activiti.engine.impl.persistence.entity.MessageEntity" extends="jobResultMap"/>
T
tombaeyens 已提交
58

T
tombaeyens 已提交
59
  <resultMap id="timerResultMap" type="org.activiti.engine.impl.persistence.entity.TimerEntity" extends="jobResultMap">
T
tombaeyens 已提交
60 61 62 63
    <result property="duedate" column="DUEDATE_" jdbcType="TIMESTAMP" />
    <result property="repeat" column="REPEAT_" jdbcType="VARCHAR" />
  </resultMap>

T
tombaeyens 已提交
64
  <!-- JOB SELECT (FOR TIMER AND MESSAGE) -->  
T
tombaeyens 已提交
65 66

  <select id="selectJob" parameterType="string" resultMap="jobResultMap">
M
meyerd 已提交
67
    select * from ${prefix}ACT_RU_JOB where ID_ = #{id}
T
tombaeyens 已提交
68 69
  </select>

70 71
  <select id="selectNextJobsToExecute" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="jobResultMap">
  	${limitBefore}
72
    select 
73 74 75 76 77 78
    	RES.* ${limitBetween}    		
    from ${prefix}ACT_RU_JOB RES    
    	LEFT OUTER JOIN ${prefix}ACT_RU_EXECUTION PI ON PI.ID_ = RES.PROCESS_INSTANCE_ID_
    where (RES.RETRIES_ &gt; 0)
      and (RES.DUEDATE_ is null or RES.DUEDATE_ &lt; #{parameter, jdbcType=TIMESTAMP})
      and (RES.LOCK_OWNER_ is null or RES.LOCK_EXP_TIME_ &lt; #{parameter, jdbcType=TIMESTAMP})
79
	  and (
80
	  	    (RES.EXECUTION_ID_ is null)
81 82
	  		or 
	  		(PI.SUSPENSION_STATE_ = 1)
83 84
      )  
    ${limitAfter}	    
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
  </select>     
  
  <!--  ACT-1064: MySQL-specific select's are needed to handle non-millisecond precision -->
  <select id="selectNextJobsToExecute_mysql" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="jobResultMap">
    ${limitBefore}
    select RES.* ${limitBetween} 
    from ${prefix}ACT_RU_JOB RES
      LEFT OUTER JOIN ${prefix}ACT_RU_EXECUTION PI ON PI.ID_ = RES.PROCESS_INSTANCE_ID_
    where (RETRIES_ &gt; 0)
      and (DUEDATE_ is null or DUEDATE_ &lt;= #{parameter, jdbcType=TIMESTAMP})
      and (LOCK_OWNER_ is null or LOCK_EXP_TIME_ &lt;= #{parameter, jdbcType=TIMESTAMP})
      and (
          (RES.EXECUTION_ID_ is null)
        or 
        (PI.SUSPENSION_STATE_ = 1)     
      )  
    ${limitAfter}
  </select>              
103

104 105
  <select id="selectExclusiveJobsToExecute" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="jobResultMap">
  	${limitBefore}
106 107
    select RES.* ${limitBetween} 
    from ${prefix}ACT_RU_JOB RES    
M
meyerd 已提交
108
    where (RETRIES_ &gt; 0)
109 110
      and (DUEDATE_ is null or DUEDATE_ &lt; #{parameter.now, jdbcType=TIMESTAMP})
      and (LOCK_OWNER_ is null or LOCK_EXP_TIME_ &lt; #{parameter.now, jdbcType=TIMESTAMP})
M
meyerd 已提交
111
      and (EXCLUSIVE_ = TRUE)
112 113
      and (PROCESS_INSTANCE_ID_ = #{parameter.pid})  
    ${limitAfter}
M
meyerd 已提交
114 115
  </select>
  
116 117 118 119 120 121 122 123 124 125 126 127
  <select id="selectExclusiveJobsToExecute_mysql" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="jobResultMap">
    ${limitBefore}
    select RES.* ${limitBetween} 
    from ${prefix}ACT_RU_JOB RES
    where (RETRIES_ &gt; 0)
      and (DUEDATE_ is null or DUEDATE_ &lt;= #{parameter.now, jdbcType=TIMESTAMP})
      and (LOCK_OWNER_ is null or LOCK_EXP_TIME_ &lt;= #{parameter.now, jdbcType=TIMESTAMP})
      and (EXCLUSIVE_ = TRUE)
      and (PROCESS_INSTANCE_ID_ = #{parameter.pid})
    ${limitAfter}
  </select>
  
128 129
  <select id="selectExclusiveJobsToExecute_integerBoolean" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="jobResultMap">
  	${limitBefore}
130 131
    select RES.* ${limitBetween} 
    from ${prefix}ACT_RU_JOB RES  
M
meyerd 已提交
132
    where (RETRIES_ &gt; 0)
133 134
      and (DUEDATE_ is null or DUEDATE_ &lt; #{parameter.now, jdbcType=TIMESTAMP})
      and (LOCK_OWNER_ is null or LOCK_EXP_TIME_ &lt; #{parameter.now, jdbcType=TIMESTAMP})
M
meyerd 已提交
135
      and (EXCLUSIVE_ = 1)
136 137
      and (PROCESS_INSTANCE_ID_ = #{parameter.pid})  
    ${limitAfter}   
M
meyerd 已提交
138 139
  </select>
  
140
  <select id="selectJobsByConfiguration" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="jobResultMap">
M
meyerd 已提交
141
      select * from ${prefix}ACT_RU_JOB
142 143
      where HANDLER_TYPE_ = #{parameter.handlerType}
      and HANDLER_CFG_ =  #{parameter.handlerConfiguration}
M
ACT-551  
mproch 已提交
144
  </select>
145

146
  <select id="selectJobsByExecutionId" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="jobResultMap">
147
    select *
M
meyerd 已提交
148
    from ${prefix}ACT_RU_JOB J
149
    where J.EXECUTION_ID_ = #{parameter}
150
  </select>
M
ACT-551  
mproch 已提交
151

T
tombaeyens 已提交
152
  <select id="selectJobByQueryCriteria" parameterType="org.activiti.engine.impl.JobQueryImpl" resultMap="jobResultMap">
153
  	${limitBefore}
154
    select RES.* ${limitBetween}
T
tombaeyens 已提交
155
    <include refid="selectJobByQueryCriteriaSql"/>
156
    ${orderBy}
157
    ${limitAfter}
T
tombaeyens 已提交
158 159
  </select>

T
tombaeyens 已提交
160
  <select id="selectJobCountByQueryCriteria" parameterType="org.activiti.engine.impl.JobQueryImpl" resultType="long">
161
    select count(distinct RES.ID_)
T
tombaeyens 已提交
162
    <include refid="selectJobByQueryCriteriaSql"/>
T
tombaeyens 已提交
163 164
  </select>
  
T
tombaeyens 已提交
165
  <sql id="selectJobByQueryCriteriaSql">
166
    from ${prefix}ACT_RU_JOB RES
167 168 169
    <if test="executable">
        LEFT OUTER JOIN ${prefix}ACT_RU_EXECUTION PI ON PI.ID_ = RES.PROCESS_INSTANCE_ID_
    </if>
T
tombaeyens 已提交
170
    <where>
J
jbarrez 已提交
171
      <if test="id != null">
172
        RES.ID_ = #{id}
J
jbarrez 已提交
173
      </if>
T
tombaeyens 已提交
174
      <if test="processInstanceId != null">
175
        and RES.PROCESS_INSTANCE_ID_ = #{processInstanceId}
T
tombaeyens 已提交
176
      </if>
T
tombaeyens 已提交
177
      <if test="executionId != null">
178
        and RES.EXECUTION_ID_ = #{executionId}
T
tombaeyens 已提交
179
      </if>
180 181 182
      <if test="processDefinitionId != null">
        and RES.PROC_DEF_ID_ = #{processDefinitionId}
      </if>
183
      <if test="retriesLeft">
184
        and RES.RETRIES_ &gt; 0
185 186
      </if>
      <if test="executable">
187 188
        and (RES.RETRIES_ &gt; 0)
        and (RES.DUEDATE_ is null or RES.DUEDATE_ &lt;= #{now, jdbcType=TIMESTAMP})
189 190 191 192 193
        and (
            (RES.EXECUTION_ID_ is null)
            or 
            (PI.SUSPENSION_STATE_ = 1)     
      )
J
jbarrez 已提交
194 195
      </if>
      <if test="onlyTimers">
196
        and RES.TYPE_ = 'timer'
J
jbarrez 已提交
197 198
      </if>
      <if test="onlyMessages">
199
        and RES.TYPE_ = 'message'
J
jbarrez 已提交
200
      </if>
201 202
      <if test="duedateHigherThan != null">
        and RES.DUEDATE_ &gt; #{duedateHigherThan}
J
jbarrez 已提交
203
      </if>
204 205
      <if test="duedateLowerThan != null">
        and RES.DUEDATE_ &lt; #{duedateLowerThan}
J
jbarrez 已提交
206
      </if>
207 208
      <if test="duedateHigherThanOrEqual != null">
        and RES.DUEDATE_ &gt;= #{duedateHigherThanOrEqual}
J
jbarrez 已提交
209
      </if>
210 211
      <if test="duedateLowerThanOrEqual != null">
        and RES.DUEDATE_ &lt;= #{duedateLowerThanOrEqual}
212
      </if>
F
falko.menge 已提交
213
      <if test="withException">
214
      	and (RES.EXCEPTION_MSG_ is not null or RES.EXCEPTION_STACK_ID_ is not null)
F
falko.menge 已提交
215
      </if>
216
      <if test="exceptionMessage">
217
      	and RES.EXCEPTION_MSG_ = #{exceptionMessage}
218
      </if>
219 220 221 222 223 224 225 226 227
      <if test="tenantId != null">
        and RES.TENANT_ID_ = #{tenantId}
      </if>
      <if test="tenantIdLike != null">
        and RES.TENANT_ID_ like #{tenantIdLike}
      </if>
      <if test="withoutTenantId">
        and RES.TENANT_ID_ is null
      </if>
T
tombaeyens 已提交
228 229 230
    </where>
  </sql>

T
tombaeyens 已提交
231
  <!-- TIMER INSERT -->
T
tombaeyens 已提交
232
  
T
tombaeyens 已提交
233
  <insert id="insertTimer" parameterType="org.activiti.engine.impl.persistence.entity.TimerEntity">
M
meyerd 已提交
234
    insert into ${prefix}ACT_RU_JOB (
T
tombaeyens 已提交
235
            ID_, 
236
            REV_,
T
tombaeyens 已提交
237 238 239 240 241 242
            TYPE_,
            LOCK_OWNER_, 
            LOCK_EXP_TIME_,
            EXCLUSIVE_,
            EXECUTION_ID_, 
            PROCESS_INSTANCE_ID_,
243
            PROC_DEF_ID_,
T
tombaeyens 已提交
244
            RETRIES_, 
245 246
            EXCEPTION_STACK_ID_,
            EXCEPTION_MSG_,
T
tombaeyens 已提交
247 248 249
            DUEDATE_,
            REPEAT_,
            HANDLER_TYPE_,
250 251
            HANDLER_CFG_,
            TENANT_ID_)
T
tombaeyens 已提交
252
    values (#{id, jdbcType=VARCHAR},
253
            1,
T
tombaeyens 已提交
254 255 256 257 258 259
            'timer',
            #{lockOwner, jdbcType=VARCHAR},
            #{lockExpirationTime, jdbcType=TIMESTAMP},
            #{exclusive, jdbcType=BOOLEAN},
            #{executionId, jdbcType=VARCHAR},
            #{processInstanceId, jdbcType=VARCHAR},
260
            #{processDefinitionId, jdbcType=VARCHAR},
T
tombaeyens 已提交
261
            #{retries, jdbcType=INTEGER},
M
Marcus Klimstra 已提交
262
            #{exceptionByteArrayRef, typeHandler=ByteArrayRefTypeHandler},
263
            #{exceptionMessage, jdbcType=VARCHAR},
T
tombaeyens 已提交
264 265 266
            #{duedate, jdbcType=TIMESTAMP},
            #{repeat, jdbcType=VARCHAR},
            #{jobHandlerType, jdbcType=VARCHAR},
267 268
            #{jobHandlerConfiguration, jdbcType=VARCHAR},
            #{tenantId, jdbcType=VARCHAR}
T
tombaeyens 已提交
269 270 271
    )
  </insert>

T
tombaeyens 已提交
272 273
  <!-- TIMER UPDATE -->

T
tombaeyens 已提交
274
  <update id="updateTimer" parameterType="org.activiti.engine.impl.persistence.entity.TimerEntity">
M
meyerd 已提交
275
    update ${prefix}ACT_RU_JOB
T
tombaeyens 已提交
276
    <set>
277
       REV_ =  #{revisionNext, jdbcType=INTEGER},
T
tombaeyens 已提交
278 279 280
       LOCK_EXP_TIME_ = #{lockExpirationTime, jdbcType=TIMESTAMP},
       LOCK_OWNER_ = #{lockOwner, jdbcType=VARCHAR},
       RETRIES_ = #{retries, jdbcType=INTEGER},
M
Marcus Klimstra 已提交
281
       EXCEPTION_STACK_ID_ = #{exceptionByteArrayRef, typeHandler=ByteArrayRefTypeHandler},
282
       EXCEPTION_MSG_ = #{exceptionMessage, jdbcType=VARCHAR},
T
tombaeyens 已提交
283 284 285
       DUEDATE_ = #{duedate, jdbcType=TIMESTAMP}
    </set>
    where ID_= #{id, jdbcType=VARCHAR}
286
      and REV_ = #{revision, jdbcType=INTEGER}
T
tombaeyens 已提交
287 288 289 290
  </update>
  
  <!-- TIMER SELECT -->
  
291
  <select id="selectUnlockedTimersByDuedate" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="jobResultMap">
292 293 294 295 296 297 298 299 300 301 302 303 304
    select RES.*
    from ${prefix}ACT_RU_JOB RES
    LEFT OUTER JOIN ${prefix}ACT_RU_EXECUTION PI ON PI.ID_ = RES.PROCESS_INSTANCE_ID_
    where (RES.TYPE_ = 'timer')
      and (RES.DUEDATE_ is not null)
      and (RES.DUEDATE_ &lt; #{parameter, jdbcType=TIMESTAMP})
      and (RES.LOCK_OWNER_ is null or RES.LOCK_EXP_TIME_ &lt; #{parameter, jdbcType=TIMESTAMP})
      and (RES.RETRIES_  &gt; 0)
      and (
        (RES.EXECUTION_ID_ is null)
        or 
        (PI.SUSPENSION_STATE_ = 1)    
      )
T
tombaeyens 已提交
305 306 307
    order by DUEDATE_
  </select>

308
  <select id="selectTimersByExecutionId" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="jobResultMap">
T
tombaeyens 已提交
309
    select * 
M
meyerd 已提交
310
    from ${prefix}ACT_RU_JOB 
T
tombaeyens 已提交
311 312
    where (RETRIES_ &gt; 0)
      and (TYPE_ = 'timer')
313
      and (EXECUTION_ID_ = #{parameter})
T
tombaeyens 已提交
314 315 316 317 318
  </select>
  

  <!-- MESSAGE INSERT -->

T
tombaeyens 已提交
319
  <insert id="insertMessage" parameterType="org.activiti.engine.impl.persistence.entity.MessageEntity">
M
meyerd 已提交
320
    insert into ${prefix}ACT_RU_JOB (
T
tombaeyens 已提交
321
            ID_, 
322
            REV_, 
T
tombaeyens 已提交
323 324 325 326 327 328
            TYPE_,
            LOCK_OWNER_, 
            LOCK_EXP_TIME_,
            EXCLUSIVE_,
            EXECUTION_ID_, 
            PROCESS_INSTANCE_ID_,
329
            PROC_DEF_ID_,
T
tombaeyens 已提交
330
            RETRIES_, 
331 332
            EXCEPTION_STACK_ID_,
            EXCEPTION_MSG_,
T
tombaeyens 已提交
333
            HANDLER_TYPE_,
334 335
            HANDLER_CFG_,
            TENANT_ID_)
T
tombaeyens 已提交
336
    values (#{id, jdbcType=VARCHAR},
337
            1,
T
tombaeyens 已提交
338 339 340 341 342 343
            'message',
            #{lockOwner, jdbcType=VARCHAR},
            #{lockExpirationTime, jdbcType=TIMESTAMP},
            #{exclusive, jdbcType=BOOLEAN},
            #{executionId, jdbcType=VARCHAR},
            #{processInstanceId, jdbcType=VARCHAR},
344
            #{processDefinitionId, jdbcType=VARCHAR},
T
tombaeyens 已提交
345
            #{retries, jdbcType=INTEGER},
M
Marcus Klimstra 已提交
346
            #{exceptionByteArrayRef, typeHandler=ByteArrayRefTypeHandler},
347
            #{exceptionMessage, jdbcType=VARCHAR},
T
tombaeyens 已提交
348
            #{jobHandlerType, jdbcType=VARCHAR},
349 350
            #{jobHandlerConfiguration, jdbcType=VARCHAR},
            #{tenantId, jdbcType=VARCHAR}
T
tombaeyens 已提交
351 352 353
    )
  </insert>
  
T
tombaeyens 已提交
354
  <!-- MESSAGE UPDATE -->
T
tombaeyens 已提交
355
  
T
tombaeyens 已提交
356
  <update id="updateMessage" parameterType="org.activiti.engine.impl.persistence.entity.MessageEntity">
M
meyerd 已提交
357
    update ${prefix}ACT_RU_JOB
T
tombaeyens 已提交
358
    <set>
359
       REV_ =  #{revisionNext, jdbcType=INTEGER},
T
tombaeyens 已提交
360 361 362
       LOCK_EXP_TIME_ = #{lockExpirationTime, jdbcType=TIMESTAMP},
       LOCK_OWNER_ = #{lockOwner, jdbcType=VARCHAR},
       RETRIES_ = #{retries, jdbcType=INTEGER},
M
Marcus Klimstra 已提交
363
       EXCEPTION_STACK_ID_ = #{exceptionByteArrayRef, typeHandler=ByteArrayRefTypeHandler},
364
       EXCEPTION_MSG_ = #{exceptionMessage, jdbcType=VARCHAR}
T
tombaeyens 已提交
365 366
    </set>
    where ID_= #{id, jdbcType=VARCHAR}
367
      and REV_ = #{revision, jdbcType=INTEGER}
T
tombaeyens 已提交
368 369 370
  </update>

</mapper>