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;
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;
}
this.usage = usage;
return this;
}
-
- public Integer getWeight() {
- return weight;
- }
-
- public DependencyDto setWeight(Integer weight) {
- this.weight = weight;
- return this;
- }
}
import org.apache.ibatis.session.ResultHandler;
-import java.util.List;
-
public interface DependencyMapper {
- List<DependencyDto> selectAll();
-
void selectAll(ResultHandler handler);
}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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);
+}
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;
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);
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);
<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>
--- /dev/null
+<?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>
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();
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");
}
}
--- /dev/null
+/*
+ * 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");
+ }
+}
<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
--- /dev/null
+<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