diff options
author | Eric Giffon <eric.giffon@sonarsource.com> | 2023-07-21 12:39:37 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-07-24 20:03:21 +0000 |
commit | 2f9bcaa9ef14dc86c5216d7cd22b2c1d2d041dcf (patch) | |
tree | e514005f1c84ba9ce7ab5df96b96fe6af925234b /server/sonar-db-dao/src | |
parent | b9dc13e46a0f77ccaefc2585fb738d69042c4366 (diff) | |
download | sonarqube-2f9bcaa9ef14dc86c5216d7cd22b2c1d2d041dcf.tar.gz sonarqube-2f9bcaa9ef14dc86c5216d7cd22b2c1d2d041dcf.zip |
SONAR-7704 Change type of components.created_at to bigint
Diffstat (limited to 'server/sonar-db-dao/src')
7 files changed, 23 insertions, 26 deletions
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java index 2299f88c60f..2131e1b0cef 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java @@ -24,7 +24,6 @@ import com.tngtech.java.junit.dataprovider.DataProviderRunner; import com.tngtech.java.junit.dataprovider.UseDataProvider; import java.util.Arrays; import java.util.Collections; -import java.util.Date; import java.util.List; import java.util.Map; import java.util.Optional; @@ -987,9 +986,9 @@ public class ComponentDaoIT { @Test public void selectByQuery_verify_order() { - Date firstDate = new Date(system2.now()); - Date secondDate = new Date(system2.now()); - Date thirdDate = new Date(system2.now()); + Long firstDate = system2.now(); + Long secondDate = system2.now(); + Long thirdDate = system2.now(); ComponentDto project3 = db.components().insertPrivateProject(componentDto -> componentDto.setName("project3").setCreatedAt(thirdDate)).getMainBranchComponent(); ComponentDto project1 = db.components().insertPrivateProject(componentDto -> componentDto.setName("project1").setCreatedAt(firstDate)).getMainBranchComponent(); @@ -1364,15 +1363,15 @@ public class ComponentDaoIT { @Test public void selectByQuery_filter_created_at() { - ComponentDto project1 = db.components().insertPrivateProject(p -> p.setCreatedAt(parseDate("2018-02-01"))).getMainBranchComponent(); - ComponentDto project2 = db.components().insertPrivateProject(p -> p.setCreatedAt(parseDate("2018-06-01"))).getMainBranchComponent(); + ComponentDto project1 = db.components().insertPrivateProject(p -> p.setCreatedAt(parseDate("2018-02-01").getTime())).getMainBranchComponent(); + ComponentDto project2 = db.components().insertPrivateProject(p -> p.setCreatedAt(parseDate("2018-06-01").getTime())).getMainBranchComponent(); - assertThat(selectProjectUuidsByQuery(q -> q.setCreatedAfter(parseDate("2017-12-01")))) + assertThat(selectProjectUuidsByQuery(q -> q.setCreatedAfter(parseDate("2017-12-01").getTime()))) .containsExactlyInAnyOrder(project1.uuid(), project2.uuid()); - assertThat(selectProjectUuidsByQuery(q -> q.setCreatedAfter(parseDate("2018-02-20")))) + assertThat(selectProjectUuidsByQuery(q -> q.setCreatedAfter(parseDate("2018-02-20").getTime()))) .containsExactlyInAnyOrder(project2.uuid()); - assertThat(selectProjectUuidsByQuery(q -> q.setCreatedAfter(parseDate("2019-01-01")))) + assertThat(selectProjectUuidsByQuery(q -> q.setCreatedAfter(parseDate("2019-01-01").getTime()))) .isEmpty(); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java index 2cf4f9dec67..9cc41cad9e3 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java @@ -21,7 +21,6 @@ package org.sonar.db.component; import com.google.common.base.Splitter; import com.google.common.base.Strings; -import java.util.Date; import java.util.List; import java.util.Objects; import javax.annotation.CheckForNull; @@ -98,7 +97,7 @@ public class ComponentDto { private boolean enabled = true; private boolean isPrivate = false; - private Date createdAt; + private Long createdAt; public static String formatUuidPathFromParent(ComponentDto parent) { checkArgument(!Strings.isNullOrEmpty(parent.getUuidPath())); @@ -245,12 +244,12 @@ public class ComponentDto { return this; } - public Date getCreatedAt() { + public Long getCreatedAt() { return createdAt; } - public ComponentDto setCreatedAt(Date datetime) { - this.createdAt = datetime; + public ComponentDto setCreatedAt(Long createdAt) { + this.createdAt = createdAt; return this; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentQuery.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentQuery.java index 7baf5d3c409..c71729ace88 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentQuery.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentQuery.java @@ -19,7 +19,6 @@ */ package org.sonar.db.component; -import java.util.Date; import java.util.Locale; import java.util.Set; import java.util.stream.Stream; @@ -41,7 +40,7 @@ public class ComponentQuery { private final Long anyBranchAnalyzedBefore; private final Long anyBranchAnalyzedAfter; private final Long allBranchesAnalyzedBefore; - private final Date createdAfter; + private final Long createdAfter; private final boolean onProvisionedOnly; private ComponentQuery(Builder builder) { @@ -119,7 +118,7 @@ public class ComponentQuery { } @CheckForNull - public Date getCreatedAfter() { + public Long getCreatedAfter() { return createdAfter; } @@ -147,7 +146,7 @@ public class ComponentQuery { private Long anyBranchAnalyzedBefore; private Long anyBranchAnalyzedAfter; private Long allBranchesAnalyzedBefore; - private Date createdAfter; + private Long createdAfter; private boolean onProvisionedOnly = false; public Builder setNameOrKeyQuery(@Nullable String nameOrKeyQuery) { @@ -208,7 +207,7 @@ public class ComponentQuery { return this; } - public Builder setCreatedAfter(@Nullable Date l) { + public Builder setCreatedAfter(@Nullable Long l) { this.createdAfter = l; return this; } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml index e55f64f3fde..795916561fe 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml @@ -343,7 +343,7 @@ ) </if> <if test="query.createdAfter != null"> - and p.created_at >= #{query.createdAfter,jdbcType=TIMESTAMP} + and p.created_at >= #{query.createdAfter,jdbcType=BIGINT} </if> </sql> @@ -539,7 +539,7 @@ #{path,jdbcType=VARCHAR}, #{copyComponentUuid,jdbcType=VARCHAR}, #{enabled,jdbcType=BOOLEAN}, - #{createdAt,jdbcType=TIMESTAMP}, + #{createdAt,jdbcType=BIGINT}, ${_false}, null, null, diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index b043cd08d28..f09fbe6fb2d 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -226,7 +226,7 @@ CREATE TABLE "COMPONENTS"( "B_COPY_COMPONENT_UUID" CHARACTER VARYING(50), "B_PATH" CHARACTER VARYING(2000), "B_UUID_PATH" CHARACTER VARYING(1500), - "CREATED_AT" TIMESTAMP + "CREATED_AT" BIGINT ); CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER" NULLS FIRST); CREATE UNIQUE INDEX "COMPONENTS_UUID" ON "COMPONENTS"("UUID" NULLS FIRST); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentQueryTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentQueryTest.java index ced666d7df6..a2a6d7ea364 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentQueryTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentQueryTest.java @@ -38,7 +38,7 @@ public class ComponentQueryTest { .setNameOrKeyQuery("key") .setAnyBranchAnalyzedBefore(100L) .setAnyBranchAnalyzedAfter(200L) - .setCreatedAfter(new Date(300L)) + .setCreatedAfter(new Date(300L).getTime()) .setQualifiers(PROJECT) .build(); @@ -46,7 +46,7 @@ public class ComponentQueryTest { assertThat(underTest.getQualifiers()).containsOnly(PROJECT); assertThat(underTest.getAnyBranchAnalyzedBefore()).isEqualTo(100L); assertThat(underTest.getAnyBranchAnalyzedAfter()).isEqualTo(200L); - assertThat(underTest.getCreatedAfter().getTime()).isEqualTo(300L); + assertThat(underTest.getCreatedAfter()).isEqualTo(300L); assertThat(underTest.isOnProvisionedOnly()).isFalse(); assertThat(underTest.isPartialMatchOnKey()).isFalse(); assertThat(underTest.hasEmptySetOfComponents()).isFalse(); diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java index cf638ea7a4d..275d75ba575 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java @@ -68,7 +68,7 @@ public class ComponentTesting { .setBranchUuid(branch.branchUuid()) .setQualifier(Qualifiers.FILE) .setPath(path) - .setCreatedAt(new Date()) + .setCreatedAt(new Date().getTime()) .setLanguage("xoo"); } @@ -214,7 +214,7 @@ public class ComponentTesting { .setUuidPath(formatUuidPathFromParent(parent)) .setKey(uuid) .setBranchUuid(branch.branchUuid()) - .setCreatedAt(new Date()) + .setCreatedAt(new Date().getTime()) .setEnabled(true) .setPrivate(branch.isPrivate()); } |