aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-12-19 16:07:56 +0400
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-12-19 19:32:53 +0400
commitfe5480b895f576efb36e3659a2b5a0fe5dc60430 (patch)
treeb15f95ce68da523b52d70c197a69d2350e82a128 /plugins
parent17a932cde5030121ddec6094b9b89852152cefde (diff)
downloadsonarqube-fe5480b895f576efb36e3659a2b5a0fe5dc60430.tar.gz
sonarqube-fe5480b895f576efb36e3659a2b5a0fe5dc60430.zip
SONAR-3090 Remove DUPLICATIONS_INDEX.ID
In order to do this - remove entity DuplicationBlock and use native query in PurgeUtils.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java40
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots-result.xml4
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots.xml4
3 files changed, 31 insertions, 17 deletions
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java
index 20bcb0f6241..d6598a62619 100644
--- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java
@@ -33,7 +33,6 @@ import org.sonar.api.database.model.Snapshot;
import org.sonar.api.database.model.SnapshotSource;
import org.sonar.api.design.DependencyDto;
import org.sonar.api.utils.TimeProfiler;
-import org.sonar.jpa.entity.DuplicationBlock;
/**
* @since 2.5
@@ -70,7 +69,7 @@ public final class PurgeUtils {
deleteSnapshots(session, snapshotIds);
}
- public static void deleteDependencies(DatabaseSession session, List<Integer> snapshotIds) {
+ public static void deleteDependencies(DatabaseSession session, List<Integer> snapshotIds) {
executeQuery(session, "delete dependencies", snapshotIds, "delete from " + DependencyDto.class.getSimpleName() + " d where d.fromSnapshotId in (:ids)");
executeQuery(session, "delete dependencies", snapshotIds, "delete from " + DependencyDto.class.getSimpleName() + " d where d.toSnapshotId in (:ids)");
}
@@ -78,7 +77,7 @@ public final class PurgeUtils {
/**
* Delete all measures, including MEASURE_DATA
*/
- public static void deleteMeasuresBySnapshotId(DatabaseSession session, List<Integer> snapshotIds) {
+ public static void deleteMeasuresBySnapshotId(DatabaseSession session, List<Integer> snapshotIds) {
executeQuery(session, "delete measures by snapshot id", snapshotIds, "delete from " + MeasureData.class.getSimpleName() + " m where m.snapshotId in (:ids)");
executeQuery(session, "delete measures by snapshot id", snapshotIds, "delete from " + MeasureModel.class.getSimpleName() + " m where m.snapshotId in (:ids)");
}
@@ -86,7 +85,7 @@ public final class PurgeUtils {
/**
* Delete all measures, including MEASURE_DATA
*/
- public static void deleteMeasuresById(DatabaseSession session, List<Integer> measureIds) {
+ public static void deleteMeasuresById(DatabaseSession session, List<Integer> measureIds) {
executeQuery(session, "delete measures by id", measureIds, "delete from " + MeasureData.class.getSimpleName() + " m where m.measure.id in (:ids)");
executeQuery(session, "delete measures by id", measureIds, "delete from " + MeasureModel.class.getSimpleName() + " m where m.id in (:ids)");
}
@@ -94,58 +93,73 @@ public final class PurgeUtils {
/**
* Delete SNAPSHOT_SOURCES table
*/
- public static void deleteSources(DatabaseSession session, List<Integer> snapshotIds) {
+ public static void deleteSources(DatabaseSession session, List<Integer> snapshotIds) {
executeQuery(session, "delete sources", snapshotIds, "delete from " + SnapshotSource.class.getSimpleName() + " e where e.snapshotId in (:ids)");
}
/**
* Delete violations (RULE_FAILURES table)
*/
- public static void deleteViolations(DatabaseSession session, List<Integer> snapshotIds) {
+ public static void deleteViolations(DatabaseSession session, List<Integer> snapshotIds) {
executeQuery(session, "delete violations", snapshotIds, "delete from " + RuleFailureModel.class.getSimpleName() + " e where e.snapshotId in (:ids)");
}
/**
+ * Delete DUPLICATIONS_INDEX table
+ *
* @since 2.11
*/
private static void deleteDuplicationBlocks(DatabaseSession session, List<Integer> snapshotIds) {
- executeQuery(session, "delete duplication blocks", snapshotIds, "delete from " + DuplicationBlock.class.getSimpleName() + " e where e.snapshotId in (:ids)");
+ executeNativeQuery(session, "delete duplication blocks", snapshotIds, "delete from duplications_index e where e.snapshot_id in (:ids)");
}
/**
* Delete EVENTS table
*/
- public static void deleteEvents(DatabaseSession session, List<Integer> snapshotIds) {
+ public static void deleteEvents(DatabaseSession session, List<Integer> snapshotIds) {
executeQuery(session, "delete events", snapshotIds, "delete from " + Event.class.getSimpleName() + " e where e.snapshot.id in (:ids)");
}
/**
* Delete SNAPSHOTS table
*/
- public static void deleteSnapshots(DatabaseSession session, List<Integer> snapshotIds) {
+ public static void deleteSnapshots(DatabaseSession session, List<Integer> snapshotIds) {
executeQuery(session, "delete snapshots", snapshotIds, "delete from " + Snapshot.class.getSimpleName() + " s where s.id in (:ids)");
}
/**
* Paginate execution of SQL requests to avoid exceeding size of rollback segment
*/
- public static void executeQuery(DatabaseSession session, String description, List<Integer> ids, String hql) {
+ public static void executeQuery(DatabaseSession session, String description, List<Integer> ids, String hql) {
if (ids == null || ids.isEmpty()) {
return;
}
+ executeQuery(session, description, ids, session.createQuery(hql));
+ }
- TimeProfiler profiler = new TimeProfiler().setLevelToDebug().start("Execute " + description);
+ /**
+ * @since 2.13
+ */
+ private static void executeNativeQuery(DatabaseSession session, String description, List<Integer> ids, String sql) {
+ if (ids == null || ids.isEmpty()) {
+ return;
+ }
+ executeQuery(session, description, ids, session.createNativeQuery(sql));
+ }
+ /**
+ * @since 2.13
+ */
+ private static void executeQuery(DatabaseSession session, String description, List<Integer> ids, Query query) {
+ TimeProfiler profiler = new TimeProfiler().setLevelToDebug().start("Execute " + description);
int index = 0;
while (index < ids.size()) {
- Query query = session.createQuery(hql);
List<Integer> paginedSids = ids.subList(index, Math.min(ids.size(), index + MAX_IN_ELEMENTS));
query.setParameter("ids", paginedSids);
query.executeUpdate();
index += MAX_IN_ELEMENTS;
session.commit();
}
-
profiler.stop();
}
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots-result.xml
index cc74ed382d4..767062ce46a 100644
--- a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots-result.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots-result.xml
@@ -114,8 +114,8 @@
<!--parent_dependency_id="[null]" project_snapshot_id="1"-->
<!--dep_usage="INHERITS" dep_weight="1" from_scope="FIL" to_scope="FIL"/>-->
- <!--<duplications_index id="1" project_snapshot_id="1" snapshot_id="3" hash="bb" index_in_file="0" start_line="0" end_line="0" />-->
- <!--<duplications_index id="2" project_snapshot_id="1" snapshot_id="4" hash="bb" index_in_file="0" start_line="0" end_line="0" />-->
+ <!--<duplications_index project_snapshot_id="1" snapshot_id="3" hash="bb" index_in_file="0" start_line="0" end_line="0" />-->
+ <!--<duplications_index project_snapshot_id="1" snapshot_id="4" hash="bb" index_in_file="0" start_line="0" end_line="0" />-->
<events id="1" name="Version 1.0" resource_id="1" snapshot_id="1" category="VERSION" description="[null]" event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]"/>
<!--events id="2" name="Version 2.0" resource_id="3" snapshot_id="3" category="VERSION" description="[null]" event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]"/-->
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots.xml
index 09e1ecd3edf..4e2999bcb46 100644
--- a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots.xml
@@ -120,8 +120,8 @@
parent_dependency_id="[null]" project_snapshot_id="1"
dep_usage="INHERITS" dep_weight="1" from_scope="FIL" to_scope="FIL"/>
- <duplications_index id="1" project_snapshot_id="1" snapshot_id="3" hash="bb" index_in_file="0" start_line="0" end_line="0"/>
- <duplications_index id="2" project_snapshot_id="1" snapshot_id="4" hash="bb" index_in_file="0" start_line="0" end_line="0"/>
+ <duplications_index project_snapshot_id="1" snapshot_id="3" hash="bb" index_in_file="0" start_line="0" end_line="0"/>
+ <duplications_index project_snapshot_id="1" snapshot_id="4" hash="bb" index_in_file="0" start_line="0" end_line="0"/>
<events id="1" name="Version 1.0" resource_id="1" snapshot_id="1" category="VERSION" description="[null]" event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]"/>
<events id="2" name="Version 2.0" resource_id="3" snapshot_id="3" category="VERSION" description="[null]" event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]"/>