]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6458 Create FileDependencyDao to insert and select file dependencies
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 29 Apr 2015 14:44:09 +0000 (16:44 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 30 Apr 2015 14:29:13 +0000 (16:29 +0200)
16 files changed:
server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java
server/sonar-server/src/main/java/org/sonar/server/design/db/FileDependencyDao.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/design/db/FileDependencyDaoTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/event/db/EventDaoTest.java
server/sonar-server/src/test/resources/org/sonar/server/design/db/FileDependencyDaoTest/insert.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/design/db/FileDependencyDaoTest/shared.xml [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/design/DependencyDto.java [deleted file]
sonar-core/src/main/java/org/sonar/core/design/DependencyMapper.java [deleted file]
sonar-core/src/main/java/org/sonar/core/design/FileDependencyDto.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/design/FileDependencyMapper.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/design/DependencyMapper.xml [deleted file]
sonar-core/src/main/resources/org/sonar/core/design/FileDependencyMapper.xml [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/design/DependencyMapperTest.java [deleted file]
sonar-core/src/test/java/org/sonar/core/design/FileDependencyDtoTest.java [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/design/DependencyMapperTest/fixture.xml [deleted file]

index 6cda0323c7e6b5d1801dcaf833a15cd112d4f5b2..d3340efd5fe1b473254523ed3579aaddbf022db2 100644 (file)
@@ -43,6 +43,7 @@ import org.sonar.server.computation.db.AnalysisReportDao;
 import org.sonar.server.dashboard.db.DashboardDao;
 import org.sonar.server.dashboard.db.WidgetDao;
 import org.sonar.server.dashboard.db.WidgetPropertyDao;
+import org.sonar.server.design.db.FileDependencyDao;
 import org.sonar.server.event.db.EventDao;
 import org.sonar.server.issue.db.IssueDao;
 import org.sonar.server.measure.persistence.MeasureDao;
@@ -97,6 +98,7 @@ public class DbClient implements ServerComponent {
   private final ComponentIndexDao componentIndexDao;
   private final ComponentLinkDao componentLinkDao;
   private final EventDao eventDao;
+  private final FileDependencyDao fileDependencyDao;
 
   public DbClient(Database db, MyBatis myBatis, DaoComponent... daoComponents) {
     this.db = db;
@@ -135,6 +137,7 @@ public class DbClient implements ServerComponent {
     componentIndexDao = getDao(map, ComponentIndexDao.class);
     componentLinkDao = getDao(map, ComponentLinkDao.class);
     eventDao = getDao(map, EventDao.class);
+    fileDependencyDao = getDao(map, FileDependencyDao.class);
   }
 
   public Database database() {
@@ -261,6 +264,10 @@ public class DbClient implements ServerComponent {
     return eventDao;
   }
 
+  public FileDependencyDao fileDependencyDao() {
+    return fileDependencyDao;
+  }
+
   private <K> K getDao(Map<Class, DaoComponent> map, Class<K> clazz) {
     return (K) map.get(clazz);
   }
diff --git a/server/sonar-server/src/main/java/org/sonar/server/design/db/FileDependencyDao.java b/server/sonar-server/src/main/java/org/sonar/server/design/db/FileDependencyDao.java
new file mode 100644 (file)
index 0000000..0a7bfcd
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.server.design.db;
+
+import org.sonar.api.ServerComponent;
+import org.sonar.core.design.FileDependencyDto;
+import org.sonar.core.design.FileDependencyMapper;
+import org.sonar.core.persistence.DaoComponent;
+import org.sonar.core.persistence.DbSession;
+
+import java.util.List;
+
+public class FileDependencyDao implements ServerComponent, DaoComponent {
+
+  public List<FileDependencyDto> selectFromParents(DbSession session, String fromParentUuid, String toParentUuid, Long projectId) {
+    return session.getMapper(FileDependencyMapper.class).selectFromParents(fromParentUuid, toParentUuid, projectId);
+  }
+
+  public void insert(DbSession session, FileDependencyDto dto) {
+    session.getMapper(FileDependencyMapper.class).insert(dto);
+  }
+
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/design/db/FileDependencyDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/design/db/FileDependencyDaoTest.java
new file mode 100644 (file)
index 0000000..e7877bf
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.server.design.db;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.sonar.core.design.FileDependencyDto;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.DbTester;
+import org.sonar.test.DbTests;
+
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@Category(DbTests.class)
+public class FileDependencyDaoTest {
+
+  @ClassRule
+  public static DbTester dbTester = new DbTester();
+
+  DbSession session;
+
+  FileDependencyDao dao;
+
+  @Before
+  public void setup() throws Exception {
+    dbTester.truncateTables();
+    session = dbTester.myBatis().openSession(false);
+    dao = new FileDependencyDao();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    session.close();
+  }
+
+  @Test
+  public void select_from_parents() throws Exception {
+    dbTester.prepareDbUnit(getClass(), "shared.xml");
+
+    List<FileDependencyDto> dtos = dao.selectFromParents(session, "MNOP", "QRST", 1L);
+    assertThat(dtos).hasSize(1);
+
+    assertThat(dtos.get(0).getId()).isEqualTo(1);
+    assertThat(dtos.get(0).getFromComponentUuid()).isEqualTo("EFGH");
+    assertThat(dtos.get(0).getToComponentUuid()).isEqualTo("IJKL");
+    assertThat(dtos.get(0).getFromParentUuid()).isEqualTo("MNOP");
+    assertThat(dtos.get(0).getToParentUuid()).isEqualTo("QRST");
+    assertThat(dtos.get(0).getWeight()).isEqualTo(2);
+    assertThat(dtos.get(0).getRootProjectSnapshotId()).isEqualTo(10L);
+    assertThat(dtos.get(0).getCreatedAt()).isEqualTo(1000L);
+
+    assertThat(dao.selectFromParents(session, "MNOP", "QRST", 123L)).isEmpty();
+  }
+
+  @Test
+  public void insert() throws Exception {
+    dao.insert(session, new FileDependencyDto()
+      .setFromComponentUuid("ABCD")
+      .setToComponentUuid("EFGH")
+      .setFromParentUuid("IJKL")
+      .setToParentUuid("MNOP")
+      .setRootProjectSnapshotId(10L)
+      .setWeight(2)
+      .setCreatedAt(1000L)
+    );
+    session.commit();
+
+    dbTester.assertDbUnit(getClass(), "insert.xml", new String[]{"id"}, "dependencies");
+  }
+}
index 30464f7273a6a13d8a4b49711403da5b91337e58..9068f1cce32397e2bfc3d845439ebee1a1ef05e4 100644 (file)
@@ -46,6 +46,7 @@ public class EventDaoTest {
 
   @Before
   public void setup() throws Exception {
+    dbTester.truncateTables();
     session = dbTester.myBatis().openSession(false);
     dao = new EventDao();
   }
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/design/db/FileDependencyDaoTest/insert.xml b/server/sonar-server/src/test/resources/org/sonar/server/design/db/FileDependencyDaoTest/insert.xml
new file mode 100644 (file)
index 0000000..84dc736
--- /dev/null
@@ -0,0 +1,6 @@
+<dataset>
+
+  <dependencies id="1" from_component_uuid="ABCD" to_component_uuid="EFGH" from_parent_uuid="IJKL" to_parent_uuid="MNOP" dep_weight="2" root_project_snapshot_id="10" created_at="1000"
+                from_snapshot_id="[null]" to_snapshot_id="[null]" parent_dependency_id="[null]" project_snapshot_id="[null]" dep_usage="[null]" from_scope="[null]" to_scope="[null]" />
+
+</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/design/db/FileDependencyDaoTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/design/db/FileDependencyDaoTest/shared.xml
new file mode 100644 (file)
index 0000000..d45b572
--- /dev/null
@@ -0,0 +1,19 @@
+<dataset>
+
+  <!-- Two dependencies from current snapshot -->
+  <dependencies id="1" from_component_uuid="EFGH" to_component_uuid="IJKL" from_parent_uuid="MNOP" to_parent_uuid="QRST" dep_weight="2" root_project_snapshot_id="10" created_at="1000"
+                from_snapshot_id="[null]" to_snapshot_id="[null]" parent_dependency_id="[null]" project_snapshot_id="[null]" dep_usage="[null]" from_scope="[null]" to_scope="[null]" />
+
+  <dependencies id="2" from_component_uuid="UVWX" to_component_uuid="YZAB" from_parent_uuid="PONM" to_parent_uuid="TSRQ" dep_weight="3" root_project_snapshot_id="10" created_at="1000"
+                from_snapshot_id="[null]" to_snapshot_id="[null]" parent_dependency_id="[null]" project_snapshot_id="[null]" dep_usage="[null]" from_scope="[null]" to_scope="[null]" />
+
+  <!-- Dependency on previous snapshot -->
+  <dependencies id="3" from_component_uuid="EFGH" to_component_uuid="LKJI" from_parent_uuid="MNOP" to_parent_uuid="QRST" dep_weight="2" root_project_snapshot_id="11" created_at="1000"
+                from_snapshot_id="[null]" to_snapshot_id="[null]" parent_dependency_id="[null]" project_snapshot_id="[null]" dep_usage="[null]" from_scope="[null]" to_scope="[null]" />
+
+  <projects id="1" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."/>
+
+  <snapshots id="10" islast="[true]" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"/>
+  <snapshots id="11" islast="[false]" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"/>
+
+</dataset>
diff --git a/sonar-core/src/main/java/org/sonar/core/design/DependencyDto.java b/sonar-core/src/main/java/org/sonar/core/design/DependencyDto.java
deleted file mode 100644 (file)
index f7c3aa7..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.design;
-
-public final class DependencyDto {
-  private Long id;
-  private Long fromSnapshotId;
-  private Long toSnapshotId;
-  private String usage;
-
-  public Long getId() {
-    return id;
-  }
-
-  public DependencyDto setId(Long id) {
-    this.id = id;
-    return this;
-  }
-
-  public Long getFromSnapshotId() {
-    return fromSnapshotId;
-  }
-
-  public DependencyDto setFromSnapshotId(Long fromSnapshotId) {
-    this.fromSnapshotId = fromSnapshotId;
-    return this;
-  }
-
-  public Long getToSnapshotId() {
-    return toSnapshotId;
-  }
-
-  public DependencyDto setToSnapshotId(Long toSnapshotId) {
-    this.toSnapshotId = toSnapshotId;
-    return this;
-  }
-
-  public String getUsage() {
-    return usage;
-  }
-
-  public DependencyDto setUsage(String usage) {
-    this.usage = usage;
-    return this;
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/design/DependencyMapper.java b/sonar-core/src/main/java/org/sonar/core/design/DependencyMapper.java
deleted file mode 100644 (file)
index d596bbc..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.design;
-
-import org.apache.ibatis.session.ResultHandler;
-
-public interface DependencyMapper {
-  void selectAll(ResultHandler handler);
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/design/FileDependencyDto.java b/sonar-core/src/main/java/org/sonar/core/design/FileDependencyDto.java
new file mode 100644 (file)
index 0000000..1c5fa2e
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.core.design;
+
+public final class FileDependencyDto {
+
+  private Long id;
+  private String fromComponentUuid;
+  private String fromParentUuid;
+  private String toComponentUuid;
+  private String toParentUuid;
+  private Long rootProjectSnapshotId;
+  private Integer weight;
+  private Long createdAt;
+
+  public Long getId() {
+    return id;
+  }
+
+  public FileDependencyDto setId(Long id) {
+    this.id = id;
+    return this;
+  }
+
+  public String getFromComponentUuid() {
+    return fromComponentUuid;
+  }
+
+  public FileDependencyDto setFromComponentUuid(String fromComponentUuid) {
+    this.fromComponentUuid = fromComponentUuid;
+    return this;
+  }
+
+  public String getFromParentUuid() {
+    return fromParentUuid;
+  }
+
+  public FileDependencyDto setFromParentUuid(String fromParentUuid) {
+    this.fromParentUuid = fromParentUuid;
+    return this;
+  }
+
+  public Long getRootProjectSnapshotId() {
+    return rootProjectSnapshotId;
+  }
+
+  public FileDependencyDto setRootProjectSnapshotId(Long rootProjectSnapshotId) {
+    this.rootProjectSnapshotId = rootProjectSnapshotId;
+    return this;
+  }
+
+  public String getToComponentUuid() {
+    return toComponentUuid;
+  }
+
+  public FileDependencyDto setToComponentUuid(String toComponentUuid) {
+    this.toComponentUuid = toComponentUuid;
+    return this;
+  }
+
+  public String getToParentUuid() {
+    return toParentUuid;
+  }
+
+  public FileDependencyDto setToParentUuid(String toParentUuid) {
+    this.toParentUuid = toParentUuid;
+    return this;
+  }
+
+  public Integer getWeight() {
+    return weight;
+  }
+
+  public FileDependencyDto setWeight(Integer weight) {
+    this.weight = weight;
+    return this;
+  }
+
+  public Long getCreatedAt() {
+    return createdAt;
+  }
+
+  public FileDependencyDto setCreatedAt(Long createdAt) {
+    this.createdAt = createdAt;
+    return this;
+  }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/design/FileDependencyMapper.java b/sonar-core/src/main/java/org/sonar/core/design/FileDependencyMapper.java
new file mode 100644 (file)
index 0000000..1db9580
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.core.design;
+
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+public interface FileDependencyMapper {
+
+  List<FileDependencyDto> selectFromParents(@Param("fromParentUuid") String fromParentUuid, @Param("toParentUuid") String toParentUuid, @Param("projectId") Long projectId);
+
+  void insert(FileDependencyDto dto);
+
+}
index d95c62afbab32498086a5547ebfb55692f7cd3c7..fefd39960cee5ed5c866955004e58e0e6eb7f883 100644 (file)
@@ -59,8 +59,7 @@ import org.sonar.core.dashboard.WidgetDto;
 import org.sonar.core.dashboard.WidgetMapper;
 import org.sonar.core.dashboard.WidgetPropertyDto;
 import org.sonar.core.dashboard.WidgetPropertyMapper;
-import org.sonar.core.design.DependencyDto;
-import org.sonar.core.design.DependencyMapper;
+import org.sonar.core.design.FileDependencyMapper;
 import org.sonar.core.duplication.DuplicationMapper;
 import org.sonar.core.duplication.DuplicationUnitDto;
 import org.sonar.core.event.EventDto;
@@ -193,7 +192,6 @@ public class MyBatis implements BatchComponent, ServerComponent {
     loadAlias(conf, "Component", ComponentDto.class);
     loadAlias(conf, "ComponentLink", ComponentLinkDto.class);
     loadAlias(conf, "Dashboard", DashboardDto.class);
-    loadAlias(conf, "Dependency", DependencyDto.class);
     loadAlias(conf, "DuplicationUnit", DuplicationUnitDto.class);
     loadAlias(conf, "Graph", GraphDto.class);
     loadAlias(conf, "Group", GroupDto.class);
@@ -251,7 +249,7 @@ public class MyBatis implements BatchComponent, ServerComponent {
 
     loadMapper(conf, "org.sonar.core.permission.PermissionMapper");
     Class<?>[] mappers = {ActivityMapper.class, ActiveDashboardMapper.class, AuthorMapper.class, DashboardMapper.class,
-      DependencyMapper.class, DuplicationMapper.class, GraphDtoMapper.class,
+      FileDependencyMapper.class, DuplicationMapper.class, GraphDtoMapper.class,
       IssueMapper.class, IssueChangeMapper.class, IssueFilterMapper.class, IssueFilterFavouriteMapper.class,
       LoadedTemplateMapper.class, MeasureFilterMapper.class, Migration44Mapper.class, PermissionTemplateMapper.class, PropertiesMapper.class, PurgeMapper.class,
       ResourceKeyUpdaterMapper.class, ResourceIndexerMapper.class, RoleMapper.class, RuleMapper.class,
diff --git a/sonar-core/src/main/resources/org/sonar/core/design/DependencyMapper.xml b/sonar-core/src/main/resources/org/sonar/core/design/DependencyMapper.xml
deleted file mode 100644 (file)
index 313a9ba..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-<?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.design.DependencyMapper">
-
-  <select id="selectAll" resultType="dependency" >
-    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/design/FileDependencyMapper.xml b/sonar-core/src/main/resources/org/sonar/core/design/FileDependencyMapper.xml
new file mode 100644 (file)
index 0000000..e738132
--- /dev/null
@@ -0,0 +1,33 @@
+<?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.design.FileDependencyMapper">
+
+  <sql id="fileDependenciesColumns">
+    d.id as id,
+    d.from_component_uuid as fromComponentUuid,
+    d.to_component_uuid as toComponentUuid,
+    d.from_parent_uuid as fromParentUuid,
+    d.to_parent_uuid as toParentUuid,
+    d.root_project_snapshot_id as rootProjectSnapshotId,
+    d.dep_weight as "weight",
+    d.created_at as "createdAt"
+  </sql>
+
+  <select id="selectFromParents" resultType="org.sonar.core.design.FileDependencyDto" >
+    SELECT <include refid="fileDependenciesColumns"/>
+    FROM dependencies d
+    INNER JOIN snapshots root_snapshot on root_snapshot.id=d.root_project_snapshot_id AND root_snapshot.project_id=#{projectId} AND root_snapshot.islast=${_true}
+    <where>
+      AND d.from_parent_uuid=#{fromParentUuid}
+      AND d.to_parent_uuid=#{toParentUuid}
+    </where>
+  </select>
+
+  <insert id="insert" parameterType="org.sonar.core.design.FileDependencyDto" useGeneratedKeys="false">
+    INSERT INTO dependencies (from_component_uuid, to_component_uuid, from_parent_uuid, to_parent_uuid, root_project_snapshot_id, dep_weight, created_at)
+    VALUES (#{fromComponentUuid,jdbcType=VARCHAR}, #{toComponentUuid,jdbcType=VARCHAR}, #{fromParentUuid,jdbcType=VARCHAR}, #{toParentUuid,jdbcType=BOOLEAN},
+    #{rootProjectSnapshotId,jdbcType=VARCHAR}, #{weight,jdbcType=VARCHAR}, #{createdAt,jdbcType=VARCHAR})
+  </insert>
+
+</mapper>
diff --git a/sonar-core/src/test/java/org/sonar/core/design/DependencyMapperTest.java b/sonar-core/src/test/java/org/sonar/core/design/DependencyMapperTest.java
deleted file mode 100644 (file)
index 98244b3..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.design;
-
-import com.google.common.collect.Lists;
-import org.apache.ibatis.session.ResultContext;
-import org.apache.ibatis.session.ResultHandler;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.DbTester;
-
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DependencyMapperTest {
-
-  @ClassRule
-  public static DbTester dbtester = new DbTester();
-
-  DbSession session;
-
-  @Before
-  public void setUp() throws Exception {
-    dbtester.truncateTables();
-    session = dbtester.myBatis().openSession(false);
-  }
-
-  @After
-  public void tearDown() throws Exception {
-    session.close();
-  }
-
-  @Test
-  public void select_all_dependencies() {
-    dbtester.prepareDbUnit(getClass(), "fixture.xml");
-
-    final List<DependencyDto> dependencies = Lists.newArrayList();
-
-    session.getMapper(DependencyMapper.class).selectAll(new ResultHandler() {
-      public void handleResult(ResultContext context) {
-        dependencies.add((DependencyDto) context.getResultObject());
-      }
-    });
-
-    assertThat(dependencies).hasSize(2);
-
-    DependencyDto dep = dependencies.get(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/design/FileDependencyDtoTest.java b/sonar-core/src/test/java/org/sonar/core/design/FileDependencyDtoTest.java
new file mode 100644 (file)
index 0000000..2870056
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.core.design;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class FileDependencyDtoTest {
+
+  @Test
+  public void test_getters_and_setters() throws Exception {
+    FileDependencyDto dto = new FileDependencyDto()
+      .setId(1L)
+      .setFromComponentUuid("ABCD")
+      .setToComponentUuid("EFGH")
+      .setFromParentUuid("IJKL")
+      .setToParentUuid("MNOP")
+      .setRootProjectSnapshotId(10L)
+      .setWeight(2)
+      .setCreatedAt(1000L);
+
+    assertThat(dto.getId()).isEqualTo(1L);
+    assertThat(dto.getFromComponentUuid()).isEqualTo("ABCD");
+    assertThat(dto.getToComponentUuid()).isEqualTo("EFGH");
+    assertThat(dto.getFromParentUuid()).isEqualTo("IJKL");
+    assertThat(dto.getToParentUuid()).isEqualTo("MNOP");
+    assertThat(dto.getRootProjectSnapshotId()).isEqualTo(10L);
+    assertThat(dto.getWeight()).isEqualTo(2);
+    assertThat(dto.getCreatedAt()).isEqualTo(1000L);
+  }
+
+}
diff --git a/sonar-core/src/test/resources/org/sonar/core/design/DependencyMapperTest/fixture.xml b/sonar-core/src/test/resources/org/sonar/core/design/DependencyMapperTest/fixture.xml
deleted file mode 100644 (file)
index f190e3a..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-<dataset>
-  <dependencies id="1" from_component_uuid="ABCD" to_component_uuid="EFGH" from_snapshot_id="1000" to_snapshot_id="1001" dep_usage="compile" dep_weight="1" />
-  <dependencies id="2" from_component_uuid="DCBA" to_component_uuid="HGFE" from_snapshot_id="2000" to_snapshot_id="2001" dep_usage="provided" dep_weight="1" />
-</dataset>