This is an automated email from the ASF dual-hosted git repository.

zhangzicheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 1c5cf16a4 [ISSUE #4029]Add ParameterMapper (#4163)
1c5cf16a4 is described below

commit 1c5cf16a4d8cd7fe926509209b001fdafff78cab
Author: Zihao Huang <[email protected]>
AuthorDate: Wed Nov 9 11:56:52 2022 +0800

    [ISSUE #4029]Add ParameterMapper (#4163)
    
    Co-authored-by: moremind <[email protected]>
---
 .../shenyu/admin/mapper/ParameterMapper.java       |  76 +++++
 .../shenyu/admin/model/entity/ParameterDO.java     | 377 +++++++++++++++++++++
 .../main/resources/mappers/parameter-sqlmap.xml    | 196 +++++++++++
 .../shenyu/admin/mapper/ParameterMapperTest.java   |  99 ++++++
 4 files changed, 748 insertions(+)

diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/ParameterMapper.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/ParameterMapper.java
new file mode 100644
index 000000000..a4f08af76
--- /dev/null
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/ParameterMapper.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.shenyu.admin.mapper;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.shenyu.admin.model.entity.ParameterDO;
+
+/**
+ * ParameterMapper.
+ */
+@Mapper
+public interface ParameterMapper {
+
+    /**
+     * select by parameter id.
+     *
+     * @param id primary key
+     * @return ParameterDo
+     */
+    ParameterDO selectByPrimaryKey(String id);
+
+    /**
+     * insert parameter.
+     *
+     * @param parameterDO the inserted parameterDO
+     * @return counts of rows inserted
+     */
+    int insert(ParameterDO parameterDO);
+
+    /**
+     * insert parameter with selective fields.
+     *
+     * @param parameterDO the inserted parameterDO
+     * @return counts of row inserted
+     */
+    int insertSelective(ParameterDO parameterDO);
+
+    /**
+     * update parameter.
+     *
+     * @param parameterDO the updated parameterDO
+     * @return counts of row updated
+     */
+    int updateByPrimaryKey(ParameterDO parameterDO);
+
+    /**
+     * update parameter with selective fields.
+     *
+     * @param parameterDO the updated parameterDO
+     * @return counts of row updated
+     */
+    int updateByPrimaryKeySelective(ParameterDO parameterDO);
+
+    /**
+     * delete parameter.
+     *
+     * @param id the primary key
+     * @return counts of row deleted
+     */
+    int deleteByPrimaryKey(String id);
+}
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/ParameterDO.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/ParameterDO.java
new file mode 100644
index 000000000..3233d8732
--- /dev/null
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/ParameterDO.java
@@ -0,0 +1,377 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.shenyu.admin.model.entity;
+
+import java.sql.Timestamp;
+import java.util.Objects;
+
+/**
+ * parameter.
+ */
+public final class ParameterDO extends BaseDO {
+
+    /**
+     * the api_id.
+     */
+    private String apiId;
+
+    /**
+     * the model_id.
+     */
+    private String modelId;
+
+    /**
+     * the type, 
0-requestPathVariable,1-requestUrlParam,2-requestHeader,3-requestBody,
+     * 4-responseHeader,5-responseBody.
+     */
+    private Integer type;
+
+    /**
+     * the parameter name.
+     */
+    private String name;
+
+    /**
+     * the description of parameter.
+     */
+    private String paramDesc;
+
+    /**
+     * whether to require (0 not required, 1 required).
+     */
+    private Boolean required;
+
+    /**
+     * extended fields.
+     */
+    private String ext;
+
+    /**
+     * get api_id.
+     *
+     * @return api_Id
+     */
+    public String getApiId() {
+        return apiId;
+    }
+
+    /**
+     * set api_id.
+     *
+     * @param apiId the api_id
+     */
+    public void setApiId(final String apiId) {
+        this.apiId = apiId;
+    }
+
+    /**
+     * get model_id.
+     *
+     * @return model_id
+     */
+    public String getModelId() {
+        return modelId;
+    }
+
+    /**
+     * set model_id.
+     *
+     * @param modelId the model_id
+     */
+    public void setModelId(final String modelId) {
+        this.modelId = modelId;
+    }
+
+    /**
+     * get the type.
+     *
+     * @return type
+     */
+    public Integer getType() {
+        return type;
+    }
+
+    /**
+     * set the type.
+     *
+     * @param type the type
+     */
+    public void setType(final Integer type) {
+        this.type = type;
+    }
+
+    /**
+     * get the parameter name.
+     *
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * set the parameter name.
+     *
+     * @param name the parameter name
+     */
+    public void setName(final String name) {
+        this.name = name;
+    }
+
+    /**
+     * get the description of parameter.
+     *
+     * @return paramDesc
+     */
+    public String getParamDesc() {
+        return paramDesc;
+    }
+
+    /**
+     * set the description of parameter.
+     *
+     * @param paramDesc the param_desc
+     */
+    public void setParamDesc(final String paramDesc) {
+        this.paramDesc = paramDesc;
+    }
+
+    /**
+     * get required.
+     *
+     * @return required
+     */
+    public Boolean getRequired() {
+        return required;
+    }
+
+    /**
+     * set required.
+     *
+     * @param required whether of require
+     */
+    public void setRequired(final Boolean required) {
+        this.required = required;
+    }
+
+    /**
+     * get extend fields.
+     *
+     * @return ext
+     */
+    public String getExt() {
+        return ext;
+    }
+
+    /**
+     * set ext-fields.
+     *
+     * @param ext the ext-fields
+     */
+    public void setExt(final String ext) {
+        this.ext = ext;
+    }
+
+    @Override
+    public boolean equals(final Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        if (!super.equals(o)) {
+            return false;
+        }
+        ParameterDO parameterDO = (ParameterDO) o;
+        return Objects.equals(apiId, parameterDO.apiId)
+                && Objects.equals(modelId, parameterDO.modelId)
+                && Objects.equals(type, parameterDO.type)
+                && Objects.equals(name, parameterDO.name)
+                && Objects.equals(paramDesc, parameterDO.paramDesc)
+                && Objects.equals(required, parameterDO.required)
+                && Objects.equals(ext, parameterDO.ext);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(super.hashCode(), apiId, modelId, type, name, 
paramDesc, required, ext);
+    }
+
+    /**
+     * return ParameterDOBuilder.
+     *
+     * @return ParameterDOBuilder
+     */
+    public static ParameterDOBuilder builder() {
+        return new ParameterDOBuilder();
+    }
+
+    public static final class ParameterDOBuilder {
+
+        private String id;
+
+        private String apiId;
+
+        private String modelId;
+
+        private Integer type;
+
+        private String name;
+
+        private String paramDesc;
+
+        private Boolean required;
+
+        private String ext;
+
+        private Timestamp dateCreated;
+
+        private Timestamp dateUpdated;
+
+        /**
+         * id.
+         *
+         * @param id the primary key
+         * @return ParameterDOBuilder
+         */
+        public ParameterDOBuilder id(final String id) {
+            this.id = id;
+            return this;
+        }
+
+        /**
+         * apiId.
+         *
+         * @param apiId the api_id
+         * @return ParameterDOBuilder
+         */
+        public ParameterDOBuilder apiId(final String apiId) {
+            this.apiId = apiId;
+            return this;
+        }
+
+        /**
+         * modelId.
+         *
+         * @param modelId the model_id
+         * @return ParameterDOBuilder
+         */
+        public ParameterDOBuilder modelId(final String modelId) {
+            this.modelId = modelId;
+            return this;
+        }
+
+        /**
+         * type.
+         *
+         * @param type the type
+         * @return ParameterDOBuilder
+         */
+        public ParameterDOBuilder type(final Integer type) {
+            this.type = type;
+            return this;
+        }
+
+        /**
+         * name.
+         *
+         * @param name the parameter name
+         * @return ParameterDOBuilder
+         */
+        public ParameterDOBuilder name(final String name) {
+            this.name = name;
+            return this;
+        }
+
+        /**
+         * paramDesc.
+         *
+         * @param paramDesc the param_desc
+         * @return ParameterDOBuilder
+         */
+        public ParameterDOBuilder paramDesc(final String paramDesc) {
+            this.paramDesc = paramDesc;
+            return this;
+        }
+
+        /**
+         * required.
+         *
+         * @param required whether of require
+         * @return ParameterDOBuilder
+         */
+        public ParameterDOBuilder required(final Boolean required) {
+            this.required = required;
+            return this;
+        }
+
+        /**
+         * ext.
+         *
+         * @param ext the ext_fields
+         * @return ParameterDOBuilder
+         */
+        public ParameterDOBuilder ext(final String ext) {
+            this.ext = ext;
+            return this;
+        }
+
+        /**
+         * dateCreated.
+         *
+         * @param dateCreated the created date
+         * @return ParameterDOBuilder
+         */
+        public ParameterDOBuilder dateCreated(final Timestamp dateCreated) {
+            this.dateCreated = dateCreated;
+            return this;
+        }
+
+        /**
+         * dateUpdated.
+         *
+         * @param dateUpdated the updated date
+         * @return ParameterDOBuilder
+         */
+        public ParameterDOBuilder dateUpdated(final Timestamp dateUpdated) {
+            this.dateUpdated = dateUpdated;
+            return this;
+        }
+
+        /**
+         * build a ParameterDO.
+         *
+         * @return ParameterDO
+         */
+        public ParameterDO build() {
+            ParameterDO parameterDO = new ParameterDO();
+            parameterDO.setId(this.id);
+            parameterDO.setApiId(this.apiId);
+            parameterDO.setModelId(this.modelId);
+            parameterDO.setType(this.type);
+            parameterDO.setName(this.name);
+            parameterDO.setParamDesc(this.paramDesc);
+            parameterDO.setRequired(this.required);
+            parameterDO.setExt(this.ext);
+            parameterDO.setDateCreated(this.dateCreated);
+            parameterDO.setDateUpdated(this.dateUpdated);
+            return parameterDO;
+        }
+    }
+}
diff --git a/shenyu-admin/src/main/resources/mappers/parameter-sqlmap.xml 
b/shenyu-admin/src/main/resources/mappers/parameter-sqlmap.xml
new file mode 100644
index 000000000..7c77a7c14
--- /dev/null
+++ b/shenyu-admin/src/main/resources/mappers/parameter-sqlmap.xml
@@ -0,0 +1,196 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You 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="org.apache.shenyu.admin.mapper.ParameterMapper">
+    <resultMap id="BaseResultMap" 
type="org.apache.shenyu.admin.model.entity.ParameterDO">
+        <id column="id" jdbcType="VARCHAR" property="id"/>
+        <result column="api_id" jdbcType="VARCHAR" property="apiId"/>
+        <result column="model_id" jdbcType="VARCHAR" property="modelId"/>
+        <result column="type" jdbcType="INTEGER" property="type"/>
+        <result column="name" jdbcType="VARCHAR" property="name"/>
+        <result column="param_desc" jdbcType="VARCHAR" property="paramDesc"/>
+        <result column="required" jdbcType="TINYINT" property="required"/>
+        <result column="ext" jdbcType="VARCHAR" property="ext"/>
+        <result column="date_created" jdbcType="TIMESTAMP" 
property="dateCreated"/>
+        <result column="date_updated" jdbcType="TIMESTAMP" 
property="dateUpdated"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id,
+        api_id,
+        model_id,
+        type,
+        name,
+        param_desc,
+        required,
+        ext,
+        date_created,
+        date_updated
+    </sql>
+
+    <select id="selectByPrimaryKey" parameterType="java.lang.String" 
resultMap="BaseResultMap">
+        SELECT
+               <include refid="Base_Column_List"/>
+          FROM param
+         WHERE id = #{id, jdbcType=VARCHAR}
+    </select>
+
+    <insert id="insert" 
parameterType="org.apache.shenyu.admin.model.entity.ParameterDO">
+        INSERT INTO param
+                    (id,
+                    api_id,
+                    model_id,
+                    type,
+                    name,
+                    param_desc,
+                    required,
+                    ext,
+                    date_created,
+                    date_updated)
+             VALUES
+                    (#{id, jdbcType=VARCHAR},
+                    #{apiId, jdbcType=VARCHAR},
+                    #{modelId, jdbcType=VARCHAR},
+                    #{type, jdbcType=INTEGER},
+                    #{name, jdbcType=VARCHAR},
+                    #{paramDesc, jdbcType=VARCHAR},
+                    #{required, jdbcType=TINYINT},
+                    #{ext, jdbcType=VARCHAR},
+                    #{dateCreated,jdbcType=TIMESTAMP},
+                    #{dateUpdated,jdbcType=TIMESTAMP})
+    </insert>
+
+    <insert id="insertSelective" 
parameterType="org.apache.shenyu.admin.model.entity.ParameterDO">
+        INSERT INTO param
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            id,
+            <if test="apiId != null">
+                api_id,
+            </if>
+            <if test="modelId != null">
+                model_id,
+            </if>
+            <if test="type != null">
+                type,
+            </if>
+            <if test="name != null">
+                name,
+            </if>
+            <if test="paramDesc != null">
+                param_desc,
+            </if>
+            <if test="required != null">
+                required,
+            </if>
+            <if test="ext != null">
+                ext,
+            </if>
+            <if test="dateCreated != null">
+                date_created,
+            </if>
+            <if test="dateUpdated != null">
+                date_updated,
+            </if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            #{id, jdbcType=VARCHAR},
+            <if test="apiId != null">
+                #{apiId, jdbcType=VARCHAR},
+            </if>
+            <if test="modelId != null">
+                #{modelId, jdbcType=VARCHAR},
+            </if>
+            <if test="type != null">
+                #{type, jdbcType=INTEGER},
+            </if>
+            <if test="name != null">
+                #{name, jdbcType=VARCHAR},
+            </if>
+            <if test="paramDesc != null">
+                #{paramDesc, jdbcType=VARCHAR},
+            </if>
+            <if test="required != null">
+                #{required, jdbcType=TINYINT},
+            </if>
+            <if test="ext != null">
+                #{ext, jdbcType=VARCHAR},
+            </if>
+            <if test="dateCreated != null">
+                #{dateCreated, jdbcType=TIMESTAMP},
+            </if>
+            <if test="dateUpdated != null">
+                #{dateUpdated, jdbcType=TIMESTAMP},
+            </if>
+        </trim>
+    </insert>
+
+    <update id="updateByPrimaryKey" 
parameterType="org.apache.shenyu.admin.model.entity.ParameterDO">
+        UPDATE param
+           SET
+               api_id = #{apiId, jdbcType=VARCHAR},
+               model_id = #{modelId, jdbcType=VARCHAR},
+               type = #{type, jdbcType=INTEGER},
+               name = #{name, jdbcType=VARCHAR},
+               param_desc = #{paramDesc, jdbcType=VARCHAR},
+               required = #{required, jdbcType=TINYINT},
+               ext = #{ext, jdbcType=VARCHAR},
+               date_created = #{dateCreated,jdbcType=TIMESTAMP},
+               date_updated = #{dateUpdated,jdbcType=TIMESTAMP}
+         WHERE id = #{id, jdbcType=VARCHAR}
+    </update>
+
+    <update id="updateByPrimaryKeySelective" 
parameterType="org.apache.shenyu.admin.model.entity.ParameterDO">
+        UPDATE param
+        <set>
+            <if test="apiId != null">
+                api_id = #{apiId, jdbcType=VARCHAR},
+            </if>
+            <if test="modelId != null">
+                model_id = #{modelId, jdbcType=VARCHAR},
+            </if>
+            <if test="type != null">
+                type = #{type, jdbcType=INTEGER},
+            </if>
+            <if test="name != null">
+                name = #{name, jdbcType=VARCHAR},
+            </if>
+            <if test="paramDesc != null">
+                param_desc = #{paramDesc, jdbcType=VARCHAR},
+            </if>
+            <if test="required != null">
+                required = #{required, jdbcType=TINYINT},
+            </if>
+            <if test="ext != null">
+                ext = #{ext, jdbcType=VARCHAR},
+            </if>
+            <if test="dateCreated != null">
+                date_created =#{dateCreated, jdbcType=TIMESTAMP},
+            </if>
+            <if test="dateUpdated != null">
+                date_updated = #{dateUpdated, jdbcType=TIMESTAMP},
+            </if>
+        </set>
+         WHERE id = #{id, jdbcType=VARCHAR}
+    </update>
+
+    <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
+        DELETE FROM param
+         WHERE id = #{id, jdbcType=VARCHAR}
+    </delete>
+</mapper>
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ParameterMapperTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ParameterMapperTest.java
new file mode 100644
index 000000000..1e1a43606
--- /dev/null
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ParameterMapperTest.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.shenyu.admin.mapper;
+
+import org.apache.shenyu.admin.AbstractSpringIntegrationTest;
+import org.apache.shenyu.admin.model.entity.ParameterDO;
+import org.apache.shenyu.common.utils.UUIDUtils;
+import org.junit.jupiter.api.Test;
+
+import javax.annotation.Resource;
+import java.sql.Timestamp;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Test cases for ParameterMapper.
+ */
+public class ParameterMapperTest extends AbstractSpringIntegrationTest {
+
+    @Resource
+    private ParameterMapper parameterMapper;
+
+    private ParameterDO buildParameterDO() {
+        Timestamp now = new Timestamp(System.currentTimeMillis());
+        String id = UUIDUtils.getInstance().generateShortUuid();
+        return ParameterDO.builder()
+                .id(id)
+                .apiId("testApi")
+                .modelId("111")
+                .type(1)
+                .name("test")
+                .paramDesc("test_desc")
+                .required(true)
+                .ext("test")
+                .dateCreated(now)
+                .dateUpdated(now)
+                .build();
+    }
+
+    @Test
+    public void testInsertAndDelete() {
+        ParameterDO parameterDO = buildParameterDO();
+        assertEquals(parameterMapper.insert(parameterDO), 1);
+        assertEquals(parameterMapper.deleteByPrimaryKey(parameterDO.getId()), 
1);
+    }
+
+    @Test
+    public void testSelectByPrimaryKey() {
+        ParameterDO parameterDO = buildParameterDO();
+        parameterMapper.insert(parameterDO);
+        assertNotNull(parameterMapper.selectByPrimaryKey(parameterDO.getId()));
+        parameterMapper.deleteByPrimaryKey(parameterDO.getId());
+    }
+
+    @Test
+    public void testInsertSelective() {
+        ParameterDO parameterDO = buildParameterDO();
+        assertEquals(parameterMapper.insertSelective(parameterDO), 1);
+        parameterMapper.deleteByPrimaryKey(parameterDO.getId());
+    }
+
+    @Test
+    public void testUpdateByPrimaryKey() {
+        ParameterDO parameterDO = buildParameterDO();
+        parameterMapper.insert(parameterDO);
+        parameterDO.setApiId("updateApi");
+        parameterDO.setExt("update");
+        parameterDO.setDateUpdated(new Timestamp(System.currentTimeMillis()));
+        assertEquals(parameterMapper.updateByPrimaryKey(parameterDO), 1);
+        parameterMapper.deleteByPrimaryKey(parameterDO.getId());
+    }
+
+    @Test
+    public void testUpdateSelective() {
+        ParameterDO parameterDO = buildParameterDO();
+        parameterMapper.insert(parameterDO);
+        parameterDO.setApiId("updateApi");
+        parameterDO.setExt("selective update");
+        parameterDO.setDateUpdated(new Timestamp(System.currentTimeMillis()));
+        assertEquals(parameterMapper.updateByPrimaryKeySelective(parameterDO), 
1);
+        parameterMapper.deleteByPrimaryKey(parameterDO.getId());
+    }
+}

Reply via email to