aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-09-27 13:08:38 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-09-28 12:52:05 +0200
commitc99e452a6928472ccdbd61c51cbc18aaf73f3f5d (patch)
tree9f5a1ed0706e2aef935ad2b937e4d696d0afaef8 /sonar-db
parent434e7bc3aac6b59075ec4e9578c1b2480f002262 (diff)
downloadsonarqube-c99e452a6928472ccdbd61c51cbc18aaf73f3f5d.tar.gz
sonarqube-c99e452a6928472ccdbd61c51cbc18aaf73f3f5d.zip
SONAR-6834 search activity by dates
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/ce/CeActivityQuery.java22
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml12
-rw-r--r--sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java43
3 files changed, 73 insertions, 4 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/ce/CeActivityQuery.java b/sonar-db/src/main/java/org/sonar/db/ce/CeActivityQuery.java
index 98e0269eb6e..04f6d0ca7f4 100644
--- a/sonar-db/src/main/java/org/sonar/db/ce/CeActivityQuery.java
+++ b/sonar-db/src/main/java/org/sonar/db/ce/CeActivityQuery.java
@@ -28,6 +28,8 @@ public class CeActivityQuery {
private String componentUuid;
private CeActivityDto.Status status;
private String type;
+ private Long minSubmittedAt;
+ private Long maxFinishedAt;
@CheckForNull
public String getComponentUuid() {
@@ -67,4 +69,24 @@ public class CeActivityQuery {
this.type = type;
return this;
}
+
+ @CheckForNull
+ public Long getMaxFinishedAt() {
+ return maxFinishedAt;
+ }
+
+ public CeActivityQuery setMaxFinishedAt(@Nullable Long l) {
+ this.maxFinishedAt = l;
+ return this;
+ }
+
+ @CheckForNull
+ public Long getMinSubmittedAt() {
+ return minSubmittedAt;
+ }
+
+ public CeActivityQuery setMinSubmittedAt(@Nullable Long l) {
+ this.minSubmittedAt = l;
+ return this;
+ }
}
diff --git a/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml b/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
index 0b6090577a8..d6a13c87fac 100644
--- a/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
+++ b/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
@@ -58,6 +58,12 @@
<if test="query.type != null">
and ca.task_type=#{query.type}
</if>
+ <if test="query.minSubmittedAt != null">
+ and ca.submitted_at &gt;= #{query.minSubmittedAt}
+ </if>
+ <if test="query.maxFinishedAt != null">
+ and ca.finished_at &lt;= #{query.maxFinishedAt}
+ </if>
</where>
order by ca.id desc
</select>
@@ -78,6 +84,12 @@
<if test="query.type != null">
and ca.task_type=#{query.type}
</if>
+ <if test="query.minSubmittedAt != null">
+ and ca.submitted_at &gt;= #{query.minSubmittedAt}
+ </if>
+ <if test="query.maxFinishedAt != null">
+ and ca.finished_at &lt;= #{query.maxFinishedAt}
+ </if>
</where>
</select>
diff --git a/sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java b/sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java
index e9830ab9b9b..b52f6da2272 100644
--- a/sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java
@@ -146,10 +146,45 @@ public class CeActivityDaoTest {
}
@Test
+ public void select_and_count_by_date() throws Exception {
+ insertWithDates("UUID1", 1_450_000_000_000L, 1_470_000_000_000L);
+ insertWithDates("UUID2", 1_460_000_000_000L, 1_480_000_000_000L);
+
+ // search by min submitted date
+ CeActivityQuery query = new CeActivityQuery().setMinSubmittedAt(1_455_000_000_000L);
+ assertThat(underTest.selectByQuery(db.getSession(), query, new RowBounds(0, 10))).extracting("uuid").containsOnly("UUID2");
+ assertThat(underTest.countByQuery(db.getSession(), query)).isEqualTo(1);
+
+ // search by max finished date
+ query = new CeActivityQuery().setMaxFinishedAt(1_475_000_000_000L);
+ assertThat(underTest.selectByQuery(db.getSession(), query, new RowBounds(0, 10))).extracting("uuid").containsOnly("UUID1");
+ assertThat(underTest.countByQuery(db.getSession(), query)).isEqualTo(1);
+
+ // search by both dates
+ query = new CeActivityQuery()
+ .setMinSubmittedAt(1_400_000_000_000L)
+ .setMaxFinishedAt(1_475_000_000_000L);
+ assertThat(underTest.selectByQuery(db.getSession(), query, new RowBounds(0, 10))).extracting("uuid").containsOnly("UUID1");
+ assertThat(underTest.countByQuery(db.getSession(), query)).isEqualTo(1);
+
+ }
+
+ private void insertWithDates(String uuid, long submittedAt, long finishedAt) {
+ CeQueueDto queueDto = new CeQueueDto();
+ queueDto.setUuid(uuid);
+ queueDto.setTaskType("fake");
+ CeActivityDto dto = new CeActivityDto(queueDto);
+ dto.setStatus(CeActivityDto.Status.SUCCESS);
+ dto.setSubmittedAt(submittedAt);
+ dto.setFinishedAt(finishedAt);
+ underTest.insert(db.getSession(), dto);
+ }
+
+ @Test
public void deleteOlderThan() throws Exception {
- insertWithDate("TASK_1", 1_450_000_000_000L);
- insertWithDate("TASK_2", 1_460_000_000_000L);
- insertWithDate("TASK_3", 1_470_000_000_000L);
+ insertWithCreationDate("TASK_1", 1_450_000_000_000L);
+ insertWithCreationDate("TASK_2", 1_460_000_000_000L);
+ insertWithCreationDate("TASK_3", 1_470_000_000_000L);
underTest.deleteOlderThan(db.getSession(), 1_465_000_000_000L);
db.getSession().commit();
@@ -175,7 +210,7 @@ public class CeActivityDaoTest {
underTest.insert(db.getSession(), dto);
}
- private void insertWithDate(String uuid, long date) {
+ private void insertWithCreationDate(String uuid, long date) {
CeQueueDto queueDto = new CeQueueDto();
queueDto.setUuid(uuid);
queueDto.setTaskType("fake");