diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-01-25 19:26:18 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-01-25 19:26:52 +0100 |
commit | c0d6299259de839375a9653f0ff2b19cba2ce042 (patch) | |
tree | d4019e33c6bbcc93b53b4214d348ffe72a58fe54 /sonar-core | |
parent | 88c258902a4e33017028bc28207f4b4def3e168e (diff) | |
download | sonarqube-c0d6299259de839375a9653f0ff2b19cba2ce042.tar.gz sonarqube-c0d6299259de839375a9653f0ff2b19cba2ce042.zip |
SONAR-2061 add the flag Metric#deleteHistoricalData. Default value is false.
* New column METRICS.DELETE_HISTORICAL_DATA (boolean, nullable)
* Hidden core metrics and some data metrics have this new field to true
Diffstat (limited to 'sonar-core')
13 files changed, 169 insertions, 22 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java index fc8ff41e816..8bbe33b44b8 100644 --- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java @@ -67,6 +67,7 @@ public class PurgeDao { purgeSnapshot(snapshotId, purgeMapper); } }); + // must be executed at the end for reentrance purgeSnapshot(projectSnapshotId, purgeMapper); } @@ -159,11 +160,9 @@ public class PurgeDao { mapper.deleteSnapshotDuplications(snapshotId); mapper.deleteSnapshotSource(snapshotId); mapper.deleteSnapshotViolations(snapshotId); - mapper.deleteSnapshotRuleMeasures(snapshotId); - mapper.deleteSnapshotCharacteristicMeasures(snapshotId); - // TODO SONAR-2061 delete wasted measures (!metric.keepHistory) + mapper.deleteSnapshotWastedMeasures(snapshotId); mapper.updatePurgeStatusToOne(snapshotId); - return 8; // nb of SQL requests + return 7; // nb of SQL requests } @VisibleForTesting diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java index 65536f6acc1..38cccfe0e60 100644 --- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java @@ -41,9 +41,7 @@ public interface PurgeMapper { void deleteSnapshotViolations(long snapshotId); - void deleteSnapshotRuleMeasures(long snapshotId); - - void deleteSnapshotCharacteristicMeasures(long snapshotId); + void deleteSnapshotWastedMeasures(long snapshotId); void updatePurgeStatusToOne(long snapshotId); diff --git a/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java b/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java index a6e8c7653e0..4481fef39a7 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java +++ b/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java @@ -34,7 +34,7 @@ public class SchemaMigration { public final static int VERSION_UNKNOWN = -1; - public static final int LAST_VERSION = 253; + public static final int LAST_VERSION = 254; public static final int VERSION_2_13 = 241; public final static String TABLE_NAME = "schema_migrations"; diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql index 6b842872b00..fd4626b9267 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql @@ -172,6 +172,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('250'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('251'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('252'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('253'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('254'); INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl index 81491225d86..1dcd74b9e03 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl @@ -450,7 +450,8 @@ CREATE TABLE "METRICS" ( "WORST_VALUE" DECIMAL(30,20), "BEST_VALUE" DECIMAL(30,20), "OPTIMIZED_BEST_VALUE" BOOLEAN, - "HIDDEN" BOOLEAN + "HIDDEN" BOOLEAN, + "DELETE_HISTORICAL_DATA" BOOLEAN ); CREATE TABLE "LOADED_TEMPLATES" ( diff --git a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml index 44eaed90b43..3f942d66c6b 100644 --- a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml @@ -85,12 +85,9 @@ delete from snapshots where id=#{id} </delete> - <delete id="deleteSnapshotRuleMeasures" parameterType="long"> - delete from project_measures where snapshot_id=#{id} and rule_id is not null - </delete> - - <delete id="deleteSnapshotCharacteristicMeasures" parameterType="long"> - delete from project_measures where snapshot_id=#{id} and characteristic_id is not null + <delete id="deleteSnapshotWastedMeasures" parameterType="long"> + delete from project_measures where snapshot_id=#{id} and + (characteristic_id is not null or rule_id is not null or metric_id in (select id from metrics where delete_historical_data=${_true})) </delete> <update id="updatePurgeStatusToOne" parameterType="long"> diff --git a/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java b/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java index 88f56b9e083..b6644f9b275 100644 --- a/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java @@ -58,7 +58,6 @@ public class PurgeDaoTest extends DaoTestCase { /** * Test that all related data is purged. */ - @Test public void shouldPurgeSnapshot() { setupData("shouldPurgeSnapshot"); @@ -77,6 +76,39 @@ public class PurgeDaoTest extends DaoTestCase { } @Test + public void shouldDeleteWastedMeasuresWhenPurgingSnapshot() { + setupData("shouldDeleteWastedMeasuresWhenPurgingSnapshot"); + + SqlSession session = getMyBatis().openSession(); + try { + // this method does not commit and close the session + dao.purgeSnapshot(1L, session.getMapper(PurgeMapper.class)); + session.commit(); + + } finally { + MyBatis.closeQuietly(session); + } + checkTables("shouldDeleteWastedMeasuresWhenPurgingSnapshot", "project_measures"); + } + + @Test + public void shouldCloseReviewWhenDisablingResource() { + setupData("shouldCloseReviewWhenDisablingResource"); + + SqlSession session = getMyBatis().openSession(); + try { + // this method does not commit and close the session + dao.disableResource(1L, session.getMapper(PurgeMapper.class)); + session.commit(); + + } finally { + MyBatis.closeQuietly(session); + } + checkTables("shouldCloseReviewWhenDisablingResource", /* excluded column */new String[]{"updated_at"}, "reviews"); + } + + + @Test public void shouldPurgeProject() { setupData("shouldPurgeProject"); dao.purgeProject(1); diff --git a/sonar-core/src/test/resources/org/sonar/core/metric/CacheMetricFinderTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/metric/CacheMetricFinderTest/shared.xml index 85709bcbf98..dd645d66ec1 100644 --- a/sonar-core/src/test/resources/org/sonar/core/metric/CacheMetricFinderTest/shared.xml +++ b/sonar-core/src/test/resources/org/sonar/core/metric/CacheMetricFinderTest/shared.xml @@ -1,12 +1,12 @@ <dataset> - <metrics id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" + <metrics delete_historical_data="[null]" id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="false"/> - <metrics id="2" name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" + <metrics delete_historical_data="[null]" id="2" name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" enabled="true" worst_value="0" optimized_best_value="true" best_value="100" direction="1" hidden="false"/> - <metrics id="3" name="disabled" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" + <metrics delete_historical_data="[null]" id="3" name="disabled" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" enabled="false" worst_value="0" optimized_best_value="true" best_value="100" direction="1" hidden="false"/> </dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/metric/DefaultMetricFinderTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/metric/DefaultMetricFinderTest/shared.xml index 85709bcbf98..dd645d66ec1 100644 --- a/sonar-core/src/test/resources/org/sonar/core/metric/DefaultMetricFinderTest/shared.xml +++ b/sonar-core/src/test/resources/org/sonar/core/metric/DefaultMetricFinderTest/shared.xml @@ -1,12 +1,12 @@ <dataset> - <metrics id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" + <metrics delete_historical_data="[null]" id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="false"/> - <metrics id="2" name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" + <metrics delete_historical_data="[null]" id="2" name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" enabled="true" worst_value="0" optimized_best_value="true" best_value="100" direction="1" hidden="false"/> - <metrics id="3" name="disabled" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" + <metrics delete_historical_data="[null]" id="3" name="disabled" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" enabled="false" worst_value="0" optimized_best_value="true" best_value="100" direction="1" hidden="false"/> </dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldCloseReviewWhenDisablingResource-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldCloseReviewWhenDisablingResource-result.xml new file mode 100644 index 00000000000..562d1940e0d --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldCloseReviewWhenDisablingResource-result.xml @@ -0,0 +1,15 @@ +<!-- + +Changes: +* review.status=CLOSED + +Note that the column updated_at has been removed because it's excluded from DBUnit comparison. +--> + +<dataset> + + <reviews id="1" project_id="1" resource_id="1" status="CLOSED" + rule_failure_permanent_id="1" resolution="[null]" created_at="[null]" resource_line="200" severity="BLOCKER" + user_id="300" assignee_id="300" rule_id="500" manual_violation="[true]" manual_severity="[false]" title="[null]"/> + +</dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldCloseReviewWhenDisablingResource.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldCloseReviewWhenDisablingResource.xml new file mode 100644 index 00000000000..6f6ca9ca0a1 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldCloseReviewWhenDisablingResource.xml @@ -0,0 +1,16 @@ +<dataset> + + <snapshots id="1" + project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]" + status="P" islast="true" purge_status="[null]" + period1_mode="[null]" period1_param="[null]" period1_date="[null]" + period2_mode="[null]" period2_param="[null]" period2_date="[null]" + period3_mode="[null]" period3_param="[null]" period3_date="[null]" + period4_mode="[null]" period4_param="[null]" period4_date="[null]" + period5_mode="[null]" period5_param="[null]" period5_date="[null]" + depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> + + <reviews id="1" project_id="1" resource_id="1" status="OPEN" + rule_failure_permanent_id="1" resolution="[null]" created_at="[null]" updated_at="[null]" resource_line="200" severity="BLOCKER" + user_id="300" assignee_id="300" rule_id="500" manual_violation="[true]" manual_severity="[false]" title="[null]"/> +</dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml new file mode 100644 index 00000000000..fd36604b248 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml @@ -0,0 +1,44 @@ +<dataset> + + <metrics id="1" delete_historical_data="[null]" + name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" + direction="0" hidden="false"/> + + <metrics id="2" delete_historical_data="true" + name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" enabled="true" worst_value="0" optimized_best_value="true" best_value="100" + direction="1" hidden="false"/> + + <snapshots id="1" + project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]" + status="P" islast="true" purge_status="[null]" + period1_mode="[null]" period1_param="[null]" period1_date="[null]" + period2_mode="[null]" period2_param="[null]" period2_date="[null]" + period3_mode="[null]" period3_param="[null]" period3_date="[null]" + period4_mode="[null]" period4_param="[null]" period4_date="[null]" + period5_mode="[null]" period5_param="[null]" period5_date="[null]" + depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> + + <!-- do not delete standard measure --> + <project_measures ID="1" project_id="1" SNAPSHOT_ID="1" RULE_ID="[null]" characteristic_id="[null]" METRIC_ID="1" + url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" + variation_value_5="[null]" rule_priority="[null]" alert_text="[null]" VALUE="10.0" rules_category_id="[null]" + text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]" description="[null]"/> + + <!-- delete measure on rule --> + <!--<project_measures ID="2" project_id="1" SNAPSHOT_ID="1" RULE_ID="33" characteristic_id="[null]" METRIC_ID="1" --> + <!--url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]"--> + <!--variation_value_5="[null]" rule_priority="[null]" alert_text="[null]" VALUE="10.0" rules_category_id="[null]"--> + <!--text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]" description="[null]"/>--> + + <!-- delete measure on quality model characteristic --> + <!--<project_measures ID="3" project_id="1" SNAPSHOT_ID="1" RULE_ID="[null]" characteristic_id="22" METRIC_ID="1" --> + <!--url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]"--> + <!--variation_value_5="[null]" rule_priority="[null]" alert_text="[null]" VALUE="10.0" rules_category_id="[null]"--> + <!--text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]" description="[null]"/>--> + + <!-- delete measure on metrics that are flagged with delete_historical_data=true --> + <!--<project_measures ID="4" project_id="1" SNAPSHOT_ID="1" RULE_ID="[null]" characteristic_id="[null]" METRIC_ID="2"--> + <!--url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]"--> + <!--variation_value_5="[null]" rule_priority="[null]" alert_text="[null]" VALUE="10.0" rules_category_id="[null]"--> + <!--text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]" description="[null]"/>--> +</dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot.xml new file mode 100644 index 00000000000..17db23c661a --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot.xml @@ -0,0 +1,44 @@ +<dataset> + + <metrics id="1" delete_historical_data="[null]" + name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" + direction="0" hidden="false"/> + + <metrics id="2" delete_historical_data="true" + name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" enabled="true" worst_value="0" optimized_best_value="true" best_value="100" + direction="1" hidden="false"/> + + <snapshots id="1" + project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]" + status="P" islast="true" purge_status="[null]" + period1_mode="[null]" period1_param="[null]" period1_date="[null]" + period2_mode="[null]" period2_param="[null]" period2_date="[null]" + period3_mode="[null]" period3_param="[null]" period3_date="[null]" + period4_mode="[null]" period4_param="[null]" period4_date="[null]" + period5_mode="[null]" period5_param="[null]" period5_date="[null]" + depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> + + <!-- do not delete standard measure --> + <project_measures ID="1" project_id="1" SNAPSHOT_ID="1" RULE_ID="[null]" characteristic_id="[null]" METRIC_ID="1" + url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" + variation_value_5="[null]" rule_priority="[null]" alert_text="[null]" VALUE="10.0" rules_category_id="[null]" + text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]" description="[null]"/> + + <!-- delete measure on rule --> + <project_measures ID="2" project_id="1" SNAPSHOT_ID="1" RULE_ID="33" characteristic_id="[null]" METRIC_ID="1" + url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" + variation_value_5="[null]" rule_priority="[null]" alert_text="[null]" VALUE="10.0" rules_category_id="[null]" + text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]" description="[null]"/> + + <!-- delete measure on quality model characteristic --> + <project_measures ID="3" project_id="1" SNAPSHOT_ID="1" RULE_ID="[null]" characteristic_id="22" METRIC_ID="1" + url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" + variation_value_5="[null]" rule_priority="[null]" alert_text="[null]" VALUE="10.0" rules_category_id="[null]" + text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]" description="[null]"/> + + <!-- delete measure on metrics that are flagged with delete_historical_data=true --> + <project_measures ID="4" project_id="1" SNAPSHOT_ID="1" RULE_ID="[null]" characteristic_id="[null]" METRIC_ID="2" + url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" + variation_value_5="[null]" rule_priority="[null]" alert_text="[null]" VALUE="10.0" rules_category_id="[null]" + text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]" description="[null]"/> +</dataset>
\ No newline at end of file |