diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DataBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DataBO.java index 9242eb6a9d35fc78f67399a6f6510886e1a82768..f6aa3ef979c5d4a1f0e099588ab8871f74b24611 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DataBO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DataBO.java @@ -120,7 +120,7 @@ public class DataBO extends AbstractDataSetBusinessObject implements IDataBO if (dataSetId instanceof DataSetCodeId) { DataSetCodeId codeId = (DataSetCodeId) dataSetId; - return getDataDAO().tryToFindDataSetByCode(codeId.getCode()); + return tryToFindDataSetByCode(codeId.getCode()); } else if (dataSetId instanceof DataSetTechIdId) { DataSetTechIdId techIdId = (DataSetTechIdId) dataSetId; @@ -297,11 +297,11 @@ public class DataBO extends AbstractDataSetBusinessObject implements IDataBO { for (String parentCode : parentDataSetCodes) { - DataPE parent = this.getCache().getParentDataSets().get(parentCode); + DataPE parent = this.getCache().getDataSets().get(parentCode); if (parent == null) { parent = getOrCreateData(parentCode, experiment, sample); - this.getCache().getParentDataSets().put(parentCode, parent); + this.getCache().getDataSets().put(parentCode, parent); } parentsToAdd.add(parent); } @@ -544,7 +544,7 @@ public class DataBO extends AbstractDataSetBusinessObject implements IDataBO assert dataSetCode != null : "Unspecified parent data set code."; final IDataDAO dataDAO = getDataDAO(); - DataPE result = dataDAO.tryToFindDataSetByCode(dataSetCode); + DataPE result = tryToFindDataSetByCode(dataSetCode); if (result == null) { result = new DataPE(); @@ -560,6 +560,17 @@ public class DataBO extends AbstractDataSetBusinessObject implements IDataBO return result; } + private DataPE tryToFindDataSetByCode(final String dataSetCode) + { + DataPE dataSet = this.getCache().getDataSets().get(dataSetCode); + if (dataSet == null) + { + dataSet = getDataDAO().tryToFindDataSetByCode(dataSetCode); + this.getCache().getDataSets().put(dataSetCode, dataSet); + } + return dataSet; + } + @Override public void save() throws UserFailureException { @@ -567,7 +578,7 @@ public class DataBO extends AbstractDataSetBusinessObject implements IDataBO IDataDAO dataDAO = getDataDAO(); String dataCode = data.getCode(); - DataPE placeholder = dataDAO.tryToFindDataSetByCode(dataCode); + DataPE placeholder = tryToFindDataSetByCode(dataCode); if (placeholder == null) { dataDAO.createDataSet(data, findPerson()); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/util/DataSetRegistrationCache.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/util/DataSetRegistrationCache.java index fe18e2ba14d4058c005a3fdd98ecaa2fc7e20a39..75e5db45be6223734491d8cb9961ac03c0ef24a2 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/util/DataSetRegistrationCache.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/util/DataSetRegistrationCache.java @@ -55,11 +55,11 @@ public class DataSetRegistrationCache private Map<EntityTypePE, List<EntityTypePropertyTypePE>> entityTypePropertyTypes = new HashMap<>(); - private Map<String, DataPE> parentDataSets = new HashMap<>(); + private Map<String, DataPE> dataSets = new HashMap<>(); - public Map<String, DataPE> getParentDataSets() + public Map<String, DataPE> getDataSets() { - return parentDataSets; + return dataSets; } public Map<EntityTypePE, List<EntityTypePropertyTypePE>> getEntityTypePropertyTypes() diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DataBOTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DataBOTest.java index 46824dfcf93f4dec66266061529048bbd9c3c6ca..ec65c7bb5e1d1fcccade5dfbf8e06ef0091d4dca 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DataBOTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DataBOTest.java @@ -509,6 +509,13 @@ public class DataBOTest extends AbstractBOTest final DataPE data = new DataPE(); data.setCode(COMPONENT_CODE); data.setExperiment(createExperiment("EXP1", "S2")); + context.checking(new Expectations() + { + { + allowing(dataDAO).tryToFindDataSetByCode(COMPONENT_CODE); + will(returnValue(data)); + } + }); IDataBO dataBO = createDataBO(); NewContainerDataSet newData = createContainerDataSetWithComponents(COMPONENT_CODE); @@ -518,9 +525,6 @@ public class DataBOTest extends AbstractBOTest context.checking(new Expectations() { { - one(dataDAO).tryToFindDataSetByCode(COMPONENT_CODE); - will(returnValue(data)); - one(relationshipService).assignDataSetToContainer(with(EXAMPLE_SESSION), with(data), with(conatinerMatcher)); } }); @@ -532,9 +536,6 @@ public class DataBOTest extends AbstractBOTest context.checking(new Expectations() { { - one(dataDAO).tryToFindDataSetByCode(COMPONENT_CODE); - will(returnValue(data)); - one(relationshipService).assignDataSetToContainer(with(EXAMPLE_SESSION), with(data), with(conatinerMatcher2)); } });