From 91d66108379d7cd397aedc30da4801d20643ee68 Mon Sep 17 00:00:00 2001 From: mpriyank Date: Fri, 26 Aug 2022 13:26:01 +0100 Subject: Performance Improvement:save cmhandles capability - add saveCmHandleBatch in InventoryPersistence - add saveListElementsBatch in CpsDataService - have addListElementsBatch in CpsDataPersistenceService - Test scenarios for the same Issue-ID: CPS-1229 Issue-ID: CPS-1126 Change-Id: I0a1401818da5a4e523d7d0751cac6a526d1611b2 Signed-off-by: mpriyank --- .../org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java | 10 ++++++++++ .../spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'cps-ri/src') 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 c4a2c2fe98..61e1d5b569 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 @@ -101,6 +101,16 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService addChildDataNodes(dataspaceName, anchorName, parentNodeXpath, newListElements); } + @Override + @Transactional + public void addListElementsBatch(final String dataspaceName, final String anchorName, final String parentNodeXpath, + final Collection> newListsElements) { + + newListsElements.forEach( + newListElement -> addListElements(dataspaceName, anchorName, parentNodeXpath, newListElement)); + + } + private void addChildDataNodes(final String dataspaceName, final String anchorName, final String parentNodeXpath, final Collection newChildren) { final FragmentEntity parentFragmentEntity = getFragmentByXpath(dataspaceName, anchorName, parentNodeXpath); diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy index fee489d18b..acc243b5b4 100755 --- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy +++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy @@ -157,7 +157,7 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase { } @Sql([CLEAR_DATA, SET_DATA]) - def 'Add multiple new list elements including an element with a child datanode.'() { + def 'Add collection of multiple new list elements including an element with a child datanode.'() { given: 'two new child list elements for an existing parent' def listElementXpaths = ['/parent-201/child-204[@key="NEW1"]', '/parent-201/child-204[@key="NEW2"]'] def listElements = toDataNodes(listElementXpaths) @@ -165,7 +165,7 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase { def grandChild = buildDataNode('/parent-201/child-204[@key="NEW1"]/grand-child-204[@key2="NEW1-CHILD"]', [leave:'value'], []) listElements[0].childDataNodes = [grandChild] when: 'the new data node (list elements) are added to an existing parent node' - objectUnderTest.addListElements(DATASPACE_NAME, ANCHOR_NAME3, '/parent-201', listElements) + objectUnderTest.addListElementsBatch(DATASPACE_NAME, ANCHOR_NAME3, '/parent-201', [listElements]) then: 'new entries are successfully persisted, parent node now contains 5 children (2 new + 3 existing before)' def parentFragment = fragmentRepository.getById(LIST_DATA_NODE_PARENT201_FRAGMENT_ID) def allChildXpaths = parentFragment.childFragments.collect { it.xpath } -- cgit 1.2.3-korg