aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao/src/main/java/org/sonar/db/component/ApplicationProjectsDao.java
blob: 7038498b05dab67d84a07e7322252f5c2b567cbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * SonarQube
 * Copyright (C) 2009-2025 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;

import java.util.Collection;
import java.util.List;
import java.util.Set;
import org.sonar.api.utils.System2;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import org.sonar.db.project.ProjectDto;

public class ApplicationProjectsDao implements Dao {
  private final System2 system2;
  private final UuidFactory uuidFactory;

  public ApplicationProjectsDao(System2 system2, UuidFactory uuidFactory) {
    this.system2 = system2;
    this.uuidFactory = uuidFactory;
  }

  public void addProject(DbSession dbSession, String applicationUuid, String projectUuid) {
    getMapper(dbSession).addProject(uuidFactory.create(), applicationUuid, projectUuid, system2.now());
  }

  public void removeApplicationProjectsByApplicationAndProject(DbSession dbSession, String applicationUuid, String projectUuid) {
    getMapper(dbSession).removeApplicationBranchProjectBranchesByApplicationAndProject(applicationUuid, projectUuid);
    getMapper(dbSession).removeApplicationProjectsByApplicationAndProject(applicationUuid, projectUuid);
  }

  public int countApplicationProjects(DbSession dbSession, String applicationUuid) {
    return getMapper(dbSession).countApplicationProjects(applicationUuid);
  }

  public Set<ProjectDto> selectProjects(DbSession dbSession, String applicationUuid) {
    return getMapper(dbSession).selectProjects(applicationUuid);
  }

  public void addProjectBranchToAppBranch(DbSession dbSession, BranchDto applicationBranch, BranchDto projectBranch) {
    getMapper(dbSession).addProjectBranchToAppBranch(
      uuidFactory.create(),
      applicationBranch.getProjectUuid(),
      applicationBranch.getUuid(),
      projectBranch.getProjectUuid(),
      projectBranch.getUuid(),
      system2.now());
  }

  public void addProjectBranchToAppBranch(DbSession dbSession, String applicationUuid, String applicationBranchUuid, String projectUuid, String projectBranchUuid) {
    getMapper(dbSession).addProjectBranchToAppBranch(
      uuidFactory.create(),
      applicationUuid,
      applicationBranchUuid,
      projectUuid,
      projectBranchUuid,
      system2.now());
  }

  public void removeProjectBranchFromAppBranch(DbSession dbSession, String applicationBranchUuid, String projectBranchUuid) {
    getMapper(dbSession).removeProjectBranchFromAppBranch(applicationBranchUuid, projectBranchUuid);
  }

  public Set<BranchDto> selectProjectBranchesFromAppBranchUuid(DbSession dbSession, String applicationBranchUuid) {
    return getMapper(dbSession).selectProjectBranchesFromAppBranchUuid(applicationBranchUuid);
  }

  public Set<BranchDto> selectProjectBranchesFromAppBranchKey(DbSession dbSession, String applicationUuid, String applicationBranchKey) {
    return getMapper(dbSession).selectProjectBranchesFromAppBranchKey(applicationUuid, applicationBranchKey);
  }

  public Set<ProjectDto> selectApplicationsFromProjectBranch(DbSession dbSession, String projectUuid, String branchKey) {
    return getMapper(dbSession).selectApplicationsFromProjectBranch(projectUuid, branchKey);
  }

  public Set<ProjectDto> selectApplicationsFromProjects(DbSession dbSession, Collection<String> projectUuids) {
    return getMapper(dbSession).selectApplicationsFromProjects(projectUuids);
  }

  public List<BranchDto> selectProjectsMainBranchesOfApplication(DbSession dbSession, String applicationUuid) {
    return getMapper(dbSession).selectProjectsMainBranchesOfApplication(applicationUuid);
  }

  private static ApplicationProjectsMapper getMapper(DbSession session) {
    return session.getMapper(ApplicationProjectsMapper.class);
  }
}