diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-02-10 01:08:56 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-02-10 23:32:49 +0100 |
commit | f22279cfd17b1af30e631ee305acdb59c3f7ab21 (patch) | |
tree | 37ef9fcbc03b4a37227d0eb64a258796694dcc69 /sonar-db/src/main/java/org | |
parent | 4872092c687a2f5e9d91db44c2fc8ca6dcdc2081 (diff) | |
download | sonarqube-f22279cfd17b1af30e631ee305acdb59c3f7ab21.tar.gz sonarqube-f22279cfd17b1af30e631ee305acdb59c3f7ab21.zip |
SONAR-8761 clean-up ResourceDao
Diffstat (limited to 'sonar-db/src/main/java/org')
4 files changed, 6 insertions, 198 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/AbstractDao.java b/sonar-db/src/main/java/org/sonar/db/AbstractDao.java deleted file mode 100644 index fddc22c3890..00000000000 --- a/sonar-db/src/main/java/org/sonar/db/AbstractDao.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db; - -import org.sonar.api.utils.System2; - -public abstract class AbstractDao implements Dao { - - private final MyBatis myBatis; - private final System2 system2; - - public AbstractDao(MyBatis myBatis, System2 system2) { - this.myBatis = myBatis; - this.system2 = system2; - } - - protected MyBatis myBatis() { - return myBatis; - } - - protected long now() { - return system2.now(); - } -} diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceDao.java b/sonar-db/src/main/java/org/sonar/db/component/ResourceDao.java index 107cb5c2164..70c84928174 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ResourceDao.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ResourceDao.java @@ -19,102 +19,20 @@ */ package org.sonar.db.component; -import java.util.List; -import javax.annotation.CheckForNull; import org.apache.ibatis.session.SqlSession; import org.sonar.api.utils.System2; -import org.sonar.db.AbstractDao; -import org.sonar.db.DbSession; -import org.sonar.db.MyBatis; +import org.sonar.db.Dao; -public class ResourceDao extends AbstractDao { +public class ResourceDao implements Dao { - public ResourceDao(MyBatis myBatis, System2 system2) { - super(myBatis, system2); - } - - @CheckForNull - private static ResourceDto selectResource(ResourceQuery query, DbSession session) { - List<ResourceDto> resources = getResources(query, session); - if (!resources.isEmpty()) { - return resources.get(0); - } - return null; - } - - private static List<ResourceDto> getResources(ResourceQuery query, SqlSession session) { - return session.getMapper(ResourceMapper.class).selectResources(query); - } - - @CheckForNull - public ResourceDto selectResource(String componentUuid) { - SqlSession session = myBatis().openSession(false); - try { - return selectResource(componentUuid, session); - } finally { - MyBatis.closeQuietly(session); - } - } + private final System2 system2; - @CheckForNull - private static ResourceDto selectResource(String componentUuid, SqlSession session) { - return session.getMapper(ResourceMapper.class).selectResourceByUuid(componentUuid); + public ResourceDao(System2 system2) { + this.system2 = system2; } public void updateAuthorizationDate(Long projectId, SqlSession session) { - session.getMapper(ResourceMapper.class).updateAuthorizationDate(projectId, now()); - } - - /** - * Return the root project of a component. - * Will return the component itself if it's already the root project - * Can return null if the component does not exists. - * - * The implementation should rather use a new column already containing the root project, see https://jira.sonarsource.com/browse/SONAR-5188. - */ - @CheckForNull - private static ResourceDto getRootProjectByComponentKey(DbSession session, String componentKey) { - ResourceDto component = selectResource(ResourceQuery.create().setKey(componentKey), session); - if (component != null) { - String rootUuid = component.getRootUuid(); - if (rootUuid.equals(component.getUuid())) { - return component; - } else { - return getParentModuleByComponentUuid(rootUuid, session); - } - } - return null; - } - - @CheckForNull - public ResourceDto getRootProjectByComponentKey(String componentKey) { - DbSession session = myBatis().openSession(false); - try { - return getRootProjectByComponentKey(session, componentKey); - } finally { - MyBatis.closeQuietly(session); - } - } - - @CheckForNull - private static ResourceDto getParentModuleByComponentUuid(String componentUUid, DbSession session) { - ResourceDto component = selectResource(componentUUid, session); - if (component != null) { - String rootUuid = component.getRootUuid(); - if (rootUuid.equals(component.getUuid())) { - return component; - } else { - return getParentModuleByComponentUuid(rootUuid, session); - } - } - return null; - } - - /** - * Return provisioned project with given key - */ - public ResourceDto selectProvisionedProject(DbSession session, String key) { - return session.getMapper(ResourceMapper.class).selectProvisionedProject(key); + session.getMapper(ResourceMapper.class).updateAuthorizationDate(projectId, system2.now()); } } diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceMapper.java b/sonar-db/src/main/java/org/sonar/db/component/ResourceMapper.java index fc7c805a74e..06bc63393c9 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ResourceMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ResourceMapper.java @@ -19,15 +19,9 @@ */ package org.sonar.db.component; -import java.util.List; import org.apache.ibatis.annotations.Param; public interface ResourceMapper { - ResourceDto selectResourceByUuid(String uuid); - - List<ResourceDto> selectResources(ResourceQuery query); - - ResourceDto selectProvisionedProject(@Param("key") String key); void updateAuthorizationDate(@Param("projectId") Long projectId, @Param("authorizationDate") Long authorizationDate); diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceQuery.java b/sonar-db/src/main/java/org/sonar/db/component/ResourceQuery.java deleted file mode 100644 index df0fb7c79d3..00000000000 --- a/sonar-db/src/main/java/org/sonar/db/component/ResourceQuery.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.component; - -/** - * @since 3.0 - */ -public class ResourceQuery { - private String[] qualifiers = null; - private String key = null; - private boolean excludeDisabled = false; - - private ResourceQuery() { - } - - public static ResourceQuery create() { - return new ResourceQuery(); - } - - public String[] getQualifiers() { - return qualifiers; - } - - public ResourceQuery setQualifiers(String[] qualifiers) { - this.qualifiers = qualifiers; - return this; - } - - public String getKey() { - return key; - } - - public ResourceQuery setKey(String key) { - this.key = key; - return this; - } - - public boolean isExcludeDisabled() { - return excludeDisabled; - } - - public ResourceQuery setExcludeDisabled(boolean b) { - this.excludeDisabled = b; - return this; - } -} |