summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabrice Bellingard <fabrice.bellingard@sonarsource.com>2012-09-27 11:11:28 +0200
committerFabrice Bellingard <fabrice.bellingard@sonarsource.com>2012-09-27 11:11:28 +0200
commit3ab8e7ef440c7c604edb0914bafc6b331c98da28 (patch)
tree94c9b050a97a492839d751a76e1898515c4cc9cc
parent5a0c6a2c549a6dba1bfee0d7a7bae3b1d7e622bc (diff)
downloadsonarqube-3ab8e7ef440c7c604edb0914bafc6b331c98da28.tar.gz
sonarqube-3ab8e7ef440c7c604edb0914bafc6b331c98da28.zip
SONAR-3636 Add and feed a new column projects.created_at
=> MyBatis layer is updated
-rw-r--r--sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/resource/ResourceDto.java12
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml9
-rw-r--r--sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java27
4 files changed, 34 insertions, 16 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java
index 58763fb621e..deaa26e9baf 100644
--- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java
@@ -23,6 +23,7 @@ import com.google.common.collect.Lists;
import org.apache.ibatis.session.SqlSession;
import org.sonar.core.persistence.MyBatis;
+import java.util.Date;
import java.util.List;
public class ResourceDao {
@@ -105,6 +106,7 @@ public class ResourceDao {
try {
for (ResourceDto resource : resources) {
if (resource.getId() == null) {
+ resource.setDate(new Date());
mapper.insert(resource);
} else {
mapper.update(resource);
diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDto.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDto.java
index 4049df31883..d8855935b84 100644
--- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDto.java
+++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDto.java
@@ -19,6 +19,8 @@
*/
package org.sonar.core.resource;
+import java.util.Date;
+
public final class ResourceDto {
private Long id;
@@ -34,6 +36,7 @@ public final class ResourceDto {
private Long copyResourceId;
private Long personId;
private Long profileId;
+ private Date date;
public Long getId() {
return id;
@@ -151,4 +154,13 @@ public final class ResourceDto {
this.profileId = profileId;
return this;
}
+
+ public Date getDate() {
+ return date;// NOSONAR May expose internal representation by returning reference to mutable object
+ }
+
+ public ResourceDto setDate(Date date) {
+ this.date = date;// NOSONAR May expose internal representation by incorporating reference to mutable object
+ return this;
+ }
}
diff --git a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml
index 5a89472deac..de2ba7b4c45 100644
--- a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml
@@ -35,6 +35,7 @@
<result property="copyResourceId" column="copy_resource_id"/>
<result property="personId" column="person_id"/>
<result property="profileId" column="profile_id"/>
+ <result property="date" column="created_at"/>
</resultMap>
<select id="selectResources" parameterType="map" resultMap="resourceResultMap">
@@ -85,11 +86,11 @@
<insert id="insert" parameterType="Resource" useGeneratedKeys="true" keyProperty="id">
insert into projects
- (name, long_name, description, scope, qualifier, kee, language, root_id, copy_resource_id, person_id, profile_id, enabled)
+ (name, long_name, description, scope, qualifier, kee, language, root_id, copy_resource_id, person_id, profile_id, enabled, created_at)
values (
#{name}, #{longName}, #{description}, #{scope}, #{qualifier},
#{key}, #{language}, #{rootId}, #{copyResourceId},
- #{personId}, #{profileId}, #{enabled}
+ #{personId}, #{profileId}, #{enabled}, #{date}
)
</insert>
@@ -99,11 +100,11 @@
select projects_seq.NEXTVAL from DUAL
</selectKey>
insert into projects
- (id, name, long_name, description, scope, qualifier, kee, language, root_id, copy_resource_id, person_id, profile_id, enabled)
+ (id, name, long_name, description, scope, qualifier, kee, language, root_id, copy_resource_id, person_id, profile_id, enabled, created_at)
values (
#{id}, #{name}, #{longName}, #{description}, #{scope}, #{qualifier},
#{key}, #{language}, #{rootId}, #{copyResourceId},
- #{personId}, #{profileId}, #{enabled}
+ #{personId}, #{profileId}, #{enabled}, #{date}
)
</insert>
diff --git a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java
index f33b4f30a9a..86d75afbef5 100644
--- a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java
@@ -90,13 +90,13 @@ public class ResourceDaoTest extends AbstractDaoTestCase {
public void getResources_filter_by_qualifier() {
setupData("fixture");
- List<ResourceDto> resources = dao.getResources(ResourceQuery.create().setQualifiers(new String[]{"TRK", "BRC"}));
+ List<ResourceDto> resources = dao.getResources(ResourceQuery.create().setQualifiers(new String[] {"TRK", "BRC"}));
assertThat(resources).onProperty("qualifier").containsOnly("TRK", "BRC");
- resources = dao.getResources(ResourceQuery.create().setQualifiers(new String[]{"XXX"}));
+ resources = dao.getResources(ResourceQuery.create().setQualifiers(new String[] {"XXX"}));
assertThat(resources).isEmpty();
- resources = dao.getResources(ResourceQuery.create().setQualifiers(new String[]{}));
+ resources = dao.getResources(ResourceQuery.create().setQualifiers(new String[] {}));
assertThat(resources).hasSize(4);
}
@@ -125,13 +125,13 @@ public class ResourceDaoTest extends AbstractDaoTestCase {
public void getResourceIds_filter_by_qualifier() {
setupData("fixture");
- List<Long> ids = dao.getResourceIds(ResourceQuery.create().setQualifiers(new String[]{"TRK", "BRC"}));
+ List<Long> ids = dao.getResourceIds(ResourceQuery.create().setQualifiers(new String[] {"TRK", "BRC"}));
assertThat(ids).containsOnly(1L, 2L);
- ids = dao.getResourceIds(ResourceQuery.create().setQualifiers(new String[]{"XXX"}));
+ ids = dao.getResourceIds(ResourceQuery.create().setQualifiers(new String[] {"XXX"}));
assertThat(ids).isEmpty();
- ids = dao.getResourceIds(ResourceQuery.create().setQualifiers(new String[]{}));
+ ids = dao.getResourceIds(ResourceQuery.create().setQualifiers(new String[] {}));
assertThat(ids).hasSize(4);
}
@@ -163,17 +163,20 @@ public class ResourceDaoTest extends AbstractDaoTestCase {
setupData("insert");
ResourceDto file1 = new ResourceDto()
- .setKey("org.struts:struts:org.struts.Action").setScope(Scopes.FILE).setQualifier(Qualifiers.FILE)
- .setLanguage("java").setName("Action").setLongName("org.struts.Action");
+ .setKey("org.struts:struts:org.struts.Action").setScope(Scopes.FILE).setQualifier(Qualifiers.FILE)
+ .setLanguage("java").setName("Action").setLongName("org.struts.Action");
ResourceDto file2 = new ResourceDto()
- .setKey("org.struts:struts:org.struts.Filter").setScope(Scopes.FILE).setQualifier(Qualifiers.FILE)
- .setLanguage("java").setName("Filter").setLongName("org.struts.Filter");
+ .setKey("org.struts:struts:org.struts.Filter").setScope(Scopes.FILE).setQualifier(Qualifiers.FILE)
+ .setLanguage("java").setName("Filter").setLongName("org.struts.Filter");
dao.insertOrUpdate(file1, file2);
assertThat(file1.getId()).isNotNull();
assertThat(file2.getId()).isNotNull();
- checkTables("insert", "projects");
+ checkTables("insert", new String[] {"created_at"}, "projects");
+
+ // SONAR-3636 : created_at must be fed when inserting a new entry in the 'projects' table
+ ResourceDto fileLoadedFromDB = dao.getResource(file1.getId());
+ assertThat(fileLoadedFromDB.getDate()).isNotNull();
}
}
-