aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-05-12 21:29:40 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-05-12 21:29:40 +0200
commit5765e0955d1516e035e7a970be9b992d9a90b270 (patch)
tree984a2cb5dada83778de77d36a57b798647bfd3e8 /sonar-core
parent2b27e74cff921c1fa9a96fa4b5e5e5c11aad2352 (diff)
downloadsonarqube-5765e0955d1516e035e7a970be9b992d9a90b270.tar.gz
sonarqube-5765e0955d1516e035e7a970be9b992d9a90b270.zip
SONAR-3755 refactor comments
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueComment.java13
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/db/ChangeDtoConverter.java5
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java47
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java9
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java26
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java11
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/db/IssueStorage.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java3
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml18
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml82
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/db/ChangeDtoConverterTest.java4
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java74
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeMapperTest.java8
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java18
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/db/IssueStorageTest.java4
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/delete-result.xml39
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/delete.xml35
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/update-result.xml35
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/update.xml35
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/insert_comment-result.xml (renamed from sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/testInsertComment-result.xml)0
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/insert_diff-result.xml (renamed from sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/testInsertDiff-result.xml)0
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/selectByChangeKey.xml76
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_issue_and_component_ids.xml (renamed from sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_issue_ids_and_components_ids.xml)0
24 files changed, 450 insertions, 96 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueComment.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueComment.java
index c248c2097a8..1a5e1f29b99 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueComment.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueComment.java
@@ -29,6 +29,7 @@ import java.util.UUID;
public class DefaultIssueComment implements Serializable, IssueComment {
+ private String issueKey;
private String userLogin;
private Date createdAt, updatedAt;
private String key;
@@ -45,6 +46,15 @@ public class DefaultIssueComment implements Serializable, IssueComment {
return this;
}
+ public String issueKey() {
+ return issueKey;
+ }
+
+ public DefaultIssueComment setIssueKey(String s) {
+ this.issueKey = s;
+ return this;
+ }
+
@Override
public String key() {
return key;
@@ -98,8 +108,9 @@ public class DefaultIssueComment implements Serializable, IssueComment {
return this;
}
- public static DefaultIssueComment create(@Nullable String login, String text) {
+ public static DefaultIssueComment create(String issueKey, @Nullable String login, String text) {
DefaultIssueComment comment = new DefaultIssueComment();
+ comment.setIssueKey(issueKey);
comment.setKey(UUID.randomUUID().toString());
Date now = new Date();
comment.setUserLogin(login);
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java b/sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java
index f42780fe36e..90da11f6076 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java
@@ -100,7 +100,7 @@ public class IssueUpdater implements BatchComponent, ServerComponent {
}
public void addComment(DefaultIssue issue, String text, IssueChangeContext context) {
- issue.addComment(DefaultIssueComment.create(context.login(), text));
+ issue.addComment(DefaultIssueComment.create(issue.key(), context.login(), text));
}
public void setCloseDate(DefaultIssue issue, @Nullable Date d) {
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/ChangeDtoConverter.java b/sonar-core/src/main/java/org/sonar/core/issue/db/ChangeDtoConverter.java
index d2cfeefdc8b..19b9e9cffa9 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/db/ChangeDtoConverter.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/db/ChangeDtoConverter.java
@@ -33,8 +33,8 @@ class ChangeDtoConverter {
static final String TYPE_FIELD_CHANGE = "diff";
static final String TYPE_COMMENT = "comment";
- static IssueChangeDto commentToDto(String issueKey, DefaultIssueComment comment) {
- IssueChangeDto dto = newDto(issueKey);
+ static IssueChangeDto commentToDto(DefaultIssueComment comment) {
+ IssueChangeDto dto = newDto(comment.issueKey());
dto.setKey(comment.key());
dto.setChangeType(TYPE_COMMENT);
dto.setChangeData(comment.text());
@@ -68,6 +68,7 @@ class ChangeDtoConverter {
.setCreatedAt(dto.getCreatedAt())
.setUpdatedAt(dto.getUpdatedAt())
.setUserLogin(dto.getUserLogin())
+ .setIssueKey(dto.getIssueKey())
.setNew(false);
}
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java
index b355ac4ebc0..7de80f403c7 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java
@@ -20,11 +20,12 @@
package org.sonar.core.issue.db;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
import org.apache.ibatis.session.SqlSession;
import org.sonar.api.BatchComponent;
import org.sonar.api.ServerComponent;
import org.sonar.core.issue.DefaultIssueComment;
-import org.sonar.core.issue.FieldDiffs;
import org.sonar.core.persistence.MyBatis;
import java.util.Collection;
@@ -41,32 +42,44 @@ public class IssueChangeDao implements BatchComponent, ServerComponent {
this.mybatis = mybatis;
}
- public DefaultIssueComment[] selectIssueComments(String issueKey) {
- List<IssueChangeDto> dtos = selectByIssue(issueKey, ChangeDtoConverter.TYPE_COMMENT);
- DefaultIssueComment[] result = new DefaultIssueComment[dtos.size()];
- for (int index = 0; index < dtos.size(); index++) {
- result[index] = ChangeDtoConverter.dtoToComment(dtos.get(index));
+ public List<DefaultIssueComment> selectCommentsByIssues(SqlSession session, Collection<String> issueKeys) {
+ return selectByIssuesAndType(session, issueKeys, ChangeDtoConverter.TYPE_COMMENT);
+ }
+
+ List<DefaultIssueComment> selectByIssuesAndType(SqlSession session, Collection<String> issueKeys, String changeType) {
+ Preconditions.checkArgument(issueKeys.size() < 1000, "Number of issue keys is greater than or equal 1000");
+ List<DefaultIssueComment> result = Lists.newArrayList();
+ if (!issueKeys.isEmpty()) {
+ IssueChangeMapper mapper = session.getMapper(IssueChangeMapper.class);
+ List<IssueChangeDto> dtos = mapper.selectByIssuesAndType(issueKeys, changeType);
+ for (IssueChangeDto dto : dtos) {
+ result.add(ChangeDtoConverter.dtoToComment(dto));
+ }
}
return result;
}
- public FieldDiffs[] selectIssueChanges(String issueKey) {
- List<IssueChangeDto> dtos = selectByIssue(issueKey, ChangeDtoConverter.TYPE_FIELD_CHANGE);
- FieldDiffs[] result = new FieldDiffs[dtos.size()];
- for (int index = 0; index < dtos.size(); index++) {
- result[index] = ChangeDtoConverter.dtoToChange(dtos.get(index));
+ public boolean delete(String key) {
+ SqlSession session = mybatis.openSession();
+ try {
+ IssueChangeMapper mapper = session.getMapper(IssueChangeMapper.class);
+ int count = mapper.delete(key);
+ session.commit();
+ return count==1;
+
+ } finally {
+ MyBatis.closeQuietly(session);
}
- return result;
}
- /**
- * Issue changes by chronological date of creation
- */
- private List<IssueChangeDto> selectByIssue(String issueKey, String changeType) {
+ public boolean update(IssueChangeDto change) {
SqlSession session = mybatis.openSession();
try {
IssueChangeMapper mapper = session.getMapper(IssueChangeMapper.class);
- return mapper.selectByIssueAndType(issueKey, changeType);
+ int count = mapper.update(change);
+ session.commit();
+ return count==1;
+
} finally {
MyBatis.closeQuietly(session);
}
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java
index 9c049b38b65..2f797a13801 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java
@@ -22,6 +22,7 @@ package org.sonar.core.issue.db;
import org.apache.ibatis.annotations.Param;
+import java.util.Collection;
import java.util.List;
/**
@@ -31,9 +32,13 @@ public interface IssueChangeMapper {
void insert(IssueChangeDto dto);
+ int delete(String key);
+
+ int update(IssueChangeDto change);
+
/**
* Issue changes by chronological date of creation
*/
- List<IssueChangeDto> selectByIssueAndType(@Param("issueKey") String issueKey, @Param("changeType") String changeType);
-
+ List<IssueChangeDto> selectByIssuesAndType(@Param("issueKeys") Collection<String> issueKeys,
+ @Param("changeType") String changeType);
}
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java
index 9e6bcf82f4c..b280000920e 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java
@@ -50,7 +50,18 @@ public class IssueDao implements BatchComponent, ServerComponent {
public IssueDto selectByKey(String key) {
SqlSession session = mybatis.openSession();
try {
- return session.selectOne("org.sonar.core.issue.db.IssueMapper.selectByKey", key);
+ IssueMapper mapper = session.getMapper(IssueMapper.class);
+ return mapper.selectByKey(key);
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public IssueDto selectByChangeKey(String commentKey) {
+ SqlSession session = mybatis.openSession();
+ try {
+ IssueMapper mapper = session.getMapper(IssueMapper.class);
+ return mapper.selectByChangeKey(commentKey);
} finally {
MyBatis.closeQuietly(session);
}
@@ -69,17 +80,18 @@ public class IssueDao implements BatchComponent, ServerComponent {
public List<IssueDto> select(IssueQuery query) {
SqlSession session = mybatis.openSession();
try {
- return session.selectList("org.sonar.core.issue.db.IssueMapper.select", query);
+ IssueMapper mapper = session.getMapper(IssueMapper.class);
+ return mapper.select(query);
} finally {
MyBatis.closeQuietly(session);
}
}
@VisibleForTesting
- List<IssueDto> selectIssueIdsAndComponentsId(IssueQuery query) {
+ List<IssueDto> selectIssueAndComponentIds(IssueQuery query) {
SqlSession session = mybatis.openSession();
try {
- return selectIssueIdsAndComponentsId(query, session);
+ return selectIssueAndComponentIds(query, session);
} finally {
MyBatis.closeQuietly(session);
}
@@ -88,9 +100,9 @@ public class IssueDao implements BatchComponent, ServerComponent {
/**
* The returned IssueDto list contains only the issue id and the resource id
*/
- public List<IssueDto> selectIssueIdsAndComponentsId(IssueQuery query, SqlSession session) {
- // TODO support ordering
- return session.selectList("org.sonar.core.issue.db.IssueMapper.selectIssueIdsAndComponentsId", query);
+ public List<IssueDto> selectIssueAndComponentIds(IssueQuery query, SqlSession session) {
+ IssueMapper mapper = session.getMapper(IssueMapper.class);
+ return mapper.selectIssueAndComponentIds(query);
}
Collection<IssueDto> selectByIds(Collection<Long> ids) {
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java
index 4e65007e824..1073d3a2766 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java
@@ -19,9 +19,18 @@
*/
package org.sonar.core.issue.db;
+import org.sonar.api.issue.IssueQuery;
+
+import java.util.List;
+
public interface IssueMapper {
+ IssueDto selectByKey(String key);
+ IssueDto selectByChangeKey(String changeKey);
+ List<IssueDto> selectIssueAndComponentIds(IssueQuery query);
+
+ List<IssueDto> select(IssueQuery query);
void insert(IssueDto issue);
- int update(IssueDto issue);
+ int update(IssueDto issue);
}
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueStorage.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueStorage.java
index 7bf78f6af1d..af308fb0029 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueStorage.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueStorage.java
@@ -81,7 +81,7 @@ public abstract class IssueStorage {
for (IssueComment comment : issue.comments()) {
DefaultIssueComment c = (DefaultIssueComment) comment;
if (c.isNew()) {
- IssueChangeDto changeDto = ChangeDtoConverter.commentToDto(issue.key(), c);
+ IssueChangeDto changeDto = ChangeDtoConverter.commentToDto(c);
mapper.insert(changeDto);
}
}
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 be615a6eadc..e5dfb458eb2 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
@@ -126,14 +126,13 @@ public class MyBatis implements BatchComponent, ServerComponent {
loadAlias(conf, "ActionPlanStats", ActionPlanStatsDto.class);
Class<?>[] mappers = {ActiveDashboardMapper.class, AuthorMapper.class, DashboardMapper.class,
- DependencyMapper.class, DuplicationMapper.class, GraphDtoMapper.class, IssueChangeMapper.class, LoadedTemplateMapper.class,
+ DependencyMapper.class, DuplicationMapper.class, GraphDtoMapper.class, IssueMapper.class, IssueChangeMapper.class, LoadedTemplateMapper.class,
MeasureFilterMapper.class, PropertiesMapper.class, PurgeMapper.class, ResourceKeyUpdaterMapper.class, ResourceIndexerMapper.class, ResourceMapper.class,
ResourceSnapshotMapper.class, ReviewCommentMapper.class, ReviewMapper.class, RoleMapper.class, RuleMapper.class, SchemaMigrationMapper.class,
SemaphoreMapper.class, UserMapper.class, WidgetMapper.class, WidgetPropertyMapper.class, MeasureMapper.class, SnapshotDataMapper.class,
SnapshotSourceMapper.class, ActionPlanMapper.class, ActionPlanStatsMapper.class
};
loadMappers(conf, mappers);
- loadMapper(conf, "org.sonar.core.issue.db.IssueMapper");
loadMapper(conf, "org.sonar.core.user.AuthorizationMapper");
configureLogback(mappers);
diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml
index c54639a2c2d..5c2a92b2cab 100644
--- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml
@@ -41,7 +41,8 @@
</insert>
<!-- Oracle -->
- <insert id="insert" databaseId="oracle" parameterType="IssueChange" keyColumn="id" useGeneratedKeys="false" keyProperty="id">
+ <insert id="insert" databaseId="oracle" parameterType="IssueChange" keyColumn="id" useGeneratedKeys="false"
+ keyProperty="id">
<selectKey order="BEFORE" resultType="Long" keyProperty="id">
select issue_changes_seq.NEXTVAL from DUAL
</selectKey>
@@ -49,13 +50,22 @@
VALUES (#{id}, #{kee}, #{issueKey}, #{userLogin}, #{changeType}, #{changeData}, #{createdAt}, #{updatedAt})
</insert>
- <select id="selectByIssueAndType" parameterType="map" resultType="IssueChange">
+ <delete id="delete" parameterType="string">
+ delete from issue_changes where kee=#{id}
+ </delete>
+
+ <update id="update" parameterType="map">
+ update issue_changes set change_data=#{changeData}, updated_at=#{updatedAt} where kee=#{kee}
+ </update>
+
+ <select id="selectByIssuesAndType" parameterType="map" resultType="IssueChange">
select
<include refid="issueChangeColumns"/>
from issue_changes c
- where c.issue_key=#{issueKey} and c.change_type=#{changeType}
+ where c.change_type=#{changeType} and c.issue_key in (
+ <foreach collection="issueKeys" item="key" separator=",">#{key}</foreach>
+ )
order by c.created_at
</select>
-
</mapper>
diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml
index 5c3a81d1fc0..92e325ad2d2 100644
--- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml
@@ -34,50 +34,55 @@
</sql>
<insert id="insert" parameterType="Issue" useGeneratedKeys="false" keyProperty="id">
- INSERT INTO issues (kee, resource_id, rule_id, action_plan_key, severity, manual_severity, manual_issue, description, line, effort_to_fix, status,
+ INSERT INTO issues (kee, resource_id, rule_id, action_plan_key, severity, manual_severity, manual_issue,
+ description, line, effort_to_fix, status,
resolution, checksum, user_login, assignee_login, author_login, attributes, issue_creation_date, issue_update_date,
issue_close_date, created_at, updated_at)
- VALUES (#{kee}, #{resourceId}, #{ruleId}, #{actionPlanKey}, #{severity}, #{manualSeverity}, #{manualIssue}, #{description}, #{line}, #{effortToFix}, #{status},
+ VALUES (#{kee}, #{resourceId}, #{ruleId}, #{actionPlanKey}, #{severity}, #{manualSeverity}, #{manualIssue},
+ #{description}, #{line}, #{effortToFix}, #{status},
#{resolution}, #{checksum}, #{userLogin}, #{assignee}, #{authorLogin}, #{attributes}, #{issueCreationDate},
#{issueUpdateDate}, #{issueCloseDate}, #{createdAt}, #{updatedAt})
</insert>
<!-- Oracle -->
- <insert id="insert" databaseId="oracle" parameterType="Issue" keyColumn="id" useGeneratedKeys="false" keyProperty="id">
+ <insert id="insert" databaseId="oracle" parameterType="Issue" keyColumn="id" useGeneratedKeys="false"
+ keyProperty="id">
<selectKey order="BEFORE" resultType="Long" keyProperty="id">
select issues_seq.NEXTVAL from DUAL
</selectKey>
- INSERT INTO issues (id, kee, resource_id, rule_id, action_plan_key, severity, manual_severity, manual_issue, description, line, effort_to_fix, status,
+ INSERT INTO issues (id, kee, resource_id, rule_id, action_plan_key, severity, manual_severity, manual_issue,
+ description, line, effort_to_fix, status,
resolution, checksum, user_login, assignee_login, author_login, attributes, issue_creation_date, issue_update_date,
issue_close_date, created_at, updated_at)
- VALUES (#{id}, #{kee}, #{resourceId}, #{ruleId}, #{actionPlanKey}, #{severity}, #{manualSeverity}, #{manualIssue}, #{description}, #{line}, #{effortToFix}, #{status},
+ VALUES (#{id}, #{kee}, #{resourceId}, #{ruleId}, #{actionPlanKey}, #{severity}, #{manualSeverity}, #{manualIssue},
+ #{description}, #{line}, #{effortToFix}, #{status},
#{resolution}, #{checksum}, #{userLogin}, #{assignee}, #{authorLogin}, #{attributes}, #{issueCreationDate},
#{issueUpdateDate}, #{issueCloseDate}, #{createdAt}, #{updatedAt})
</insert>
<update id="update" parameterType="Issue">
update issues set
- resource_id=#{resourceId},
- rule_id=#{ruleId},
- action_plan_key=#{actionPlanKey},
- severity=#{severity},
- manual_severity=#{manualSeverity},
- manual_issue=#{manualIssue},
- description=#{description},
- line=#{line},
- effort_to_fix=#{effortToFix},
- status=#{status},
- resolution=#{resolution},
- checksum=#{checksum},
- user_login=#{userLogin},
- assignee_login=#{assignee},
- author_login=#{authorLogin},
- attributes=#{attributes},
- issue_creation_date=#{issueCreationDate},
- issue_update_date=#{issueUpdateDate},
- issue_close_date=#{issueCloseDate},
- created_at=#{createdAt},
- updated_at=#{updatedAt}
+ resource_id=#{resourceId},
+ rule_id=#{ruleId},
+ action_plan_key=#{actionPlanKey},
+ severity=#{severity},
+ manual_severity=#{manualSeverity},
+ manual_issue=#{manualIssue},
+ description=#{description},
+ line=#{line},
+ effort_to_fix=#{effortToFix},
+ status=#{status},
+ resolution=#{resolution},
+ checksum=#{checksum},
+ user_login=#{userLogin},
+ assignee_login=#{assignee},
+ author_login=#{authorLogin},
+ attributes=#{attributes},
+ issue_creation_date=#{issueCreationDate},
+ issue_update_date=#{issueUpdateDate},
+ issue_close_date=#{issueCloseDate},
+ created_at=#{createdAt},
+ updated_at=#{updatedAt}
where kee = #{kee}
</update>
@@ -88,14 +93,23 @@
where i.kee=#{kee} and i.rule_id=r.id and p.id=i.resource_id
</select>
+ <select id="selectByChangeKey" parameterType="String" resultType="Issue">
+ select
+ <include refid="issueColumns"/>
+ from issues i, rules r, projects p, issue_changes ic
+ where
+ i.kee=ic.issue_key and ic.kee=#{id}
+ and i.rule_id=r.id and p.id=i.resource_id
+ </select>
+
<select id="selectOpenIssues" parameterType="String" resultType="Issue">
select distinct
<include refid="issueColumns"/>
from issues i, rules r, projects p
where i.status &lt;&gt; 'CLOSED'
- and (p.root_id=#{componentId} or (p.root_id is null and p.id=#{componentId}))
- and i.resource_id=p.id
- and r.id=i.rule_id
+ and (p.root_id=#{componentId} or (p.root_id is null and p.id=#{componentId}))
+ and i.resource_id=p.id
+ and r.id=i.rule_id
</select>
<select id="selectByIds" parameterType="map" resultType="Issue">
@@ -104,7 +118,7 @@
from issues i, rules r, projects p
<where>
and
- <foreach collection="ids" open="i.id in (" close=")" item="list" separator=") or i.id in (" >
+ <foreach collection="ids" open="i.id in (" close=")" item="list" separator=") or i.id in (">
<foreach collection="list" item="element" separator=",">
#{element}
</foreach>
@@ -114,7 +128,7 @@
</where>
</select>
- <select id="selectIssueIdsAndComponentsId" parameterType="map" resultType="Issue">
+ <select id="selectIssueAndComponentIds" parameterType="map" resultType="Issue">
select i.id, i.resource_id as resourceId
<include refid="selectQueryConditions"/>
</select>
@@ -213,11 +227,13 @@
</if>
</if>
<if test="rules != null and rules.size() > 0">
- and (<foreach item="rule" index="index" collection="rules" open="(" separator=" or " close=")">r.plugin_name=#{rule.repository} and r.plugin_rule_key=#{rule.rule}</foreach>)
+ and (<foreach item="rule" index="index" collection="rules" open="(" separator=" or " close=")">
+ r.plugin_name=#{rule.repository} and r.plugin_rule_key=#{rule.rule}</foreach>)
</if>
<if test="actionPlans != null">
and i.action_plan_key in
- <foreach item="action_plan" index="index" collection="actionPlans" open="(" separator="," close=")">#{action_plan}
+ <foreach item="action_plan" index="index" collection="actionPlans" open="(" separator="," close=")">
+ #{action_plan}
</foreach>
</if>
<if test="createdAfter != null">
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/ChangeDtoConverterTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/ChangeDtoConverterTest.java
index e7f5ff2b26c..8b0e67347d9 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/db/ChangeDtoConverterTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/db/ChangeDtoConverterTest.java
@@ -28,9 +28,9 @@ import static org.fest.assertions.Assertions.assertThat;
public class ChangeDtoConverterTest {
@Test
public void testToChangeDtos() throws Exception {
- DefaultIssueComment comment = DefaultIssueComment.create("emmerik", "the comment");
+ DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
- IssueChangeDto dto = ChangeDtoConverter.commentToDto("ABCDE", comment);
+ IssueChangeDto dto = ChangeDtoConverter.commentToDto(comment);
assertThat(dto.getChangeData()).isEqualTo("the comment");
assertThat(dto.getChangeType()).isEqualTo("comment");
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java
index 426ea6b2e14..3d3c641ba8f 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java
@@ -19,17 +19,19 @@
*/
package org.sonar.core.issue.db;
+import org.apache.ibatis.session.SqlSession;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.utils.DateUtils;
import org.sonar.core.issue.DefaultIssueComment;
-import org.sonar.core.issue.FieldDiffs;
import org.sonar.core.persistence.AbstractDaoTestCase;
import java.util.Arrays;
-import java.util.Date;
+import java.util.Collections;
+import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
public class IssueChangeDaoTest extends AbstractDaoTestCase {
@@ -41,31 +43,77 @@ public class IssueChangeDaoTest extends AbstractDaoTestCase {
}
@Test
- public void should_select_issue_comments() {
+ public void selectCommentsByIssues() {
setupData("shared");
- DefaultIssueComment[] comments = dao.selectIssueComments("1000");
+ SqlSession session = getMyBatis().openSession();
+ List<DefaultIssueComment> comments = dao.selectCommentsByIssues(session, Arrays.asList("1000"));
+ session.close();
assertThat(comments).hasSize(2);
// chronological order
- DefaultIssueComment first = comments[0];
+ DefaultIssueComment first = comments.get(0);
assertThat(first.text()).isEqualTo("old comment");
- DefaultIssueComment second = comments[1];
+ DefaultIssueComment second = comments.get(1);
assertThat(second.userLogin()).isEqualTo("arthur");
assertThat(second.key()).isEqualTo("FGHIJ");
assertThat(second.text()).isEqualTo("recent comment");
}
@Test
- public void should_select_issue_changes() {
- setupData("shared");
+ public void selectCommentsByIssues_empty_input() {
+ // no need to connect to db
+ SqlSession session = mock(SqlSession.class);
+ List<DefaultIssueComment> comments = dao.selectCommentsByIssues(session, Collections.<String>emptyList());
+
+ assertThat(comments).isEmpty();
+ }
+
+ @Test
+ public void delete() {
+ setupData("delete");
+
+ assertThat(dao.delete("COMMENT-2")).isTrue();
+
+ checkTable("delete", "issue_changes");
+ }
+
+ @Test
+ public void delete_unknown_key() {
+ setupData("delete");
+
+ assertThat(dao.delete("UNKNOWN")).isFalse();
+ }
+
+ @Test
+ public void update() {
+ setupData("update");
+
+ IssueChangeDto change = new IssueChangeDto();
+ change.setKey("COMMENT-2");
+
+ // Only the following fields can be updated:
+ change.setChangeData("new comment");
+ change.setUpdatedAt(DateUtils.parseDate("2013-06-30"));
+
+ assertThat(dao.update(change)).isTrue();
+
+ checkTable("update", "issue_changes");
+ }
+
+ @Test
+ public void update_unknown_key() {
+ setupData("update");
+
+ IssueChangeDto change = new IssueChangeDto();
+ change.setKey("UNKNOWN");
+
+ // Only the following fields can be updated:
+ change.setChangeData("new comment");
+ change.setUpdatedAt(DateUtils.parseDate("2013-06-30"));
- FieldDiffs[] ordered = dao.selectIssueChanges("1000");
- assertThat(ordered).hasSize(1);
- FieldDiffs.Diff severityDiff = ordered[0].get("severity");
- assertThat(severityDiff.oldValue()).isEqualTo("MAJOR");
- assertThat(severityDiff.newValue()).isEqualTo("BLOCKER");
+ assertThat(dao.update(change)).isFalse();
}
}
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeMapperTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeMapperTest.java
index 9c320bf12cd..316c041879a 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeMapperTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeMapperTest.java
@@ -38,7 +38,7 @@ public class IssueChangeMapperTest extends AbstractDaoTestCase {
}
@Test
- public void testInsertDiff() throws Exception {
+ public void insert_diff() throws Exception {
IssueChangeDto dto = new IssueChangeDto();
dto.setKey(null /* no key on field changes */);
dto.setUserLogin("emmerik");
@@ -51,11 +51,11 @@ public class IssueChangeMapperTest extends AbstractDaoTestCase {
mapper.insert(dto);
session.commit();
- checkTables("testInsertDiff", new String[]{"id"}, "issue_changes");
+ checkTables("insert_diff", new String[]{"id"}, "issue_changes");
}
@Test
- public void testInsertComment() throws Exception {
+ public void insert_comment() throws Exception {
IssueChangeDto dto = new IssueChangeDto();
dto.setKey("COMMENT-1234");
dto.setUserLogin("emmerik");
@@ -68,6 +68,6 @@ public class IssueChangeMapperTest extends AbstractDaoTestCase {
mapper.insert(dto);
session.commit();
- checkTables("testInsertComment", new String[]{"id"}, "issue_changes");
+ checkTables("insert_comment", new String[]{"id"}, "issue_changes");
}
}
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java
index 0d35a9b5327..4238afe1fc9 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java
@@ -204,7 +204,7 @@ public class IssueDaoTest extends AbstractDaoTestCase {
setupData("shared", "should_select_returned_sorted_result");
IssueQuery query = IssueQuery.builder().sort(IssueQuery.Sort.ASSIGNEE).asc(true).build();
- List < IssueDto > results = newArrayList(dao.select(query));
+ List<IssueDto> results = newArrayList(dao.select(query));
assertThat(results).hasSize(3);
assertThat(results.get(0).getAssignee()).isEqualTo("arthur");
assertThat(results.get(1).getAssignee()).isEqualTo("henry");
@@ -212,11 +212,11 @@ public class IssueDaoTest extends AbstractDaoTestCase {
}
@Test
- public void should_select_issue_ids_and_components_ids() {
- setupData("shared", "should_select_issue_ids_and_components_ids");
+ public void should_select_issue_and_component_ids() {
+ setupData("shared", "should_select_issue_and_component_ids");
IssueQuery query = IssueQuery.builder().build();
- List<IssueDto> results = dao.selectIssueIdsAndComponentsId(query);
+ List<IssueDto> results = dao.selectIssueAndComponentIds(query);
assertThat(results).hasSize(3);
}
@@ -241,4 +241,14 @@ public class IssueDaoTest extends AbstractDaoTestCase {
assertThat(results).hasSize(3);
}
+ @Test
+ public void selectByChangeKey() throws Exception {
+ setupData("shared", "selectByChangeKey");
+ IssueDto issue = dao.selectByChangeKey("COMMENT-20");
+ assertThat(issue.getKee()).isEqualTo("ISSUE-2");
+
+ issue = dao.selectByChangeKey("COMMENT-UNKNOWN");
+ assertThat(issue).isNull();
+ }
+
}
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueStorageTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueStorageTest.java
index 1aa38f19657..1668bcfcde6 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueStorageTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueStorageTest.java
@@ -42,7 +42,7 @@ public class IssueStorageTest extends AbstractDaoTestCase {
public void should_insert_new_issues() throws Exception {
FakeSaver saver = new FakeSaver(getMyBatis(), new FakeRuleFinder());
- DefaultIssueComment comment = DefaultIssueComment.create("emmerik", "the comment");
+ DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
// override generated key
comment.setKey("FGHIJ");
@@ -71,7 +71,7 @@ public class IssueStorageTest extends AbstractDaoTestCase {
FakeSaver saver = new FakeSaver(getMyBatis(), new FakeRuleFinder());
- DefaultIssueComment comment = DefaultIssueComment.create("emmerik", "the comment");
+ DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
// override generated key
comment.setKey("FGHIJ");
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/delete-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/delete-result.xml
new file mode 100644
index 00000000000..38915608de0
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/delete-result.xml
@@ -0,0 +1,39 @@
+<dataset>
+
+ <issue_changes
+ id="100"
+ kee="COMMENT-1"
+ issue_key="ISSUE-1"
+ user_login="arthur"
+ change_type="comment"
+ change_data="old comment"
+ created_at="2013-01-01"
+ updated_at="2013-01-01"
+ />
+
+ <issue_changes
+ id="101"
+ kee="[null]"
+ issue_key="1000"
+ user_login="arthur"
+ change_type="diff"
+ change_data="severity=MAJOR|BLOCKER"
+ created_at="2013-02-02"
+ updated_at="2013-02-02"
+ />
+
+ <!--
+ DELETED
+
+ <issue_changes
+ id="102"
+ kee="COMMENT-2"
+ issue_key="ISSUE-1"
+ user_login="arthur"
+ change_type="comment"
+ change_data="recent comment"
+ created_at="2013-05-05"
+ updated_at="2013-05-05"
+ />
+ -->
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/delete.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/delete.xml
new file mode 100644
index 00000000000..91b53b495ee
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/delete.xml
@@ -0,0 +1,35 @@
+<dataset>
+
+ <issue_changes
+ id="100"
+ kee="COMMENT-1"
+ issue_key="ISSUE-1"
+ user_login="arthur"
+ change_type="comment"
+ change_data="old comment"
+ created_at="2013-01-01"
+ updated_at="2013-01-01"
+ />
+
+ <issue_changes
+ id="101"
+ kee="[null]"
+ issue_key="1000"
+ user_login="arthur"
+ change_type="diff"
+ change_data="severity=MAJOR|BLOCKER"
+ created_at="2013-02-02"
+ updated_at="2013-02-02"
+ />
+
+ <issue_changes
+ id="102"
+ kee="COMMENT-2"
+ issue_key="ISSUE-1"
+ user_login="arthur"
+ change_type="comment"
+ change_data="recent comment"
+ created_at="2013-05-05"
+ updated_at="2013-05-05"
+ />
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/update-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/update-result.xml
new file mode 100644
index 00000000000..02577e213df
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/update-result.xml
@@ -0,0 +1,35 @@
+<dataset>
+
+ <issue_changes
+ id="100"
+ kee="COMMENT-1"
+ issue_key="ISSUE-1"
+ user_login="arthur"
+ change_type="comment"
+ change_data="old comment"
+ created_at="2013-01-01"
+ updated_at="2013-01-01"
+ />
+
+ <issue_changes
+ id="101"
+ kee="[null]"
+ issue_key="1000"
+ user_login="arthur"
+ change_type="diff"
+ change_data="severity=MAJOR|BLOCKER"
+ created_at="2013-02-02"
+ updated_at="2013-02-02"
+ />
+
+ <issue_changes
+ id="102"
+ kee="COMMENT-2"
+ issue_key="ISSUE-1"
+ user_login="arthur"
+ change_type="comment"
+ change_data="new comment"
+ created_at="2013-05-05"
+ updated_at="2013-06-30"
+ />
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/update.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/update.xml
new file mode 100644
index 00000000000..f7dfdc84832
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/update.xml
@@ -0,0 +1,35 @@
+<dataset>
+
+ <issue_changes
+ id="100"
+ kee="COMMENT-1"
+ issue_key="ISSUE-1"
+ user_login="arthur"
+ change_type="comment"
+ change_data="old comment"
+ created_at="2013-01-01"
+ updated_at="2013-01-01"
+ />
+
+ <issue_changes
+ id="101"
+ kee="[null]"
+ issue_key="1000"
+ user_login="arthur"
+ change_type="diff"
+ change_data="severity=MAJOR|BLOCKER"
+ created_at="2013-02-02"
+ updated_at="2013-02-02"
+ />
+
+ <issue_changes
+ id="102"
+ kee="COMMENT-2"
+ issue_key="ISSUE-1"
+ user_login="arthur"
+ change_type="comment"
+ change_data="old value"
+ created_at="2013-05-05"
+ updated_at="2013-05-05"
+ />
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/testInsertComment-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/insert_comment-result.xml
index c1f10296b62..c1f10296b62 100644
--- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/testInsertComment-result.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/insert_comment-result.xml
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/testInsertDiff-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/insert_diff-result.xml
index 4d7045179e9..4d7045179e9 100644
--- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/testInsertDiff-result.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/insert_diff-result.xml
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/selectByChangeKey.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/selectByChangeKey.xml
new file mode 100644
index 00000000000..a8da7191bdf
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/selectByChangeKey.xml
@@ -0,0 +1,76 @@
+<dataset>
+
+ <issues
+ id="100"
+ kee="ISSUE-1"
+ resource_id="400"
+ rule_id="500"
+ severity="INFO"
+ manual_severity="[false]"
+ manual_issue="[false]"
+ description="[null]"
+ line="[null]"
+ effort_to_fix="4.2"
+ status="OPEN"
+ resolution="FIXED"
+ checksum="XXX"
+ user_login="arthur"
+ assignee_login="perceval"
+ author_login="[null]"
+ attributes="JIRA=FOO-1234"
+ issue_creation_date="2013-04-16"
+ issue_update_date="2013-04-16"
+ issue_close_date="2013-04-16"
+ created_at="2013-04-16"
+ updated_at="2013-04-16"
+ />
+
+
+ <!-- the issue to return -->
+ <issues
+ id="101"
+ kee="ISSUE-2"
+ resource_id="400"
+ rule_id="500"
+ severity="BLOCKER"
+ manual_severity="[false]"
+ manual_issue="[false]"
+ description="[null]"
+ line="200"
+ effort_to_fix="4.2"
+ status="OPEN"
+ resolution="FIXED"
+ checksum="XXX"
+ user_login="arthur"
+ assignee_login="perceval"
+ author_login="[null]"
+ attributes="JIRA=FOO-1234"
+ issue_creation_date="2013-04-16"
+ issue_update_date="2013-04-16"
+ issue_close_date="2013-04-16"
+ created_at="2013-04-16"
+ updated_at="2013-04-16"
+ />
+
+ <issue_changes
+ id="1"
+ kee="COMMENT-10"
+ issue_key="ISSUE-1"
+ user_login="emmerik"
+ change_type="comment"
+ change_data="the comment"
+ created_at="2013-05-18"
+ updated_at="2013-05-18"
+ />
+
+ <issue_changes
+ id="2"
+ kee="COMMENT-20"
+ issue_key="ISSUE-2"
+ user_login="emmerik"
+ change_type="comment"
+ change_data="the comment"
+ created_at="2013-05-18"
+ updated_at="2013-05-18"
+ />
+</dataset> \ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_issue_ids_and_components_ids.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_issue_and_component_ids.xml
index b4bd5440f19..b4bd5440f19 100644
--- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_issue_ids_and_components_ids.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_issue_and_component_ids.xml