aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-11-03 14:33:23 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-11-03 15:36:46 +0100
commitd965fca5ff557a3d2cab134435ce05b8d8ab5df1 (patch)
treecfca2eb7d00810dcab622a41d011bede62a05f5a /sonar-db
parent0b3cf3fe412da603e81a9d01ff3ad55a2b4922e3 (diff)
downloadsonarqube-d965fca5ff557a3d2cab134435ce05b8d8ab5df1.tar.gz
sonarqube-d965fca5ff557a3d2cab134435ce05b8d8ab5df1.zip
SONAR-8325 Authorization#keepAuthorizedProjectIds now returns a set
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/DatabaseUtils.java16
-rw-r--r--sonar-db/src/main/java/org/sonar/db/permission/AuthorizationDao.java5
-rw-r--r--sonar-db/src/main/java/org/sonar/db/permission/AuthorizationMapper.java4
3 files changed, 18 insertions, 7 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/DatabaseUtils.java b/sonar-db/src/main/java/org/sonar/db/DatabaseUtils.java
index 278d932390f..aa76ec2849d 100644
--- a/sonar-db/src/main/java/org/sonar/db/DatabaseUtils.java
+++ b/sonar-db/src/main/java/org/sonar/db/DatabaseUtils.java
@@ -33,6 +33,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
@@ -123,12 +124,21 @@ public class DatabaseUtils {
* and with MsSQL when there's more than 2000 parameters in a query
*/
public static <OUTPUT, INPUT extends Comparable<INPUT>> List<OUTPUT> executeLargeInputs(Collection<INPUT> input, Function<List<INPUT>, List<OUTPUT>> function) {
+ return executeLargeInputs(input, function, size -> size == 0 ? Collections.emptyList() : new ArrayList<>(size));
+ }
+
+ public static <OUTPUT, INPUT extends Comparable<INPUT>> Set<OUTPUT> executeLargeInputsIntoSet(Collection<INPUT> input, Function<List<INPUT>, Set<OUTPUT>> function) {
+ return executeLargeInputs(input, function, size -> size == 0 ? Collections.emptySet() : new HashSet<>(size));
+ }
+
+ private static <OUTPUT, INPUT extends Comparable<INPUT>, RESULT extends Collection<OUTPUT>> RESULT executeLargeInputs(Collection<INPUT> input,
+ Function<List<INPUT>, RESULT> function, java.util.function.Function<Integer, RESULT> outputInitializer) {
if (input.isEmpty()) {
- return Collections.emptyList();
+ return outputInitializer.apply(0);
}
- List<OUTPUT> results = new ArrayList<>(input.size());
+ RESULT results = outputInitializer.apply(input.size());
for (List<INPUT> partition : toUniqueAndSortedPartitions(input)) {
- List<OUTPUT> subResults = function.apply(partition);
+ RESULT subResults = function.apply(partition);
if (subResults != null) {
results.addAll(subResults);
}
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 2cd2195ab91..9b60f610117 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
@@ -31,6 +31,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
+import static org.sonar.db.DatabaseUtils.executeLargeInputsIntoSet;
/**
* The SQL requests used to verify authorization (the permissions
@@ -95,8 +96,8 @@ public class AuthorizationDao implements Dao {
return mapper(dbSession).countUsersWithGlobalPermissionExcludingUser(organizationUuid, permission, excludedUSerId);
}
- public Collection<Long> keepAuthorizedProjectIds(DbSession dbSession, Collection<Long> componentIds, @Nullable Integer userId, String role) {
- return executeLargeInputs(
+ public Set<Long> keepAuthorizedProjectIds(DbSession dbSession, Collection<Long> componentIds, @Nullable Integer userId, String role) {
+ return executeLargeInputsIntoSet(
componentIds,
partition -> {
if (userId == null) {
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 00cbcd9e28e..df686f1cac6 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
@@ -43,9 +43,9 @@ public interface AuthorizationMapper {
int countUsersWithGlobalPermissionExcludingUser(@Param("organizationUuid") String organizationUuid, @Param("permission") String permission,
@Param("excludedUserId") long excludedUserId);
- List<Long> keepAuthorizedProjectIdsForAnonymous(@Param("role") String role, @Param("componentIds") Collection<Long> componentIds);
+ Set<Long> keepAuthorizedProjectIdsForAnonymous(@Param("role") String role, @Param("componentIds") Collection<Long> componentIds);
- List<Long> keepAuthorizedProjectIdsForUser(@Param("userId") long userId, @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);
List<String> keepAuthorizedComponentKeysForAnonymous(@Param("role") String role, @Param("componentKeys") Collection<String> componentKeys);