You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GroupMapper.xml 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
  3. <mapper namespace="org.sonar.db.user.GroupMapper">
  4. <sql id="groupColumns">
  5. g.uuid as uuid,
  6. g.name as name,
  7. g.description as description,
  8. g.created_at as "createdAt",
  9. g.updated_at as "updatedAt"
  10. </sql>
  11. <select id="selectByName" parameterType="map" resultType="Group">
  12. select
  13. <include refid="groupColumns"/>
  14. from groups g
  15. where g.name = #{name,jdbcType=VARCHAR}
  16. </select>
  17. <select id="selectByUuids" parameterType="String" resultType="Group">
  18. select
  19. <include refid="groupColumns"/>
  20. from groups g
  21. where g.uuid in
  22. <foreach item="uuid" index="index" collection="uuids" open="(" separator="," close=")">
  23. #{uuid,jdbcType=VARCHAR}
  24. </foreach>
  25. </select>
  26. <select id="selectByUuid" parameterType="String" resultType="Group">
  27. SELECT
  28. <include refid="groupColumns"/>
  29. FROM groups g
  30. <where>
  31. g.uuid=#{uuid,jdbcType=VARCHAR}
  32. </where>
  33. </select>
  34. <delete id="deleteByUuid" parameterType="String">
  35. DELETE FROM groups
  36. <where>
  37. uuid=#{uuid,jdbcType=VARCHAR}
  38. </where>
  39. </delete>
  40. <select id="selectByUserLogin" parameterType="string" resultType="Group">
  41. select
  42. <include refid="groupColumns"/>
  43. from groups g
  44. inner join groups_users gu on gu.group_uuid = g.uuid
  45. inner join users u on u.uuid = gu.user_uuid
  46. where u.login=#{login,jdbcType=VARCHAR}
  47. </select>
  48. <select id="selectByNames" parameterType="map" resultType="Group">
  49. select
  50. <include refid="groupColumns"/>
  51. from groups g
  52. where
  53. g.name in
  54. <foreach item="name" index="index" collection="names" open="(" separator="," close=")">
  55. #{name,jdbcType=VARCHAR}
  56. </foreach>
  57. </select>
  58. <insert id="insert" parameterType="Group" useGeneratedKeys="false">
  59. insert into groups (
  60. uuid,
  61. name,
  62. description,
  63. created_at,
  64. updated_at
  65. ) values (
  66. #{uuid,jdbcType=VARCHAR},
  67. #{name,jdbcType=VARCHAR},
  68. #{description,jdbcType=VARCHAR},
  69. #{createdAt,jdbcType=TIMESTAMP},
  70. #{updatedAt,jdbcType=TIMESTAMP}
  71. )
  72. </insert>
  73. <update id="update" parameterType="Group">
  74. UPDATE groups SET
  75. name=#{name,jdbcType=VARCHAR},
  76. description=#{description,jdbcType=VARCHAR},
  77. updated_at=#{updatedAt,jdbcType=TIMESTAMP}
  78. WHERE uuid=#{uuid}
  79. </update>
  80. <select id="selectByQuery" parameterType="map" resultType="Group">
  81. select
  82. <include refid="groupColumns"/>
  83. from groups g
  84. <if test="query!=null">
  85. where upper(g.name) like #{query,jdbcType=VARCHAR} escape '/'
  86. </if>
  87. order by upper(g.name)
  88. </select>
  89. <select id="countByQuery" parameterType="map" resultType="int">
  90. select count(1)
  91. from groups g
  92. <if test="query!=null">
  93. where upper(g.name) like #{query,jdbcType=VARCHAR} escape '/'
  94. </if>
  95. </select>
  96. </mapper>