From: Teryk Bellahsene Date: Wed, 23 Dec 2015 13:06:12 +0000 (+0100) Subject: SONAR-7129 Fix snapshot path builder for Oracle X-Git-Tag: 5.4-M2~7 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e79441c60f92861462124347bdf2d598aaeb18c3;p=sonarqube.git SONAR-7129 Fix snapshot path builder for Oracle --- diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java index bdde220e428..cffa000bc2f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java @@ -361,15 +361,15 @@ public class TreeActionTest { for (JsonElement componentAsJsonElement : components) { JsonObject componentAsJsonObject = componentAsJsonElement.getAsJsonObject(); componentDb.insertComponentAndSnapshot(new ComponentDto() - .setUuid(getJsonField(componentAsJsonObject, "id")) - .setKey(getJsonField(componentAsJsonObject, "key")) - .setName(getJsonField(componentAsJsonObject, "name")) - .setPath(getJsonField(componentAsJsonObject, "path")) - .setProjectUuid(project.projectUuid()) - .setQualifier(getJsonField(componentAsJsonObject, "qualifier")) - .setDescription(getJsonField(componentAsJsonObject, "description")) - .setEnabled(true) - .setCreatedAt(now), + .setUuid(getJsonField(componentAsJsonObject, "id")) + .setKey(getJsonField(componentAsJsonObject, "key")) + .setName(getJsonField(componentAsJsonObject, "name")) + .setPath(getJsonField(componentAsJsonObject, "path")) + .setProjectUuid(project.projectUuid()) + .setQualifier(getJsonField(componentAsJsonObject, "qualifier")) + .setDescription(getJsonField(componentAsJsonObject, "description")) + .setEnabled(true) + .setCreatedAt(now), projectSnapshot); } db.commit(); diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java index 749c21e3aff..7fe84cd77c1 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java @@ -54,7 +54,7 @@ public class ComponentTreeQuery { this.page = builder.page; this.pageSize = builder.pageSize; this.baseSnapshot = builder.baseSnapshot; - this.baseSnapshotPath = buildLikeValue(baseSnapshot.getPath() + baseSnapshot.getId() + ".", WildcardPosition.AFTER); + this.baseSnapshotPath = buildBaseSnapshotPath(baseSnapshot); this.direction = builder.asc ? "ASC" : "DESC"; this.sqlSort = sortFieldsToSqlSort(builder.sortFields, direction); } @@ -112,6 +112,11 @@ public class ComponentTreeQuery { return Joiner.on(", ").join(sqlSortFields); } + private String buildBaseSnapshotPath(SnapshotDto baseSnapshot) { + String existingSnapshotPath = baseSnapshot.getPath() == null ? "" : baseSnapshot.getPath(); + return buildLikeValue(existingSnapshotPath + baseSnapshot.getId() + ".", WildcardPosition.AFTER); + } + public static class Builder { @CheckForNull private String nameOrKeyQuery;