| <?xml version="1.0" encoding="UTF-8" ?> |
| <!-- |
| ~ Copyright 2019 WeBank |
| ~ |
| ~ Licensed under the Apache License, Version 2.0 (the "License"); |
| ~ you may not use this file except in compliance with the License. |
| ~ You may obtain a copy of the License at |
| ~ |
| ~ http://www.apache.org/licenses/LICENSE-2.0 |
| ~ |
| ~ Unless required by applicable law or agreed to in writing, software |
| ~ distributed under the License is distributed on an "AS IS" BASIS, |
| ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| ~ See the License for the specific language governing permissions and |
| ~ limitations under the License. |
| ~ |
| --> |
| |
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
| |
| |
| <mapper namespace="com.webank.wedatasphere.linkis.cs.persistence.dao.ContextMapMapper"> |
| |
| <sql id="context_map"> |
| `id`,`key`,`context_scope`,`context_type`,`props`,`value`,`context_id`,`keywords` |
| </sql> |
| |
| <insert id="createMap" |
| parameterType="com.webank.wedatasphere.linkis.cs.persistence.entity.PersistenceContextKeyValue"> |
| INSERT INTO linkis_cs_context_map(<include refid="context_map"/>) |
| VALUES (#{id},#{contextKey.key},#{contextKey.contextScope},#{contextKey.contextType}, |
| #{props},#{contextValue.valueStr},#{contextId},#{contextValue.keywords}) |
| </insert> |
| |
| <resultMap id="PersistenceContextKeyValue" |
| type="com.webank.wedatasphere.linkis.cs.persistence.entity.PersistenceContextKeyValue"> |
| <id column="id" property="id"></id> |
| <result column="context_id" property="contextId"></result> |
| <result column="props" property="props"></result> |
| <association property="contextKey" |
| javaType="com.webank.wedatasphere.linkis.cs.persistence.entity.PersistenceContextKey"> |
| <result column="key" property="key"></result> |
| <result column="context_scope" property="contextScope"></result> |
| <result column="context_type" property="contextType"></result> |
| <result column="keywords" property="keywords"></result> |
| </association> |
| <association property="contextValue" |
| javaType="com.webank.wedatasphere.linkis.cs.persistence.entity.PersistenceContextValue"> |
| <result column="value" property="valueStr"></result> |
| </association> |
| </resultMap> |
| |
| <select id="getContextMap" resultMap="PersistenceContextKeyValue"> |
| SELECT * FROM linkis_cs_context_map |
| <where> |
| <if test="contextID.contextId != null">context_id = #{contextID.contextId}</if> |
| <if test="contextKey.key != null">AND `key` = #{contextKey.key}</if> |
| </where> |
| </select> |
| |
| <select id="getAllContextMapByKey" resultMap="PersistenceContextKeyValue"> |
| SELECT * FROM linkis_cs_context_map WHERE context_id = #{contextID.contextId} AND `key` LIKE "%"#{key}"%" |
| </select> |
| |
| |
| <select id="getAllContextMapByContextID" resultMap="PersistenceContextKeyValue"> |
| SELECT * FROM linkis_cs_context_map WHERE context_id = #{contextID.contextId} |
| </select> |
| |
| <select id="getAllContextMapByScope" resultMap="PersistenceContextKeyValue"> |
| SELECT * FROM linkis_cs_context_map WHERE context_id = #{contextID.contextId} AND context_scope = #{contextScope} |
| </select> |
| |
| <select id="getAllContextMapByType" resultMap="PersistenceContextKeyValue"> |
| SELECT * FROM linkis_cs_context_map WHERE context_id = #{contextID.contextId} AND context_type = #{contextType} |
| </select> |
| |
| <delete id="removeContextMap"> |
| DELETE FROM linkis_cs_context_map |
| <where> |
| <if test="contextID.contextId != null">context_id = #{contextID.contextId}</if> |
| <if test="contextKey.key != null">AND `key` = #{contextKey.key}</if> |
| </where> |
| </delete> |
| |
| <delete id="removeAllContextMapByContextID"> |
| DELETE FROM linkis_cs_context_map WHERE context_id = #{contextID.contextId} |
| </delete> |
| |
| <delete id="removeAllContextMapByType"> |
| DELETE FROM linkis_cs_context_map WHERE context_id = #{contextID.contextId} AND context_type = #{contextType} |
| </delete> |
| |
| <delete id="removeAllContextMapByScope"> |
| DELETE FROM linkis_cs_context_map WHERE context_id = #{contextID.contextId} AND context_scope = #{contextScope} |
| </delete> |
| |
| <update id="updateMap" |
| parameterType="com.webank.wedatasphere.linkis.cs.persistence.entity.PersistenceContextKeyValue"> |
| UPDATE linkis_cs_context_map |
| <trim prefix="set" suffixOverrides=","> |
| <if test="contextKey.contextScope != null">`context_scope` = #{contextKey.contextScope},</if> |
| <if test="contextKey.contextType != null">`context_type` = #{contextKey.contextType},</if> |
| <if test="contextValue.valueStr != null">`value` = #{contextValue.valueStr},</if> |
| <if test="contextValue.keywords != null">`keywords` = #{contextValue.keywords},</if> |
| </trim> |
| WHERE context_id = #{contextId} AND `key` = #{contextKey.key} |
| </update> |
| |
| <delete id="removeByKeyPrefix"> |
| delete from linkis_cs_context_map |
| <where> |
| <if test="#{contextID.contextId} !=null">context_id = #{contextID.contextId} and </if> |
| <!--<if test="#{contextType} !=null">context_type = #{contextType} and </if>--> |
| <if test="#{keyPrefix} !=null">`key` like concat(#{keyPrefix},'%')</if> |
| </where> |
| </delete> |
| <!--todo 和上面的合并sql--> |
| <delete id="removeByKeyPrefixAndContextType"> |
| delete from linkis_cs_context_map |
| <where> |
| <if test="#{contextID.contextId} !=null">context_id = #{contextID.contextId} and </if> |
| <if test="#{contextType} !=null">context_type = #{contextType} and </if> |
| <if test="#{keyPrefix} !=null">`key` like concat(#{keyPrefix},'%')</if> |
| </where> |
| </delete> |
| |
| </mapper> |