]> source.dussan.org Git - sonarqube.git/commitdiff
Resource Snapshot Mapper
authorDavid Gageot <david@gageot.net>
Thu, 28 Jun 2012 13:15:44 +0000 (15:15 +0200)
committerDavid Gageot <david@gageot.net>
Thu, 28 Jun 2012 13:18:41 +0000 (15:18 +0200)
sonar-core/src/main/java/org/sonar/core/dependency/DependencyDto.java
sonar-core/src/main/java/org/sonar/core/dependency/DependencyMapper.java
sonar-core/src/main/java/org/sonar/core/dependency/ResourceSnapshotDto.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/dependency/ResourceSnapshotMapper.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
sonar-core/src/main/resources/org/sonar/core/dependency/DependencyMapper.xml
sonar-core/src/main/resources/org/sonar/core/dependency/ResourceSnapshotMapper.xml [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/dependency/DependencyMapperTest.java
sonar-core/src/test/java/org/sonar/core/dependency/ResourceSnapshotMapperTest.java [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/dependency/DependencyMapperTest/fixture.xml
sonar-core/src/test/resources/org/sonar/core/dependency/ResourceSnapshotMapperTest/fixture.xml [new file with mode: 0644]

index 00599da2344ff6eb3063e5c4ff56c075f9e9c3e4..40d7e12cc02cdebff257296d233f58f6892e9660 100644 (file)
@@ -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;
-  }
 }
index e2f2d450ad92f1db5710da35018584429fe2cb01..e42257b8ee132fd37ecebc84c1cdfa82cbdb7f59 100644 (file)
@@ -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 (file)
index 0000000..10d07da
--- /dev/null
@@ -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 (file)
index 0000000..343fb77
--- /dev/null
@@ -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);
+}
index 501efd8ed36dee26d4cdf4da63425c47ca58b860..6f1d450e016fc32f7961981eac66954927344f0b 100644 (file)
@@ -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);
index b4bad32087a6fb02db1542732bdc325d859b34f7..b12dbb37535eca149e33cc43394e1284a11ca0dd 100644 (file)
@@ -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 (file)
index 0000000..7fdb3e7
--- /dev/null
@@ -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>
index 45f408e7824204f05994b615b8af36282cdccca8..d236ff29ce1f77acd0a5cf06abf51a14559a53dd 100644 (file)
@@ -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 (file)
index 0000000..76ddf64
--- /dev/null
@@ -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");
+  }
+}
index b6cc818679b49d3acfb00cabde1e0dc5859fb7f3..7e8a8e9f677dcca2e235391b329a3384799e2fbd 100644 (file)
@@ -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 (file)
index 0000000..9b9fa7d
--- /dev/null
@@ -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