From 9b840618f52c0de8f40b9a2e318233239df600db Mon Sep 17 00:00:00 2001 From: Oleksandr Buhaiov Date: Fri, 1 Aug 2025 09:45:13 +0300 Subject: [PATCH 1/4] Revert "remove optional type attribute for StreamCompactDataWriterEngine" This reverts commit 191651cbe4aa0dd25aa6149a6bbb24ab577a1d5a. --- .../engine/writer/streaming/StreamCompactDataWriterEngine.java | 1 + 1 file changed, 1 insertion(+) diff --git a/SdmxDataParser/src/main/java/org/sdmxsource/sdmx/dataparser/engine/writer/streaming/StreamCompactDataWriterEngine.java b/SdmxDataParser/src/main/java/org/sdmxsource/sdmx/dataparser/engine/writer/streaming/StreamCompactDataWriterEngine.java index eeb6438..3bf5b8d 100644 --- a/SdmxDataParser/src/main/java/org/sdmxsource/sdmx/dataparser/engine/writer/streaming/StreamCompactDataWriterEngine.java +++ b/SdmxDataParser/src/main/java/org/sdmxsource/sdmx/dataparser/engine/writer/streaming/StreamCompactDataWriterEngine.java @@ -128,6 +128,7 @@ public void startGroup(String groupId, AnnotationBean... annotations) { if (isTwoPointOne()) { writer.writeStartElement("Group"); //WRITE THE START GROUP + writer.writeAttribute(XSI_NS, "type", COMPACT_NS.namespacePrefix + ":" + groupId); writeAnnotations(writer, annotations); } else { groupAnnotations = annotations; From 66db0aa181ffb632e37f046e9e687b2269a49d4e Mon Sep 17 00:00:00 2001 From: Oleksandr Buhaiov Date: Thu, 21 Aug 2025 11:00:34 +0300 Subject: [PATCH 2/4] Fix performance of CodeBean instantiation with large number of child codes --- .../beans/codelist/CodelistBeanImpl.java | 44 +++++++++++-------- .../sdmxbeans/test/CodeListSuperBeanTest.java | 17 +++---- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/SdmxBeans/src/main/java/org/sdmxsource/sdmx/sdmxbeans/model/beans/codelist/CodelistBeanImpl.java b/SdmxBeans/src/main/java/org/sdmxsource/sdmx/sdmxbeans/model/beans/codelist/CodelistBeanImpl.java index 18c8729..56bbdb1 100644 --- a/SdmxBeans/src/main/java/org/sdmxsource/sdmx/sdmxbeans/model/beans/codelist/CodelistBeanImpl.java +++ b/SdmxBeans/src/main/java/org/sdmxsource/sdmx/sdmxbeans/model/beans/codelist/CodelistBeanImpl.java @@ -54,12 +54,14 @@ public class CodelistBeanImpl extends ItemSchemeBeanImpl implements CodelistBean { private static final long serialVersionUID = 1L; + private final Map codeMap; /////////////////////////////////////////////////////////////////////////////////////////////////// ////////////BUILD FROM ITSELF, CREATES STUB BEAN ////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// private CodelistBeanImpl(CodelistBean bean, URL actualLocation, boolean isServiceUrl) { super(bean, actualLocation, isServiceUrl); + this.codeMap = new HashMap<>(); } /** @@ -72,10 +74,13 @@ private CodelistBeanImpl(CodelistBean bean, URL actualLocation, boolean isServic /////////////////////////////////////////////////////////////////////////////////////////////////// public CodelistBeanImpl(CodelistMutableBean codelist) { super(codelist); + codeMap = new HashMap<>(); try { if (codelist.getItems() != null) { - for (CodeMutableBean code : codelist.getItems()) { - this.items.add(new CodeBeanImpl(this, code)); + for (CodeMutableBean mutableCode : codelist.getItems()) { + final var code = new CodeBeanImpl(this, mutableCode); + this.items.add(code); + this.codeMap.put(code.getId(), code); } } } catch (SdmxSemmanticException ex) { @@ -134,10 +139,13 @@ public CodelistBeanImpl(org.sdmx.resources.sdmxml.schemas.v10.xmlbeans.structure bean.getNameList(), createTertiary(bean.isSetIsExternalReference(), bean.getIsExternalReference()), bean.getAnnotations()); + this.codeMap = new HashMap<>(); try { for (org.sdmx.resources.sdmxml.schemas.v10.xmlbeans.structure.CodeType currentCode : bean.getCodeList()) { - items.add(new CodeBeanImpl(this, currentCode)); + var code = new CodeBeanImpl(this, currentCode); + items.add(code); + codeMap.put(code.getId(), code); } } catch (SdmxSemmanticException ex) { throw new SdmxSemmanticException(ex, ExceptionCode.BEAN_STRUCTURE_CONSTRUCTION_ERROR, this.getUrn()); @@ -176,10 +184,13 @@ public CodelistBeanImpl(CodeListType bean) { createTertiary(bean.isSetIsExternalReference(), bean.getIsExternalReference()), bean.getAnnotations()); + this.codeMap = new HashMap<>(); try { for (CodeType currentCode : bean.getCodeList()) { - items.add(new CodeBeanImpl(this, currentCode)); + CodeBeanImpl code = new CodeBeanImpl(this, currentCode); + items.add(code); + codeMap.put(code.getId(), code); } } catch (SdmxSemmanticException ex) { throw new SdmxSemmanticException(ex, ExceptionCode.BEAN_STRUCTURE_CONSTRUCTION_ERROR, this.getUrn()); @@ -205,10 +216,13 @@ public CodelistBeanImpl(CodeListType bean) { /////////////////////////////////////////////////////////////////////////////////////////////////// public CodelistBeanImpl(CodelistType bean) { super(bean, SDMX_STRUCTURE_TYPE.CODE_LIST); + this.codeMap = new HashMap<>(); try { for (org.sdmx.resources.sdmxml.schemas.v21.structure.CodeType currentCode : bean.getCodeList()) { - items.add(new CodeBeanImpl(this, currentCode)); + CodeBeanImpl code = new CodeBeanImpl(this, currentCode); + items.add(code); + codeMap.put(code.getId(), code); } } catch (SdmxSemmanticException ex) { throw new SdmxSemmanticException(ex, ExceptionCode.BEAN_STRUCTURE_CONSTRUCTION_ERROR, this.getUrn()); @@ -255,7 +269,7 @@ private void validate() throws ValidationException { urns.add(code.getUrn()); if (ObjectUtil.validString(code.getParentCode())) { - CodeBean parentCode = getCode(items, code.getParentCode()); + CodeBean parentCode = getCode(code.getParentCode()); Set children; if (parentChildMap.containsKey(parentCode)) { children = parentChildMap.get(parentCode); @@ -296,13 +310,12 @@ private void recurseParentMap(Set children, CodeBean parentCode, Map codes, String id) { - for (CodeBean currentCode : codes) { - if (currentCode.getId().equals(id)) { - return currentCode; - } + private CodeBean getCode(String id) { + CodeBean code = getCodeById(id); + if (code == null) { + throw new SdmxSemmanticException(ExceptionCode.CAN_NOT_RESOLVE_PARENT, id); } - throw new SdmxSemmanticException(ExceptionCode.CAN_NOT_RESOLVE_PARENT, id); + return code; } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -321,11 +334,6 @@ public CodelistMutableBean getMutableInstance() { @Override public CodeBean getCodeById(String id) { - for (CodeBean currentCode : items) { - if (currentCode.getId().equals(id)) { - return currentCode; - } - } - return null; + return codeMap.get(id); } } diff --git a/SdmxBeans/src/test/java/org/sdmxsource/sdmx/sdmxbeans/test/CodeListSuperBeanTest.java b/SdmxBeans/src/test/java/org/sdmxsource/sdmx/sdmxbeans/test/CodeListSuperBeanTest.java index d051bc2..846a6d0 100644 --- a/SdmxBeans/src/test/java/org/sdmxsource/sdmx/sdmxbeans/test/CodeListSuperBeanTest.java +++ b/SdmxBeans/src/test/java/org/sdmxsource/sdmx/sdmxbeans/test/CodeListSuperBeanTest.java @@ -1,5 +1,12 @@ package org.sdmxsource.sdmx.sdmxbeans.test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.sdmxsource.sdmx.sdmxbeans.data.DataHelper.buildCodelist; + +import java.util.List; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.sdmxsource.sdmx.api.model.beans.codelist.CodeBean; @@ -9,12 +16,6 @@ import org.sdmxsource.sdmx.sdmxbeans.model.mutablesuperbeans.codelist.CodelistMutableSuperBeanImpl; import org.sdmxsource.sdmx.sdmxbeans.model.superbeans.codelist.CodelistSuperBeanImpl; -import java.util.List; - -import static java.util.stream.Collectors.toList; -import static org.junit.jupiter.api.Assertions.*; -import static org.sdmxsource.sdmx.sdmxbeans.data.DataHelper.buildCodelist; - public class CodeListSuperBeanTest { private CodelistBean codelistBean; @@ -22,7 +23,7 @@ public class CodeListSuperBeanTest { @BeforeEach public void setup() { - codelistBean = buildCodelist(10).getImmutableInstance(); + codelistBean = buildCodelist(50_000).getImmutableInstance(); codelistSuperBean = new CodelistSuperBeanImpl(codelistBean); } @@ -40,7 +41,7 @@ public void shouldCheckExceptionForInvalidCodeId() { public void shouldCheckNumberOfCodes() { List codesWithoutParent = codelistBean.getItems().stream() .filter(code -> code.getParentCode() == null) - .collect(toList()); + .toList(); assertEquals(codesWithoutParent.size(), codelistSuperBean.getCodes().size()); } From 37ad66df752bcb42674a75006891c3283e06b955 Mon Sep 17 00:00:00 2001 From: Oleksandr Buhaiov Date: Thu, 21 Aug 2025 11:27:30 +0300 Subject: [PATCH 3/4] Fix performance of CodeBean instantiation with large number of child codes --- .../sdmxsource/sdmx/sdmxbeans/test/CodeListSuperBeanTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SdmxBeans/src/test/java/org/sdmxsource/sdmx/sdmxbeans/test/CodeListSuperBeanTest.java b/SdmxBeans/src/test/java/org/sdmxsource/sdmx/sdmxbeans/test/CodeListSuperBeanTest.java index 846a6d0..646be89 100644 --- a/SdmxBeans/src/test/java/org/sdmxsource/sdmx/sdmxbeans/test/CodeListSuperBeanTest.java +++ b/SdmxBeans/src/test/java/org/sdmxsource/sdmx/sdmxbeans/test/CodeListSuperBeanTest.java @@ -23,7 +23,7 @@ public class CodeListSuperBeanTest { @BeforeEach public void setup() { - codelistBean = buildCodelist(50_000).getImmutableInstance(); + codelistBean = buildCodelist(5_000).getImmutableInstance(); codelistSuperBean = new CodelistSuperBeanImpl(codelistBean); } From af875cdaadcd92e8b27883ecd6926381a11cfe0c Mon Sep 17 00:00:00 2001 From: Oleksandr Buhaiov Date: Thu, 21 Aug 2025 11:38:20 +0300 Subject: [PATCH 4/4] fix codestyle --- .../sdmxbeans/model/beans/codelist/CodelistBeanImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SdmxBeans/src/main/java/org/sdmxsource/sdmx/sdmxbeans/model/beans/codelist/CodelistBeanImpl.java b/SdmxBeans/src/main/java/org/sdmxsource/sdmx/sdmxbeans/model/beans/codelist/CodelistBeanImpl.java index 56bbdb1..6e5f276 100644 --- a/SdmxBeans/src/main/java/org/sdmxsource/sdmx/sdmxbeans/model/beans/codelist/CodelistBeanImpl.java +++ b/SdmxBeans/src/main/java/org/sdmxsource/sdmx/sdmxbeans/model/beans/codelist/CodelistBeanImpl.java @@ -78,7 +78,7 @@ public CodelistBeanImpl(CodelistMutableBean codelist) { try { if (codelist.getItems() != null) { for (CodeMutableBean mutableCode : codelist.getItems()) { - final var code = new CodeBeanImpl(this, mutableCode); + var code = new CodeBeanImpl(this, mutableCode); this.items.add(code); this.codeMap.put(code.getId(), code); } @@ -188,7 +188,7 @@ public CodelistBeanImpl(CodeListType bean) { try { for (CodeType currentCode : bean.getCodeList()) { - CodeBeanImpl code = new CodeBeanImpl(this, currentCode); + var code = new CodeBeanImpl(this, currentCode); items.add(code); codeMap.put(code.getId(), code); } @@ -220,7 +220,7 @@ public CodelistBeanImpl(CodelistType bean) { try { for (org.sdmx.resources.sdmxml.schemas.v21.structure.CodeType currentCode : bean.getCodeList()) { - CodeBeanImpl code = new CodeBeanImpl(this, currentCode); + var code = new CodeBeanImpl(this, currentCode); items.add(code); codeMap.put(code.getId(), code); }