aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLee Anjella Macabuhay <lee.anjella.macabuhay@est.tech>2024-02-14 11:30:37 +0000
committerGerrit Code Review <gerrit@onap.org>2024-02-14 11:30:37 +0000
commite6991972ddb02306d92bcbe2cbbbe23e43c54daf (patch)
tree739278b6c503e5c084d3836f04cee11a0a40a156
parent4f5671a73677db89bf21f6c1a9ff6a0585f5783e (diff)
parent8d0a18c7e5fb8bd98baeb98aaa006b3b385964f5 (diff)
Merge "Faster absolute xpath query using parent path lookup"
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentQueryBuilder.java33
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) {