From d2b5b2d7a2d9890a77ce99e2c6bcb0fe33b69217 Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Thu, 10 Feb 2011 14:24:37 +0000 Subject: [PATCH] LMS-1995 strange bug concerning update with data set size = null fixed SVN: 19882 --- .../server/dataaccess/db/ExternalDataDAO.java | 23 ++++++++++++++----- .../dataaccess/db/ExternalDataDAOTest.java | 15 ++++++++++-- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/ExternalDataDAO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/ExternalDataDAO.java index 1022053cb89..ae11cac8775 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/ExternalDataDAO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/ExternalDataDAO.java @@ -363,12 +363,23 @@ final class ExternalDataDAO extends AbstractGenericEntityWithPropertiesDAO<Exter Long fileFormatTypeID = externalData.getFileFormatType().getId(); char complete = externalData.getComplete().name().charAt(0); Long storageFormatTermID = externalData.getStorageFormatVocabularyTerm().getId(); - executeUpdate( - "insert into " - + TableNames.EXTERNAL_DATA_TABLE - + " (data_id, share_id, location, size, loty_id, ffty_id, is_complete, cvte_id_stor_fmt) " - + "values (?, ?, ?, ?, ?, ?, ?, ?)", id, shareId, location, size, - locatorTypeID, fileFormatTypeID, complete, storageFormatTermID); + if (size == null) + { + executeUpdate( + "insert into " + + TableNames.EXTERNAL_DATA_TABLE + + " (data_id, share_id, location, loty_id, ffty_id, is_complete, cvte_id_stor_fmt) " + + "values (?, ?, ?, ?, ?, ?, ?)", id, shareId, location, + locatorTypeID, fileFormatTypeID, complete, storageFormatTermID); + } else + { + executeUpdate( + "insert into " + + TableNames.EXTERNAL_DATA_TABLE + + " (data_id, share_id, location, size, loty_id, ffty_id, is_complete, cvte_id_stor_fmt) " + + "values (?, ?, ?, ?, ?, ?, ?, ?)", id, shareId, location, size, + locatorTypeID, fileFormatTypeID, complete, storageFormatTermID); + } hibernateTemplate.evict(loaded); } hibernateTemplate.update(externalData); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/ExternalDataDAOTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/ExternalDataDAOTest.java index 9760c4fae7c..fbc94392c1b 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/ExternalDataDAOTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/ExternalDataDAOTest.java @@ -155,7 +155,18 @@ public final class ExternalDataDAOTest extends AbstractDAOTest } @Test - public void testUpdateDataSetAquiredFromSample() + public void testUpdateDataSetAquiredFromSampleWithoutDataSetSize() + { + checkUpdate(null); + } + + @Test + public void testUpdateDataSetAquiredFromSampleWithDataSetSize() + { + checkUpdate(4711L); + } + + private void checkUpdate(Long size) { IExternalDataDAO externalDataDAO = daoFactory.getExternalDataDAO(); DataPE data = new DataPE(); @@ -180,7 +191,7 @@ public final class ExternalDataDAOTest extends AbstractDAOTest externalData.setLocatorType(pickALocatorType()); externalData.setLocation("abcd"); externalData.setShareId("share-42"); - externalData.setSize(4711L); + externalData.setSize(size); externalData.setComplete(BooleanOrUnknown.U); externalData.setStorageFormatVocabularyTerm(pickAStorageFormatVocabularyTerm()); externalData.setPlaceholder(true); -- GitLab