aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db/src/main/java/org/sonar/db
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-09-11 10:12:36 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2016-09-12 14:11:59 +0200
commit6c0b5563fbc8b0fbf9ed0aa722302a8f1e74cdf4 (patch)
treeb777f55fbb3408d696260c54a369bc0d9f3227eb /sonar-db/src/main/java/org/sonar/db
parentb5851d0ff8318549c2356b20df36401b879fc5a2 (diff)
downloadsonarqube-6c0b5563fbc8b0fbf9ed0aa722302a8f1e74cdf4.tar.gz
sonarqube-6c0b5563fbc8b0fbf9ed0aa722302a8f1e74cdf4.zip
SONAR-7851 add QProfileChangeDao
Diffstat (limited to 'sonar-db/src/main/java/org/sonar/db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/DaoModule.java7
-rw-r--r--sonar-db/src/main/java/org/sonar/db/DbClient.java7
-rw-r--r--sonar-db/src/main/java/org/sonar/db/MyBatis.java3
-rw-r--r--sonar-db/src/main/java/org/sonar/db/qualityprofile/QProfileChangeDao.java56
-rw-r--r--sonar-db/src/main/java/org/sonar/db/qualityprofile/QProfileChangeDto.java117
-rw-r--r--sonar-db/src/main/java/org/sonar/db/qualityprofile/QProfileChangeMapper.java32
-rw-r--r--sonar-db/src/main/java/org/sonar/db/qualityprofile/QProfileChangeQuery.java92
-rw-r--r--sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java4
8 files changed, 311 insertions, 7 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/DaoModule.java b/sonar-db/src/main/java/org/sonar/db/DaoModule.java
index 880090dcdde..630f07632b9 100644
--- a/sonar-db/src/main/java/org/sonar/db/DaoModule.java
+++ b/sonar-db/src/main/java/org/sonar/db/DaoModule.java
@@ -25,6 +25,7 @@ import org.sonar.core.platform.Module;
import org.sonar.db.activity.ActivityDao;
import org.sonar.db.ce.CeActivityDao;
import org.sonar.db.ce.CeQueueDao;
+import org.sonar.db.ce.CeScannerContextDao;
import org.sonar.db.ce.CeTaskInputDao;
import org.sonar.db.component.ComponentDao;
import org.sonar.db.component.ComponentKeyUpdaterDao;
@@ -59,9 +60,9 @@ import org.sonar.db.qualitygate.ProjectQgateAssociationDao;
import org.sonar.db.qualitygate.QualityGateConditionDao;
import org.sonar.db.qualitygate.QualityGateDao;
import org.sonar.db.qualityprofile.ActiveRuleDao;
+import org.sonar.db.qualityprofile.QProfileChangeDao;
import org.sonar.db.qualityprofile.QualityProfileDao;
import org.sonar.db.rule.RuleDao;
-import org.sonar.db.ce.CeScannerContextDao;
import org.sonar.db.source.FileSourceDao;
import org.sonar.db.user.AuthorDao;
import org.sonar.db.user.AuthorizationDao;
@@ -110,6 +111,7 @@ public class DaoModule extends Module {
QualityGateDao.class,
QualityGateConditionDao.class,
QualityProfileDao.class,
+ QProfileChangeDao.class,
CeScannerContextDao.class,
RuleDao.class,
ActiveRuleDao.class,
@@ -122,7 +124,8 @@ public class DaoModule extends Module {
UserGroupDao.class,
UserTokenDao.class,
WidgetDao.class,
- WidgetPropertyDao.class).build();
+ WidgetPropertyDao.class
+ ).build();
@Override
protected void configureModule() {
diff --git a/sonar-db/src/main/java/org/sonar/db/DbClient.java b/sonar-db/src/main/java/org/sonar/db/DbClient.java
index 6a6f4d182ca..ceabd8c62ae 100644
--- a/sonar-db/src/main/java/org/sonar/db/DbClient.java
+++ b/sonar-db/src/main/java/org/sonar/db/DbClient.java
@@ -60,6 +60,7 @@ import org.sonar.db.qualitygate.ProjectQgateAssociationDao;
import org.sonar.db.qualitygate.QualityGateConditionDao;
import org.sonar.db.qualitygate.QualityGateDao;
import org.sonar.db.qualityprofile.ActiveRuleDao;
+import org.sonar.db.qualityprofile.QProfileChangeDao;
import org.sonar.db.qualityprofile.QualityProfileDao;
import org.sonar.db.rule.RuleDao;
import org.sonar.db.source.FileSourceDao;
@@ -125,6 +126,7 @@ public class DbClient {
private final GroupDao groupDao;
private final RuleDao ruleDao;
private final ActiveRuleDao activeRuleDao;
+ private final QProfileChangeDao qProfileChangeDao;
public DbClient(Database database, MyBatis myBatis, Dao... daos) {
this.database = database;
@@ -183,6 +185,7 @@ public class DbClient {
groupDao = getDao(map, GroupDao.class);
ruleDao = getDao(map, RuleDao.class);
activeRuleDao = getDao(map, ActiveRuleDao.class);
+ qProfileChangeDao = getDao(map, QProfileChangeDao.class);
}
public DbSession openSession(boolean batch) {
@@ -393,6 +396,10 @@ public class DbClient {
return activeRuleDao;
}
+ public QProfileChangeDao qProfileChangeDao() {
+ return qProfileChangeDao;
+ }
+
protected <K extends Dao> K getDao(Map<Class, Dao> map, Class<K> clazz) {
return (K) map.get(clazz);
}
diff --git a/sonar-db/src/main/java/org/sonar/db/MyBatis.java b/sonar-db/src/main/java/org/sonar/db/MyBatis.java
index e2d37996d3c..ca25a31117a 100644
--- a/sonar-db/src/main/java/org/sonar/db/MyBatis.java
+++ b/sonar-db/src/main/java/org/sonar/db/MyBatis.java
@@ -108,6 +108,7 @@ import org.sonar.db.qualitygate.QualityGateMapper;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleMapper;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
+import org.sonar.db.qualityprofile.QProfileChangeMapper;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.QualityProfileMapper;
import org.sonar.db.rule.RuleDto;
@@ -236,7 +237,7 @@ public class MyBatis {
UserMapper.class, GroupMapper.class, UserGroupMapper.class, UserTokenMapper.class,
FileSourceMapper.class,
NotificationQueueMapper.class,
- GroupMembershipMapper.class, QualityProfileMapper.class, ActiveRuleMapper.class,
+ GroupMembershipMapper.class, QualityProfileMapper.class, ActiveRuleMapper.class, QProfileChangeMapper.class,
MeasureMapper.class, MetricMapper.class, CustomMeasureMapper.class, QualityGateMapper.class, QualityGateConditionMapper.class, ComponentMapper.class, SnapshotMapper.class,
ProjectQgateAssociationMapper.class, EventMapper.class,
CeQueueMapper.class, CeActivityMapper.class, CeTaskInputMapper.class, CeScannerContextMapper.class,
diff --git a/sonar-db/src/main/java/org/sonar/db/qualityprofile/QProfileChangeDao.java b/sonar-db/src/main/java/org/sonar/db/qualityprofile/QProfileChangeDao.java
new file mode 100644
index 00000000000..41c6474d4e4
--- /dev/null
+++ b/sonar-db/src/main/java/org/sonar/db/qualityprofile/QProfileChangeDao.java
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.qualityprofile;
+
+import java.util.List;
+import org.sonar.api.utils.System2;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+
+import static com.google.common.base.Preconditions.checkState;
+
+public class QProfileChangeDao implements Dao {
+
+ private final System2 system2;
+ private final UuidFactory uuidFactory;
+
+ public QProfileChangeDao(System2 system2, UuidFactory uuidFactory) {
+ this.system2 = system2;
+ this.uuidFactory = uuidFactory;
+ }
+
+ public void insert(DbSession dbSession, QProfileChangeDto dto) {
+ checkState(dto.getKey() == null, "Key of QProfileChangeDto must be set by DAO only. Got %s.", dto.getKey());
+ checkState(dto.getCreatedAt() == 0L, "Date of QProfileChangeDto must be set by DAO only. Got %s.", dto.getCreatedAt());
+
+ dto.setKey(uuidFactory.create());
+ dto.setCreatedAt(system2.now());
+ dbSession.getMapper(QProfileChangeMapper.class).insert(dto);
+ }
+
+ public List<QProfileChangeDto> selectByQuery(DbSession dbSession, QProfileChangeQuery query) {
+ return dbSession.getMapper(QProfileChangeMapper.class).selectByQuery(query);
+ }
+
+ public int countForProfileKey(DbSession dbSession, String profileKey) {
+ return dbSession.getMapper(QProfileChangeMapper.class).countForProfileKey(profileKey);
+ }
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/qualityprofile/QProfileChangeDto.java b/sonar-db/src/main/java/org/sonar/db/qualityprofile/QProfileChangeDto.java
new file mode 100644
index 00000000000..ab12cb0908f
--- /dev/null
+++ b/sonar-db/src/main/java/org/sonar/db/qualityprofile/QProfileChangeDto.java
@@ -0,0 +1,117 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.qualityprofile;
+
+import java.util.Collections;
+import java.util.Map;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.apache.commons.lang.builder.ReflectionToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+import org.sonar.api.utils.KeyValueFormat;
+
+public class QProfileChangeDto {
+
+ private String key;
+ private String profileKey;
+ // can't be named "type" because it's a reserved word in Oracle
+ // (used by Mybatis to map DB column with DTO field)
+ private String changeType;
+ private String login;
+ private String data;
+ private long createdAt;
+
+ public String getKey() {
+ return key;
+ }
+
+ public QProfileChangeDto setKey(String s) {
+ this.key = s;
+ return this;
+ }
+
+ public String getProfileKey() {
+ return profileKey;
+ }
+
+ public QProfileChangeDto setProfileKey(String s) {
+ this.profileKey = s;
+ return this;
+ }
+
+ public String getChangeType() {
+ return changeType;
+ }
+
+ public QProfileChangeDto setChangeType(String s) {
+ this.changeType = s;
+ return this;
+ }
+
+ public long getCreatedAt() {
+ return createdAt;
+ }
+
+ public QProfileChangeDto setCreatedAt(long l) {
+ this.createdAt = l;
+ return this;
+ }
+
+ @CheckForNull
+ public String getLogin() {
+ return login;
+ }
+
+ public QProfileChangeDto setLogin(@Nullable String s) {
+ this.login = s;
+ return this;
+ }
+
+ @CheckForNull
+ public String getData() {
+ return data;
+ }
+
+ public Map<String, String> getDataAsMap() {
+ if (data == null) {
+ return Collections.emptyMap();
+ }
+ return KeyValueFormat.parse(data);
+ }
+
+ public QProfileChangeDto setData(@Nullable String csv) {
+ this.data = csv;
+ return this;
+ }
+
+ public QProfileChangeDto setData(@Nullable Map m) {
+ if (m == null || m.isEmpty()) {
+ this.data = null;
+ } else {
+ this.data = KeyValueFormat.format(m);
+ }
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
+ }
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/qualityprofile/QProfileChangeMapper.java b/sonar-db/src/main/java/org/sonar/db/qualityprofile/QProfileChangeMapper.java
new file mode 100644
index 00000000000..a50c9b8cbf1
--- /dev/null
+++ b/sonar-db/src/main/java/org/sonar/db/qualityprofile/QProfileChangeMapper.java
@@ -0,0 +1,32 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.qualityprofile;
+
+import java.util.List;
+import org.apache.ibatis.annotations.Param;
+
+public interface QProfileChangeMapper {
+
+ void insert(QProfileChangeDto dto);
+
+ List<QProfileChangeDto> selectByQuery(@Param("query") QProfileChangeQuery query);
+
+ int countForProfileKey(@Param("profileKey") String profileKey);
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/qualityprofile/QProfileChangeQuery.java b/sonar-db/src/main/java/org/sonar/db/qualityprofile/QProfileChangeQuery.java
new file mode 100644
index 00000000000..334dbaab240
--- /dev/null
+++ b/sonar-db/src/main/java/org/sonar/db/qualityprofile/QProfileChangeQuery.java
@@ -0,0 +1,92 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.qualityprofile;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.apache.commons.lang.builder.ReflectionToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+
+import static java.util.Objects.requireNonNull;
+
+public class QProfileChangeQuery {
+
+ private final String profileKey;
+ private Long fromIncluded;
+ private Long toExcluded;
+ private int offset = 0;
+ private int limit = 100;
+
+ public QProfileChangeQuery(String profileKey) {
+ this.profileKey = requireNonNull(profileKey);
+ }
+
+ public String getProfileKey() {
+ return profileKey;
+ }
+
+ @CheckForNull
+ public Long getFromIncluded() {
+ return fromIncluded;
+ }
+
+ public void setFromIncluded(@Nullable Long l) {
+ this.fromIncluded = l;
+ }
+
+ @CheckForNull
+ public Long getToExcluded() {
+ return toExcluded;
+ }
+
+ public void setToExcluded(@Nullable Long l) {
+ this.toExcluded = l;
+ }
+
+ public int getOffset() {
+ return offset;
+ }
+
+ public void setOffset(int offset) {
+ this.offset = offset;
+ }
+
+ public int getLimit() {
+ return limit;
+ }
+
+ public void setLimit(int limit) {
+ this.limit = limit;
+ }
+
+ public void setPage(int page, int pageSize) {
+ offset = (page -1) * pageSize;
+ limit = pageSize;
+ }
+
+ public int getTotal() {
+ return offset + limit;
+ }
+
+ @Override
+ public String toString() {
+ return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
+ }
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java
index 9bd60db038d..3d97895f8ac 100644
--- a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java
+++ b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java
@@ -322,13 +322,9 @@ public class MigrationStepModule extends Module {
ShrinkModuleUuidPathOfProjects.class,
AddBUuidPathToProjects.class,
AddErrorColumnsToCeActivity.class,
-<<<<<<< HEAD
PopulateTableProperties2.class,
- RemoveViewsDefinitionFromProperties.class);
-=======
RemoveViewsDefinitionFromProperties.class,
CopyActivitiesToQprofileChanges.class
);
->>>>>>> SONAR-7851 copy activities to qprofile_changes
}
}