from users u left join user_roles ur on ur.user_uuid = u.uuid left join () entity on ur.entity_uuid = entity.uuid and u.active = ${_true} and ( lower(u.name) like #{query.searchQueryToSqlLowercase,jdbcType=VARCHAR} ESCAPE '/' or lower(u.email) like #{query.searchQueryToSql,jdbcType=VARCHAR} ESCAPE '/' or lower(u.login) like #{query.searchQueryToSql,jdbcType=VARCHAR} ESCAPE '/') and ur.role is not null and ur.entity_uuid is null and entity.uuid = #{query.entityUuid,jdbcType=VARCHAR} and ur.role = #{query.permission,jdbcType=VARCHAR} insert into user_roles ( uuid, user_uuid, entity_uuid, role ) values ( #{dto.uuid,jdbcType=VARCHAR}, #{dto.userUuid,jdbcType=VARCHAR}, #{dto.entityUuid,jdbcType=VARCHAR}, #{dto.permission,jdbcType=VARCHAR} ) delete from user_roles where role = #{permission,jdbcType=VARCHAR} and user_uuid = #{userUuid,jdbcType=VARCHAR} and entity_uuid is null delete from user_roles where role = #{permission,jdbcType=VARCHAR} and user_uuid = #{userUuid,jdbcType=VARCHAR} and entity_uuid = #{entityUuid,jdbcType=VARCHAR} delete from user_roles where entity_uuid = #{entityUuid,jdbcType=VARCHAR} delete from user_roles where entity_uuid = #{entityUuid,jdbcType=VARCHAR} and role = #{permission,jdbcType=VARCHAR} DELETE FROM user_roles WHERE user_uuid=#{userUuid,jdbcType=VARCHAR}