public void purge(PurgeContext context) {
Query query = getSession().createQuery("SELECT d.projectSnapshotId FROM " + DependencyDto.class.getSimpleName() +
- " d WHERE NOT EXISTS(FROM " + Snapshot.class.getSimpleName() + " s WHERE s.id=d.projectSnapshotId AND s.last=:last)");
- query.setParameter("last", true);
+ " d WHERE EXISTS(FROM " + Snapshot.class.getSimpleName() + " s WHERE s.id=d.projectSnapshotId AND s.last=:last and s.status=:status)");
+ query.setParameter("last", false);
+ query.setParameter("status", Snapshot.STATUS_PROCESSED);
+
final List<Integer> projectSnapshotIds = query.getResultList();
PurgeUtils.executeQuery(getSession(), "", projectSnapshotIds, "DELETE FROM " + DependencyDto.class.getSimpleName() + " WHERE projectSnapshotId in (:ids)");
}
assertPurge("purgeDependencies");
}
+ /**
+ * See https://jira.codehaus.org/browse/SONAR-2707
+ * Do not remove dependencies which are computed at the same time in other parallel jobs.
+ */
+ @Test
+ public void shouldNotPurgeUnprocessedSnapshots() throws SQLException {
+ assertPurge("shouldNotPurgeUnprocessedSnapshots");
+ }
+
private void assertPurge(String testName) {
setupData(testName);
new PurgeDependencies(getSession()).purge(null);
--- /dev/null
+<dataset>
+
+ <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="first:project" name="One"
+ root_id="[null]"
+ description="[null]"
+ enabled="true" language="java" copy_resource_id="[null]"/>
+
+ <projects long_name="[null]" id="2" scope="PRJ" qualifier="TRK" kee="second:project" name="Two"
+ root_id="[null]"
+ description="[null]"
+ enabled="true" language="java" copy_resource_id="[null]"/>
+
+
+ <!-- old -->
+ <snapshots 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]" id="1" scope="PRJ" qualifier="TRK" created_at="2008-12-01 13:58:00.00" version="[null]"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+
+ <snapshots 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]" id="2" scope="PRJ" qualifier="TRK" created_at="2008-12-01 13:58:00.00" version="[null]"
+ project_id="2"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+
+
+ <!-- last -->
+ <snapshots 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]" id="3" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" version="[null]"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="true"
+ path="[null]"/>
+
+ <snapshots 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]" id="4" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" version="[null]"
+ project_id="2"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="true"
+ path="[null]"/>
+
+
+ <!-- in progress -->
+ <snapshots 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]" id="5" scope="PRJ" qualifier="TRK" created_at="2008-12-03 13:58:00.00" version="[null]"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="U" islast="false"
+ path="[null]"/>
+
+ <snapshots 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]" id="6" scope="PRJ" qualifier="TRK" created_at="2008-12-03 13:58:00.00" version="[null]"
+ project_id="2"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="U" islast="false"
+ path="[null]"/>
+
+
+
+ <!-- old dependencies -->
+ <!--<dependencies id="1" from_resource_id="1" from_snapshot_id="1" to_resource_id="2" to_snapshot_id="2"-->
+ <!--parent_dependency_id="[null]" project_snapshot_id="1"-->
+ <!--dep_usage="compile" dep_weight="1" from_scope="PRJ" to_scope="PRJ"/>-->
+
+
+ <!-- last dependencies -->
+ <dependencies id="2" from_resource_id="1" from_snapshot_id="3" to_resource_id="2" to_snapshot_id="4"
+ parent_dependency_id="[null]" project_snapshot_id="3"
+ dep_usage="compile" dep_weight="1" from_scope="PRJ" to_scope="PRJ"/>
+
+ <!-- in progress -->
+ <dependencies id="3" from_resource_id="1" from_snapshot_id="5" to_resource_id="2" to_snapshot_id="6"
+ parent_dependency_id="[null]" project_snapshot_id="5"
+ dep_usage="uses" dep_weight="1" from_scope="PRJ" to_scope="PRJ"/>
+
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+
+ <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="first:project" name="One"
+ root_id="[null]"
+ description="[null]"
+ enabled="true" language="java" copy_resource_id="[null]"/>
+
+ <projects long_name="[null]" id="2" scope="PRJ" qualifier="TRK" kee="second:project" name="Two"
+ root_id="[null]"
+ description="[null]"
+ enabled="true" language="java" copy_resource_id="[null]"/>
+
+
+ <!-- old -->
+ <snapshots 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]" id="1" scope="PRJ" qualifier="TRK" created_at="2008-12-01 13:58:00.00" version="[null]"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+
+ <snapshots 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]" id="2" scope="PRJ" qualifier="TRK" created_at="2008-12-01 13:58:00.00" version="[null]"
+ project_id="2"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+
+
+ <!-- last -->
+ <snapshots 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]" id="3" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" version="[null]"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="true"
+ path="[null]"/>
+
+ <snapshots 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]" id="4" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" version="[null]"
+ project_id="2"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="true"
+ path="[null]"/>
+
+
+ <!-- in progress -->
+ <snapshots 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]" id="5" scope="PRJ" qualifier="TRK" created_at="2008-12-03 13:58:00.00" version="[null]"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="U" islast="false"
+ path="[null]"/>
+
+ <snapshots 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]" id="6" scope="PRJ" qualifier="TRK" created_at="2008-12-03 13:58:00.00" version="[null]"
+ project_id="2"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="U" islast="false"
+ path="[null]"/>
+
+
+
+ <!-- old dependencies -->
+ <dependencies id="1" from_resource_id="1" from_snapshot_id="1" to_resource_id="2" to_snapshot_id="2"
+ parent_dependency_id="[null]" project_snapshot_id="1"
+ dep_usage="compile" dep_weight="1" from_scope="PRJ" to_scope="PRJ"/>
+
+
+ <!-- last dependencies -->
+ <dependencies id="2" from_resource_id="1" from_snapshot_id="3" to_resource_id="2" to_snapshot_id="4"
+ parent_dependency_id="[null]" project_snapshot_id="3"
+ dep_usage="compile" dep_weight="1" from_scope="PRJ" to_scope="PRJ"/>
+
+ <!-- in progress -->
+ <dependencies id="3" from_resource_id="1" from_snapshot_id="5" to_resource_id="2" to_snapshot_id="6"
+ parent_dependency_id="[null]" project_snapshot_id="5"
+ dep_usage="uses" dep_weight="1" from_scope="PRJ" to_scope="PRJ"/>
+
+</dataset>
\ No newline at end of file