Job.xml 9.2 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

T
tombaeyens 已提交
7 8 9
  <!-- JOB DELETE (FOR TIMER AND MESSAGE) -->

  <delete id="deleteJob" parameterType="string">
10
    delete from ACT_RU_JOB where ID_ = #{id}
T
tombaeyens 已提交
11 12 13
  </delete>
  
  <!-- JOB RESULTMAP (FOR TIMER AND MESSAGE) -->
T
tombaeyens 已提交
14

T
tombaeyens 已提交
15
  <resultMap id="jobResultMap" type="org.activiti.engine.impl.persistence.entity.JobEntity">
T
tombaeyens 已提交
16
    <id property="id" column="ID_" jdbcType="VARCHAR" />
17
    <result property="revision" column="REV_" jdbcType="INTEGER" />
T
tombaeyens 已提交
18 19 20 21 22 23
    <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" />
    <result property="retries" column="RETRIES_" jdbcType="INTEGER" />
24 25
    <result property="exceptionByteArrayId" column="EXCEPTION_STACK_ID_" jdbcType="VARCHAR" />
    <result property="exceptionMessage" column="EXCEPTION_MSG_" jdbcType="VARCHAR" />
T
tombaeyens 已提交
26 27 28 29 30 31 32 33
    <result property="jobHandlerType" column="HANDLER_TYPE_" jdbcType="VARCHAR" />
    <result property="jobHandlerConfiguration" column="HANDLER_CFG_" jdbcType="VARCHAR" />
    <discriminator javaType="string" column="TYPE_">
      <case value="message" resultMap="messageResultMap"/> 
      <case value="timer" resultMap="timerResultMap"/> 
    </discriminator>
  </resultMap>

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

T
tombaeyens 已提交
36
  <resultMap id="timerResultMap" type="org.activiti.engine.impl.persistence.entity.TimerEntity" extends="jobResultMap">
T
tombaeyens 已提交
37 38 39 40
    <result property="duedate" column="DUEDATE_" jdbcType="TIMESTAMP" />
    <result property="repeat" column="REPEAT_" jdbcType="VARCHAR" />
  </resultMap>

T
tombaeyens 已提交
41
  <!-- JOB SELECT (FOR TIMER AND MESSAGE) -->  
T
tombaeyens 已提交
42
  <select id="selectJobs" resultMap="jobResultMap">
43
    select * from ACT_RU_JOB
T
tombaeyens 已提交
44 45 46
  </select>

  <select id="selectJob" parameterType="string" resultMap="jobResultMap">
47
    select * from ACT_RU_JOB where ID_ = #{id}
T
tombaeyens 已提交
48 49 50 51
  </select>

  <select id="selectNextJobsToExecute" parameterType="string" resultMap="jobResultMap">
    select * 
52
    from ACT_RU_JOB 
