package com.leanwo.activiti.service.base;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface DeploymentVariableMapper {
	
	@Select("SELECT ID_ AS id, DEPLOYMENT_ID_ AS deploymentId, NAME_ AS name, VALUE_ AS value, REV_ AS rev FROM ACT_RE_VARIABLE WHERE DEPLOYMENT_ID_ = #{deploymentId} AND NAME_ = #{name}")
	DeploymentVariable uniqueByDeploymentIdName(@Param("deploymentId") String deploymentId, @Param("name") String name);
	
	@Insert("INSERT INTO ACT_RE_VARIABLE(ID_, DEPLOYMENT_ID_, NAME_, VALUE_, REV_) VALUES(#{id}, #{deploymentId}, #{name}, #{value}, #{rev})")
	int insert(@Param("id") String id, @Param("deploymentId") String deploymentId, @Param("name") String name, @Param("value") String value, @Param("rev") int rev);
	
	@Update("UPDATE ACT_RE_VARIABLE SET NAME_ = #{name}, VALUE_ = #{value}, REV_ = (REV_ + 1) WHERE ID_ = #{id} AND DEPLOYMENT_ID_ = #{deploymentId} AND NAME_ = #{name} AND REV_ = #{rev}")
	int update(@Param("id") String id, @Param("deploymentId") String deploymentId, @Param("name") String name, @Param("value") String value, @Param("rev") int rev);
}
