--- /dev/null
+<?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.sonar.core.user.RoleMapper">
+
+ <insert id="insertGroupRole" parameterType="GroupRole" useGeneratedKeys="true" keyProperty="id">
+ <selectKey order="BEFORE" resultType="Long" keyProperty="id">
+ select group_roles_seq.NEXTVAL from DUAL
+ </selectKey>
+ INSERT INTO group_roles (id, group_id, resource_id, role)
+ VALUES (#{id}, #{groupId, jdbcType=INTEGER}, #{resourceId, jdbcType=INTEGER}, #{role, jdbcType=VARCHAR})
+ </insert>
+
+ <insert id="insertUserRole" parameterType="UserRole" useGeneratedKeys="true" keyProperty="id">
+ <selectKey order="BEFORE" resultType="Long" keyProperty="id">
+ select user_roles_seq.NEXTVAL from DUAL
+ </selectKey>
+ INSERT INTO user_roles (id, user_id, resource_id, role)
+ VALUES (#{id}, #{userId, jdbcType=INTEGER}, #{resourceId, jdbcType=INTEGER}, #{role, jdbcType=VARCHAR})
+ </insert>
+
+ <delete id="deleteGroupRolesByResourceId" parameterType="long">
+ delete from group_roles where resource_id=#{id}
+ </delete>
+
+ <delete id="deleteUserRolesByResourceId" parameterType="long">
+ delete from user_roles where resource_id=#{id}
+ </delete>
+
+ <select id="countUserRoles" parameterType="long" resultType="int">
+ SELECT count(id)
+ FROM user_roles WHERE resource_id=#{id}
+ </select>
+
+ <select id="countGroupRoles" parameterType="long" resultType="int">
+ SELECT count(id)
+ FROM group_roles WHERE resource_id=#{id}
+ </select>
+</mapper>