Update of top-level data node fails with SQL error 64/135764/4
authordanielhanrahan <daniel.hanrahan@est.tech>
Thu, 17 Aug 2023 14:43:34 +0000 (15:43 +0100)
committerDaniel Hanrahan <daniel.hanrahan@est.tech>
Thu, 17 Aug 2023 15:17:15 +0000 (15:17 +0000)
The error is caused by the fetch-descendants code using
ResultSet.getLong which returns a 'long' primitive instead
of a 'Long' object. Thus a parent ID of 'NULL' becomes '0',
which causes an error during update. To preserve the NULL
value, ResultSet.getObject must be used.

Issue-ID: CPS-1841
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: Ida6837a04954cd3c23f0f2faabd7d0712d8ee19d

cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentPrefetchRepositoryImpl.java
docs/release-notes.rst
integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsDataServiceIntegrationSpec.groovy

index 4f056c8..c187f20 100644 (file)
@@ -94,7 +94,7 @@ public class FragmentPrefetchRepositoryImpl implements FragmentPrefetchRepositor
             final FragmentEntity fragmentEntity = new FragmentEntity();
             fragmentEntity.setId(resultSet.getLong("id"));
             fragmentEntity.setXpath(resultSet.getString("xpath"));
-            fragmentEntity.setParentId(resultSet.getLong("parentId"));
+            fragmentEntity.setParentId(resultSet.getObject("parentId", Long.class));
             fragmentEntity.setAttributes(resultSet.getString("attributes"));
             fragmentEntity.setAnchor(anchorEntityPerId.get(resultSet.getLong("anchorId")));
             fragmentEntity.setChildFragments(new HashSet<>());
index cd70cf8..3f672ad 100755 (executable)
@@ -39,6 +39,7 @@ Release Data
 Bug Fixes
 ---------
 3.3.6
+    - `CPS-1841 <https://jira.onap.org/browse/CPS-1841>`_ Update of top-level data node fails with exception
 
 Features
 --------
index 9716cb5..82a415e 100644 (file)
@@ -394,6 +394,17 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
             restoreBookstoreDataAnchor(1)
     }
 
+    def 'Update bookstore top-level container data node.'() {
+        when: 'the bookstore top-level container is updated'
+            def json = '{ "bookstore": { "bookstore-name": "new bookstore" }}'
+            objectUnderTest.updateDataNodeAndDescendants(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/', json, now)
+        then: 'bookstore name has been updated'
+            def result = objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', DIRECT_CHILDREN_ONLY)
+            result.leaves.'bookstore-name'[0] == 'new bookstore'
+        cleanup:
+            restoreBookstoreDataAnchor(1)
+    }
+
     def 'Update multiple data node leaves.'() {
         given: 'Updated json for bookstore data'
             def jsonData =  "{'book-store:books':{'lang':'English/French','price':100,'title':'Matilda'}}"