diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-05-13 09:59:47 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-05-13 13:28:07 +0200 |
commit | 98c745aaed5d98118f47a57ef43317fb4962c8a8 (patch) | |
tree | 23f56b18cd4645c4a48983833393fc7595bfe202 /sonar-db/src/main/java/org/sonar/db/version/v50 | |
parent | b56ffa9f1bb13182f0c7e85729d72a611816b417 (diff) | |
download | sonarqube-98c745aaed5d98118f47a57ef43317fb4962c8a8.tar.gz sonarqube-98c745aaed5d98118f47a57ef43317fb4962c8a8.zip |
SONAR-6846 don't fail on duplicate row in snapshot_sources
Diffstat (limited to 'sonar-db/src/main/java/org/sonar/db/version/v50')
-rw-r--r-- | sonar-db/src/main/java/org/sonar/db/version/v50/FeedFileSources.java | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/version/v50/FeedFileSources.java b/sonar-db/src/main/java/org/sonar/db/version/v50/FeedFileSources.java index 83424ff4d5d..bf45c9ee424 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v50/FeedFileSources.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v50/FeedFileSources.java @@ -96,7 +96,10 @@ public class FeedFileSources extends BaseDataChange { // duplication_data "m13.text_value, " + - "m13.measure_data " + + "m13.measure_data, " + + + // to detect multiple rows in snapshot_sources for the same snapshot + "s.id " + "FROM snapshots s " + "JOIN snapshot_sources ss " + @@ -137,15 +140,17 @@ public class FeedFileSources extends BaseDataChange { "f.enabled = ? " + "AND f.scope = 'FIL' " + "AND p.scope = 'PRJ' AND p.qualifier = 'TRK' " + - "AND fs.file_uuid IS NULL"; + "AND fs.file_uuid IS NULL " + + "ORDER BY s.id, ss.id desc"; public FeedFileSources(Database db, System2 system) { super(db); this.system = system; } - + private static final class FileSourceBuilder implements MassUpdate.Handler { private final long now; + private long previousSnapshotId = -1; public FileSourceBuilder(System2 system) { now = system.now(); @@ -183,6 +188,12 @@ public class FeedFileSources extends BaseDataChange { byte[] longOverallCovCond = row.getNullableBytes(28); byte[] shortDuplicationData = row.getNullableBytes(29); byte[] longDuplicationData = row.getNullableBytes(30); + long snapshotId = row.getLong(31); + + if (snapshotId == previousSnapshotId) { + return false; + } + this.previousSnapshotId = snapshotId; String[] sourceData = new FileSourceDto(source, ofNullableBytes(shortRevisions, longRevisions), @@ -197,8 +208,7 @@ public class FeedFileSources extends BaseDataChange { ofNullableBytes(shortOverallHits, longOverallHits), ofNullableBytes(shortOverallCond, longOverallCond), ofNullableBytes(shortOverallCovCond, longOverallCovCond), - ofNullableBytes(shortDuplicationData, longDuplicationData) - ).getSourceData(); + ofNullableBytes(shortDuplicationData, longDuplicationData)).getSourceData(); update.setString(1, projectUuid) .setString(2, fileUuid) @@ -210,7 +220,7 @@ public class FeedFileSources extends BaseDataChange { return true; } - + private static String ofNullableBytes(@Nullable byte[] shortBytes, @Nullable byte[] longBytes) { byte[] result; if (shortBytes == null) { |