diff options
author | danielhanrahan <daniel.hanrahan@est.tech> | 2023-11-20 16:37:46 +0000 |
---|---|---|
committer | danielhanrahan <daniel.hanrahan@est.tech> | 2024-02-14 10:25:52 +0000 |
commit | 8d0a18c7e5fb8bd98baeb98aaa006b3b385964f5 (patch) | |
tree | 36a9d0b03e1c9490d7d1257fbf985ee3fe8936cf /cps-ri | |
parent | a6e62210e7d81a98ae2587ec0684a27e638911cc (diff) |
Faster absolute xpath query using parent path lookup
Issue-ID: CPS-2087
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: I62b452f34f08a32a6d80671c7af560fbceec1285
Diffstat (limited to 'cps-ri')
-rw-r--r-- | cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentQueryBuilder.java | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentQueryBuilder.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentQueryBuilder.java index e62471b005..b2014757d7 100644 --- a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentQueryBuilder.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentQueryBuilder.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022-2023 Nordix Foundation + * Copyright (C) 2022-2024 Nordix Foundation * Modifications Copyright (C) 2023 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -92,7 +92,8 @@ public class FragmentQueryBuilder { sqlStringBuilder.append("SELECT distinct(fragment.anchor_id) FROM fragment " + "JOIN anchor ON anchor.id = fragment.anchor_id WHERE dataspace_id = :dataspaceId"); queryParameters.put("dataspaceId", dataspaceEntity.getId()); - addXpathSearch(cpsPathQuery, sqlStringBuilder, queryParameters); + addAbsoluteParentXpathSearchCondition(cpsPathQuery, sqlStringBuilder, queryParameters, ACROSS_ALL_ANCHORS); + addXpathSearchCondition(cpsPathQuery, sqlStringBuilder, queryParameters); addLeafConditions(cpsPathQuery, sqlStringBuilder); addTextFunctionCondition(cpsPathQuery, sqlStringBuilder, queryParameters); addContainsFunctionCondition(cpsPathQuery, sqlStringBuilder, queryParameters); @@ -125,7 +126,8 @@ public class FragmentQueryBuilder { sqlStringBuilder.append("SELECT * FROM fragment WHERE anchor_id = :anchorId"); queryParameters.put("anchorId", anchorEntity.getId()); } - addXpathSearch(cpsPathQuery, sqlStringBuilder, queryParameters); + addAbsoluteParentXpathSearchCondition(cpsPathQuery, sqlStringBuilder, queryParameters, anchorEntity); + addXpathSearchCondition(cpsPathQuery, sqlStringBuilder, queryParameters); addLeafConditions(cpsPathQuery, sqlStringBuilder); addTextFunctionCondition(cpsPathQuery, sqlStringBuilder, queryParameters); addContainsFunctionCondition(cpsPathQuery, sqlStringBuilder, queryParameters); @@ -135,9 +137,9 @@ public class FragmentQueryBuilder { return query; } - private static void addXpathSearch(final CpsPathQuery cpsPathQuery, - final StringBuilder sqlStringBuilder, - final Map<String, Object> queryParameters) { + private static void addXpathSearchCondition(final CpsPathQuery cpsPathQuery, + final StringBuilder sqlStringBuilder, + final Map<String, Object> queryParameters) { sqlStringBuilder.append(" AND (xpath LIKE :escapedXpath OR " + "(xpath LIKE :escapedXpath||'[@%]' AND xpath NOT LIKE :escapedXpath||'[@%]/%[@%]'))"); if (CpsPathPrefixType.ABSOLUTE.equals(cpsPathQuery.getCpsPathPrefixType())) { @@ -147,6 +149,25 @@ public class FragmentQueryBuilder { } } + private static void addAbsoluteParentXpathSearchCondition(final CpsPathQuery cpsPathQuery, + final StringBuilder sqlStringBuilder, + final Map<String, Object> queryParameters, + final AnchorEntity anchorEntity) { + if (CpsPathPrefixType.ABSOLUTE.equals(cpsPathQuery.getCpsPathPrefixType())) { + if (cpsPathQuery.getNormalizedParentPath().isEmpty()) { + sqlStringBuilder.append(" AND parent_id IS NULL"); + } else { + if (anchorEntity == ACROSS_ALL_ANCHORS) { + sqlStringBuilder.append(" AND parent_id IN (SELECT id FROM fragment WHERE xpath = :parentXpath)"); + } else { + sqlStringBuilder.append(" AND parent_id = (SELECT id FROM fragment WHERE xpath = :parentXpath" + + " AND anchor_id = :anchorId)"); + } + queryParameters.put("parentXpath", cpsPathQuery.getNormalizedParentPath()); + } + } + } + private static void addPaginationCondition(final StringBuilder sqlStringBuilder, final Map<String, Object> queryParameters, final PaginationOption paginationOption) { |