aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2016-07-26 17:21:33 +0200
committerStas Vilchik <vilchiks@gmail.com>2016-07-28 17:31:14 +0200
commit1d702b6b507bd7c346381cf371d16fd8c556b99e (patch)
tree85d9a4a21dee50a8410477ea5eeb52157808737f /sonar-db
parentfa27bf616fad3cb743994ea8407feabd96a22ae9 (diff)
downloadsonarqube-1d702b6b507bd7c346381cf371d16fd8c556b99e.tar.gz
sonarqube-1d702b6b507bd7c346381cf371d16fd8c556b99e.zip
SONAR-7926 Create WS to add project link
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ComponentLinkDao.java9
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ComponentLinkMapper.java2
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/component/ComponentLinkMapper.xml8
-rw-r--r--sonar-db/src/test/java/org/sonar/db/component/ComponentLinkDaoTest.java9
4 files changed, 27 insertions, 1 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentLinkDao.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentLinkDao.java
index ec7d9e33bf5..28fc47ee364 100644
--- a/sonar-db/src/main/java/org/sonar/db/component/ComponentLinkDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentLinkDao.java
@@ -20,6 +20,7 @@
package org.sonar.db.component;
import java.util.List;
+import javax.annotation.CheckForNull;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
@@ -35,8 +36,14 @@ public class ComponentLinkDao implements Dao {
return componentUuids.isEmpty() ? emptyList() : mapper(dbSession).selectByComponentUuids(componentUuids);
}
- public void insert(DbSession session, ComponentLinkDto dto) {
+ @CheckForNull
+ public ComponentLinkDto selectById(DbSession session, long id) {
+ return session.getMapper(ComponentLinkMapper.class).selectById(id);
+ }
+
+ public ComponentLinkDto insert(DbSession session, ComponentLinkDto dto) {
session.getMapper(ComponentLinkMapper.class).insert(dto);
+ return dto;
}
public void update(DbSession session, ComponentLinkDto dto) {
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentLinkMapper.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentLinkMapper.java
index d8df30879d8..a7ff04b9508 100644
--- a/sonar-db/src/main/java/org/sonar/db/component/ComponentLinkMapper.java
+++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentLinkMapper.java
@@ -28,6 +28,8 @@ public interface ComponentLinkMapper {
List<ComponentLinkDto> selectByComponentUuids(@Param("componentUuids") List<String> componentUuids);
+ ComponentLinkDto selectById(@Param("id") String id);
+
void insert(ComponentLinkDto dto);
void update(ComponentLinkDto dto);
diff --git a/sonar-db/src/main/resources/org/sonar/db/component/ComponentLinkMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/ComponentLinkMapper.xml
index bd1b90792dd..d74de88a667 100644
--- a/sonar-db/src/main/resources/org/sonar/db/component/ComponentLinkMapper.xml
+++ b/sonar-db/src/main/resources/org/sonar/db/component/ComponentLinkMapper.xml
@@ -33,6 +33,14 @@
order by p.id
</select>
+ <select id="selectById" parameterType="String" resultType="ComponentLink">
+ SELECT
+ <include refid="componentLinkColumns"/>
+ FROM project_links p
+ <where>
+ p.id=#{id}
+ </where>
+ </select>
<insert id="insert" parameterType="ComponentLink" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
INSERT INTO project_links (component_uuid, link_type, name, href)
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentLinkDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentLinkDaoTest.java
index 685079b6cfb..c24788ceabe 100644
--- a/sonar-db/src/test/java/org/sonar/db/component/ComponentLinkDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentLinkDaoTest.java
@@ -85,6 +85,15 @@ public class ComponentLinkDaoTest {
}
@Test
+ public void select_by_id() {
+ ComponentLinkDto link = underTest.insert(dbSession, newComponentLinkDto());
+ db.commit();
+
+ ComponentLinkDto candidate = underTest.selectById(dbSession, link.getId());
+ assertThat(candidate.getId()).isNotNull();
+ }
+
+ @Test
public void insert() {
db.prepareDbUnit(getClass(), "empty.xml");