summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main
diff options
context:
space:
mode:
authorToine Siebelink <toine.siebelink@est.tech>2022-11-11 14:17:34 +0000
committerGerrit Code Review <gerrit@onap.org>2022-11-11 14:17:34 +0000
commit2cdcee3c22b6757cdacb42ef34be7c006519d70c (patch)
tree8804241a1411590f9ac4ac76c42444154c21fc2f /cps-ri/src/main
parent58f31cb1244c13f426250beaace700e7d12bec7f (diff)
parent1d5a12201981035805add15dbad3637e182ee061 (diff)
Merge "Node API - Find root by anchor method performance"
Diffstat (limited to 'cps-ri/src/main')
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/entities/FragmentEntityArranger.java6
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java8
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java26
3 files changed, 29 insertions, 11 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/entities/FragmentEntityArranger.java b/cps-ri/src/main/java/org/onap/cps/spi/entities/FragmentEntityArranger.java
index 50187a487b..27891c525e 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/entities/FragmentEntityArranger.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/entities/FragmentEntityArranger.java
@@ -57,6 +57,7 @@ public class FragmentEntityArranger {
fragmentEntity.setAttributes(fragmentExtract.getAttributes());
fragmentEntity.setParentId(fragmentExtract.getParentId());
fragmentEntity.setChildFragments(new HashSet<>());
+ fragmentEntity.setDataspace(anchorEntity.getDataspace());
return fragmentEntity;
}
@@ -70,10 +71,7 @@ public class FragmentEntityArranger {
parentFragmentEntity.getChildFragments().add(fragmentEntity);
}
}
- if (fragmentEntitiesWithoutParentInResultSet.iterator().hasNext()) {
- return fragmentEntitiesWithoutParentInResultSet.iterator().next();
- }
- return null;
+ return fragmentEntitiesWithoutParentInResultSet.stream().findFirst().orElse(null);
}
}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
index dc848e657c..ac1be1cd30 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
@@ -230,7 +230,11 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
final AnchorEntity anchorEntity = anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName);
if (isRootXpath(xpath)) {
- return fragmentRepository.findFirstRootByDataspaceAndAnchor(dataspaceEntity, anchorEntity);
+ final List<FragmentExtract> fragmentExtracts = fragmentRepository.getTopLevelFragments(dataspaceEntity,
+ anchorEntity);
+ final FragmentEntity fragmentEntity = FragmentEntityArranger.toFragmentEntityTree(anchorEntity,
+ fragmentExtracts);
+ return fragmentEntity;
} else {
final String normalizedXpath = getNormalizedXpath(xpath);
final FragmentEntity fragmentEntity;
@@ -500,7 +504,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
final boolean onlySupportListNodeDeletion) {
final String parentNodeXpath;
FragmentEntity parentFragmentEntity = null;
- boolean targetDeleted = false;
+ boolean targetDeleted;
if (isRootXpath(targetXpath)) {
deleteDataNodes(dataspaceName, anchorName);
targetDeleted = true;
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java
index 112ebfda70..2c25a61a7e 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2020-2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* Modifications Copyright (C) 2020-2021 Bell Canada.
* Modifications Copyright (C) 2020-2021 Pantheon.tech.
* ================================================================================
@@ -58,10 +58,26 @@ public interface FragmentRepository extends JpaRepository<FragmentEntity, Long>,
List<FragmentEntity> findRootsByDataspaceAndAnchor(@Param("dataspace") int dataspaceId,
@Param("anchor") int anchorId);
- default FragmentEntity findFirstRootByDataspaceAndAnchor(@NonNull DataspaceEntity dataspaceEntity,
- @NonNull AnchorEntity anchorEntity) {
- return findRootsByDataspaceAndAnchor(dataspaceEntity.getId(), anchorEntity.getId()).stream().findFirst()
- .orElseThrow(() -> new DataNodeNotFoundException(dataspaceEntity.getName(), anchorEntity.getName()));
+ @Query(value = "SELECT id, anchor_id AS anchorId, xpath, parent_id AS parentId,"
+ + " CAST(attributes AS TEXT) AS attributes"
+ + " FROM FRAGMENT WHERE anchor_id = :anchorId",
+ nativeQuery = true)
+ List<FragmentExtract> findRootsByAnchorId(@Param("anchorId") int anchorId);
+
+ /**
+ * find top level fragment by anchor.
+ *
+ * @param dataspaceEntity dataspace entity
+ * @param anchorEntity anchor entity
+ * @return FragmentEntity fragment entity
+ */
+ default List<FragmentExtract> getTopLevelFragments(DataspaceEntity dataspaceEntity,
+ AnchorEntity anchorEntity) {
+ final List<FragmentExtract> fragmentExtracts = findRootsByAnchorId(anchorEntity.getId());
+ if (fragmentExtracts.isEmpty()) {
+ throw new DataNodeNotFoundException(dataspaceEntity.getName(), anchorEntity.getName());
+ }
+ return fragmentExtracts;
}
List<FragmentEntity> findAllByAnchorAndXpathIn(@NonNull AnchorEntity anchorEntity,