aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-06-28 15:15:44 +0200
committerDavid Gageot <david@gageot.net>2012-06-28 15:18:41 +0200
commitcbf9a517c208b45b1b6b719436fa08ef217e5196 (patch)
tree9532c0942f3d3863101fd9c0288b2d4df3862b24 /sonar-core
parent63c8a0f791f241505701e8498b9d25c59a6f9f20 (diff)
downloadsonarqube-cbf9a517c208b45b1b6b719436fa08ef217e5196.tar.gz
sonarqube-cbf9a517c208b45b1b6b719436fa08ef217e5196.zip
Resource Snapshot Mapper
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/dependency/DependencyDto.java50
-rw-r--r--sonar-core/src/main/java/org/sonar/core/dependency/DependencyMapper.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/dependency/ResourceSnapshotDto.java53
-rw-r--r--sonar-core/src/main/java/org/sonar/core/dependency/ResourceSnapshotMapper.java26
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java4
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/dependency/DependencyMapper.xml5
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/dependency/ResourceSnapshotMapper.xml10
-rw-r--r--sonar-core/src/test/java/org/sonar/core/dependency/DependencyMapperTest.java33
-rw-r--r--sonar-core/src/test/java/org/sonar/core/dependency/ResourceSnapshotMapperTest.java59
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/dependency/DependencyMapperTest/fixture.xml4
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/dependency/ResourceSnapshotMapperTest/fixture.xml4
11 files changed, 171 insertions, 81 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/dependency/DependencyDto.java b/sonar-core/src/main/java/org/sonar/core/dependency/DependencyDto.java
index 00599da2344..40d7e12cc02 100644
--- a/sonar-core/src/main/java/org/sonar/core/dependency/DependencyDto.java
+++ b/sonar-core/src/main/java/org/sonar/core/dependency/DependencyDto.java
@@ -21,12 +21,9 @@ package org.sonar.core.dependency;
public final class DependencyDto {
private Long id;
- private Long fromResourceId;
- private String fromVersion;
- private Long toResourceId;
- private String toVersion;
+ private Long fromSnapshotId;
+ private Long toSnapshotId;
private String usage;
- private Integer weight;
public Long getId() {
return id;
@@ -37,39 +34,21 @@ public final class DependencyDto {
return this;
}
- public Long getFromResourceId() {
- return fromResourceId;
+ public Long getFromSnapshotId() {
+ return fromSnapshotId;
}
- public DependencyDto setFromResourceId(Long fromResourceId) {
- this.fromResourceId = fromResourceId;
+ public DependencyDto setFromSnapshotId(Long fromSnapshotId) {
+ this.fromSnapshotId = fromSnapshotId;
return this;
}
- public String getFromVersion() {
- return fromVersion;
+ public Long getToSnapshotId() {
+ return toSnapshotId;
}
- public DependencyDto setFromVersion(String fromVersion) {
- this.fromVersion = fromVersion;
- return this;
- }
-
- public Long getToResourceId() {
- return toResourceId;
- }
-
- public DependencyDto setToResourceId(Long toResourceId) {
- this.toResourceId = toResourceId;
- return this;
- }
-
- public String getToVersion() {
- return toVersion;
- }
-
- public DependencyDto setToVersion(String toVersion) {
- this.toVersion = toVersion;
+ public DependencyDto setToSnapshotId(Long toSnapshotId) {
+ this.toSnapshotId = toSnapshotId;
return this;
}
@@ -81,13 +60,4 @@ public final class DependencyDto {
this.usage = usage;
return this;
}
-
- public Integer getWeight() {
- return weight;
- }
-
- public DependencyDto setWeight(Integer weight) {
- this.weight = weight;
- return this;
- }
}
diff --git a/sonar-core/src/main/java/org/sonar/core/dependency/DependencyMapper.java b/sonar-core/src/main/java/org/sonar/core/dependency/DependencyMapper.java
index e2f2d450ad9..e42257b8ee1 100644
--- a/sonar-core/src/main/java/org/sonar/core/dependency/DependencyMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/dependency/DependencyMapper.java
@@ -21,10 +21,6 @@ package org.sonar.core.dependency;
import org.apache.ibatis.session.ResultHandler;
-import java.util.List;
-
public interface DependencyMapper {
- List<DependencyDto> selectAll();
-
void selectAll(ResultHandler handler);
}
diff --git a/sonar-core/src/main/java/org/sonar/core/dependency/ResourceSnapshotDto.java b/sonar-core/src/main/java/org/sonar/core/dependency/ResourceSnapshotDto.java
new file mode 100644
index 00000000000..10d07da572e
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/dependency/ResourceSnapshotDto.java
@@ -0,0 +1,53 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.dependency;
+
+public final class ResourceSnapshotDto {
+ private Long id;
+ private Long projectId;
+ private String version;
+
+ public Long getId() {
+ return id;
+ }
+
+ public ResourceSnapshotDto setId(Long id) {
+ this.id = id;
+ return this;
+ }
+
+ public Long getProjectId() {
+ return projectId;
+ }
+
+ public ResourceSnapshotDto setProjectId(Long projectId) {
+ this.projectId = projectId;
+ return this;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public ResourceSnapshotDto setVersion(String version) {
+ this.version = version;
+ return this;
+ }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/dependency/ResourceSnapshotMapper.java b/sonar-core/src/main/java/org/sonar/core/dependency/ResourceSnapshotMapper.java
new file mode 100644
index 00000000000..343fb771d3c
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/dependency/ResourceSnapshotMapper.java
@@ -0,0 +1,26 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.dependency;
+
+import org.apache.ibatis.session.ResultHandler;
+
+public interface ResourceSnapshotMapper {
+ void selectAll(ResultHandler handler);
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
index 501efd8ed36..6f1d450e016 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
@@ -43,6 +43,8 @@ import org.sonar.core.dashboard.WidgetPropertyDto;
import org.sonar.core.dashboard.WidgetPropertyMapper;
import org.sonar.core.dependency.DependencyDto;
import org.sonar.core.dependency.DependencyMapper;
+import org.sonar.core.dependency.ResourceSnapshotDto;
+import org.sonar.core.dependency.ResourceSnapshotMapper;
import org.sonar.core.duplication.DuplicationMapper;
import org.sonar.core.duplication.DuplicationUnitDto;
import org.sonar.core.filter.CriterionDto;
@@ -99,6 +101,7 @@ public class MyBatis implements BatchComponent, ServerComponent {
loadAlias(conf, "FilterColumn", FilterColumnDto.class);
loadAlias(conf, "Dashboard", DashboardDto.class);
loadAlias(conf, "Dependency", DependencyDto.class);
+ loadAlias(conf, "ResourceSnapshot", ResourceSnapshotDto.class);
loadAlias(conf, "DuplicationUnit", DuplicationUnitDto.class);
loadAlias(conf, "LoadedTemplate", LoadedTemplateDto.class);
loadAlias(conf, "Property", PropertyDto.class);
@@ -120,6 +123,7 @@ public class MyBatis implements BatchComponent, ServerComponent {
loadMapper(conf, FilterColumnMapper.class);
loadMapper(conf, DashboardMapper.class);
loadMapper(conf, DependencyMapper.class);
+ loadMapper(conf, ResourceSnapshotMapper.class);
loadMapper(conf, DuplicationMapper.class);
loadMapper(conf, LoadedTemplateMapper.class);
loadMapper(conf, PropertiesMapper.class);
diff --git a/sonar-core/src/main/resources/org/sonar/core/dependency/DependencyMapper.xml b/sonar-core/src/main/resources/org/sonar/core/dependency/DependencyMapper.xml
index b4bad32087a..b12dbb37535 100644
--- a/sonar-core/src/main/resources/org/sonar/core/dependency/DependencyMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/dependency/DependencyMapper.xml
@@ -4,10 +4,7 @@
<mapper namespace="org.sonar.core.dependency.DependencyMapper">
<select id="selectAll" resultType="dependency">
- SELECT dependencies.id as id, from_resource_id as fromResourceId, sLeft.version as fromVersion, to_resource_id as toResourceId, sRight.version as toVersion, dep_usage as "usage", dep_weight as weight
- FROM dependencies
- JOIN snapshots as sLeft ON dependencies.from_snapshot_id = sLeft.id
- JOIN snapshots as sRight ON dependencies.to_snapshot_id = sRight.id
+ SELECT id, from_snapshot_id as fromSnapshotId, to_snapshot_id as toSnapshotId, dep_usage as "usage" FROM dependencies
</select>
</mapper>
diff --git a/sonar-core/src/main/resources/org/sonar/core/dependency/ResourceSnapshotMapper.xml b/sonar-core/src/main/resources/org/sonar/core/dependency/ResourceSnapshotMapper.xml
new file mode 100644
index 00000000000..7fdb3e7f36c
--- /dev/null
+++ b/sonar-core/src/main/resources/org/sonar/core/dependency/ResourceSnapshotMapper.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.core.dependency.ResourceSnapshotMapper">
+
+ <select id="selectAll" resultType="ResourceSnapshot">
+ SELECT id, project_id as projectId, version FROM snapshots
+ </select>
+
+</mapper>
diff --git a/sonar-core/src/test/java/org/sonar/core/dependency/DependencyMapperTest.java b/sonar-core/src/test/java/org/sonar/core/dependency/DependencyMapperTest.java
index 45f408e7824..d236ff29ce1 100644
--- a/sonar-core/src/test/java/org/sonar/core/dependency/DependencyMapperTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/dependency/DependencyMapperTest.java
@@ -32,31 +32,8 @@ import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
public class DependencyMapperTest extends DaoTestCase {
-
@Test
- public void testDescendantProjects_do_not_include_self() {
- setupData("fixture");
-
- SqlSession session = getMyBatis().openSession();
- try {
- List<DependencyDto> dependencies = session.getMapper(DependencyMapper.class).selectAll();
-
- assertThat(dependencies).hasSize(2);
-
- DependencyDto dep = dependencies.get(0);
- assertThat(dep.getUsage()).isEqualTo("compile");
- assertThat(dep.getFromResourceId()).isEqualTo(100L);
- assertThat(dep.getFromVersion()).isEqualTo("1.0");
- assertThat(dep.getToResourceId()).isEqualTo(101L);
- assertThat(dep.getToVersion()).isEqualTo("3.0");
- assertThat(dep.getId()).isEqualTo(1L);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- @Test
- public void should_use_result_handler() {
+ public void should_find_all() {
setupData("fixture");
final List<DependencyDto> dependencies = Lists.newArrayList();
@@ -75,11 +52,9 @@ public class DependencyMapperTest extends DaoTestCase {
assertThat(dependencies).hasSize(2);
DependencyDto dep = dependencies.get(0);
- assertThat(dep.getUsage()).isEqualTo("compile");
- assertThat(dep.getFromResourceId()).isEqualTo(100L);
- assertThat(dep.getFromVersion()).isEqualTo("1.0");
- assertThat(dep.getToResourceId()).isEqualTo(101L);
- assertThat(dep.getToVersion()).isEqualTo("3.0");
assertThat(dep.getId()).isEqualTo(1L);
+ assertThat(dep.getFromSnapshotId()).isEqualTo(1000L);
+ assertThat(dep.getToSnapshotId()).isEqualTo(1001L);
+ assertThat(dep.getUsage()).isEqualTo("compile");
}
}
diff --git a/sonar-core/src/test/java/org/sonar/core/dependency/ResourceSnapshotMapperTest.java b/sonar-core/src/test/java/org/sonar/core/dependency/ResourceSnapshotMapperTest.java
new file mode 100644
index 00000000000..76ddf641b04
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/dependency/ResourceSnapshotMapperTest.java
@@ -0,0 +1,59 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.dependency;
+
+import com.google.common.collect.Lists;
+import org.apache.ibatis.session.ResultContext;
+import org.apache.ibatis.session.ResultHandler;
+import org.apache.ibatis.session.SqlSession;
+import org.junit.Test;
+import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.MyBatis;
+
+import java.util.List;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class ResourceSnapshotMapperTest extends DaoTestCase {
+ @Test
+ public void should_find_all() {
+ setupData("fixture");
+
+ final List<ResourceSnapshotDto> snapshots = Lists.newArrayList();
+
+ SqlSession session = getMyBatis().openSession();
+ try {
+ session.getMapper(ResourceSnapshotMapper.class).selectAll(new ResultHandler() {
+ public void handleResult(ResultContext context) {
+ snapshots.add((ResourceSnapshotDto) context.getResultObject());
+ }
+ });
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+
+ assertThat(snapshots).hasSize(2);
+
+ ResourceSnapshotDto dep = snapshots.get(0);
+ assertThat(dep.getId()).isEqualTo(1L);
+ assertThat(dep.getProjectId()).isEqualTo(1000L);
+ assertThat(dep.getVersion()).isEqualTo("1.0");
+ }
+}
diff --git a/sonar-core/src/test/resources/org/sonar/core/dependency/DependencyMapperTest/fixture.xml b/sonar-core/src/test/resources/org/sonar/core/dependency/DependencyMapperTest/fixture.xml
index b6cc818679b..7e8a8e9f677 100644
--- a/sonar-core/src/test/resources/org/sonar/core/dependency/DependencyMapperTest/fixture.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/dependency/DependencyMapperTest/fixture.xml
@@ -1,8 +1,4 @@
<dataset>
<dependencies id="1" from_resource_id="100" to_resource_id="101" from_snapshot_id="1000" to_snapshot_id="1001" dep_usage="compile" dep_weight="1" />
<dependencies id="2" from_resource_id="200" to_resource_id="201" from_snapshot_id="2000" to_snapshot_id="2001" dep_usage="provided" dep_weight="1" />
- <snapshots id="1000" version="1.0" project_id="1" />
- <snapshots id="2000" version="2.0" project_id="1" />
- <snapshots id="1001" version="3.0" project_id="1" />
- <snapshots id="2001" version="4.0" project_id="1" />
</dataset> \ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/dependency/ResourceSnapshotMapperTest/fixture.xml b/sonar-core/src/test/resources/org/sonar/core/dependency/ResourceSnapshotMapperTest/fixture.xml
new file mode 100644
index 00000000000..9b9fa7d4942
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/dependency/ResourceSnapshotMapperTest/fixture.xml
@@ -0,0 +1,4 @@
+<dataset>
+ <snapshots id="1" project_id="1000" version="1.0" />
+ <snapshots id="2" project_id="1001" version="2.0-SNAPSHOT" />
+</dataset> \ No newline at end of file