From 5ea219961b0b8cf1c06616ffdfd8c0ff88bd6be9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Fri, 3 Jun 2016 13:33:50 +0200 Subject: [PATCH] fix quality flaw: use method references in DAO rather than lamdba --- .../main/java/org/sonar/db/component/ComponentDao.java | 8 ++++---- .../src/main/java/org/sonar/db/component/SnapshotDao.java | 2 +- sonar-db/src/main/java/org/sonar/db/issue/IssueDao.java | 2 +- sonar-db/src/main/java/org/sonar/db/metric/MetricDao.java | 4 ++-- .../java/org/sonar/db/qualityprofile/ActiveRuleDao.java | 6 +++--- .../org/sonar/db/qualityprofile/QualityProfileDao.java | 2 +- sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java | 8 ++++---- sonar-db/src/main/java/org/sonar/db/user/AuthorDao.java | 2 +- sonar-db/src/main/java/org/sonar/db/user/GroupDao.java | 2 +- sonar-db/src/main/java/org/sonar/db/user/UserDao.java | 8 ++------ 10 files changed, 20 insertions(+), 24 deletions(-) diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java index fb1fd79536b..e006032271a 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java @@ -103,15 +103,15 @@ public class ComponentDao implements Dao { } public List selectByIds(DbSession session, Collection ids) { - return executeLargeInputs(ids, partition -> mapper(session).selectByIds(partition)); + return executeLargeInputs(ids, mapper(session)::selectByIds); } public List selectByUuids(DbSession session, Collection uuids) { - return executeLargeInputs(uuids, partition -> mapper(session).selectByUuids(partition)); + return executeLargeInputs(uuids, mapper(session)::selectByUuids); } public List selectExistingUuids(DbSession session, Collection uuids) { - return executeLargeInputs(uuids, partition -> mapper(session).selectExistingUuids(partition)); + return executeLargeInputs(uuids, mapper(session)::selectExistingUuids); } /** @@ -126,7 +126,7 @@ public class ComponentDao implements Dao { } public List selectByKeys(DbSession session, Collection keys) { - return executeLargeInputs(keys, partitionOfKeys -> mapper(session).selectByKeys(partitionOfKeys)); + return executeLargeInputs(keys, mapper(session)::selectByKeys); } public List selectComponentsHavingSameKeyOrderedById(DbSession session, String key) { diff --git a/sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java b/sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java index 781fe79fa14..2fd248d7c52 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java +++ b/sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java @@ -55,7 +55,7 @@ public class SnapshotDao implements Dao { } public List selectByIds(DbSession dbSession, List snapshotIds) { - return executeLargeInputs(snapshotIds, (input) -> mapper(dbSession).selectByIds(input)); + return executeLargeInputs(snapshotIds, mapper(dbSession)::selectByIds); } @CheckForNull diff --git a/sonar-db/src/main/java/org/sonar/db/issue/IssueDao.java b/sonar-db/src/main/java/org/sonar/db/issue/IssueDao.java index ef405d5c3e9..b2c521bfac7 100644 --- a/sonar-db/src/main/java/org/sonar/db/issue/IssueDao.java +++ b/sonar-db/src/main/java/org/sonar/db/issue/IssueDao.java @@ -76,7 +76,7 @@ public class IssueDao implements Dao { *

Results may be in a different order as input keys (see {@link #selectByOrderedKeys(DbSession, List)}).

*/ public List selectByKeys(final DbSession session, List keys) { - return executeLargeInputs(keys, partitionOfKeys -> mapper(session).selectByKeys(partitionOfKeys)); + return executeLargeInputs(keys, mapper(session)::selectByKeys); } /** diff --git a/sonar-db/src/main/java/org/sonar/db/metric/MetricDao.java b/sonar-db/src/main/java/org/sonar/db/metric/MetricDao.java index 6a4cd25a77b..71d872c8ccf 100644 --- a/sonar-db/src/main/java/org/sonar/db/metric/MetricDao.java +++ b/sonar-db/src/main/java/org/sonar/db/metric/MetricDao.java @@ -48,7 +48,7 @@ public class MetricDao implements Dao { } public List selectByKeys(final DbSession session, List keys) { - return executeLargeInputs(keys, input -> mapper(session).selectByKeys(input)); + return executeLargeInputs(keys, mapper(session)::selectByKeys); } public MetricDto selectOrFailByKey(DbSession session, String key) { @@ -105,7 +105,7 @@ public class MetricDao implements Dao { } public List selectByIds(DbSession session, Set idsSet) { - return executeLargeInputs(new ArrayList<>(idsSet), ids1 -> mapper(session).selectByIds(ids1)); + return executeLargeInputs(new ArrayList<>(idsSet), mapper(session)::selectByIds); } private static class NotEmptyPredicate implements Predicate { diff --git a/sonar-db/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java b/sonar-db/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java index 35fe171ec47..c8c0aa0c777 100644 --- a/sonar-db/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java +++ b/sonar-db/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java @@ -54,7 +54,7 @@ public class ActiveRuleDao implements Dao { } public List selectByKeys(DbSession dbSession, List keys) { - return executeLargeInputs(keys, partitionOfIds -> mapper(dbSession).selectByKeys(partitionOfIds)); + return executeLargeInputs(keys, mapper(dbSession)::selectByKeys); } public List selectByRuleId(DbSession dbSession, int ruleId) { @@ -62,7 +62,7 @@ public class ActiveRuleDao implements Dao { } public List selectByRuleIds(DbSession dbSession, List ids) { - return executeLargeInputs(ids, partitionOfRuleIds -> mapper(dbSession).selectByRuleIds(partitionOfRuleIds)); + return executeLargeInputs(ids, mapper(dbSession)::selectByRuleIds); } // TODO As it's only used by MediumTest, it should be replaced by DbTester.countRowsOfTable() @@ -110,7 +110,7 @@ public class ActiveRuleDao implements Dao { } public List selectParamsByActiveRuleIds(final DbSession dbSession, List activeRuleIds) { - return executeLargeInputs(activeRuleIds, partitionOfIds -> mapper(dbSession).selectParamsByActiveRuleIds(partitionOfIds)); + return executeLargeInputs(activeRuleIds, mapper(dbSession)::selectParamsByActiveRuleIds); } @CheckForNull diff --git a/sonar-db/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java b/sonar-db/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java index c20fab99954..274eb63d36a 100644 --- a/sonar-db/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java +++ b/sonar-db/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java @@ -173,7 +173,7 @@ public class QualityProfileDao implements Dao { @CheckForNull public List selectDefaultProfiles(DbSession session, Collection languageKeys) { - return executeLargeInputs(languageKeys, input -> mapper(session).selectDefaultProfiles(input)); + return executeLargeInputs(languageKeys, mapper(session)::selectDefaultProfiles); } @CheckForNull diff --git a/sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java b/sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java index 9ca5a5fccbf..3385b66084f 100644 --- a/sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java +++ b/sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java @@ -55,7 +55,7 @@ public class RuleDao implements Dao { } public List selectByIds(DbSession session, List ids) { - return executeLargeInputs(ids, partitionOfIds -> mapper(session).selectByIds(partitionOfIds)); + return executeLargeInputs(ids, mapper(session)::selectByIds); } /** @@ -63,7 +63,7 @@ public class RuleDao implements Dao { * if the list of {@code keys} is empty, without any db round trip. */ public List selectByKeys(DbSession session, List keys) { - return executeLargeInputs(keys, partitionOfKeys -> mapper(session).selectByKeys(partitionOfKeys)); + return executeLargeInputs(keys, mapper(session)::selectByKeys); } public List selectEnabled(DbSession session) { @@ -103,11 +103,11 @@ public class RuleDao implements Dao { } public List selectRuleParamsByRuleKeys(DbSession session, List ruleKeys) { - return executeLargeInputs(ruleKeys, partitionOfKeys -> mapper(session).selectParamsByRuleKeys(partitionOfKeys)); + return executeLargeInputs(ruleKeys, mapper(session)::selectParamsByRuleKeys); } public List selectRuleParamsByRuleIds(DbSession dbSession, List ruleIds) { - return executeLargeInputs(ruleIds, partitionOfIds -> mapper(dbSession).selectParamsByRuleIds(partitionOfIds)); + return executeLargeInputs(ruleIds, mapper(dbSession)::selectParamsByRuleIds); } public void insertRuleParam(DbSession session, RuleDto rule, RuleParamDto param) { diff --git a/sonar-db/src/main/java/org/sonar/db/user/AuthorDao.java b/sonar-db/src/main/java/org/sonar/db/user/AuthorDao.java index 93743e10b66..15dc5101405 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/AuthorDao.java +++ b/sonar-db/src/main/java/org/sonar/db/user/AuthorDao.java @@ -53,7 +53,7 @@ public class AuthorDao implements Dao { } public List selectScmAccountsByDeveloperUuids(final DbSession session, Collection developerUuids) { - return executeLargeInputs(developerUuids, partition -> getMapper(session).selectScmAccountsByDeveloperUuids(partition)); + return executeLargeInputs(developerUuids, getMapper(session)::selectScmAccountsByDeveloperUuids); } private static AuthorMapper getMapper(SqlSession session) { 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 a176deb8b11..03b1c582ca8 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 @@ -58,7 +58,7 @@ public class GroupDao implements Dao { } public List selectByNames(DbSession session, Collection names) { - return executeLargeInputs(names, partitionOfNames -> mapper(session).selectByNames(partitionOfNames)); + return executeLargeInputs(names, mapper(session)::selectByNames); } public GroupDto selectOrFailById(DbSession dbSession, long 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 e7ca86823a9..b2029c369a1 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 @@ -70,9 +70,7 @@ public class UserDao implements Dao { * Used by the Governance plugin */ public List selectByIds(DbSession session, Collection ids) { - return executeLargeInputs( - ids, - partitionOfLogins -> session.getMapper(UserMapper.class).selectByIds(partitionOfLogins)); + return executeLargeInputs(ids, session.getMapper(UserMapper.class)::selectByIds); } /** @@ -101,9 +99,7 @@ public class UserDao implements Dao { * if list of logins is empty, without any db round trips. */ public List selectByLogins(DbSession session, Collection logins) { - return executeLargeInputs( - logins, - partitionOfLogins -> session.getMapper(UserMapper.class).selectByLogins(partitionOfLogins)); + return executeLargeInputs(logins, session.getMapper(UserMapper.class)::selectByLogins); } public List selectByLogins(Collection logins) { -- 2.39.5