diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-02-11 15:29:08 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-02-16 21:09:41 +0100 |
commit | 33acda7596369ed1bffbcd25b8d0d590fa87be49 (patch) | |
tree | 250e922234793c6b3d7bab1caf05b3fc21c33c65 /sonar-db/src | |
parent | e6dd781f43af40b2648543249855e1c53796c91c (diff) | |
download | sonarqube-33acda7596369ed1bffbcd25b8d0d590fa87be49.tar.gz sonarqube-33acda7596369ed1bffbcd25b8d0d590fa87be49.zip |
Fix integer type of user and group ids
User IDs are INTEGER in database. The java classes are fixed
to replace long by int.
Diffstat (limited to 'sonar-db/src')
63 files changed, 293 insertions, 291 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/organization/OrganizationDto.java b/sonar-db/src/main/java/org/sonar/db/organization/OrganizationDto.java index 79705021095..7ba488b6c16 100644 --- a/sonar-db/src/main/java/org/sonar/db/organization/OrganizationDto.java +++ b/sonar-db/src/main/java/org/sonar/db/organization/OrganizationDto.java @@ -40,7 +40,7 @@ public class OrganizationDto { */ private boolean guarded = false; /** If of the user for whom the organization was created, can be null. */ - private Long userId; + private Integer userId; private long createdAt; private long updatedAt; @@ -108,11 +108,11 @@ public class OrganizationDto { } @CheckForNull - public Long getUserId() { + public Integer getUserId() { return userId; } - public OrganizationDto setUserId(@Nullable Long userId) { + public OrganizationDto setUserId(@Nullable Integer userId) { this.userId = userId; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationDao.java b/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationDao.java index 4a168a5a826..6f843f537ed 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationDao.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationDao.java @@ -44,7 +44,7 @@ public class AuthorizationDao implements Dao { /** * Loads all the permissions granted to logged-in user for the specified organization */ - public Set<String> selectOrganizationPermissions(DbSession dbSession, String organizationUuid, long userId) { + public Set<String> selectOrganizationPermissions(DbSession dbSession, String organizationUuid, int userId) { return mapper(dbSession).selectOrganizationPermissions(organizationUuid, userId); } @@ -60,7 +60,7 @@ public class AuthorizationDao implements Dao { * is deleted. The anyone virtual group is not taken into account. */ public int countUsersWithGlobalPermissionExcludingGroup(DbSession dbSession, String organizationUuid, - String permission, long excludedGroupId) { + String permission, int excludedGroupId) { return mapper(dbSession).countUsersWithGlobalPermissionExcludingGroup(organizationUuid, permission, excludedGroupId); } @@ -69,29 +69,29 @@ public class AuthorizationDao implements Dao { * is deleted. The anyone virtual group is not taken into account. */ public int countUsersWithGlobalPermissionExcludingUser(DbSession dbSession, String organizationUuid, - String permission, long excludedUSerId) { - return mapper(dbSession).countUsersWithGlobalPermissionExcludingUser(organizationUuid, permission, excludedUSerId); + String permission, int excludedUserId) { + return mapper(dbSession).countUsersWithGlobalPermissionExcludingUser(organizationUuid, permission, excludedUserId); } /** * The number of users who will still have the permission if the user {@code userId} * is removed from group {@code groupId}. The anyone virtual group is not taken into account. - * Contrary to {@link #countUsersWithGlobalPermissionExcludingUser(DbSession, String, String, long)}, user + * Contrary to {@link #countUsersWithGlobalPermissionExcludingUser(DbSession, String, String, int)}, user * still exists and may have the permission directly or through other groups. */ public int countUsersWithGlobalPermissionExcludingGroupMember(DbSession dbSession, String organizationUuid, - String permission, long groupId, long userId) { + String permission, int groupId, int userId) { return mapper(dbSession).countUsersWithGlobalPermissionExcludingGroupMember(organizationUuid, permission, groupId, userId); } /** * The number of users who will still have the permission if the permission {@code permission} * is removed from user {@code userId}. The anyone virtual group is not taken into account. - * Contrary to {@link #countUsersWithGlobalPermissionExcludingUser(DbSession, String, String, long)}, user + * Contrary to {@link #countUsersWithGlobalPermissionExcludingUser(DbSession, String, String, int)}, user * still exists and may have the permission through groups. */ public int countUsersWithGlobalPermissionExcludingUserPermission(DbSession dbSession, String organizationUuid, - String permission, long userId) { + String permission, int userId) { return mapper(dbSession).countUsersWithGlobalPermissionExcludingUserPermission(organizationUuid, permission, userId); } @@ -102,7 +102,7 @@ public class AuthorizationDao implements Dao { * <br/> * Group membership is taken into account. Anonymous privileges are ignored. */ - public Set<String> selectOrganizationUuidsOfUserWithGlobalPermission(DbSession dbSession, long userId, String permission) { + public Set<String> selectOrganizationUuidsOfUserWithGlobalPermission(DbSession dbSession, int userId, String permission) { return mapper(dbSession).selectOrganizationUuidsOfUserWithGlobalPermission(userId, permission); } @@ -131,7 +131,7 @@ public class AuthorizationDao implements Dao { * Keep only authorized user that have the given permission on a given project. * Please Note that if the permission is 'Anyone' is NOT taking into account by thie method. */ - public Collection<Long> keepAuthorizedUsersForRoleAndProject(DbSession dbSession, Collection<Long> userIds, String role, long projectId) { + public Collection<Integer> keepAuthorizedUsersForRoleAndProject(DbSession dbSession, Collection<Integer> userIds, String role, long projectId) { return executeLargeInputs( userIds, partitionOfIds -> mapper(dbSession).keepAuthorizedUsersForRoleAndProject(role, projectId, partitionOfIds)); diff --git a/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationMapper.java b/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationMapper.java index f13bbd37f85..cc5f1f7f1fc 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationMapper.java @@ -29,28 +29,28 @@ import org.apache.ibatis.annotations.Param; */ public interface AuthorizationMapper { - Set<String> selectOrganizationPermissions(@Param("organizationUuid") String organizationUuid, @Param("userId") long userId); + Set<String> selectOrganizationPermissions(@Param("organizationUuid") String organizationUuid, @Param("userId") int userId); Set<String> selectOrganizationPermissionsOfAnonymous(@Param("organizationUuid") String organizationUuid); int countUsersWithGlobalPermissionExcludingGroup(@Param("organizationUuid") String organizationUuid, - @Param("permission") String permission, @Param("excludedGroupId") long excludedGroupId); + @Param("permission") String permission, @Param("excludedGroupId") int excludedGroupId); int countUsersWithGlobalPermissionExcludingUser(@Param("organizationUuid") String organizationUuid, @Param("permission") String permission, - @Param("excludedUserId") long excludedUserId); + @Param("excludedUserId") int excludedUserId); int countUsersWithGlobalPermissionExcludingGroupMember(@Param("organizationUuid") String organizationUuid, - @Param("permission") String permission, @Param("groupId") long groupId, @Param("userId") long userId); + @Param("permission") String permission, @Param("groupId") int groupId, @Param("userId") int userId); int countUsersWithGlobalPermissionExcludingUserPermission(@Param("organizationUuid") String organizationUuid, - @Param("permission") String permission, @Param("userId") long userId); + @Param("permission") String permission, @Param("userId") int userId); - Set<String> selectOrganizationUuidsOfUserWithGlobalPermission(@Param("userId") long userId, @Param("permission") String permission); + Set<String> selectOrganizationUuidsOfUserWithGlobalPermission(@Param("userId") int userId, @Param("permission") String permission); Set<Long> keepAuthorizedProjectIdsForAnonymous(@Param("role") String role, @Param("componentIds") Collection<Long> componentIds); - Set<Long> keepAuthorizedProjectIdsForUser(@Param("userId") long userId, @Param("role") String role, @Param("componentIds") Collection<Long> componentIds); + Set<Long> keepAuthorizedProjectIdsForUser(@Param("userId") int userId, @Param("role") String role, @Param("componentIds") Collection<Long> componentIds); - List<Long> keepAuthorizedUsersForRoleAndProject(@Param("role") String role, @Param("componentId") long componentId, @Param("userIds") List<Long> userIds); + List<Integer> keepAuthorizedUsersForRoleAndProject(@Param("role") String role, @Param("componentId") long componentId, @Param("userIds") List<Integer> userIds); } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDao.java b/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDao.java index 4f1680a444d..c8fe45a4cd3 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDao.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDao.java @@ -60,7 +60,7 @@ public class GroupPermissionDao implements Dao { * Select global or project permission of given groups and organization. Anyone virtual group is supported * through the value "zero" (0L) in {@code groupIds}. */ - public List<GroupPermissionDto> selectByGroupIds(DbSession dbSession, String organizationUuid, List<Long> groupIds, @Nullable Long projectId) { + public List<GroupPermissionDto> selectByGroupIds(DbSession dbSession, String organizationUuid, List<Integer> groupIds, @Nullable Long projectId) { return executeLargeInputs(groupIds, groups -> mapper(dbSession).selectByGroupIds(organizationUuid, groups, projectId)); } @@ -84,7 +84,7 @@ public class GroupPermissionDao implements Dao { * Selects the global permissions granted to group. An empty list is returned if the * group does not exist. */ - public List<String> selectGlobalPermissionsOfGroup(DbSession session, String organizationUuid, @Nullable Long groupId) { + public List<String> selectGlobalPermissionsOfGroup(DbSession session, String organizationUuid, @Nullable Integer groupId) { return mapper(session).selectGlobalPermissionsOfGroup(organizationUuid, groupId); } @@ -92,7 +92,7 @@ public class GroupPermissionDao implements Dao { * Selects the permissions granted to group and project. An empty list is returned if the * group or project do not exist. */ - public List<String> selectProjectPermissionsOfGroup(DbSession session, String organizationUuid, @Nullable Long groupId, long projectId) { + public List<String> selectProjectPermissionsOfGroup(DbSession session, String organizationUuid, @Nullable Integer groupId, long projectId) { return mapper(session).selectProjectPermissionsOfGroup(organizationUuid, groupId, projectId); } @@ -145,7 +145,7 @@ public class GroupPermissionDao implements Dao { * @param groupId if null, then anyone, else id of group * @param rootComponentId if null, then global permission, else id of root component (project) */ - public void delete(DbSession dbSession, String permission, String organizationUuid, @Nullable Long groupId, @Nullable Long rootComponentId) { + public void delete(DbSession dbSession, String permission, String organizationUuid, @Nullable Integer groupId, @Nullable Long rootComponentId) { mapper(dbSession).delete(permission, organizationUuid, groupId, rootComponentId); } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDto.java b/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDto.java index f84d5c76aa1..2a1d166b67f 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDto.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDto.java @@ -24,11 +24,11 @@ import javax.annotation.Nullable; public class GroupPermissionDto { private String organizationUuid; - private Long groupId; + private Integer groupId; private Long resourceId; private String role; - public Long getGroupId() { + public Integer getGroupId() { return groupId; } @@ -44,7 +44,7 @@ public class GroupPermissionDto { /** * Null when Anyone */ - public GroupPermissionDto setGroupId(@Nullable Long groupId) { + public GroupPermissionDto setGroupId(@Nullable Integer groupId) { this.groupId = groupId; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java b/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java index 9c6ebec558f..10484b173d9 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java @@ -34,7 +34,7 @@ public interface GroupPermissionMapper { int countGroupsByQuery(@Param("organizationUuid") String organizationUuid, @Param("query") PermissionQuery query); List<GroupPermissionDto> selectByGroupIds(@Param("organizationUuid") String organizationUuid, - @Param("groupIds") List<Long> groupIds, @Nullable @Param("projectId") Long projectId); + @Param("groupIds") List<Integer> groupIds, @Nullable @Param("projectId") Long projectId); void groupsCountByProjectIdAndPermission(Map<String, Object> parameters, ResultHandler resultHandler); @@ -43,13 +43,13 @@ public interface GroupPermissionMapper { void deleteByRootComponentId(@Param("rootComponentId") long componentId); void delete(@Param("permission") String permission, @Param("organizationUuid") String organizationUuid, - @Nullable @Param("groupId") Long groupId, @Nullable @Param("rootComponentId") Long rootComponentId); + @Nullable @Param("groupId") Integer groupId, @Nullable @Param("rootComponentId") Long rootComponentId); List<String> selectGlobalPermissionsOfGroup(@Param("organizationUuid") String organizationUuid, - @Nullable @Param("groupId") Long groupId); + @Nullable @Param("groupId") Integer groupId); List<String> selectProjectPermissionsOfGroup(@Param("organizationUuid") String organizationUuid, - @Nullable @Param("groupId") Long groupId, @Param("projectId") long projectId); + @Nullable @Param("groupId") Integer groupId, @Param("projectId") long projectId); void deleteByOrganization(@Param("organizationUuid") String organizationUuid); diff --git a/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionDao.java b/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionDao.java index 765a7ee03f2..6ae036500f2 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionDao.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionDao.java @@ -58,7 +58,7 @@ public class UserPermissionDao implements Dao { * Shortcut over {@link #select(DbSession, String, PermissionQuery, Collection)} to return only distinct user * ids, keeping the same order. */ - public List<Long> selectUserIds(DbSession dbSession, String organizationUuid, PermissionQuery query) { + public List<Integer> selectUserIds(DbSession dbSession, String organizationUuid, PermissionQuery query) { List<UserPermissionDto> dtos = select(dbSession, organizationUuid, query, null); return dtos.stream() .map(UserPermissionDto::getUserId) @@ -87,7 +87,7 @@ public class UserPermissionDao implements Dao { * * @return the global permissions. An empty list is returned if user or organization do not exist. */ - public List<String> selectGlobalPermissionsOfUser(DbSession dbSession, long userId, String organizationUuid) { + public List<String> selectGlobalPermissionsOfUser(DbSession dbSession, int userId, String organizationUuid) { return mapper(dbSession).selectGlobalPermissionsOfUser(userId, organizationUuid); } @@ -96,7 +96,7 @@ public class UserPermissionDao implements Dao { * * @return the project permissions. An empty list is returned if project or user do not exist. */ - public List<String> selectProjectPermissionsOfUser(DbSession dbSession, long userId, long projectId) { + public List<String> selectProjectPermissionsOfUser(DbSession dbSession, int userId, long projectId) { return mapper(dbSession).selectProjectPermissionsOfUser(userId, projectId); } @@ -119,14 +119,14 @@ public class UserPermissionDao implements Dao { /** * Removes a single global permission from user */ - public void deleteGlobalPermission(DbSession dbSession, long userId, String permission, String organizationUuid) { + public void deleteGlobalPermission(DbSession dbSession, int userId, String permission, String organizationUuid) { mapper(dbSession).deleteGlobalPermission(userId, permission, organizationUuid); } /** * Removes a single project permission from user */ - public void deleteProjectPermission(DbSession dbSession, long userId, String permission, long projectId) { + public void deleteProjectPermission(DbSession dbSession, int userId, String permission, long projectId) { mapper(dbSession).deleteProjectPermission(userId, permission, projectId); } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionDto.java b/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionDto.java index ae561ffe438..6638cd64d16 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionDto.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionDto.java @@ -26,14 +26,14 @@ public class UserPermissionDto { private String organizationUuid; private String permission; - private long userId; + private int userId; private Long componentId; public UserPermissionDto() { // used by MyBatis } - public UserPermissionDto(String organizationUuid, String permission, long userId, @Nullable Long componentId) { + public UserPermissionDto(String organizationUuid, String permission, int userId, @Nullable Long componentId) { this.organizationUuid = organizationUuid; this.permission = permission; this.userId = userId; @@ -44,7 +44,7 @@ public class UserPermissionDto { return permission; } - public long getUserId() { + public int getUserId() { return userId; } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionMapper.java b/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionMapper.java index 2a6c7b32e07..56209760616 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionMapper.java @@ -48,17 +48,17 @@ public interface UserPermissionMapper { void insert(UserPermissionDto dto); - void deleteGlobalPermission(@Param("userId") long userId, @Param("permission") String permission, + void deleteGlobalPermission(@Param("userId") int userId, @Param("permission") String permission, @Param("organizationUuid") String organizationUuid); - void deleteProjectPermission(@Param("userId") long userId, @Param("permission") String permission, + void deleteProjectPermission(@Param("userId") int userId, @Param("permission") String permission, @Param("projectId") long projectId); void deleteProjectPermissions(@Param("projectId") long projectId); - List<String> selectGlobalPermissionsOfUser(@Param("userId") long userId, @Param("organizationUuid") String organizationUuid); + List<String> selectGlobalPermissionsOfUser(@Param("userId") int userId, @Param("organizationUuid") String organizationUuid); - List<String> selectProjectPermissionsOfUser(@Param("userId") long userId, @Param("projectId") long projectId); + List<String> selectProjectPermissionsOfUser(@Param("userId") int userId, @Param("projectId") long projectId); void deleteByOrganization(@Param("organizationUuid") String organizationUuid); } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java index 061a547d095..a2aed9311f4 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java @@ -88,7 +88,7 @@ public class PermissionTemplateDao implements Dao { /** * @return {@code true} if template contains groups that are granted with {@code permission}, else {@code false} */ - public boolean hasGroupsWithPermission(DbSession dbSession, long templateId, String permission, @Nullable Long groupId) { + public boolean hasGroupsWithPermission(DbSession dbSession, long templateId, String permission, @Nullable Integer groupId) { return mapper(dbSession).countGroupsWithPermission(templateId, permission, groupId) > 0; } @@ -157,7 +157,7 @@ public class PermissionTemplateDao implements Dao { return permissionTemplate; } - public void insertUserPermission(DbSession session, Long templateId, Long userId, String permission) { + public void insertUserPermission(DbSession session, Long templateId, Integer userId, String permission) { PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto() .setTemplateId(templateId) .setUserId(userId) @@ -169,7 +169,7 @@ public class PermissionTemplateDao implements Dao { session.commit(); } - public void deleteUserPermission(DbSession session, Long templateId, Long userId, String permission) { + public void deleteUserPermission(DbSession session, Long templateId, Integer userId, String permission) { PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto() .setTemplateId(templateId) .setPermission(permission) @@ -178,7 +178,7 @@ public class PermissionTemplateDao implements Dao { session.commit(); } - public void insertGroupPermission(DbSession session, long templateId, @Nullable Long groupId, String permission) { + public void insertGroupPermission(DbSession session, long templateId, @Nullable Integer groupId, String permission) { PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto() .setTemplateId(templateId) .setPermission(permission) @@ -192,7 +192,7 @@ public class PermissionTemplateDao implements Dao { mapper(session).insertGroupPermission(permissionTemplateGroup); } - public void deleteGroupPermission(DbSession session, Long templateId, @Nullable Long groupId, String permission) { + public void deleteGroupPermission(DbSession session, Long templateId, @Nullable Integer groupId, String permission) { PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto() .setTemplateId(templateId) .setPermission(permission) @@ -205,14 +205,14 @@ public class PermissionTemplateDao implements Dao { return mapper(dbSession).selectByName(organizationUuid, name.toUpperCase(Locale.ENGLISH)); } - public List<String> selectPotentialPermissionsByUserIdAndTemplateId(DbSession dbSession, @Nullable Long currentUserId, long templateId) { + public List<String> selectPotentialPermissionsByUserIdAndTemplateId(DbSession dbSession, @Nullable Integer currentUserId, long templateId) { return mapper(dbSession).selectPotentialPermissionsByUserIdAndTemplateId(currentUserId, templateId); } /** * Remove a group from all templates (used when removing a group) */ - public void deleteByGroup(DbSession session, long groupId) { + public void deleteByGroup(DbSession session, int groupId) { session.getMapper(PermissionTemplateMapper.class).deleteByGroupId(groupId); } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateGroupDto.java b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateGroupDto.java index 06289c90a73..d37b2a4ebf7 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateGroupDto.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateGroupDto.java @@ -25,7 +25,7 @@ import javax.annotation.Nullable; public class PermissionTemplateGroupDto { private Long id; private Long templateId; - private Long groupId; + private Integer groupId; private String permission; private String groupName; private Date createdAt; @@ -49,11 +49,11 @@ public class PermissionTemplateGroupDto { return this; } - public Long getGroupId() { + public Integer getGroupId() { return groupId; } - public PermissionTemplateGroupDto setGroupId(@Nullable Long groupId) { + public PermissionTemplateGroupDto setGroupId(@Nullable Integer groupId) { this.groupId = groupId; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java index 59de7f79d84..ddf2c0a4c0d 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java @@ -62,7 +62,7 @@ public interface PermissionTemplateMapper { void insertGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup); - void deleteByGroupId(long groupId); + void deleteByGroupId(int groupId); PermissionTemplateDto selectByName(@Param("organizationUuid") String organizationUuid, @Param("name") String name); @@ -81,9 +81,9 @@ public interface PermissionTemplateMapper { void groupsCountByTemplateIdAndPermission(Map<String, Object> parameters, ResultHandler resultHandler); - List<String> selectPotentialPermissionsByUserIdAndTemplateId(@Param("userId") @Nullable Long currentUserId, @Param("templateId") long templateId); + List<String> selectPotentialPermissionsByUserIdAndTemplateId(@Param("userId") @Nullable Integer currentUserId, @Param("templateId") long templateId); - int countGroupsWithPermission(@Param("templateId") long templateId, @Param("permission") String permission, @Nullable @Param("groupId") Long groupId); + int countGroupsWithPermission(@Param("templateId") long templateId, @Param("permission") String permission, @Nullable @Param("groupId") Integer groupId); List<Long> selectTemplateIdsByOrganization(@Param("organizationUuid") String organizationUuid); diff --git a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateUserDto.java b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateUserDto.java index 89a0526a684..3db22ae1560 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateUserDto.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateUserDto.java @@ -24,7 +24,7 @@ import java.util.Date; public class PermissionTemplateUserDto { private Long id; private Long templateId; - private Long userId; + private Integer userId; private String permission; private String userName; private String userLogin; @@ -49,11 +49,11 @@ public class PermissionTemplateUserDto { return this; } - public Long getUserId() { + public Integer getUserId() { return userId; } - public PermissionTemplateUserDto setUserId(Long userId) { + public PermissionTemplateUserDto setUserId(Integer userId) { this.userId = userId; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java b/sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java index 0f6bfe392af..df0d6a383be 100644 --- a/sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java +++ b/sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java @@ -183,7 +183,7 @@ public class PropertiesDao implements Dao { } private void save(PropertiesMapper mapper, - String key, @Nullable Long userId, @Nullable Long componentId, + String key, @Nullable Integer userId, @Nullable Long componentId, @Nullable String value) { checkKey(key); diff --git a/sonar-db/src/main/java/org/sonar/db/property/PropertiesMapper.java b/sonar-db/src/main/java/org/sonar/db/property/PropertiesMapper.java index e7a5b25d5b0..dd8f6c562b8 100644 --- a/sonar-db/src/main/java/org/sonar/db/property/PropertiesMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/property/PropertiesMapper.java @@ -46,16 +46,16 @@ public interface PropertiesMapper { List<PropertyDto> selectDescendantModuleProperties(@Param("moduleUuid") String moduleUuid, @Param(value = "scope") String scope, @Param(value = "excludeDisabled") boolean excludeDisabled); - void insertAsEmpty(@Param("key") String key, @Nullable @Param("userId") Long userId, @Nullable @Param("componentId") Long componentId, + void insertAsEmpty(@Param("key") String key, @Nullable @Param("userId") Integer userId, @Nullable @Param("componentId") Long componentId, @Param("now") long now); - void insertAsText(@Param("key") String key, @Nullable @Param("userId") Long userId, @Nullable @Param("componentId") Long componentId, + void insertAsText(@Param("key") String key, @Nullable @Param("userId") Integer userId, @Nullable @Param("componentId") Long componentId, @Param("value") String value, @Param("now") long now); - void insertAsClob(@Param("key") String key, @Nullable @Param("userId") Long userId, @Nullable @Param("componentId") Long componentId, + void insertAsClob(@Param("key") String key, @Nullable @Param("userId") Integer userId, @Nullable @Param("componentId") Long componentId, @Param("value") String value, @Param("now") long now); - int delete(@Param("key") String key, @Nullable @Param("userId") Long userId, @Nullable @Param("componentId") Long componentId); + int delete(@Param("key") String key, @Nullable @Param("userId") Integer userId, @Nullable @Param("componentId") Long componentId); int deleteById(long id); diff --git a/sonar-db/src/main/java/org/sonar/db/property/PropertyDto.java b/sonar-db/src/main/java/org/sonar/db/property/PropertyDto.java index 6e0ebc12e8a..f9cabe4c6e7 100644 --- a/sonar-db/src/main/java/org/sonar/db/property/PropertyDto.java +++ b/sonar-db/src/main/java/org/sonar/db/property/PropertyDto.java @@ -32,7 +32,7 @@ public class PropertyDto { private String key; private String value; private Long resourceId; - private Long userId; + private Integer userId; public String getKey() { return key; @@ -64,11 +64,11 @@ public class PropertyDto { } @CheckForNull - public Long getUserId() { + public Integer getUserId() { return userId; } - public PropertyDto setUserId(@Nullable Long userId) { + public PropertyDto setUserId(@Nullable Integer userId) { this.userId = userId; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/property/PropertyTesting.java b/sonar-db/src/main/java/org/sonar/db/property/PropertyTesting.java index 14593023ae5..79d4d6fd7d1 100644 --- a/sonar-db/src/main/java/org/sonar/db/property/PropertyTesting.java +++ b/sonar-db/src/main/java/org/sonar/db/property/PropertyTesting.java @@ -74,7 +74,7 @@ public class PropertyTesting { return newPropertyDto(component.getId(), user.getId()); } - private static PropertyDto newPropertyDto(@Nullable Long componentId, @Nullable Long userId) { + private static PropertyDto newPropertyDto(@Nullable Long componentId, @Nullable Integer userId) { String key = String.valueOf(cursor); cursor++; String value = String.valueOf(cursor); @@ -82,7 +82,7 @@ public class PropertyTesting { return newPropertyDto(key, value, componentId, userId); } - private static PropertyDto newPropertyDto(String key, String value, @Nullable Long componentId, @Nullable Long userId) { + private static PropertyDto newPropertyDto(String key, String value, @Nullable Long componentId, @Nullable Integer userId) { PropertyDto propertyDto = new PropertyDto() .setKey(key) .setValue(value); diff --git a/sonar-db/src/main/java/org/sonar/db/user/GroupDao.java b/sonar-db/src/main/java/org/sonar/db/user/GroupDao.java index a046383ecb1..22fb347ada5 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/GroupDao.java +++ b/sonar-db/src/main/java/org/sonar/db/user/GroupDao.java @@ -59,15 +59,15 @@ public class GroupDao implements Dao { } @CheckForNull - public GroupDto selectById(DbSession dbSession, long groupId) { + public GroupDto selectById(DbSession dbSession, int groupId) { return mapper(dbSession).selectById(groupId); } - public List<GroupDto> selectByIds(DbSession dbSession, List<Long> ids) { + public List<GroupDto> selectByIds(DbSession dbSession, List<Integer> ids) { return executeLargeInputs(ids, mapper(dbSession)::selectByIds); } - public void deleteById(DbSession dbSession, long groupId) { + public void deleteById(DbSession dbSession, int groupId) { mapper(dbSession).deleteById(groupId); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/GroupDto.java b/sonar-db/src/main/java/org/sonar/db/user/GroupDto.java index 8077cbd5c23..8156414f47a 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/GroupDto.java +++ b/sonar-db/src/main/java/org/sonar/db/user/GroupDto.java @@ -25,18 +25,18 @@ import javax.annotation.Nullable; public class GroupDto { - private Long id; + private Integer id; private String name; private String description; private String organizationUuid; private Date createdAt; private Date updatedAt; - public Long getId() { + public Integer getId() { return id; } - public GroupDto setId(Long id) { + public GroupDto setId(Integer id) { this.id = id; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/user/GroupMapper.java b/sonar-db/src/main/java/org/sonar/db/user/GroupMapper.java index f6a7164b5b8..3f70d26a190 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/GroupMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/user/GroupMapper.java @@ -28,7 +28,7 @@ import org.apache.ibatis.session.RowBounds; public interface GroupMapper { @CheckForNull - GroupDto selectById(long groupId); + GroupDto selectById(int groupId); List<GroupDto> selectByUserLogin(String userLogin); @@ -47,9 +47,9 @@ public interface GroupMapper { * * @return 1 or 0. Either because the organization uuid is not the one of the group or because the group does not exist */ - int countGroupByOrganizationAndId(@Param("organizationUuid") String organizationUuid, @Param("groupId") long groupId); + int countGroupByOrganizationAndId(@Param("organizationUuid") String organizationUuid, @Param("groupId") int groupId); - void deleteById(long groupId); + void deleteById(int groupId); void deleteByOrganization(@Param("organizationUuid") String organizationUuid); @@ -58,5 +58,5 @@ public interface GroupMapper { List<GroupDto> selectByOrganizationUuid(@Param("organizationUuid") String organizationUuid); - List<GroupDto> selectByIds(@Param("ids") List<Long> ids); + List<GroupDto> selectByIds(@Param("ids") List<Integer> ids); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDao.java b/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDao.java index 82541371094..bde120c6167 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDao.java +++ b/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDao.java @@ -34,12 +34,12 @@ import static org.sonar.db.DatabaseUtils.executeLargeInputs; public class GroupMembershipDao implements Dao { - public List<GroupMembershipDto> selectGroups(DbSession session, GroupMembershipQuery query, Long userId, int offset, int limit) { + public List<GroupMembershipDto> selectGroups(DbSession session, GroupMembershipQuery query, Integer userId, int offset, int limit) { Map<String, Object> params = ImmutableMap.of("query", query, "userId", userId); return mapper(session).selectGroups(params, new RowBounds(offset, limit)); } - public int countGroups(DbSession session, GroupMembershipQuery query, Long userId) { + public int countGroups(DbSession session, GroupMembershipQuery query, Integer userId) { Map<String, Object> params = ImmutableMap.of("query", query, "userId", userId); return mapper(session).countGroups(params); } @@ -54,7 +54,7 @@ public class GroupMembershipDao implements Dao { return mapper(session).countMembers(params); } - public Map<String, Integer> countUsersByGroups(DbSession session, Collection<Long> groupIds) { + public Map<String, Integer> countUsersByGroups(DbSession session, Collection<Integer> groupIds) { Map<String, Integer> result = Maps.newHashMap(); executeLargeInputs( groupIds, @@ -69,7 +69,7 @@ public class GroupMembershipDao implements Dao { return result; } - public List<Long> selectGroupIdsByUserId(DbSession dbSession, long userId) { + public List<Integer> selectGroupIdsByUserId(DbSession dbSession, int userId) { return mapper(dbSession).selectGroupIdsByUserId(userId); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDto.java b/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDto.java index 64de46d6621..1307352fd60 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDto.java +++ b/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDto.java @@ -30,7 +30,7 @@ public class GroupMembershipDto { private Long id; private String name; private String description; - private Long userId; + private Integer userId; public Long getId() { return id; @@ -61,11 +61,11 @@ public class GroupMembershipDto { } @CheckForNull - public Long getUserId() { + public Integer getUserId() { return userId; } - public GroupMembershipDto setUserId(@Nullable Long userId) { + public GroupMembershipDto setUserId(@Nullable Integer userId) { this.userId = userId; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipMapper.java b/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipMapper.java index 37d7d6cbab8..6bf021b158e 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipMapper.java @@ -34,10 +34,10 @@ public interface GroupMembershipMapper { int countMembers(Map<String, Object> params); - List<GroupUserCount> countUsersByGroup(@Param("groupIds") List<Long> groupIds); + List<GroupUserCount> countUsersByGroup(@Param("groupIds") List<Integer> groupIds); List<LoginGroup> selectGroupsByLogins(@Param("logins") List<String> logins); - List<Long> selectGroupIdsByUserId(@Param("userId") long userId); + List<Integer> selectGroupIdsByUserId(@Param("userId") int userId); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/RoleDao.java b/sonar-db/src/main/java/org/sonar/db/user/RoleDao.java index 717ef99e2b6..66e14f432a1 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/RoleDao.java +++ b/sonar-db/src/main/java/org/sonar/db/user/RoleDao.java @@ -29,11 +29,11 @@ public class RoleDao implements Dao { * All the projects on which the user has {@code permission}, directly or through * groups. */ - public List<Long> selectComponentIdsByPermissionAndUserId(DbSession dbSession, String permission, long userId) { + public List<Long> selectComponentIdsByPermissionAndUserId(DbSession dbSession, String permission, int userId) { return mapper(dbSession).selectComponentIdsByPermissionAndUserId(permission, userId); } - public void deleteGroupRolesByGroupId(DbSession session, long groupId) { + public void deleteGroupRolesByGroupId(DbSession session, int groupId) { mapper(session).deleteGroupRolesByGroupId(groupId); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/RoleMapper.java b/sonar-db/src/main/java/org/sonar/db/user/RoleMapper.java index 7647ce64934..6e9e45a4b03 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/RoleMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/user/RoleMapper.java @@ -24,8 +24,8 @@ import org.apache.ibatis.annotations.Param; public interface RoleMapper { - List<Long> selectComponentIdsByPermissionAndUserId(@Param("permission") String permission, @Param("userId") long userId); + List<Long> selectComponentIdsByPermissionAndUserId(@Param("permission") String permission, @Param("userId") int userId); - void deleteGroupRolesByGroupId(long groupId); + void deleteGroupRolesByGroupId(int groupId); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserDao.java b/sonar-db/src/main/java/org/sonar/db/user/UserDao.java index 0a87ffddae5..754cb376ef5 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/UserDao.java +++ b/sonar-db/src/main/java/org/sonar/db/user/UserDao.java @@ -50,13 +50,13 @@ public class UserDao implements Dao { this.system2 = system2; } - public UserDto selectUserById(long userId) { + public UserDto selectUserById(int userId) { try (DbSession session = mybatis.openSession(false)) { return selectUserById(session, userId); } } - public UserDto selectUserById(DbSession session, long userId) { + public UserDto selectUserById(DbSession session, int userId) { return mapper(session).selectUser(userId); } @@ -66,7 +66,7 @@ public class UserDao implements Dao { * * Used by the Governance plugin */ - public List<UserDto> selectByIds(DbSession session, Collection<Long> ids) { + public List<UserDto> selectByIds(DbSession session, Collection<Integer> ids) { return executeLargeInputs(ids, mapper(session)::selectByIds); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserDto.java b/sonar-db/src/main/java/org/sonar/db/user/UserDto.java index 445990edca7..7f41ce65250 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/UserDto.java +++ b/sonar-db/src/main/java/org/sonar/db/user/UserDto.java @@ -37,7 +37,7 @@ import static java.util.Objects.requireNonNull; public class UserDto { public static final char SCM_ACCOUNTS_SEPARATOR = '\n'; - private Long id; + private Integer id; private String login; private String name; private String email; @@ -52,11 +52,11 @@ public class UserDto { private boolean local = true; private boolean root = false; - public Long getId() { + public Integer getId() { return id; } - public UserDto setId(Long id) { + public UserDto setId(Integer id) { this.id = id; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserGroupDao.java b/sonar-db/src/main/java/org/sonar/db/user/UserGroupDao.java index edea5484b5c..1e53f6a312e 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/UserGroupDao.java +++ b/sonar-db/src/main/java/org/sonar/db/user/UserGroupDao.java @@ -29,11 +29,11 @@ public class UserGroupDao implements Dao { return dto; } - public void delete(DbSession session, long groupId, long userId) { + public void delete(DbSession session, int groupId, int userId) { mapper(session).delete(groupId, userId); } - public void deleteByGroupId(DbSession session, long groupId) { + public void deleteByGroupId(DbSession session, int groupId) { mapper(session).deleteByGroupId(groupId); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserGroupDto.java b/sonar-db/src/main/java/org/sonar/db/user/UserGroupDto.java index e60ae970db1..8e8443bf830 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/UserGroupDto.java +++ b/sonar-db/src/main/java/org/sonar/db/user/UserGroupDto.java @@ -21,23 +21,23 @@ package org.sonar.db.user; public class UserGroupDto { - private Long userId; - private Long groupId; + private int userId; + private int groupId; - public Long getUserId() { + public int getUserId() { return userId; } - public UserGroupDto setUserId(Long userId) { + public UserGroupDto setUserId(int userId) { this.userId = userId; return this; } - public Long getGroupId() { + public int getGroupId() { return groupId; } - public UserGroupDto setGroupId(Long groupId) { + public UserGroupDto setGroupId(int groupId) { this.groupId = groupId; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserGroupMapper.java b/sonar-db/src/main/java/org/sonar/db/user/UserGroupMapper.java index 7de52e9e736..ce0d053d701 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/UserGroupMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/user/UserGroupMapper.java @@ -25,7 +25,7 @@ public interface UserGroupMapper { void insert(UserGroupDto dto); - void delete(@Param("groupId") long groupId, @Param("userId") long userId); + void delete(@Param("groupId") int groupId, @Param("userId") int userId); - void deleteByGroupId(@Param("groupId") long groupId); + void deleteByGroupId(@Param("groupId") int groupId); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserMapper.java b/sonar-db/src/main/java/org/sonar/db/user/UserMapper.java index b7cf25be54e..eac60d442ea 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/UserMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/user/UserMapper.java @@ -37,7 +37,7 @@ public interface UserMapper { List<UserDto> selectNullableByScmAccountOrLoginOrEmail(@Param("scmAccount") String scmAccountOrLoginOrEmail, @Param("likeScmAccount") String likeScmAccount); @CheckForNull - UserDto selectUser(long userId); + UserDto selectUser(int userId); /** * Select user by login. Note that disabled users are ignored. @@ -49,7 +49,7 @@ public interface UserMapper { List<UserDto> selectByLogins(List<String> logins); - List<UserDto> selectByIds(@Param("ids") List<Long> ids); + List<UserDto> selectByIds(@Param("ids") List<Integer> ids); long countByEmail(String email); @@ -64,14 +64,14 @@ public interface UserMapper { void setRoot(@Param("login") String login, @Param("root") boolean root, @Param("now") long now); - void removeUserFromGroups(long userId); + void removeUserFromGroups(int userId); - void deleteUserProperties(long userId); + void deleteUserProperties(int userId); - void deleteUserRoles(long userId); + void deleteUserRoles(int userId); void deletePropertiesMatchingLogin(@Param("propertyKeys") List<String> propertyKeys, @Param("login") String login); - void deactivateUser(@Param("id") long userId, @Param("now") long now); + void deactivateUser(@Param("id") int userId, @Param("now") long now); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserMembershipDto.java b/sonar-db/src/main/java/org/sonar/db/user/UserMembershipDto.java index 750bc2d2d87..a8b5dd6be1d 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/UserMembershipDto.java +++ b/sonar-db/src/main/java/org/sonar/db/user/UserMembershipDto.java @@ -25,7 +25,7 @@ import javax.annotation.Nullable; public class UserMembershipDto { private Long id; - private Long groupId; + private Integer groupId; private String login; private String name; @@ -58,11 +58,11 @@ public class UserMembershipDto { } @CheckForNull - public Long getGroupId() { + public Integer getGroupId() { return groupId; } - public UserMembershipDto setGroupId(@Nullable Long groupId) { + public UserMembershipDto setGroupId(@Nullable Integer groupId) { this.groupId = groupId; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserMembershipQuery.java b/sonar-db/src/main/java/org/sonar/db/user/UserMembershipQuery.java index 3cc3d669196..e93513c5191 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/UserMembershipQuery.java +++ b/sonar-db/src/main/java/org/sonar/db/user/UserMembershipQuery.java @@ -42,7 +42,7 @@ public class UserMembershipQuery { public static final String OUT = "OUT"; public static final Set<String> AVAILABLE_MEMBERSHIPS = ImmutableSet.of(ANY, IN, OUT); - private final long groupId; + private final int groupId; private final String membership; private final String memberSearch; @@ -67,7 +67,7 @@ public class UserMembershipQuery { this.pageIndex = builder.pageIndex; } - public long groupId() { + public int groupId() { return groupId; } @@ -97,7 +97,7 @@ public class UserMembershipQuery { } public static class Builder { - private Long groupId; + private Integer groupId; private String membership; private String memberSearch; @@ -107,7 +107,7 @@ public class UserMembershipQuery { private Builder() { } - public Builder groupId(Long groupId) { + public Builder groupId(Integer groupId) { this.groupId = groupId; return this; } diff --git a/sonar-db/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml b/sonar-db/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml index b3f13d570d4..8df1106fb02 100644 --- a/sonar-db/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml @@ -10,7 +10,7 @@ where gr.organization_uuid=#{organizationUuid,jdbcType=VARCHAR} and gr.resource_id is null and - gu.user_id=#{userId,jdbcType=BIGINT} + gu.user_id=#{userId,jdbcType=INTEGER} union @@ -27,7 +27,7 @@ from user_roles ur where ur.organization_uuid=#{organizationUuid,jdbcType=VARCHAR} and - ur.user_id=#{userId,jdbcType=BIGINT} + ur.user_id=#{userId,jdbcType=INTEGER} and ur.resource_id is null </select> @@ -46,7 +46,7 @@ inner join groups_users gu on gr.group_id=gu.group_id where gr.resource_id=#{rootComponentId,jdbcType=BIGINT} and - gu.user_id=#{userId,jdbcType=BIGINT} + gu.user_id=#{userId,jdbcType=INTEGER} union select gr.role @@ -61,7 +61,7 @@ from user_roles ur where ur.resource_id=#{rootComponentId,jdbcType=BIGINT} and - ur.user_id=#{userId,jdbcType=BIGINT} + ur.user_id=#{userId,jdbcType=INTEGER} </select> <select id="selectRootComponentPermissionsOfAnonymous" parameterType="map" resultType="string"> @@ -83,7 +83,7 @@ gr.role = #{permission,jdbcType=VARCHAR} and gr.resource_id is null and gr.group_id is not null and - gr.group_id != #{excludedGroupId,jdbcType=BIGINT} + gr.group_id != #{excludedGroupId,jdbcType=INTEGER} union @@ -107,7 +107,7 @@ gr.role = #{permission,jdbcType=VARCHAR} and gr.resource_id is null and gr.group_id is not null and - gu.user_id != #{excludedUserId,jdbcType=BIGINT} + gu.user_id != #{excludedUserId,jdbcType=INTEGER} union @@ -117,7 +117,7 @@ ur.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and ur.resource_id is null and ur.role = #{permission,jdbcType=VARCHAR} and - ur.user_id != #{excludedUserId,jdbcType=BIGINT} + ur.user_id != #{excludedUserId,jdbcType=INTEGER} ) remaining </select> @@ -132,7 +132,7 @@ gr.role = #{permission,jdbcType=VARCHAR} and gr.resource_id is null and gr.group_id is not null and - (gu.group_id != #{groupId,jdbcType=BIGINT} or gu.user_id != #{userId,jdbcType=BIGINT}) + (gu.group_id != #{groupId,jdbcType=INTEGER} or gu.user_id != #{userId,jdbcType=INTEGER}) union @@ -165,7 +165,7 @@ ur.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and ur.resource_id is null and ur.role = #{permission,jdbcType=VARCHAR} and - ur.user_id != #{userId,jdbcType=BIGINT} + ur.user_id != #{userId,jdbcType=INTEGER} ) remaining </select> @@ -177,7 +177,7 @@ gr.role = #{permission,jdbcType=VARCHAR} and gr.resource_id is null and gr.group_id is not null and - gu.user_id = #{userId,jdbcType=BIGINT} + gu.user_id = #{userId,jdbcType=INTEGER} union @@ -186,7 +186,7 @@ where ur.resource_id is null and ur.role = #{permission,jdbcType=VARCHAR} and - ur.user_id = #{userId,jdbcType=BIGINT} + ur.user_id = #{userId,jdbcType=INTEGER} </select> <select id="keepAuthorizedProjectIdsForUser" parameterType="map" resultType="long"> @@ -205,7 +205,7 @@ INNER JOIN projects p on p.id = ur.resource_id WHERE ur.role=#{role,jdbcType=VARCHAR} - and ur.user_id=#{userId,jdbcType=BIGINT} and + and ur.user_id=#{userId,jdbcType=INTEGER} and <foreach collection="componentIds" open="(" close=")" item="element" index="index" separator=" or "> p.id=#{element,jdbcType=BIGINT} </foreach> @@ -232,14 +232,14 @@ where gr.role=#{role,jdbcType=VARCHAR} and (gr.group_id is null or gr.group_id in (select gu.group_id from groups_users gu where - gu.user_id=#{userId,jdbcType=BIGINT})) + gu.user_id=#{userId,jdbcType=INTEGER})) UNION SELECT p.uuid as root_project_uuid FROM user_roles ur INNER JOIN projects p on p.id = ur.resource_id AND p.module_uuid IS NULL where ur.role=#{role,jdbcType=VARCHAR} - and ur.user_id = #{userId,jdbcType=BIGINT} + and ur.user_id = #{userId,jdbcType=INTEGER} </when> <otherwise> SELECT p.uuid as root_project_uuid @@ -252,7 +252,7 @@ </choose> </select> - <select id="keepAuthorizedUsersForRoleAndProject" parameterType="map" resultType="Long"> + <select id="keepAuthorizedUsersForRoleAndProject" parameterType="map" resultType="int"> SELECT gu.user_id FROM groups_users gu INNER JOIN group_roles gr ON gr.group_id=gu.group_id diff --git a/sonar-db/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml b/sonar-db/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml index 9d011a5d647..9d90ac5213f 100644 --- a/sonar-db/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml @@ -98,7 +98,7 @@ where sub.groupId in <foreach collection="groupIds" open="(" close=")" item="groupId" separator=","> - #{groupId,jdbcType=BIGINT} + #{groupId,jdbcType=INTEGER} </foreach> <if test="projectId != null"> and sub.componentId=#{projectId,jdbcType=BIGINT} @@ -116,7 +116,7 @@ gr.resource_id is null and <choose> <when test="groupId != null"> - gr.group_id = #{groupId,jdbcType=BIGINT} + gr.group_id = #{groupId,jdbcType=INTEGER} </when> <otherwise> gr.group_id is null @@ -132,7 +132,7 @@ gr.resource_id = #{projectId,jdbcType=BIGINT} and <choose> <when test="groupId != null"> - gr.group_id = #{groupId,jdbcType=BIGINT} + gr.group_id = #{groupId,jdbcType=INTEGER} </when> <otherwise> gr.group_id is null @@ -148,7 +148,7 @@ role ) values ( #{organizationUuid,jdbcType=VARCHAR}, - #{groupId,jdbcType=BIGINT}, + #{groupId,jdbcType=INTEGER}, #{resourceId,jdbcType=BIGINT}, #{role,jdbcType=VARCHAR} ) @@ -175,7 +175,7 @@ and <choose> <when test="groupId != null"> - group_id=#{groupId,jdbcType=BIGINT} + group_id=#{groupId,jdbcType=INTEGER} </when> <otherwise> group_id is null diff --git a/sonar-db/src/main/resources/org/sonar/db/permission/UserPermissionMapper.xml b/sonar-db/src/main/resources/org/sonar/db/permission/UserPermissionMapper.xml index 699ed00d86e..18091c27aa0 100644 --- a/sonar-db/src/main/resources/org/sonar/db/permission/UserPermissionMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/permission/UserPermissionMapper.xml @@ -58,7 +58,7 @@ from user_roles ur where ur.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and - ur.user_id = #{userId,jdbcType=BIGINT} and + ur.user_id = #{userId,jdbcType=INTEGER} and ur.resource_id is null </select> @@ -66,7 +66,7 @@ select ur.role from user_roles ur where - ur.user_id = #{userId,jdbcType=BIGINT} and + ur.user_id = #{userId,jdbcType=INTEGER} and ur.resource_id = #{projectId,jdbcType=BIGINT} </select> @@ -88,7 +88,7 @@ role ) values ( #{organizationUuid,jdbcType=VARCHAR}, - #{userId,jdbcType=BIGINT}, + #{userId,jdbcType=INTEGER}, #{componentId,jdbcType=BIGINT}, #{permission,jdbcType=VARCHAR} ) @@ -98,7 +98,7 @@ delete from user_roles where role = #{permission,jdbcType=VARCHAR} and - user_id = #{userId,jdbcType=BIGINT} and + user_id = #{userId,jdbcType=INTEGER} and organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and resource_id is null </delete> @@ -107,7 +107,7 @@ delete from user_roles where role = #{permission,jdbcType=VARCHAR} and - user_id = #{userId,jdbcType=BIGINT} and + user_id = #{userId,jdbcType=INTEGER} and resource_id = #{projectId,jdbcType=BIGINT} </delete> diff --git a/sonar-db/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml b/sonar-db/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml index 769a0f53907..9220cd6befd 100644 --- a/sonar-db/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml @@ -98,16 +98,16 @@ INSERT INTO perm_templates_groups (template_id, group_id, permission_reference, created_at, updated_at) VALUES ( #{templateId,jdbcType=BIGINT}, - #{groupId,jdbcType=BIGINT}, + #{groupId,jdbcType=INTEGER}, #{permission,jdbcType=VARCHAR}, #{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP} ) </insert> - <delete id="deleteByGroupId" parameterType="long"> + <delete id="deleteByGroupId" parameterType="int"> delete from perm_templates_groups - where group_id = #{groupId,jdbcType=BIGINT} + where group_id = #{groupId,jdbcType=INTEGER} </delete> <select id="selectUserLoginsByQueryAndTemplate" parameterType="map" resultType="string"> diff --git a/sonar-db/src/main/resources/org/sonar/db/property/PropertiesMapper.xml b/sonar-db/src/main/resources/org/sonar/db/property/PropertiesMapper.xml index 8feebbb8c7c..8a8a9359975 100644 --- a/sonar-db/src/main/resources/org/sonar/db/property/PropertiesMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/property/PropertiesMapper.xml @@ -176,7 +176,7 @@ and p.resource_id=#{query.componentId} </if> <if test="query.userId() != null"> - and p.user_id=#{query.userId} + and p.user_id=#{query.userId,jdbcType=INTEGER} </if> </where> </select> @@ -193,7 +193,7 @@ values ( #{key}, #{componentId}, - #{userId}, + #{userId,jdbcType=INTEGER}, ${_true}, #{now} ) @@ -212,7 +212,7 @@ values ( #{key}, #{componentId}, - #{userId}, + #{userId,jdbcType=INTEGER}, ${_false}, #{value}, #{now} @@ -232,7 +232,7 @@ values ( #{key}, #{componentId}, - #{userId}, + #{userId,jdbcType=INTEGER}, ${_false}, #{value}, #{now} @@ -246,7 +246,7 @@ <choose> <when test="componentId != null && userId != null"> and resource_id=#{componentId} - and user_id=#{userId} + and user_id=#{userId,jdbcType=INTEGER} </when> <when test="componentId != null"> and resource_id=#{componentId} @@ -254,7 +254,7 @@ </when> <when test="userId != null"> and resource_id is null - and user_id=#{userId} + and user_id=#{userId,jdbcType=INTEGER} </when> <otherwise> and resource_id is null @@ -305,7 +305,7 @@ and resource_id=#{query.componentId} </if> <if test="query.userId() != null"> - and user_id=#{query.userId} + and user_id=#{query.userId,jdbcType=INTEGER} </if> </where> </delete> diff --git a/sonar-db/src/main/resources/org/sonar/db/user/GroupMapper.xml b/sonar-db/src/main/resources/org/sonar/db/user/GroupMapper.xml index 4f6928e7b28..89fcbc40313 100644 --- a/sonar-db/src/main/resources/org/sonar/db/user/GroupMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/user/GroupMapper.xml @@ -20,7 +20,7 @@ where g.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and g.name = #{name,jdbcType=VARCHAR} </select> - <select id="selectByIds" parameterType="long" resultType="Group"> + <select id="selectByIds" parameterType="int" resultType="Group"> select <include refid="groupColumns"/> from groups g @@ -30,7 +30,7 @@ </foreach> </select> - <select id="selectById" parameterType="long" resultType="Group"> + <select id="selectById" parameterType="int" resultType="Group"> SELECT <include refid="groupColumns"/> FROM groups g @@ -39,7 +39,7 @@ </where> </select> - <delete id="deleteById" parameterType="long"> + <delete id="deleteById" parameterType="int"> DELETE FROM groups <where> id=#{id,jdbcType=BIGINT} @@ -126,7 +126,7 @@ from groups g where g.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} - and g.id = #{groupId,jdbcType=BIGINT} + and g.id = #{groupId,jdbcType=INTEGER} </select> <select id="selectByOrganizationUuid" parameterType="map" resultType="Group"> diff --git a/sonar-db/src/main/resources/org/sonar/db/user/GroupMembershipMapper.xml b/sonar-db/src/main/resources/org/sonar/db/user/GroupMembershipMapper.xml index 12ba914eeed..7eb8c835346 100644 --- a/sonar-db/src/main/resources/org/sonar/db/user/GroupMembershipMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/user/GroupMembershipMapper.xml @@ -32,7 +32,7 @@ <include refid="commonClauses"/> </select> - <select id="countUsersByGroup" parameterType="long" resultType="org.sonar.db.user.GroupUserCount"> + <select id="countUsersByGroup" parameterType="int" resultType="org.sonar.db.user.GroupUserCount"> SELECT g.name as groupName, count(gu.user_id) as userCount FROM groups g LEFT JOIN groups_users gu ON gu.group_id=g.id @@ -92,7 +92,7 @@ <include refid="userCommonClauses"/> </select> - <select id="selectGroupIdsByUserId" parameterType="map" resultType="long"> + <select id="selectGroupIdsByUserId" parameterType="map" resultType="int"> select group_id from groups_users where user_id = #{userId} diff --git a/sonar-db/src/main/resources/org/sonar/db/user/RoleMapper.xml b/sonar-db/src/main/resources/org/sonar/db/user/RoleMapper.xml index 98d5c9cc520..545d512be75 100644 --- a/sonar-db/src/main/resources/org/sonar/db/user/RoleMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/user/RoleMapper.xml @@ -7,8 +7,8 @@ select ur.resource_id from user_roles ur <where> - and ur.user_id = #{userId} - and ur.role = #{permission} + and ur.user_id = #{userId,jdbcType=INTEGER} + and ur.role = #{permission,jdbcType=VARCHAR} and ur.resource_id IS NOT NULL </where> UNION @@ -16,14 +16,14 @@ from group_roles gr inner join groups_users gu on gr.group_id=gu.group_id <where> - and gr.role = #{permission} + and gr.role = #{permission,jdbcType=VARCHAR} and gr.resource_id is not null - and gu.user_id=#{userId} + and gu.user_id=#{userId,jdbcType=INTEGER} </where> ORDER by resource_id </select> - <delete id="deleteGroupRolesByGroupId" parameterType="long"> - delete from group_roles where group_id=#{id} + <delete id="deleteGroupRolesByGroupId" parameterType="int"> + delete from group_roles where group_id=#{id,jdbcType=INTEGER} </delete> </mapper> diff --git a/sonar-db/src/main/resources/org/sonar/db/user/UserGroupMapper.xml b/sonar-db/src/main/resources/org/sonar/db/user/UserGroupMapper.xml index c7aaa37af75..4ff5a60ffa3 100644 --- a/sonar-db/src/main/resources/org/sonar/db/user/UserGroupMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/user/UserGroupMapper.xml @@ -8,20 +8,20 @@ user_id, group_id ) values ( - #{userId,jdbcType=BIGINT}, - #{groupId,jdbcType=BIGINT} + #{userId,jdbcType=INTEGER}, + #{groupId,jdbcType=INTEGER} ) </insert> <delete id="delete" parameterType="map"> delete from groups_users - where user_id = #{userId,jdbcType=BIGINT} and - group_id = #{groupId,jdbcType=BIGINT} + where user_id = #{userId,jdbcType=INTEGER} and + group_id = #{groupId,jdbcType=INTEGER} </delete> - <delete id="deleteByGroupId" parameterType="long"> + <delete id="deleteByGroupId" parameterType="int"> delete from groups_users - where group_id = #{groupId,jdbcType=BIGINT} + where group_id = #{groupId,jdbcType=INTEGER} </delete> </mapper> diff --git a/sonar-db/src/main/resources/org/sonar/db/user/UserMapper.xml b/sonar-db/src/main/resources/org/sonar/db/user/UserMapper.xml index 17818753a6a..3989967c5fd 100644 --- a/sonar-db/src/main/resources/org/sonar/db/user/UserMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/user/UserMapper.xml @@ -37,7 +37,7 @@ OR u.scm_accounts like #{likeScmAccount} </select> - <select id="selectUser" parameterType="long" resultType="User"> + <select id="selectUser" parameterType="int" resultType="User"> SELECT <include refid="userColumns"/> FROM users u @@ -115,30 +115,30 @@ and u.login <> #{login} </select> - <delete id="removeUserFromGroups" parameterType="long"> + <delete id="removeUserFromGroups" parameterType="int"> DELETE FROM groups_users WHERE user_id=#{id} </delete> - <delete id="deleteUserRoles" parameterType="long"> - DELETE FROM user_roles WHERE user_id=#{id} + <delete id="deleteUserRoles" parameterType="int"> + DELETE FROM user_roles WHERE user_id=#{id,jdbcType=INTEGER} </delete> - <delete id="deleteUserProperties" parameterType="long"> - DELETE FROM properties WHERE user_id=#{id} + <delete id="deleteUserProperties" parameterType="int"> + DELETE FROM properties WHERE user_id=#{id,jdbcType=BIGINT} </delete> <delete id="deletePropertiesMatchingLogin" parameterType="String"> DELETE FROM properties <where> - text_value LIKE #{login} + text_value LIKE #{login,jdbcType=VARCHAR} AND prop_key IN <foreach item="property" index="index" collection="propertyKeys" open="(" separator="," close=")"> - #{property} + #{property,jdbcType=VARCHAR} </foreach> </where> </delete> - <update id="deactivateUser" parameterType="long"> + <update id="deactivateUser" parameterType="map"> UPDATE users SET active=${_false}, email=null, @@ -149,7 +149,7 @@ crypted_password=null, updated_at=#{now,jdbcType=BIGINT} WHERE - id=#{id} + id=#{id,jdbcType=INTEGER} </update> <update id="setRoot"> @@ -207,7 +207,7 @@ crypted_password=#{cryptedPassword,jdbcType=BIGINT}, updated_at=#{updatedAt,jdbcType=BIGINT} WHERE - login = #{login} + login = #{login,jdbcType=VARCHAR} </insert> </mapper> diff --git a/sonar-db/src/test/java/org/sonar/db/favorite/FavoriteDbTester.java b/sonar-db/src/test/java/org/sonar/db/favorite/FavoriteDbTester.java index a02dd3058b9..20c59786b65 100644 --- a/sonar-db/src/test/java/org/sonar/db/favorite/FavoriteDbTester.java +++ b/sonar-db/src/test/java/org/sonar/db/favorite/FavoriteDbTester.java @@ -38,7 +38,7 @@ public class FavoriteDbTester { this.dbSession = db.getSession(); } - public void add(ComponentDto componentDto, long userId) { + public void add(ComponentDto componentDto, int userId) { dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto() .setKey(PROP_FAVORITE_KEY) .setUserId(userId) @@ -46,7 +46,7 @@ public class FavoriteDbTester { dbSession.commit(); } - public boolean hasFavorite(ComponentDto componentDto, long userId) { + public boolean hasFavorite(ComponentDto componentDto, int userId) { List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(PROP_FAVORITE_KEY) .setComponentId(componentDto.getId()) diff --git a/sonar-db/src/test/java/org/sonar/db/notification/NotificationDbTester.java b/sonar-db/src/test/java/org/sonar/db/notification/NotificationDbTester.java index f897d783bf4..2df3453d9b8 100644 --- a/sonar-db/src/test/java/org/sonar/db/notification/NotificationDbTester.java +++ b/sonar-db/src/test/java/org/sonar/db/notification/NotificationDbTester.java @@ -44,7 +44,7 @@ public class NotificationDbTester { this.dbSession = db.getSession(); } - public void assertExists(String channel, String dispatcher, long userId, @Nullable ComponentDto component) { + public void assertExists(String channel, String dispatcher, int userId, @Nullable ComponentDto component) { List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel)) .setComponentId(component == null ? null : component.getId()) @@ -56,7 +56,7 @@ public class NotificationDbTester { assertThat(result.get(0).getValue()).isEqualTo("true"); } - public void assertDoesNotExist(String channel, String dispatcher, long userId, @Nullable ComponentDto component) { + public void assertDoesNotExist(String channel, String dispatcher, int userId, @Nullable ComponentDto component) { List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel)) .setComponentId(component == null ? null : component.getId()) diff --git a/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java b/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java index 8a03cb98ad5..49195fba4c2 100644 --- a/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java @@ -66,7 +66,7 @@ public class OrganizationDaoTest { .setUrl("the url 1") .setAvatarUrl("the avatar url 1") .setGuarded(false) - .setUserId(1_000L); + .setUserId(1_000); private static final OrganizationDto ORGANIZATION_DTO_2 = new OrganizationDto() .setUuid("uuid 2") .setKey("the_key 2") @@ -75,7 +75,7 @@ public class OrganizationDaoTest { .setUrl("the url 2") .setAvatarUrl("the avatar url 2") .setGuarded(true) - .setUserId(2_000L); + .setUserId(2_000); private static final String PERMISSION_1 = "foo"; private static final String PERMISSION_2 = "bar"; diff --git a/sonar-db/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java b/sonar-db/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java index 3886c179831..07fbd3988dd 100644 --- a/sonar-db/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java @@ -45,7 +45,7 @@ public class AuthorizationDaoTest { private static final int USER = 100; private static final Long PROJECT_ID = 300L; private static final Long PROJECT_ID_WITHOUT_SNAPSHOT = 400L; - private static final long MISSING_ID = -1L; + private static final int MISSING_ID = -1; private static final String A_PERMISSION = "a-permission"; private static final String DOES_NOT_EXIST = "does-not-exist"; @@ -330,14 +330,14 @@ public class AuthorizationDaoTest { assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, // Only 100 and 101 has 'user' role on project - newHashSet(100L, 101L, 102L), "user", PROJECT_ID)).containsOnly(100L, 101L); + newHashSet(100, 101, 102), "user", PROJECT_ID)).containsOnly(100, 101); assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, // Only 100 and 101 has 'user' role on project - newHashSet(100L), "user", PROJECT_ID)).containsOnly(100L); + newHashSet(100), "user", PROJECT_ID)).containsOnly(100); // user does not have the role "admin" - assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, newHashSet(100L), "admin", PROJECT_ID)).isEmpty(); + assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, newHashSet(100), "admin", PROJECT_ID)).isEmpty(); // Empty list assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, Collections.emptySet(), "user", PROJECT_ID)).isEmpty(); @@ -349,13 +349,13 @@ public class AuthorizationDaoTest { assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, // Only 100 and 101 has 'user' role on project - newHashSet(100L, 101L, 102L), "user", PROJECT_ID)).containsOnly(100L, 101L); + newHashSet(100, 101, 102), "user", PROJECT_ID)).containsOnly(100, 101); assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, - newHashSet(100L), "user", PROJECT_ID)).containsOnly(100L); + newHashSet(100), "user", PROJECT_ID)).containsOnly(100); // user does not have the role "admin" - assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, newHashSet(100L), "admin", PROJECT_ID)).isEmpty(); + assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, newHashSet(100), "admin", PROJECT_ID)).isEmpty(); // Empty list assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, Collections.emptySet(), "user", PROJECT_ID)).isEmpty(); @@ -367,7 +367,7 @@ public class AuthorizationDaoTest { assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, // Only 100 and 101 has 'user' role on project - newHashSet(100L, 101L, 102L), "user", PROJECT_ID)).isEmpty(); + newHashSet(100, 101, 102), "user", PROJECT_ID)).isEmpty(); } @Test diff --git a/sonar-db/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java b/sonar-db/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java index d412c1f594d..bb609fa0092 100644 --- a/sonar-db/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java @@ -49,8 +49,8 @@ import static org.sonar.db.component.ComponentTesting.newProjectDto; public class GroupPermissionDaoTest { - private static final long ANYONE_ID = 0L; - private static final long MISSING_ID = -1L; + private static final int ANYONE_ID = 0; + private static final int MISSING_ID = -1; @Rule public DbTester db = DbTester.create(System2.INSTANCE); @@ -202,8 +202,8 @@ public class GroupPermissionDaoTest { assertThat(underTest.selectGroupNamesByQuery(dbSession, defaultOrganizationUuid, PermissionQuery.builder().build())) - .doesNotContain(ANYONE) - .containsExactly(group.getName()); + .doesNotContain(ANYONE) + .containsExactly(group.getName()); } @Test @@ -237,8 +237,8 @@ public class GroupPermissionDaoTest { assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), asList(ANYONE_ID), null)) .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getResourceId) .containsOnly( - tuple(0L, SCAN_EXECUTION, null), - tuple(0L, PROVISIONING, null)); + tuple(0, SCAN_EXECUTION, null), + tuple(0, PROVISIONING, null)); assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), asList(group1.getId(), group2.getId(), ANYONE_ID), null)).hasSize(3); assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), asList(MISSING_ID), null)).isEmpty(); @@ -274,7 +274,7 @@ public class GroupPermissionDaoTest { assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(ANYONE_ID), project.getId())) .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getResourceId) - .containsOnly(tuple(0L, PROVISIONING, project.getId())); + .containsOnly(tuple(0, PROVISIONING, project.getId())); assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), asList(group1.getId(), group2.getId(), ANYONE_ID), project.getId())).hasSize(2); assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(MISSING_ID), project.getId())).isEmpty(); @@ -464,7 +464,7 @@ public class GroupPermissionDaoTest { .containsOnly(organizationUuids); } - private Long insertGroupWithPermissions(OrganizationDto organization1) { + private int insertGroupWithPermissions(OrganizationDto organization1) { GroupDto group = db.users().insertGroup(organization1); db.users().insertPermissionOnGroup(group, "foo"); db.users().insertPermissionOnGroup(group, "bar"); diff --git a/sonar-db/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java b/sonar-db/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java index a86bcbffd6b..3c821f3c8d7 100644 --- a/sonar-db/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java @@ -191,7 +191,7 @@ public class GroupWithPermissionTemplateDaoTest { assertThat(underTest.selectGroupPermissionsByTemplateIdAndGroupNames(session, anotherTemplate.getId(), asList("Anyone"))) .extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getGroupName, PermissionTemplateGroupDto::getPermission) .containsOnly( - tuple(0L, "Anyone", USER)); + tuple(0, "Anyone", USER)); assertThat(underTest.selectGroupPermissionsByTemplateIdAndGroupNames(session, template.getId(), asList("Group-1", "Group-2", "Anyone"))).hasSize(3); assertThat(underTest.selectGroupPermissionsByTemplateIdAndGroupNames(session, template.getId(), asList("Unknown"))).isEmpty(); @@ -223,7 +223,7 @@ public class GroupWithPermissionTemplateDaoTest { .extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getGroupName, PermissionTemplateGroupDto::getPermission) .containsOnly( tuple(group1.getId(), "Group-1", PROVISIONING), - tuple(0L, "Anyone", USER)); + tuple(0, "Anyone", USER)); assertThat(underTest.selectGroupPermissionsByTemplateId(session, 321L)).isEmpty(); } diff --git a/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDaoTest.java b/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDaoTest.java index e1eafd638f3..b656c8371c2 100644 --- a/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDaoTest.java @@ -149,7 +149,7 @@ public class PermissionTemplateDaoTest { public void should_add_user_permission_to_template() { db.prepareDbUnit(getClass(), "addUserPermissionToTemplate.xml"); - underTest.insertUserPermission(dbSession, 1L, 1L, "new_permission"); + underTest.insertUserPermission(dbSession, 1L, 1, "new_permission"); checkTemplateTables("addUserPermissionToTemplate-result.xml"); } @@ -158,7 +158,7 @@ public class PermissionTemplateDaoTest { public void should_remove_user_permission_from_template() { db.prepareDbUnit(getClass(), "removeUserPermissionFromTemplate.xml"); - underTest.deleteUserPermission(dbSession, 1L, 2L, "permission_to_remove"); + underTest.deleteUserPermission(dbSession, 1L, 2, "permission_to_remove"); checkTemplateTables("removeUserPermissionFromTemplate-result.xml"); } @@ -167,7 +167,7 @@ public class PermissionTemplateDaoTest { public void should_add_group_permission_to_template() { db.prepareDbUnit(getClass(), "addGroupPermissionToTemplate.xml"); - underTest.insertGroupPermission(dbSession, 1L, 1L, "new_permission"); + underTest.insertGroupPermission(dbSession, 1L, 1, "new_permission"); dbSession.commit(); checkTemplateTables("addGroupPermissionToTemplate-result.xml"); @@ -177,7 +177,7 @@ public class PermissionTemplateDaoTest { public void remove_by_group() { db.prepareDbUnit(getClass(), "remove_by_group.xml"); - underTest.deleteByGroup(db.getSession(), 2L); + underTest.deleteByGroup(db.getSession(), 2); db.getSession().commit(); db.assertDbUnitTable(getClass(), "remove_by_group-result.xml", "permission_templates", "id", "name", "kee", "description"); diff --git a/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java b/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java index 8ed57a2bfba..aa4f22b07b6 100644 --- a/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java +++ b/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java @@ -60,7 +60,7 @@ public class PermissionTemplateDbTester { addGroupToTemplate(permissionTemplate.getId(), group.getId(), permission); } - public void addGroupToTemplate(long templateId, @Nullable Long groupId, String permission) { + public void addGroupToTemplate(long templateId, @Nullable Integer groupId, String permission) { dbClient.permissionTemplateDao().insertGroupPermission(dbSession, templateId, groupId, permission); db.commit(); } @@ -73,7 +73,7 @@ public class PermissionTemplateDbTester { addUserToTemplate(permissionTemplate.getId(), user.getId(), permission); } - public void addUserToTemplate(long templateId, long userId, String permission) { + public void addUserToTemplate(long templateId, int userId, String permission) { dbClient.permissionTemplateDao().insertUserPermission(dbSession, templateId, userId, permission); db.commit(); } diff --git a/sonar-db/src/test/java/org/sonar/db/property/PropertiesDaoTest.java b/sonar-db/src/test/java/org/sonar/db/property/PropertiesDaoTest.java index 570c7d96364..00c8552b381 100644 --- a/sonar-db/src/test/java/org/sonar/db/property/PropertiesDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/property/PropertiesDaoTest.java @@ -80,9 +80,9 @@ public class PropertiesDaoTest { public void shouldFindUsersForNotification() throws SQLException { ComponentDto project1 = insertProject("uuid_45"); ComponentDto project2 = insertProject("uuid_56"); - long userId1 = insertUser("user1"); - long userId2 = insertUser("user2"); - long userId3 = insertUser("user3"); + int userId1 = insertUser("user1"); + int userId2 = insertUser("user2"); + int userId3 = insertUser("user3"); insertProperty("notification.NewViolations.Email", "true", project1.getId(), userId2); insertProperty("notification.NewViolations.Twitter", "true", null, userId3); insertProperty("notification.NewViolations.Twitter", "true", project2.getId(), userId1); @@ -111,8 +111,8 @@ public class PropertiesDaoTest { @Test public void findNotificationSubscribers() throws SQLException { - long userId1 = insertUser("user1"); - long userId2 = insertUser("user2"); + int userId1 = insertUser("user1"); + int userId2 = insertUser("user2"); ComponentDto projectDto = insertProject("PROJECT_A"); long projectId = projectDto.getId(); String projectKey = projectDto.key(); @@ -148,8 +148,8 @@ public class PropertiesDaoTest { @Test public void hasNotificationSubscribers() throws SQLException { - long userId1 = insertUser("user1"); - long userId2 = insertUser("user2"); + int userId1 = insertUser("user1"); + int userId2 = insertUser("user2"); Long projectId = insertProject("PROJECT_A").getId(); // global subscription insertProperty("notification.DispatcherWithGlobalSubscribers.Email", "true", null, userId2); @@ -227,7 +227,7 @@ public class PropertiesDaoTest { // project insertProperty("project.one", "one", 10L, null); // user - insertProperty("user.one", "one", null, 100L); + insertProperty("user.one", "one", null, 100); assertThatDto(underTest.selectGlobalProperty("global.one")) .hasNoResourceId() @@ -361,8 +361,8 @@ public class PropertiesDaoTest { // commons insertProperty("commonslang.one", "one", 11L, null); // user - insertProperty("user.one", "one", null, 100L); - insertProperty("user.two", "two", 10L, 100L); + insertProperty("user.one", "one", null, 100); + insertProperty("user.two", "two", 10L, 100); // other insertProperty("other.one", "one", 12L, null); @@ -378,7 +378,7 @@ public class PropertiesDaoTest { @Test public void select_global_properties_by_keys() throws Exception { insertProject("A"); - long userId = insertUser("B"); + int userId = insertUser("B"); String key = "key"; String anotherKey = "anotherKey"; @@ -563,7 +563,7 @@ public class PropertiesDaoTest { public void saveProperty_inserts_user_properties_when_they_do_not_exist_in_db() { when(system2.now()).thenReturn(DATE_1, DATE_2, DATE_3, DATE_4, DATE_5); - long userId = 100; + int userId = 100; underTest.saveProperty(new PropertyDto().setKey("user.null").setUserId(userId).setValue(null)); underTest.saveProperty(new PropertyDto().setKey("user.empty").setUserId(userId).setValue("")); underTest.saveProperty(new PropertyDto().setKey("user.text").setUserId(userId).setValue("some text")); @@ -649,7 +649,7 @@ public class PropertiesDaoTest { @Test @UseDataProvider("valueUpdatesDataProvider") public void saveProperty_deletes_then_inserts_user_properties_when_they_exist_in_db(@Nullable String oldValue, @Nullable String newValue) throws SQLException { - long userId = 90L; + int userId = 90; long id = insertProperty("global", oldValue, null, userId, DATE_1); when(system2.now()).thenReturn(DATE_4); @@ -714,8 +714,8 @@ public class PropertiesDaoTest { long id2 = insertProperty("global.two", "two", null, null); long id3 = insertProperty("struts.one", "one", projectId1, null); long id4 = insertProperty("commonslang.one", "one", projectId2, null); - long id5 = insertProperty("user.one", "one", null, 100L); - long id6 = insertProperty("user.two", "two", null, 100L); + long id5 = insertProperty("user.one", "one", null, 100); + long id6 = insertProperty("user.two", "two", null, 100); long id7 = insertProperty("other.one", "one", projectId3, null); underTest.deleteProjectProperty("struts.one", projectId1); @@ -801,7 +801,7 @@ public class PropertiesDaoTest { // project - do not delete this project property that has the same key long id3 = insertProperty("to_be_deleted", "new_project", 10L, null); // user - long id4 = insertProperty("user.key", "new_user", null, 100L); + long id4 = insertProperty("user.key", "new_user", null, 100); underTest.deleteGlobalProperty("to_be_deleted"); @@ -898,8 +898,8 @@ public class PropertiesDaoTest { long id2 = insertProperty("old_name", "doc1", null, null, DATE_1); long id3 = insertProperty("old_name", "doc2", 15L, null, DATE_1); long id4 = insertProperty("old_name", "doc3", 16L, null, DATE_1); - long id5 = insertProperty("old_name", "doc4", null, 100L, DATE_1); - long id6 = insertProperty("old_name", "doc5", null, 101L, DATE_1); + long id5 = insertProperty("old_name", "doc4", null, 100, DATE_1); + long id6 = insertProperty("old_name", "doc5", null, 101, DATE_1); underTest.renamePropertyKey("old_name", "new_name"); @@ -987,12 +987,12 @@ public class PropertiesDaoTest { session.commit(); } - private long insertProperty(String key, @Nullable String value, @Nullable Long resourceId, @Nullable Long userId, long createdAt) throws SQLException { + private long insertProperty(String key, @Nullable String value, @Nullable Long resourceId, @Nullable Integer userId, long createdAt) throws SQLException { when(system2.now()).thenReturn(createdAt); return insertProperty(key, value, resourceId, userId); } - private long insertProperty(String key, @Nullable String value, @Nullable Long resourceId, @Nullable Long userId) throws SQLException { + private long insertProperty(String key, @Nullable String value, @Nullable Long resourceId, @Nullable Integer userId) throws SQLException { DbSession session = dbTester.getSession(); PropertyDto dto = new PropertyDto().setKey(key) .setResourceId(resourceId == null ? null : resourceId.longValue()) @@ -1015,7 +1015,7 @@ public class PropertiesDaoTest { return project; } - private long insertUser(String login) { + private int insertUser(String login) { UserDto dto = new UserDto().setLogin(login); DbSession session = dbTester.getSession(); dbClient.userDao().insert(session, dto); diff --git a/sonar-db/src/test/java/org/sonar/db/property/PropertiesRow.java b/sonar-db/src/test/java/org/sonar/db/property/PropertiesRow.java index a729cf890b6..51ee161eddc 100644 --- a/sonar-db/src/test/java/org/sonar/db/property/PropertiesRow.java +++ b/sonar-db/src/test/java/org/sonar/db/property/PropertiesRow.java @@ -24,14 +24,14 @@ import javax.annotation.Nullable; final class PropertiesRow { private final String key; - private final Long userId; + private final Integer userId; private final Long resourceId; private final Boolean empty; private final String textValue; private final String clobValue; private final Long createdAt; - public PropertiesRow(String key, @Nullable Long userId, @Nullable Long resourceId, + public PropertiesRow(String key, @Nullable Integer userId, @Nullable Long resourceId, @Nullable Boolean empty, @Nullable String textValue, @Nullable String clobValue, @Nullable Long createdAt) { this.key = key; @@ -47,7 +47,7 @@ final class PropertiesRow { return key; } - public Long getUserId() { + public Integer getUserId() { return userId; } diff --git a/sonar-db/src/test/java/org/sonar/db/property/PropertiesRowAssert.java b/sonar-db/src/test/java/org/sonar/db/property/PropertiesRowAssert.java index 81febdd8a5c..048d6d52252 100644 --- a/sonar-db/src/test/java/org/sonar/db/property/PropertiesRowAssert.java +++ b/sonar-db/src/test/java/org/sonar/db/property/PropertiesRowAssert.java @@ -67,9 +67,10 @@ final class PropertiesRowAssert extends AbstractAssert<PropertiesRowAssert, Prop return null; } else { Map<String, Object> row = rows.iterator().next(); + Long userId = (Long) row.get("userId"); return new PropertiesRow( (String) row.get("key"), - (Long) row.get("userId"), + userId == null ? null : userId.intValue(), (Long) row.get("resourceId"), toBoolean(row.get("isEmpty")), (String) row.get("textValue"), @@ -113,7 +114,7 @@ final class PropertiesRowAssert extends AbstractAssert<PropertiesRowAssert, Prop return this; } - public PropertiesRowAssert hasUserId(long expected) { + public PropertiesRowAssert hasUserId(int expected) { isNotNull(); if (!Objects.equals(actual.getUserId(), expected)) { diff --git a/sonar-db/src/test/java/org/sonar/db/property/PropertyDtoTest.java b/sonar-db/src/test/java/org/sonar/db/property/PropertyDtoTest.java index 2fd28cc116f..892f1a7b5bc 100644 --- a/sonar-db/src/test/java/org/sonar/db/property/PropertyDtoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/property/PropertyDtoTest.java @@ -49,7 +49,7 @@ public class PropertyDtoTest { @Test public void testToString() { - assertThat(new PropertyDto().setKey("foo:bar").setValue("value").setResourceId(123L).setUserId(456L).toString()).isEqualTo("PropertyDto{foo:bar, value, 123, 456}"); + assertThat(new PropertyDto().setKey("foo:bar").setValue("value").setResourceId(123L).setUserId(456).toString()).isEqualTo("PropertyDto{foo:bar, value, 123, 456}"); } @Test diff --git a/sonar-db/src/test/java/org/sonar/db/user/GroupDaoTest.java b/sonar-db/src/test/java/org/sonar/db/user/GroupDaoTest.java index ca641b39463..869ef70dc13 100644 --- a/sonar-db/src/test/java/org/sonar/db/user/GroupDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/user/GroupDaoTest.java @@ -40,7 +40,7 @@ import static org.sonar.db.user.GroupTesting.newGroupDto; public class GroupDaoTest { private static final long NOW = 1_500_000L; - private static final long MISSING_ID = -1L; + private static final int MISSING_ID = -1; private static final OrganizationDto AN_ORGANIZATION = new OrganizationDto() .setKey("an-org") .setName("An Org") diff --git a/sonar-db/src/test/java/org/sonar/db/user/GroupMembershipDaoTest.java b/sonar-db/src/test/java/org/sonar/db/user/GroupMembershipDaoTest.java index eba5aa986f0..b9f89695ffb 100644 --- a/sonar-db/src/test/java/org/sonar/db/user/GroupMembershipDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/user/GroupMembershipDaoTest.java @@ -42,23 +42,23 @@ public class GroupMembershipDaoTest { dbTester.prepareDbUnit(getClass(), "shared.xml"); // 200 is member of 3 groups - assertThat(underTest.countGroups(dbTester.getSession(), GroupMembershipQuery.builder().login("arthur").membership(GroupMembershipQuery.IN).build(), 200L)).isEqualTo(3); - assertThat(underTest.countGroups(dbTester.getSession(), GroupMembershipQuery.builder().login("arthur").membership(GroupMembershipQuery.OUT).build(), 200L)).isZero(); + assertThat(underTest.countGroups(dbTester.getSession(), GroupMembershipQuery.builder().login("arthur").membership(GroupMembershipQuery.IN).build(), 200)).isEqualTo(3); + assertThat(underTest.countGroups(dbTester.getSession(), GroupMembershipQuery.builder().login("arthur").membership(GroupMembershipQuery.OUT).build(), 200)).isZero(); // 201 is member of 1 group on 3 - assertThat(underTest.countGroups(dbTester.getSession(), GroupMembershipQuery.builder().login("arthur").membership(GroupMembershipQuery.IN).build(), 201L)).isEqualTo(1); - assertThat(underTest.countGroups(dbTester.getSession(), GroupMembershipQuery.builder().login("arthur").membership(GroupMembershipQuery.OUT).build(), 201L)).isEqualTo(2); + assertThat(underTest.countGroups(dbTester.getSession(), GroupMembershipQuery.builder().login("arthur").membership(GroupMembershipQuery.IN).build(), 201)).isEqualTo(1); + assertThat(underTest.countGroups(dbTester.getSession(), GroupMembershipQuery.builder().login("arthur").membership(GroupMembershipQuery.OUT).build(), 201)).isEqualTo(2); // 999 is member of 0 group - assertThat(underTest.countGroups(dbTester.getSession(), GroupMembershipQuery.builder().login("arthur").membership(GroupMembershipQuery.IN).build(), 999L)).isZero(); - assertThat(underTest.countGroups(dbTester.getSession(), GroupMembershipQuery.builder().login("arthur").membership(GroupMembershipQuery.OUT).build(), 2999L)).isEqualTo(3); + assertThat(underTest.countGroups(dbTester.getSession(), GroupMembershipQuery.builder().login("arthur").membership(GroupMembershipQuery.IN).build(), 999)).isZero(); + assertThat(underTest.countGroups(dbTester.getSession(), GroupMembershipQuery.builder().login("arthur").membership(GroupMembershipQuery.OUT).build(), 2999)).isEqualTo(3); } @Test public void count_users_by_group() { dbTester.prepareDbUnit(getClass(), "shared_plus_empty_group.xml"); - assertThat(underTest.countUsersByGroups(dbTester.getSession(), Arrays.asList(100L, 101L, 102L, 103L))).containsOnly( + assertThat(underTest.countUsersByGroups(dbTester.getSession(), Arrays.asList(100, 101, 102, 103))).containsOnly( entry("sonar-users", 2), entry("sonar-reviewers", 1), entry("sonar-administrators", 1), entry("sonar-nobody", 0)); - assertThat(underTest.countUsersByGroups(dbTester.getSession(), Arrays.asList(100L, 103L))).containsOnly( + assertThat(underTest.countUsersByGroups(dbTester.getSession(), Arrays.asList(100, 103))).containsOnly( entry("sonar-administrators", 1), entry("sonar-nobody", 0)); } @@ -78,17 +78,17 @@ public class GroupMembershipDaoTest { dbTester.prepareDbUnit(getClass(), "shared_plus_empty_group.xml"); // 100 has 1 member and 1 non member - assertThat(underTest.countMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).membership(UserMembershipQuery.IN).build())).isEqualTo(1); - assertThat(underTest.countMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).membership(UserMembershipQuery.OUT).build())).isEqualTo(1); + assertThat(underTest.countMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).membership(UserMembershipQuery.IN).build())).isEqualTo(1); + assertThat(underTest.countMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).membership(UserMembershipQuery.OUT).build())).isEqualTo(1); // 101 has 2 members - assertThat(underTest.countMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(101L).membership(UserMembershipQuery.IN).build())).isEqualTo(2); - assertThat(underTest.countMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(101L).membership(UserMembershipQuery.OUT).build())).isZero(); + assertThat(underTest.countMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(101).membership(UserMembershipQuery.IN).build())).isEqualTo(2); + assertThat(underTest.countMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(101).membership(UserMembershipQuery.OUT).build())).isZero(); // 102 has 1 member and 1 non member - assertThat(underTest.countMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(102L).membership(UserMembershipQuery.IN).build())).isEqualTo(1); - assertThat(underTest.countMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(102L).membership(UserMembershipQuery.OUT).build())).isEqualTo(1); + assertThat(underTest.countMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(102).membership(UserMembershipQuery.IN).build())).isEqualTo(1); + assertThat(underTest.countMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(102).membership(UserMembershipQuery.OUT).build())).isEqualTo(1); // 103 has no member - assertThat(underTest.countMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(103L).membership(UserMembershipQuery.IN).build())).isZero(); - assertThat(underTest.countMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(103L).membership(UserMembershipQuery.OUT).build())).isEqualTo(2); + assertThat(underTest.countMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(103).membership(UserMembershipQuery.IN).build())).isZero(); + assertThat(underTest.countMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(103).membership(UserMembershipQuery.OUT).build())).isEqualTo(2); } @Test @@ -96,13 +96,13 @@ public class GroupMembershipDaoTest { dbTester.prepareDbUnit(getClass(), "shared_plus_empty_group.xml"); // 100 has 1 member - assertThat(underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).membership(UserMembershipQuery.IN).build(), 0, 10)).hasSize(1); + assertThat(underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).membership(UserMembershipQuery.IN).build(), 0, 10)).hasSize(1); // 101 has 2 members - assertThat(underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(101L).membership(UserMembershipQuery.IN).build(), 0, 10)).hasSize(2); + assertThat(underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(101).membership(UserMembershipQuery.IN).build(), 0, 10)).hasSize(2); // 102 has 1 member - assertThat(underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(102L).membership(UserMembershipQuery.IN).build(), 0, 10)).hasSize(1); + assertThat(underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(102).membership(UserMembershipQuery.IN).build(), 0, 10)).hasSize(1); // 103 has no member - assertThat(underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(103L).membership(UserMembershipQuery.IN).build(), 0, 10)).isEmpty(); + assertThat(underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(103).membership(UserMembershipQuery.IN).build(), 0, 10)).isEmpty(); } @Test @@ -110,26 +110,26 @@ public class GroupMembershipDaoTest { dbTester.prepareDbUnit(getClass(), "shared_plus_empty_group.xml"); // 100 has 1 member - assertThat(underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).membership(UserMembershipQuery.OUT).build(), 0, 10)).hasSize(1); + assertThat(underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).membership(UserMembershipQuery.OUT).build(), 0, 10)).hasSize(1); // 101 has 2 members - assertThat(underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(101L).membership(UserMembershipQuery.OUT).build(), 0, 10)).isEmpty(); + assertThat(underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(101).membership(UserMembershipQuery.OUT).build(), 0, 10)).isEmpty(); // 102 has 1 member - assertThat(underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(102L).membership(UserMembershipQuery.OUT).build(), 0, 10)).hasSize(1); + assertThat(underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(102).membership(UserMembershipQuery.OUT).build(), 0, 10)).hasSize(1); // 103 has no member - assertThat(underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(103L).membership(UserMembershipQuery.OUT).build(), 0, 10)).hasSize(2); + assertThat(underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(103).membership(UserMembershipQuery.OUT).build(), 0, 10)).hasSize(2); } @Test public void search_by_user_name_or_login() { dbTester.prepareDbUnit(getClass(), "shared_plus_empty_group.xml"); - List<UserMembershipDto> result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).memberSearch("admin").build(), 0, 10); + List<UserMembershipDto> result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).memberSearch("admin").build(), 0, 10); assertThat(result).hasSize(2); assertThat(result.get(0).getName()).isEqualTo("Admin name"); assertThat(result.get(1).getName()).isEqualTo("Not Admin"); - result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).memberSearch("not").build(), 0, 10); + result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).memberSearch("not").build(), 0, 10); assertThat(result).hasSize(1); } @@ -138,13 +138,13 @@ public class GroupMembershipDaoTest { dbTester.prepareDbUnit(getClass(), "shared_plus_empty_group.xml"); // search is case insensitive only on name - List<UserMembershipDto> result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).memberSearch("NaMe").build(), 0, 10); + List<UserMembershipDto> result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).memberSearch("NaMe").build(), 0, 10); assertThat(result).hasSize(1); - result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).memberSearch("login").build(), 0, 10); + result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).memberSearch("login").build(), 0, 10); assertThat(result).hasSize(1); - result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).memberSearch("email").build(), 0, 10); + result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).memberSearch("email").build(), 0, 10); assertThat(result).hasSize(1); } @@ -152,7 +152,7 @@ public class GroupMembershipDaoTest { public void should_be_sorted_by_user_name() { dbTester.prepareDbUnit(getClass(), "shared_plus_empty_group.xml"); - List<UserMembershipDto> result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).build(), 0, 10); + List<UserMembershipDto> result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).build(), 0, 10); assertThat(result).hasSize(2); assertThat(result.get(0).getName()).isEqualTo("Admin name"); assertThat(result.get(1).getName()).isEqualTo("Not Admin"); @@ -162,16 +162,16 @@ public class GroupMembershipDaoTest { public void members_should_be_paginated() { dbTester.prepareDbUnit(getClass(), "shared_plus_empty_group.xml"); - List<UserMembershipDto> result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).build(), 0, 2); + List<UserMembershipDto> result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).build(), 0, 2); assertThat(result).hasSize(2); assertThat(result.get(0).getName()).isEqualTo("Admin name"); assertThat(result.get(1).getName()).isEqualTo("Not Admin"); - result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).build(), 1, 2); + result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).build(), 1, 2); assertThat(result).hasSize(1); assertThat(result.get(0).getName()).isEqualTo("Not Admin"); - result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).build(), 2, 1); + result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).build(), 2, 1); assertThat(result).isEmpty(); } } diff --git a/sonar-db/src/test/java/org/sonar/db/user/GroupTesting.java b/sonar-db/src/test/java/org/sonar/db/user/GroupTesting.java index 87a695712cd..50af08373f3 100644 --- a/sonar-db/src/test/java/org/sonar/db/user/GroupTesting.java +++ b/sonar-db/src/test/java/org/sonar/db/user/GroupTesting.java @@ -22,6 +22,7 @@ package org.sonar.db.user; import java.util.Date; import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; +import static org.apache.commons.lang.math.RandomUtils.nextInt; import static org.apache.commons.lang.math.RandomUtils.nextLong; public class GroupTesting { @@ -32,7 +33,7 @@ public class GroupTesting { public static GroupDto newGroupDto() { GroupDto group = new GroupDto() - .setId(nextLong()) + .setId(nextInt()) .setOrganizationUuid(randomAlphanumeric(40)) .setName(randomAlphanumeric(255)) .setDescription(randomAlphanumeric(200)) diff --git a/sonar-db/src/test/java/org/sonar/db/user/RoleDaoTest.java b/sonar-db/src/test/java/org/sonar/db/user/RoleDaoTest.java index 5a9b6ced418..580b26956aa 100644 --- a/sonar-db/src/test/java/org/sonar/db/user/RoleDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/user/RoleDaoTest.java @@ -94,7 +94,7 @@ public class RoleDaoTest { public void delete_all_group_permissions_by_group_id() { db.prepareDbUnit(getClass(), "deleteGroupPermissionsByGroupId.xml"); - underTest.deleteGroupRolesByGroupId(db.getSession(), 100L); + underTest.deleteGroupRolesByGroupId(db.getSession(), 100); db.getSession().commit(); db.assertDbUnit(getClass(), "deleteGroupPermissionsByGroupId-result.xml", "group_roles"); diff --git a/sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java b/sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java index cbd7af7558b..c1a8623223c 100644 --- a/sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java @@ -70,11 +70,11 @@ public class UserDaoTest { public void selectUsersIds() { db.prepareDbUnit(getClass(), "selectUsersByIds.xml"); - Collection<UserDto> users = underTest.selectByIds(session, asList(100L, 101L, 987L)); + Collection<UserDto> users = underTest.selectByIds(session, asList(100, 101, 987)); assertThat(users).hasSize(2); assertThat(users).extracting("login").containsOnly("marius", "inactive_user"); - assertThat(underTest.selectByIds(session, Collections.<Long>emptyList())).isEmpty(); + assertThat(underTest.selectByIds(session, Collections.emptyList())).isEmpty(); } @Test @@ -305,7 +305,7 @@ public class UserDaoTest { Long date = DateUtils.parseDate("2014-06-20").getTime(); UserDto userDto = new UserDto() - .setId(1L) + .setId(1) .setLogin("john") .setName("John") .setEmail("jo@hn.com") @@ -353,7 +353,7 @@ public class UserDaoTest { db.getSession().commit(); UserDto userDto = new UserDto() - .setId(1L) + .setId(1) .setLogin("john") .setName("John Doo") .setEmail("jodoo@hn.com") diff --git a/sonar-db/src/test/java/org/sonar/db/user/UserDbTester.java b/sonar-db/src/test/java/org/sonar/db/user/UserDbTester.java index 6257ac9434a..4a2c2c48fa9 100644 --- a/sonar-db/src/test/java/org/sonar/db/user/UserDbTester.java +++ b/sonar-db/src/test/java/org/sonar/db/user/UserDbTester.java @@ -177,7 +177,7 @@ public class UserDbTester { } @CheckForNull - public GroupDto selectGroupById(long groupId) { + public GroupDto selectGroupById(int groupId) { return db.getDbClient().groupDao().selectById(db.getSession(), groupId); } @@ -206,7 +206,7 @@ public class UserDbTester { db.commit(); } - public List<Long> selectGroupIdsOfUser(UserDto user) { + public List<Integer> selectGroupIdsOfUser(UserDto user) { return db.getDbClient().groupMembershipDao().selectGroupIdsByUserId(db.getSession(), user.getId()); } diff --git a/sonar-db/src/test/java/org/sonar/db/user/UserGroupDaoTest.java b/sonar-db/src/test/java/org/sonar/db/user/UserGroupDaoTest.java index 4e4ee16a5bc..ca36ee4e574 100644 --- a/sonar-db/src/test/java/org/sonar/db/user/UserGroupDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/user/UserGroupDaoTest.java @@ -33,7 +33,7 @@ public class UserGroupDaoTest { @Test public void insert() { - UserGroupDto userGroupDto = new UserGroupDto().setUserId(1L).setGroupId(2L); + UserGroupDto userGroupDto = new UserGroupDto().setUserId(1).setGroupId(2); underTest.insert(dbTester.getSession(), userGroupDto); dbTester.getSession().commit(); @@ -43,7 +43,7 @@ public class UserGroupDaoTest { @Test public void delete_members_by_group_id() { dbTester.prepareDbUnit(getClass(), "delete_members_by_group_id.xml"); - underTest.deleteByGroupId(dbTester.getSession(), 1L); + underTest.deleteByGroupId(dbTester.getSession(), 1); dbTester.getSession().commit(); dbTester.assertDbUnit(getClass(), "delete_members_by_group_id-result.xml", "groups_users"); } diff --git a/sonar-db/src/test/java/org/sonar/db/user/UserTesting.java b/sonar-db/src/test/java/org/sonar/db/user/UserTesting.java index f3a57b63c2d..682699ad4d9 100644 --- a/sonar-db/src/test/java/org/sonar/db/user/UserTesting.java +++ b/sonar-db/src/test/java/org/sonar/db/user/UserTesting.java @@ -34,7 +34,7 @@ public class UserTesting { public static UserDto newUserDto(String login, String name, @Nullable String email) { return new UserDto() - .setId((long)nextInt()) + .setId(nextInt()) .setActive(true) .setLocal(true) .setName(name) @@ -51,7 +51,7 @@ public class UserTesting { public static UserDto newLocalUser(String login, String name, @Nullable String email) { return new UserDto() - .setId((long)nextInt()) + .setId(nextInt()) .setActive(true) .setLocal(true) .setName(name) @@ -68,7 +68,7 @@ public class UserTesting { public static UserDto newExternalUser(String login, String name, @Nullable String email) { return new UserDto() - .setId((long)nextInt()) + .setId(nextInt()) .setActive(true) .setLocal(false) .setName(name) @@ -83,7 +83,7 @@ public class UserTesting { public static UserDto newDisabledUser(String login) { return new UserDto() - .setId((long)nextInt()) + .setId(nextInt()) .setLogin(login) .setActive(false) .setCreatedAt(nextLong()) |