]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1450: Add the column RULE_FAILURES.CREATED_AT
authorGodin <mandrikov@gmail.com>
Tue, 30 Nov 2010 14:22:02 +0000 (14:22 +0000)
committerGodin <mandrikov@gmail.com>
Tue, 30 Nov 2010 14:22:02 +0000 (14:22 +0000)
sonar-batch/src/main/java/org/sonar/batch/index/ViolationPersister.java
sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java
sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shared.xml
sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldInsertViolations-result.xml
sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldUpdateViolation-result.xml
sonar-plugin-api/src/main/java/org/sonar/api/database/model/RuleFailureModel.java

index 2ec89741dedf88b3761868182ba7f5208fa28120..84d6d8f847c343b269aa38bd88c84dac7059473c 100644 (file)
@@ -61,6 +61,7 @@ public final class ViolationPersister {
     } else {
       // insert
       model = createModel(violation);
+      model.setCreatedAt(project.getAnalysisDate());
     }
     model.setSnapshotId(snapshot.getId());
     session.save(model);
index d4b93acb3ae03f4daf47cb292e43fd33cdd994b2..238d6e4ab5733dd0429f3f19ca6c8ce163313efa 100644 (file)
@@ -39,6 +39,8 @@ import org.sonar.api.rules.Violation;
 import org.sonar.core.components.DefaultRuleFinder;
 import org.sonar.jpa.test.AbstractDbUnitTestCase;
 
+import java.sql.Date;
+
 public class ViolationPersisterTest extends AbstractDbUnitTestCase {
 
   private ViolationPersister violationPersister;
@@ -66,10 +68,11 @@ public class ViolationPersisterTest extends AbstractDbUnitTestCase {
         .setPriority(RulePriority.CRITICAL).setLineId(50).setCost(80.0);
     Violation violation2 = Violation.create(rule2, javaFile)
         .setPriority(RulePriority.MINOR);
+    Project project = new Project("project").setAnalysisDate(Date.valueOf("2010-09-01"));
 
-    violationPersister.saveViolation(new Project("project"), violation1a);
-    violationPersister.saveViolation(new Project("project"), violation1b);
-    violationPersister.saveViolation(new Project("project"), violation2);
+    violationPersister.saveViolation(project, violation1a);
+    violationPersister.saveViolation(project, violation1b);
+    violationPersister.saveViolation(project, violation2);
 
     checkTables("shouldInsertViolations", "rule_failures");
   }
index bdaac3f6b2f693eeedb1e0a5ac225bc7136a398c..e32d3cbd7b59dfb5757b3c6fb58dc6814d140ed6 100644 (file)
@@ -19,5 +19,5 @@
              scope="FIL" qualifier="CLA" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
              status="U" islast="false" depth="3" />
 
-  <RULE_FAILURES ID="1" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]"/>
-</dataset>
\ No newline at end of file
+  <RULE_FAILURES ID="1" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" />
+</dataset>
index 47117589804259c5d3f4c88458a11712828dca08..1266940fe0d57dbafd81fd9b5d7f421ee5b4ef93 100644 (file)
@@ -18,8 +18,8 @@
              scope="FIL" qualifier="CLA" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
              status="U" islast="false" depth="3" />
 
-  <RULE_FAILURES ID="1" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]"/>
-  <RULE_FAILURES ID="2" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="the message" LINE="20" COST="55.6"/>
-  <RULE_FAILURES ID="3" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="[null]" LINE="50" COST="80"/>
-  <RULE_FAILURES ID="4" SNAPSHOT_ID="1000" RULE_ID="31" FAILURE_LEVEL="1" MESSAGE="[null]" LINE="[null]" COST="[null]"/>
+  <RULE_FAILURES ID="1" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" />
+  <RULE_FAILURES ID="2" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="the message" LINE="20" COST="55.6" created_at="2010-09-01 00:00:00.0" />
+  <RULE_FAILURES ID="3" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="[null]" LINE="50" COST="80" created_at="2010-09-01 00:00:00.0" />
+  <RULE_FAILURES ID="4" SNAPSHOT_ID="1000" RULE_ID="31" FAILURE_LEVEL="1" MESSAGE="[null]" LINE="[null]" COST="[null]" created_at="2010-09-01 00:00:00.0" />
 </dataset>
\ No newline at end of file
index 0ec12a8e75efa6a60edeaa456b897449dd443763..0025c82b089bd0a16ee65c418f45d2a078314d46 100644 (file)
@@ -18,5 +18,5 @@
              scope="FIL" qualifier="CLA" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
              status="U" islast="false" depth="3" />
 
-  <RULE_FAILURES ID="1" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="55.6"/>
+  <RULE_FAILURES ID="1" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="55.6" created_at="2008-11-01 13:58:00.00" />
 </dataset>
\ No newline at end of file
index 2d18f044bb65d43ce1d21310d1c593a86766ed25..ccaea4c15c1c5fd5883d86e334face31a3550334 100644 (file)
  */
 package org.sonar.api.database.model;
 
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
-import javax.persistence.Table;
-
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.builder.EqualsBuilder;
 import org.apache.commons.lang.builder.HashCodeBuilder;
@@ -32,6 +26,10 @@ import org.apache.commons.lang.builder.ReflectionToStringBuilder;
 import org.sonar.api.database.BaseIdentifiable;
 import org.sonar.api.rules.RulePriority;
 
+import java.util.Date;
+
+import javax.persistence.*;
+
 @Entity
 @Table(name = "rule_failures")
 public class RuleFailureModel extends BaseIdentifiable {
@@ -57,6 +55,10 @@ public class RuleFailureModel extends BaseIdentifiable {
   @Column(name = "cost", updatable = true, nullable = true)
   private Double cost;
 
+  @Temporal(TemporalType.TIMESTAMP)
+  @Column(name = "created_at", updatable = true, nullable = true)
+  private Date createdAt;
+
   public String getMessage() {
     return message;
   }
@@ -114,6 +116,14 @@ public class RuleFailureModel extends BaseIdentifiable {
     return this;
   }
 
+  public Date getCreatedAt() {
+    return createdAt;
+  }
+
+  public void setCreatedAt(Date createdAt) {
+    this.createdAt = createdAt;
+  }
+
   @Override
   public boolean equals(Object obj) {
     if (!(obj instanceof RuleFailureModel)) {