T
tombaeyens 已提交
53 54 55
    where (RETRIES_ &gt; 0)
      and (DUEDATE_ is null or DUEDATE_ &lt; #{now, jdbcType=TIMESTAMP})
      and (LOCK_OWNER_ is null or LOCK_EXP_TIME_ &lt; #{now, jdbcType=TIMESTAMP})
T
tombaeyens 已提交
56
      and (RETRIES_ &gt; 0)
T
tombaeyens 已提交
57
  </select>
58 59 60
  
  <select id="selectLockedJobs" resultMap="jobResultMap">
    select * 
61
    from ACT_RU_JOB
62 63 64
    where (RETRIES_ &gt; 0)
      and (LOCK_OWNER_ is not null)
  </select>
T
tombaeyens 已提交
65

M
ACT-551  
mproch 已提交
66 67 68 69 70 71
  <select id="selectJobsByConfiguration" parameterType="map" resultMap="jobResultMap">
      select * from ACT_RU_JOB
      where HANDLER_TYPE_ = #{handlerType}
      and HANDLER_CFG_ =  #{handlerConfiguration}
  </select>

T
tombaeyens 已提交
72
  <select id="selectJobByQueryCriteria" parameterType="org.activiti.engine.impl.JobQueryImpl" resultMap="jobResultMap">
73
    select *
T
tombaeyens 已提交
74
    <include refid="selectJobByQueryCriteriaSql"/>
75 76 77
    <if test="orderBy != null">
    	order by ${orderBy}
    </if>
T
tombaeyens 已提交
78 79
  </select>

T
tombaeyens 已提交
80
  <select id="selectJobCountByQueryCriteria" parameterType="org.activiti.engine.impl.JobQueryImpl" resultType="long">
T
tombaeyens 已提交
81
    select count(distinct ID_)
T
tombaeyens 已提交
82
    <include refid="selectJobByQueryCriteriaSql"/>
T
tombaeyens 已提交
83 84
  </select>
  
T
tombaeyens 已提交
85
  <sql id="selectJobByQueryCriteriaSql">
J
jbarrez 已提交
86
    from ACT_RU_JOB J
T
tombaeyens 已提交
87
    <where>
J
jbarrez 已提交
88 89 90
      <if test="id != null">
        J.ID_ = #{id}
      </if>
T
tombaeyens 已提交
91
      <if test="processInstanceId != null">
J
jbarrez 已提交
92
        and J.PROCESS_INSTANCE_ID_ = #{processInstanceId}
T
tombaeyens 已提交
93
      </if>
T
tombaeyens 已提交
94
      <if test="executionId != null">
J
jbarrez 已提交
95
        and J.EXECUTION_ID_ = #{executionId}
T
tombaeyens 已提交
96
      </if>
97
      <if test="retriesLeft">
J
jbarrez 已提交
98
        and J.RETRIES_ &gt; 0
99 100
      </if>
      <if test="executable">
J
jbarrez 已提交
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
        (J.RETRIES_ &gt; 0)
        and (J.DUEDATE_ is null or J.DUEDATE_ &lt;= #{now, jdbcType=TIMESTAMP})
      </if>
      <if test="onlyTimers">
        and J.TYPE_ = 'timer'
      </if>
      <if test="onlyMessages">
        and J.TYPE_ = 'message'
      </if>
      <if test="duedateHigherThen != null">
        and J.DUEDATE_ &gt; #{duedateHigherThen}
      </if>
      <if test="duedateLowerThen != null">
        and J.DUEDATE_ &lt; #{duedateLowerThen}
      </if>
      <if test="duedateHigherThenOrEqual != null">
        and J.DUEDATE_ &gt;= #{duedateHigherThenOrEqual}
      </if>
      <if test="duedateLowerThenOrEqual != null">
        and J.DUEDATE_ &lt;= #{duedateLowerThenOrEqual}
121
      </if>
T
tombaeyens 已提交
122 123 124
    </where>
  </sql>

T
tombaeyens 已提交
125
  <!--  SELECT DEPENDENT -->  
126 127
   <select id="selectNextJobsToExecute_mysql" parameterType="string" resultMap="jobResultMap">
    select * 
128
    from ACT_RU_JOB 
129 130 131 132 133 134
    where (RETRIES_ &gt; 0)
      and (DUEDATE_ is null or DUEDATE_ &lt;= #{now, jdbcType=TIMESTAMP})
      and (LOCK_OWNER_ is null or LOCK_EXP_TIME_ &lt;= #{now, jdbcType=TIMESTAMP})
  </select>
  

T
tombaeyens 已提交
135 136

  <!-- TIMER INSERT -->
T
tombaeyens 已提交
137
  
T
tombaeyens 已提交
138
  <insert id="insertTimer" parameterType="org.activiti.engine.impl.persistence.entity.TimerEntity">
139
    insert into ACT_RU_JOB (
T
tombaeyens 已提交
140
            ID_, 
141
            REV_,
T
tombaeyens 已提交
142 143 144 145 146 147 148
            TYPE_,
            LOCK_OWNER_, 
            LOCK_EXP_TIME_,
            EXCLUSIVE_,
            EXECUTION_ID_, 
            PROCESS_INSTANCE_ID_,
            RETRIES_, 
149 150
            EXCEPTION_STACK_ID_,
            EXCEPTION_MSG_,
T
tombaeyens 已提交
151 152 153 154 155
            DUEDATE_,
            REPEAT_,
            HANDLER_TYPE_,
            HANDLER_CFG_ )
    values (#{id, jdbcType=VARCHAR},
156
            1,
T
tombaeyens 已提交
157 158 159 160 161 162 163
            'timer',
            #{lockOwner, jdbcType=VARCHAR},
            #{lockExpirationTime, jdbcType=TIMESTAMP},
            #{exclusive, jdbcType=BOOLEAN},
            #{executionId, jdbcType=VARCHAR},
            #{processInstanceId, jdbcType=VARCHAR},
            #{retries, jdbcType=INTEGER},
164 165
            #{exceptionByteArrayId, jdbcType=VARCHAR},
            #{exceptionMessage, jdbcType=VARCHAR},
T
tombaeyens 已提交
166 167 168 169 170 171 172
            #{duedate, jdbcType=TIMESTAMP},
            #{repeat, jdbcType=VARCHAR},
            #{jobHandlerType, jdbcType=VARCHAR},
            #{jobHandlerConfiguration, jdbcType=VARCHAR}
    )
  </insert>

T
tombaeyens 已提交
173 174
  <!-- TIMER UPDATE -->

T
tombaeyens 已提交
175
  <update id="updateTimer" parameterType="org.activiti.engine.impl.persistence.entity.TimerEntity">
176
    update ACT_RU_JOB
T
tombaeyens 已提交
177
    <set>
178
       REV_ =  #{revisionNext, jdbcType=INTEGER},
T
tombaeyens 已提交
179 180 181
       LOCK_EXP_TIME_ = #{lockExpirationTime, jdbcType=TIMESTAMP},
       LOCK_OWNER_ = #{lockOwner, jdbcType=VARCHAR},
       RETRIES_ = #{retries, jdbcType=INTEGER},
182 183
       EXCEPTION_STACK_ID_ = #{exceptionByteArrayId, jdbcType=VARCHAR},
       EXCEPTION_MSG_ = #{exceptionMessage, jdbcType=VARCHAR},
T
tombaeyens 已提交
184 185 186
       DUEDATE_ = #{duedate, jdbcType=TIMESTAMP}
    </set>
    where ID_= #{id, jdbcType=VARCHAR}
187
      and REV_ = #{revision, jdbcType=INTEGER}
T
tombaeyens 已提交
188 189 190 191 192 193
  </update>
  
  <!-- TIMER SELECT -->
  
  <select id="selectUnlockedTimersByDuedate" parameterType="date" resultMap="jobResultMap">
    select *
194
    from ACT_RU_JOB
T
tombaeyens 已提交
195 196 197 198 199 200 201 202 203 204
    where (TYPE_ = 'timer')
      and (DUEDATE_ is not null)
      and (DUEDATE_ &lt; #{duedate, jdbcType=TIMESTAMP})
      and (LOCK_OWNER_ is null or LOCK_EXP_TIME_ &lt; #{duedate, jdbcType=TIMESTAMP})
      and (RETRIES_  &gt; 0)
    order by DUEDATE_
  </select>

  <select id="selectTimersByExecutionId" parameterType="string" resultMap="jobResultMap">
    select * 
205
    from ACT_RU_JOB 
T
tombaeyens 已提交
206 207 208 209 210 211 212 213
    where (RETRIES_ &gt; 0)
      and (TYPE_ = 'timer')
      and (EXECUTION_ID_ = #{executionId})
  </select>
  

  <!-- MESSAGE INSERT -->

T
tombaeyens 已提交
214
  <insert id="insertMessage" parameterType="org.activiti.engine.impl.persistence.entity.MessageEntity">
215
    insert into ACT_RU_JOB (
T
tombaeyens 已提交
216
            ID_, 
217
            REV_, 
T
tombaeyens 已提交
218 219 220 221 222 223 224
            TYPE_,
            LOCK_OWNER_, 
            LOCK_EXP_TIME_,
            EXCLUSIVE_,
            EXECUTION_ID_, 
            PROCESS_INSTANCE_ID_,
            RETRIES_, 
225 226
            EXCEPTION_STACK_ID_,
            EXCEPTION_MSG_,
T
tombaeyens 已提交
227 228 229
            HANDLER_TYPE_,
            HANDLER_CFG_)
    values (#{id, jdbcType=VARCHAR},
230
            1,
T
tombaeyens 已提交
231 232 233 234 235 236 237
            'message',
            #{lockOwner, jdbcType=VARCHAR},
            #{lockExpirationTime, jdbcType=TIMESTAMP},
            #{exclusive, jdbcType=BOOLEAN},
            #{executionId, jdbcType=VARCHAR},
            #{processInstanceId, jdbcType=VARCHAR},
            #{retries, jdbcType=INTEGER},
238 239
            #{exceptionByteArrayId, jdbcType=VARCHAR},
            #{exceptionMessage, jdbcType=VARCHAR},
T
tombaeyens 已提交
240 241 242 243 244
            #{jobHandlerType, jdbcType=VARCHAR},
            #{jobHandlerConfiguration, jdbcType=VARCHAR}
    )
  </insert>
  
T
tombaeyens 已提交
245
  <!-- MESSAGE UPDATE -->
T
tombaeyens 已提交
246
  
T
tombaeyens 已提交
247
  <update id="updateMessage" parameterType="org.activiti.engine.impl.persistence.entity.MessageEntity">
248
    update ACT_RU_JOB
T
tombaeyens 已提交
249
    <set>
250
       REV_ =  #{revisionNext, jdbcType=INTEGER},
T
tombaeyens 已提交
251 252 253
       LOCK_EXP_TIME_ = #{lockExpirationTime, jdbcType=TIMESTAMP},
       LOCK_OWNER_ = #{lockOwner, jdbcType=VARCHAR},
       RETRIES_ = #{retries, jdbcType=INTEGER},
254 255
       EXCEPTION_STACK_ID_ = #{exceptionByteArrayId, jdbcType=VARCHAR},
       EXCEPTION_MSG_ = #{exceptionMessage, jdbcType=VARCHAR}
T
tombaeyens 已提交
256 257
    </set>
    where ID_= #{id, jdbcType=VARCHAR}
258
      and REV_ = #{revision, jdbcType=INTEGER}
T
tombaeyens 已提交
259 260 261
  </update>

</mapper>