public void execute(Context context) {
try (DbSession dbSession = dbClient.openSession(false)) {
String projectUuid = analysisMetadataHolder.getProject().getUuid();
- long maxncloc = dbClient.liveMeasureDao().sumNclocOfBiggestBranchForProject(dbSession, projectUuid);
+ long maxncloc = dbClient.liveMeasureDao().findNclocOfBiggestBranchForProject(dbSession, projectUuid);
dbClient.projectDao().updateNcloc(dbSession, projectUuid, maxncloc);
dbSession.commit();
}
db.measures().insertLiveMeasure(projectWithLinesButNoLoc, lines, m -> m.setValue(365d));
db.measures().insertLiveMeasure(projectWithLinesButNoLoc, ncloc, m -> m.setValue(0d));
- assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), simpleProject.projectUuid())).isEqualTo(10L);
- assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), projectWithBiggerBranch.projectUuid())).isEqualTo(200L);
- assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), projectWithLinesButNoLoc.projectUuid())).isZero();
+ assertThat(underTest.findNclocOfBiggestBranchForProject(db.getSession(), simpleProject.projectUuid())).isEqualTo(10L);
+ assertThat(underTest.findNclocOfBiggestBranchForProject(db.getSession(), projectWithBiggerBranch.projectUuid())).isEqualTo(200L);
+ assertThat(underTest.findNclocOfBiggestBranchForProject(db.getSession(), projectWithLinesButNoLoc.projectUuid())).isZero();
}
@Test
void countNcloc_empty() {
db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.toString()));
db.measures().insertMetric(m -> m.setKey("lines").setValueType(INT.toString()));
- long result = underTest.sumNclocOfBiggestBranchForProject(db.getSession(), "non-existing-project-uuid");
+ long result = underTest.findNclocOfBiggestBranchForProject(db.getSession(), "non-existing-project-uuid");
assertThat(result).isZero();
}
mapper(dbSession).selectTreeByQuery(query, baseComponent.uuid(), query.getUuidPath(baseComponent), resultHandler);
}
- public long sumNclocOfBiggestBranchForProject(DbSession dbSession, String projectUuid){
- Long ncloc = mapper(dbSession).sumNclocOfBiggestBranchForProject(projectUuid, NCLOC_KEY);
+ public long findNclocOfBiggestBranchForProject(DbSession dbSession, String projectUuid){
+ Long ncloc = mapper(dbSession).findNclocOfBiggestBranchForProject(projectUuid, NCLOC_KEY);
return ncloc == null ? 0L : ncloc;
}
ResultHandler<LiveMeasureDto> resultHandler);
@CheckForNull
- Long sumNclocOfBiggestBranchForProject(@Param("projectUuid") String projectUuid, @Param("ncloc") String nclocKey);
+ Long findNclocOfBiggestBranchForProject(@Param("projectUuid") String projectUuid, @Param("ncloc") String nclocKey);
List<LargestBranchNclocDto> getLargestBranchNclocPerProject(@Param("nclocUuid") String nclocUuid);
and lm.component_uuid = #{componentUuid, jdbcType=VARCHAR}
</select>
- <select id="sumNclocOfBiggestBranchForProject" parameterType="map" resultType="long">
- select sumncloc.maxncloc from (
- select b.project_uuid as projectUuid, max(lm.value) as maxncloc
- from live_measures lm
- inner join metrics m on m.uuid = lm.metric_uuid
- inner join project_branches b on b.uuid = lm.component_uuid
- inner join projects p on p.uuid = b.project_uuid and p.qualifier = 'TRK'
- <where>
- m.name = #{ncloc, jdbcType=VARCHAR}
- and b.project_uuid = #{projectUuid,jdbcType=VARCHAR}
- </where>
- group by b.project_uuid
- ) sumncloc
+ <select id="findNclocOfBiggestBranchForProject" parameterType="map" resultType="long">
+ select max(lm.value)
+ from live_measures lm
+ inner join metrics m on m.uuid = lm.metric_uuid
+ inner join project_branches b on b.uuid = lm.component_uuid
+ inner join projects p on p.uuid = b.project_uuid and p.qualifier = 'TRK'
+ <where>
+ m.name = #{ncloc, jdbcType=VARCHAR}
+ and b.project_uuid = #{projectUuid,jdbcType=VARCHAR}
+ </where>
</select>
<select id="getLargestBranchNclocPerProject" parameterType="map" resultType="LargestBranchNclocDto">
}
private void updateProjectNcloc(DbSession dbSession, String projectUuid) {
- long maxncloc = dbClient.liveMeasureDao().sumNclocOfBiggestBranchForProject(dbSession, projectUuid);
+ long maxncloc = dbClient.liveMeasureDao().findNclocOfBiggestBranchForProject(dbSession, projectUuid);
dbClient.projectDao().updateNcloc(dbSession, projectUuid, maxncloc);
}