Commit ee6bc5ec4b8c341afff28d2a9104ec3960878321
Committed by
Andrew Shvayka
1 parent
628ce799
Fixed issue for last level query in case entities have more relations in the hie…
…rarchy below requested level
Showing
1 changed file
with
7 additions
and
2 deletions
@@ -472,10 +472,13 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | @@ -472,10 +472,13 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | ||
472 | if (entityFilter.isFetchLastLevelOnly()) { | 472 | if (entityFilter.isFetchLastLevelOnly()) { |
473 | String fromOrTo = (entityFilter.getDirection().equals(EntitySearchDirection.FROM) ? "from" : "to"); | 473 | String fromOrTo = (entityFilter.getDirection().equals(EntitySearchDirection.FROM) ? "from" : "to"); |
474 | StringBuilder notExistsPart = new StringBuilder(); | 474 | StringBuilder notExistsPart = new StringBuilder(); |
475 | - notExistsPart.append(" NOT EXISTS (SELECT 1 from relation nr where ") | 475 | + notExistsPart.append(" NOT EXISTS (SELECT 1 from relation nr ") |
476 | + .append(whereFilter.replaceAll("re\\.", "nr\\.")) | ||
477 | + .append(" and ") | ||
476 | .append("nr.").append(fromOrTo).append("_id").append(" = re.").append(toOrFrom).append("_id") | 478 | .append("nr.").append(fromOrTo).append("_id").append(" = re.").append(toOrFrom).append("_id") |
477 | .append(" and ") | 479 | .append(" and ") |
478 | .append("nr.").append(fromOrTo).append("_type").append(" = re.").append(toOrFrom).append("_type"); | 480 | .append("nr.").append(fromOrTo).append("_type").append(" = re.").append(toOrFrom).append("_type"); |
481 | + | ||
479 | if (!StringUtils.isEmpty(entityFilter.getRelationType())) { | 482 | if (!StringUtils.isEmpty(entityFilter.getRelationType())) { |
480 | notExistsPart.append(" and nr.relation_type = :where_relation_type"); | 483 | notExistsPart.append(" and nr.relation_type = :where_relation_type"); |
481 | } | 484 | } |
@@ -556,7 +559,9 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | @@ -556,7 +559,9 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | ||
556 | .append(" and ") | 559 | .append(" and ") |
557 | .append("nr.").append(fromOrTo).append("_id").append(" = re.").append(toOrFrom).append("_id") | 560 | .append("nr.").append(fromOrTo).append("_id").append(" = re.").append(toOrFrom).append("_id") |
558 | .append(" and ") | 561 | .append(" and ") |
559 | - .append("nr.").append(fromOrTo).append("_type").append(" = re.").append(toOrFrom).append("_type"); | 562 | + .append("nr.").append(fromOrTo).append("_type").append(" = re.").append(toOrFrom).append("_type") |
563 | + .append(" and ") | ||
564 | + .append(whereFilter.toString().replaceAll("re\\.", "nr\\.")); | ||
560 | 565 | ||
561 | notExistsPart.append(")"); | 566 | notExistsPart.append(")"); |
562 | whereFilter.append(" and ( re.lvl = ").append(entityFilter.getMaxLevel()).append(" OR ").append(notExistsPart.toString()).append(")"); | 567 | whereFilter.append(" and ( re.lvl = ").append(entityFilter.getMaxLevel()).append(" OR ").append(notExistsPart.toString()).append(")"); |