diff options
author | Jacek <52388493+jacek-poreda-sonarsource@users.noreply.github.com> | 2019-08-02 18:23:19 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-09-24 20:21:11 +0200 |
commit | b926d579367732fc4a6de08e24be75ff23718dce (patch) | |
tree | 91f8681a4001da41ffc090c52462a1cef5d2eb0c /server/sonar-db-dao/src/main/java/org/sonar/db | |
parent | fa5508dbd860babe0d25f9cd4d78437d1ff9deb5 (diff) | |
download | sonarqube-b926d579367732fc4a6de08e24be75ff23718dce.tar.gz sonarqube-b926d579367732fc4a6de08e24be75ff23718dce.zip |
SONAR-12365 create new_code_period table (#1986)
* Create new_code_periods table along with dto and dao
Diffstat (limited to 'server/sonar-db-dao/src/main/java/org/sonar/db')
7 files changed, 247 insertions, 0 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java index 93a5d217467..f5cca91191f 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java @@ -49,6 +49,7 @@ import org.sonar.db.measure.LiveMeasureDao; import org.sonar.db.measure.MeasureDao; import org.sonar.db.measure.custom.CustomMeasureDao; import org.sonar.db.metric.MetricDao; +import org.sonar.db.newcodeperiod.NewCodePeriodDao; import org.sonar.db.notification.NotificationQueueDao; import org.sonar.db.organization.OrganizationDao; import org.sonar.db.organization.OrganizationMemberDao; @@ -122,6 +123,7 @@ public class DaoModule extends Module { LiveMeasureDao.class, MeasureDao.class, MetricDao.class, + NewCodePeriodDao.class, NotificationQueueDao.class, OrganizationAlmBindingDao.class, OrganizationDao.class, diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java index 27f1832a2bb..33fbf8d2662 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java @@ -47,6 +47,7 @@ import org.sonar.db.measure.LiveMeasureDao; import org.sonar.db.measure.MeasureDao; import org.sonar.db.measure.custom.CustomMeasureDao; import org.sonar.db.metric.MetricDao; +import org.sonar.db.newcodeperiod.NewCodePeriodDao; import org.sonar.db.notification.NotificationQueueDao; import org.sonar.db.organization.OrganizationDao; import org.sonar.db.organization.OrganizationMemberDao; @@ -152,6 +153,7 @@ public class DbClient { private final WebhookDeliveryDao webhookDeliveryDao; private final ProjectMappingsDao projectMappingsDao; private final OrganizationAlmBindingDao organizationAlmBindingDao; + private final NewCodePeriodDao newCodePeriodDao; public DbClient(Database database, MyBatis myBatis, DBSessions dbSessions, Dao... daos) { this.database = database; @@ -224,6 +226,7 @@ public class DbClient { projectMappingsDao = getDao(map, ProjectMappingsDao.class); organizationAlmBindingDao = getDao(map, OrganizationAlmBindingDao.class); internalComponentPropertiesDao = getDao(map, InternalComponentPropertiesDao.class); + newCodePeriodDao = getDao(map, NewCodePeriodDao.class); } public DbSession openSession(boolean batch) { @@ -491,4 +494,8 @@ public class DbClient { public InternalComponentPropertiesDao internalComponentPropertiesDao() { return internalComponentPropertiesDao; } + + public NewCodePeriodDao newCodePeriodDao() { + return newCodePeriodDao; + } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java index 391ee1c0933..e9bf8807ba5 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java @@ -80,6 +80,7 @@ import org.sonar.db.measure.MeasureMapper; import org.sonar.db.measure.custom.CustomMeasureDto; import org.sonar.db.measure.custom.CustomMeasureMapper; import org.sonar.db.metric.MetricMapper; +import org.sonar.db.newcodeperiod.NewCodePeriodMapper; import org.sonar.db.notification.NotificationQueueDto; import org.sonar.db.notification.NotificationQueueMapper; import org.sonar.db.organization.OrganizationDto; @@ -252,6 +253,7 @@ public class MyBatis implements Startable { IssueMapper.class, MeasureMapper.class, MetricMapper.class, + NewCodePeriodMapper.class, NotificationQueueMapper.class, OrganizationAlmBindingMapper.class, OrganizationMapper.class, diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/newcodeperiod/NewCodePeriodDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/newcodeperiod/NewCodePeriodDao.java new file mode 100644 index 00000000000..a99c2f5a83a --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/newcodeperiod/NewCodePeriodDao.java @@ -0,0 +1,74 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.newcodeperiod; + +import java.util.Optional; +import org.sonar.api.utils.System2; +import org.sonar.db.Dao; +import org.sonar.db.DbSession; + +import static java.util.Objects.requireNonNull; + +public class NewCodePeriodDao implements Dao { + + private final System2 system2; + + public NewCodePeriodDao(System2 system2) { + this.system2 = system2; + } + + public Optional<NewCodePeriodDto> selectByUuid(DbSession dbSession, String uuid) { + return mapper(dbSession).selectByUuid(uuid); + } + + public NewCodePeriodDto selectGlobal(DbSession dbSession) { + return mapper(dbSession).selectGlobal(); + } + + public void insert(DbSession dbSession, NewCodePeriodDto dto) { + requireNonNull(dto.getType(), "Type of NewCodePeriod must be specified."); + requireNonNull(dto.getValue(), "Value of NewCodePeriod must be specified."); + long currentTime = system2.now(); + mapper(dbSession).insert(dto.setCreatedAt(currentTime).setUpdatedAt(currentTime)); + } + + public void update(DbSession dbSession, NewCodePeriodDto dto) { + requireNonNull(dto.getType(), "Type of NewCodePeriod must be specified."); + requireNonNull(dto.getValue(), "Value of NewCodePeriod must be specified."); + mapper(dbSession).update(dto.setUpdatedAt(system2.now())); + } + + public Optional<NewCodePeriodDto> selectByProject(DbSession dbSession, String projectUuid) { + requireNonNull(projectUuid, "Project uuid must be specified."); + return Optional.ofNullable(mapper(dbSession).selectByProject(projectUuid)); + + } + + public Optional<NewCodePeriodDto> selectByBranch(DbSession dbSession, String projectUuid, String branchUuid) { + requireNonNull(projectUuid, "Project uuid must be specified."); + requireNonNull(branchUuid, "Branch uuid must be specified."); + return Optional.ofNullable(mapper(dbSession).selectByBranch(projectUuid, branchUuid)); + } + + private static NewCodePeriodMapper mapper(DbSession session) { + return session.getMapper(NewCodePeriodMapper.class); + } + +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/newcodeperiod/NewCodePeriodDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/newcodeperiod/NewCodePeriodDto.java new file mode 100644 index 00000000000..2ad0382c668 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/newcodeperiod/NewCodePeriodDto.java @@ -0,0 +1,97 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.newcodeperiod; + +import javax.annotation.CheckForNull; + +public class NewCodePeriodDto { + private String uuid; + private String projectUuid; + private String branchUuid; + private NewCodePeriodType type; + private String value; + private long updatedAt; + private long createdAt; + + public long getCreatedAt() { + return createdAt; + } + + public NewCodePeriodDto setCreatedAt(long createdAt) { + this.createdAt = createdAt; + return this; + } + + public long getUpdatedAt() { + return updatedAt; + } + + public NewCodePeriodDto setUpdatedAt(long updatedAt) { + this.updatedAt = updatedAt; + return this; + } + + public String getUuid() { + return uuid; + } + + public NewCodePeriodDto setUuid(String uuid) { + this.uuid = uuid; + return this; + } + + @CheckForNull + public String getProjectUuid() { + return projectUuid; + } + + public NewCodePeriodDto setProjectUuid(String projectUuid) { + this.projectUuid = projectUuid; + return this; + } + + @CheckForNull + public String getBranchUuid() { + return branchUuid; + } + + public NewCodePeriodDto setBranchUuid(String branchUuid) { + this.branchUuid = branchUuid; + return this; + } + + public NewCodePeriodType getType() { + return type; + } + + public NewCodePeriodDto setType(NewCodePeriodType type) { + this.type = type; + return this; + } + + public String getValue() { + return value; + } + + public NewCodePeriodDto setValue(String value) { + this.value = value; + return this; + } +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/newcodeperiod/NewCodePeriodMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/newcodeperiod/NewCodePeriodMapper.java new file mode 100644 index 00000000000..db9a29cca73 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/newcodeperiod/NewCodePeriodMapper.java @@ -0,0 +1,38 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.newcodeperiod; + +import java.util.Optional; +import org.apache.ibatis.annotations.Param; + +public interface NewCodePeriodMapper { + + Optional<NewCodePeriodDto> selectByUuid(String uuid); + + NewCodePeriodDto selectGlobal(); + + void insert(NewCodePeriodDto dto); + + void update(NewCodePeriodDto dto); + + NewCodePeriodDto selectByProject(String projectUuid); + + NewCodePeriodDto selectByBranch(@Param("projectUuid") String projectUuid, @Param("branchUuid") String branchUuid); +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/newcodeperiod/NewCodePeriodType.java b/server/sonar-db-dao/src/main/java/org/sonar/db/newcodeperiod/NewCodePeriodType.java new file mode 100644 index 00000000000..9a1721a2287 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/newcodeperiod/NewCodePeriodType.java @@ -0,0 +1,27 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.newcodeperiod; + +public enum NewCodePeriodType { + PREVIOUS_VERSION, + NUMBER_OF_DAYS, + DATE, + SPECIFIC_ANALYSIS +} |