All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.activiti.db.mapping.entity.Job.xml Maven / Gradle / Ivy

<?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">

<mapper namespace="org.activiti.engine.impl.persistence.entity.JobEntityImpl">

	<!-- JOB RESULTMAP -->

	<resultMap id="jobResultMap" type="org.activiti.engine.impl.persistence.entity.JobEntityImpl">
		<id property="id" column="ID_" jdbcType="VARCHAR" />
		<result property="revision" column="REV_" jdbcType="INTEGER" />
		<result property="jobType" column="TYPE_" jdbcType="VARCHAR" />
		<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="processDefinitionId" column="PROC_DEF_ID_" jdbcType="VARCHAR" />
		<result property="retries" column="RETRIES_" jdbcType="INTEGER" />
		<result property="exceptionByteArrayRef" column="EXCEPTION_STACK_ID_" typeHandler="ByteArrayRefTypeHandler" />
		<result property="exceptionMessage" column="EXCEPTION_MSG_" jdbcType="VARCHAR" />
		<result property="jobHandlerType" column="HANDLER_TYPE_" jdbcType="VARCHAR" />
		<result property="jobHandlerConfiguration" column="HANDLER_CFG_" jdbcType="VARCHAR" />
		<result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR" />
		<result property="duedate" column="DUEDATE_" jdbcType="TIMESTAMP" />
		<result property="repeat" column="REPEAT_" jdbcType="VARCHAR" />
	</resultMap>

	<!-- JOB SELECT -->

	<select id="selectJob" parameterType="string" resultMap="jobResultMap">
		select * from ${prefix}ACT_RU_JOB where ID_ = #{id, jdbcType=VARCHAR}
	</select>

	<select id="selectJobsToExecute" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="jobResultMap">
		${limitBefore}
		select
		RES.* ${limitBetween}
		from ${prefix}ACT_RU_JOB RES
		where LOCK_EXP_TIME_ is null
		${limitAfter}
	</select>

	<select id="selectExpiredJobs" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="jobResultMap">
	  	${limitBefore}
      	select
      	RES.* ${limitBetween} 
      	from ${prefix}ACT_RU_JOB RES
    	where RES.LOCK_EXP_TIME_ is not null and RES.LOCK_EXP_TIME_ &lt; #{parameter, jdbcType=TIMESTAMP}
    	${limitAfter}
  </select>

	<select id="selectJobsByTypeAndProcessDefinitionId" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="jobResultMap">
		select * from ${prefix}ACT_RU_JOB
		where HANDLER_TYPE_ = #{parameter.handlerType}
		and PROC_DEF_ID_ = #{parameter.processDefinitionId}
	</select>

	<select id="selectJobsByConfiguration" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="jobResultMap">
		select * from ${prefix}ACT_RU_JOB
		where HANDLER_TYPE_ = #{parameter.handlerType}
		and HANDLER_CFG_ like #{parameter.handlerConfiguration}${wildcardEscapeClause}
	</select>

	<select id="selectJobsByExecutionId" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="jobResultMap">
		select *
		from ${prefix}ACT_RU_JOB J
		where J.EXECUTION_ID_ = #{parameter}
	</select>

	<select id="selectJobsByProcessInstanceId" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="jobResultMap">
		select *
		from ${prefix}ACT_RU_JOB J
		where J.PROCESS_INSTANCE_ID_ = #{parameter}
	</select>

	<select id="selectJobByTypeAndProcessDefinitionId" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="jobResultMap">
		select J.*
		from ${prefix}ACT_RU_JOB J
		where J.TYPE_ = #{parameter.handlerType}
		and J.PROC_DEF_ID_ = #{parameter.processDefinitionId}
	</select>

	<select id="selectJobByProcessDefinitionId" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="jobResultMap">
		select J.*
		from ${prefix}ACT_RU_JOB J
		where J.PROC_DEF_ID_ = #{parameter.processDefinitionId}
	</select>


	<select id="selectJobByQueryCriteria" parameterType="org.activiti.engine.impl.JobQueryImpl" resultMap="jobResultMap">
		${limitBefore}
		select RES.* ${limitBetween}
		<include refid="selectJobByQueryCriteriaSql" />
		${orderBy}
		${limitAfter}
	</select>

	<select id="selectJobCountByQueryCriteria" parameterType="org.activiti.engine.impl.JobQueryImpl" resultType="long">
		select count(distinct RES.ID_)
		<include refid="selectJobByQueryCriteriaSql" />
	</select>

	<sql id="selectJobByQueryCriteriaSql">
		from ${prefix}ACT_RU_JOB RES
		<if test="executable">
			LEFT OUTER JOIN ${prefix}ACT_RU_EXECUTION PI ON PI.ID_ = RES.PROCESS_INSTANCE_ID_
		</if>
		<where>
			<if test="id != null">
				RES.ID_ = #{id}
			</if>
			<if test="processInstanceId != null">
				and RES.PROCESS_INSTANCE_ID_ = #{processInstanceId}
			</if>
			<if test="executionId != null">
				and RES.EXECUTION_ID_ = #{executionId}
			</if>
			<if test="processDefinitionId != null">
				and RES.PROC_DEF_ID_ = #{processDefinitionId}
			</if>
			<if test="onlyTimers">
				and RES.TYPE_ = 'timer'
			</if>
			<if test="onlyMessages">
				and RES.TYPE_ = 'message'
			</if>
			<if test="duedateHigherThan != null">
				and RES.DUEDATE_ &gt; #{duedateHigherThan}
			</if>
			<if test="duedateLowerThan != null">
				and RES.DUEDATE_ &lt; #{duedateLowerThan}
			</if>
			<if test="duedateHigherThanOrEqual != null">
				and RES.DUEDATE_ &gt;= #{duedateHigherThanOrEqual}
			</if>
			<if test="duedateLowerThanOrEqual != null">
				and RES.DUEDATE_ &lt;= #{duedateLowerThanOrEqual}
			</if>
			<if test="withException">
				and (RES.EXCEPTION_MSG_ is not null or RES.EXCEPTION_STACK_ID_ is not null)
			</if>
			<if test="exceptionMessage">
				and RES.EXCEPTION_MSG_ = #{exceptionMessage}
			</if>
			<if test="onlyLocked">
				and RES.LOCK_EXP_TIME_ is not null
			</if>
			<if test="onlyUnlocked">
				and RES.LOCK_EXP_TIME_ is null
			</if>
			<if test="tenantId != null">
				and RES.TENANT_ID_ = #{tenantId}
			</if>
			<if test="tenantIdLike != null">
				and RES.TENANT_ID_ like #{tenantIdLike}${wildcardEscapeClause}
			</if>
			<if test="withoutTenantId">
				and (RES.TENANT_ID_ = '' or RES.TENANT_ID_ is null)
			</if>
		</where>
	</sql>

	<!-- JOB DELETE STATEMENTS -->

	<delete id="deleteJob" parameterType="org.activiti.engine.impl.persistence.entity.JobEntityImpl">
		delete from ${prefix}ACT_RU_JOB where ID_ = #{id} and REV_ = #{revision}
	</delete>

	<delete id="bulkDeleteJob" parameterType="java.util.Collection">
		delete from ${prefix}ACT_RU_JOB where
		<foreach item="job" collection="list" index="index" separator=" or ">
			ID_ = #{job.id, jdbcType=VARCHAR}
		</foreach>
	</delete>

	<!-- 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>

	<!-- See http://stackoverflow.com/questions/4429319/you-cant-specify-target-table-for-update-in-from-clause 
		Tested this on MySQL 5.6: does NOT use a temporary table (so good, performance) -->
	<update id="updateJobTenantIdForDeployment" databaseId="mysql"
			parameterType="java.util.Map">
		update ${prefix}ACT_RU_JOB set
		TENANT_ID_ = #{tenantId, jdbcType=VARCHAR}
		where
		ID_ in (

			SELECT tempTask.tempId
			FROM (
				SELECT J.ID_ as tempId
				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}
	
			) AS tempTask

		)
	</update>

	<!-- JOB INSERT -->

	<insert id="insertJob"
			parameterType="org.activiti.engine.impl.persistence.entity.JobEntityImpl">
		insert into ${prefix}ACT_RU_JOB (
		ID_,
		REV_,
		TYPE_,
		LOCK_OWNER_,
        LOCK_EXP_TIME_,
		EXCLUSIVE_,
		EXECUTION_ID_,
		PROCESS_INSTANCE_ID_,
		PROC_DEF_ID_,
		RETRIES_,
		EXCEPTION_STACK_ID_,
		EXCEPTION_MSG_,
		DUEDATE_,
		REPEAT_,
		HANDLER_TYPE_,
		HANDLER_CFG_,
		TENANT_ID_)
		values (#{id, jdbcType=VARCHAR},
		#{revision, jdbcType=INTEGER},
		#{jobType, jdbcType=VARCHAR},
		#{lockOwner, jdbcType=VARCHAR},
        #{lockExpirationTime, jdbcType=TIMESTAMP},
		#{exclusive, jdbcType=BOOLEAN},
		#{executionId, jdbcType=VARCHAR},
		#{processInstanceId, jdbcType=VARCHAR},
		#{processDefinitionId, jdbcType=VARCHAR},
		#{retries, jdbcType=INTEGER},
		#{exceptionByteArrayRef, typeHandler=ByteArrayRefTypeHandler},
		#{exceptionMessage, jdbcType=VARCHAR},
		#{duedate, jdbcType=TIMESTAMP},
		#{repeat, jdbcType=VARCHAR},
		#{jobHandlerType, jdbcType=VARCHAR},
		#{jobHandlerConfiguration, jdbcType=VARCHAR},
		#{tenantId, jdbcType=VARCHAR}
		)
	</insert>

	<insert id="bulkInsertJob" parameterType="java.util.List">
		INSERT INTO ${prefix}ACT_RU_JOB (
		ID_,
		REV_,
		TYPE_,
		LOCK_OWNER_,
		LOCK_EXP_TIME_,
		EXCLUSIVE_,
		EXECUTION_ID_,
		PROCESS_INSTANCE_ID_,
		PROC_DEF_ID_,
		RETRIES_,
		EXCEPTION_STACK_ID_,
		EXCEPTION_MSG_,
		DUEDATE_,
		REPEAT_,
		HANDLER_TYPE_,
		HANDLER_CFG_,
		TENANT_ID_) VALUES
		<foreach collection="list" item="job" index="index" separator=",">
			(#{job.id, jdbcType=VARCHAR},
			#{job.revision, jdbcType=INTEGER},
			#{job.jobType, jdbcType=VARCHAR},
			#{job.lockOwner, jdbcType=VARCHAR},
			#{job.lockExpirationTime, jdbcType=TIMESTAMP},
			#{job.exclusive, jdbcType=BOOLEAN},
			#{job.executionId, jdbcType=VARCHAR},
			#{job.processInstanceId, jdbcType=VARCHAR},
			#{job.processDefinitionId, jdbcType=VARCHAR},
			#{job.retries, jdbcType=INTEGER},
			#{job.exceptionByteArrayRef, typeHandler=ByteArrayRefTypeHandler},
			#{job.exceptionMessage, jdbcType=VARCHAR},
			#{job.duedate, jdbcType=TIMESTAMP},
			#{job.repeat, jdbcType=VARCHAR},
			#{job.jobHandlerType, jdbcType=VARCHAR},
			#{job.jobHandlerConfiguration, jdbcType=VARCHAR},
			#{job.tenantId, jdbcType=VARCHAR})
		</foreach>
	</insert>

	<insert id="bulkInsertJob" databaseId="oracle"
			parameterType="java.util.List">
		INSERT ALL
		<foreach collection="list" item="job" index="index">
			INTO ${prefix}ACT_RU_JOB (
			ID_,
			REV_,
			TYPE_,
			LOCK_OWNER_,
			LOCK_EXP_TIME_,
			EXCLUSIVE_,
			EXECUTION_ID_,
			PROCESS_INSTANCE_ID_,
			PROC_DEF_ID_,
			DUEDATE_,
			RETRIES_,
			EXCEPTION_STACK_ID_,
			EXCEPTION_MSG_,
			HANDLER_TYPE_,
			HANDLER_CFG_,
			TENANT_ID_) VALUES
			(#{job.id, jdbcType=VARCHAR},
			#{job.revision, jdbcType=INTEGER},
			#{job.jobType, jdbcType=VARCHAR},
			#{job.lockOwner, jdbcType=VARCHAR},
			#{job.lockExpirationTime, jdbcType=TIMESTAMP},
			#{job.exclusive, jdbcType=BOOLEAN},
			#{job.executionId, jdbcType=VARCHAR},
			#{job.processInstanceId, jdbcType=VARCHAR},
			#{job.processDefinitionId, jdbcType=VARCHAR},
			#{job.duedate, jdbcType=TIMESTAMP},
			#{job.retries, jdbcType=INTEGER},
			#{job.exceptionByteArrayRef, typeHandler=ByteArrayRefTypeHandler},
			#{job.exceptionMessage, jdbcType=VARCHAR},
			#{job.jobHandlerType, jdbcType=VARCHAR},
			#{job.jobHandlerConfiguration, jdbcType=VARCHAR},
			#{job.tenantId, jdbcType=VARCHAR})
		</foreach>
		SELECT * FROM dual
	</insert>

	<!-- JOB UPDATE -->

	<update id="updateJob" parameterType="org.activiti.engine.impl.persistence.entity.JobEntityImpl">
		update ${prefix}ACT_RU_JOB
		<set>
			REV_ = #{revisionNext, jdbcType=INTEGER},
			LOCK_EXP_TIME_ = #{lockExpirationTime, jdbcType=TIMESTAMP},
			LOCK_OWNER_ = #{lockOwner, jdbcType=VARCHAR},
			RETRIES_ = #{retries, jdbcType=INTEGER},
			EXCEPTION_STACK_ID_ = #{exceptionByteArrayRef, typeHandler=ByteArrayRefTypeHandler},
			EXCEPTION_MSG_ = #{exceptionMessage, jdbcType=VARCHAR}
		</set>
		where ID_= #{id, jdbcType=VARCHAR}
		and REV_ = #{revision, jdbcType=INTEGER}
	</update>

	<update id="resetExpiredJob" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject">
    update ${prefix}ACT_RU_JOB
    set LOCK_OWNER_ = null, LOCK_EXP_TIME_ = null
    where ID_ = #{id,jdbcType=VARCHAR}
  </update>

	<select id="selectTimersByExecutionId" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="jobResultMap">
		select *
		from ${prefix}ACT_RU_JOB
		where (RETRIES_ &gt; 0)
		and (TYPE_ = 'timer')
		and (EXECUTION_ID_ = #{parameter})
	</select>

</mapper>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy