diff options
author | Eric Hartmann <hartmann.eric@gmail.com> | 2018-01-30 12:34:11 +0100 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2018-02-08 13:41:00 +0100 |
commit | 4a0df7b8f2c14211ee282b8d1335efd09375eba1 (patch) | |
tree | 088d69050780230df21f419473a4a5c76e7a5e9a /server/sonar-db-dao | |
parent | 213d3957ef79ff787d2485e72afe1927ad1c50b9 (diff) | |
download | sonarqube-4a0df7b8f2c14211ee282b8d1335efd09375eba1.tar.gz sonarqube-4a0df7b8f2c14211ee282b8d1335efd09375eba1.zip |
SONAR-10313 Keep the order of issues on Search
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r-- | server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java | 43 | ||||
-rw-r--r-- | server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java | 12 |
2 files changed, 5 insertions, 50 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java index 5570e5c8494..482857eecfb 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java @@ -19,15 +19,10 @@ */ package org.sonar.db.issue; -import com.google.common.base.Function; -import com.google.common.base.Predicates; import java.util.Collection; -import java.util.HashMap; import java.util.List; -import java.util.Map; +import java.util.Optional; import java.util.Set; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import org.apache.ibatis.session.ResultHandler; import org.sonar.db.Dao; import org.sonar.db.DbSession; @@ -35,18 +30,17 @@ import org.sonar.db.RowNotFoundException; import org.sonar.db.WildcardPosition; import org.sonar.db.component.ComponentDto; -import static com.google.common.collect.FluentIterable.from; import static org.sonar.db.DaoDatabaseUtils.buildLikeValue; import static org.sonar.db.DatabaseUtils.executeLargeInputs; public class IssueDao implements Dao { - public java.util.Optional<IssueDto> selectByKey(DbSession session, String key) { - return java.util.Optional.ofNullable(mapper(session).selectByKey(key)); + public Optional<IssueDto> selectByKey(DbSession session, String key) { + return Optional.ofNullable(mapper(session).selectByKey(key)); } public IssueDto selectOrFailByKey(DbSession session, String key) { - java.util.Optional<IssueDto> issue = selectByKey(session, key); + Optional<IssueDto> issue = selectByKey(session, key); if (!issue.isPresent()) { throw new RowNotFoundException(String.format("Issue with key '%s' does not exist", key)); } @@ -57,39 +51,12 @@ public class IssueDao implements Dao { * Gets a list issues by their keys. The result does NOT contain {@code null} values for issues not found, so * the size of result may be less than the number of keys. A single issue is returned * if input keys contain multiple occurrences of a key. - * <p>Results may be in a different order as input keys (see {@link #selectByOrderedKeys(DbSession, List)}).</p> + * <p>Results may be in a different order as input keys.</p> */ public List<IssueDto> selectByKeys(final DbSession session, Collection<String> keys) { return executeLargeInputs(keys, mapper(session)::selectByKeys); } - /** - * Gets a list issues by their keys. The result does NOT contain {@code null} values for issues not found, so - * the size of result may be less than the number of keys. A single issue is returned - * if input keys contain multiple occurrences of a key. - * <p>Contrary to {@link #selectByKeys(DbSession, Collection)}, results are in the same order as input keys.</p> - */ - public List<IssueDto> selectByOrderedKeys(DbSession session, List<String> keys) { - List<IssueDto> unordered = selectByKeys(session, keys); - return from(keys).transform(new KeyToIssue(unordered)).filter(Predicates.notNull()).toList(); - } - - private static class KeyToIssue implements Function<String, IssueDto> { - private final Map<String, IssueDto> map = new HashMap<>(); - - private KeyToIssue(Collection<IssueDto> unordered) { - for (IssueDto dto : unordered) { - map.put(dto.getKey(), dto); - } - } - - @Nullable - @Override - public IssueDto apply(@Nonnull String issueKey) { - return map.get(issueKey); - } - } - public Set<String> selectComponentUuidsOfOpenIssuesForProjectUuid(DbSession session, String projectUuid) { return mapper(session).selectComponentUuidsOfOpenIssuesForProjectUuid(projectUuid); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java index c32c54e366a..9791628fc34 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java @@ -123,18 +123,6 @@ public class IssueDaoTest { } @Test - public void selectByOrderedKeys() { - // contains I1 and I2 - prepareTables(); - - Iterable<IssueDto> issues = underTest.selectByOrderedKeys(db.getSession(), asList("I1", "I2", "I3")); - assertThat(issues).extracting("key").containsExactly("I1", "I2"); - - issues = underTest.selectByOrderedKeys(db.getSession(), asList("I2", "I3", "I1")); - assertThat(issues).extracting("key").containsExactly("I2", "I1"); - } - - @Test public void scrollNonClosedByComponentUuid() { RuleDefinitionDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); |