summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main
diff options
context:
space:
mode:
authorsourabh_sourabh <sourabh.sourabh@est.tech>2022-11-08 11:46:05 +0000
committersourabh_sourabh <sourabh.sourabh@est.tech>2022-11-11 12:30:57 +0000
commit1d5a12201981035805add15dbad3637e182ee061 (patch)
tree3a8325862c36d18a12e20121ee2c181943a9cb2a /cps-ri/src/main
parentb99f0f00cb964af7b88a85c09bbb11f6c0b1f04d (diff)
Node API - Find root by anchor method performance
- Modified findFirstRootByAnchor - Used fragment extract to build fragment entity to get root data node. Reviewers : Toine, Priyank and Joe Issue-ID: CPS-1171 Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech> Change-Id: I843f270e4781f91ae496f39b976e2a7f2a14d55e Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
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,