diff options
Diffstat (limited to 'server/sonar-db-dao')
4 files changed, 22 insertions, 0 deletions
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/project/ProjectDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/project/ProjectDaoIT.java index 51d0f300426..b44d0d98d08 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/project/ProjectDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/project/ProjectDaoIT.java @@ -490,6 +490,16 @@ class ProjectDaoIT { } @Test + void countApplications_shouldReturn_correctValue() { + assertThat(projectDao.countProjects(db.getSession())).isZero(); + + IntStream.range(0, 3).forEach(x -> db.components().insertPrivateProject()); + IntStream.range(0, 5).forEach(x -> db.components().insertPrivateApplication()); + + assertThat(projectDao.countApplications(db.getSession())).isEqualTo(5); + } + + @Test void countProjects_by_ai_codefix_enablement() { var dto1 = createProject("o1", "p1").setAiCodeFixEnabled(true); var dto2 = createProject("o1", "p2"); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java index 40ff12f7d9e..78544955364 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java @@ -160,6 +160,10 @@ public class ProjectDao implements Dao { return mapper(session).countProjects(); } + public int countApplications(DbSession session) { + return mapper(session).countApplications(); + } + public int countAiCodeFixEnabledProjects(DbSession session) { return mapper(session).countProjectsByAiCodeFixEnablement(true); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java index fff27584ee6..d0047c9a2cc 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java @@ -78,5 +78,7 @@ public interface ProjectMapper { int countProjects(); + int countApplications(); + int countProjectsByAiCodeFixEnablement(@Param("aiCodeFixEnabled") boolean aiCodeFixEnabled); } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml index fa11cb1353c..d8818c409d5 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml @@ -226,6 +226,12 @@ where p.qualifier = 'TRK' </select> + <select id="countApplications" resultType="int"> + select count(p.uuid) + from projects p + where p.qualifier = 'APP' + </select> + <select id="countProjectsByAiCodeFixEnablement" resultType="int"> select count(p.uuid) from projects p |