From 0c720c5f866a25b1d5861d8588a2b70ca4d6ef7d Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 7 Sep 2018 09:11:12 +0200 Subject: [PATCH] [EDF17719] : When comparison fails do not loose the content of data --- src/SALOMESDS/SALOMESDS_Exception.hxx | 7 ++++ src/SALOMESDS/SALOMESDS_Sha1Keeper.cxx | 8 ++-- src/SALOMESDS/SALOMESDS_Transaction.cxx | 16 ++++++- src/SALOMESDS/SALOMESDS_Transaction.hxx | 56 +++++++++++++------------ src/SALOMESDS/TestSalomeSDS.py | 2 +- 5 files changed, 56 insertions(+), 33 deletions(-) diff --git a/src/SALOMESDS/SALOMESDS_Exception.hxx b/src/SALOMESDS/SALOMESDS_Exception.hxx index 61b77f33a..9ad7dc371 100644 --- a/src/SALOMESDS/SALOMESDS_Exception.hxx +++ b/src/SALOMESDS/SALOMESDS_Exception.hxx @@ -38,6 +38,13 @@ namespace SALOMESDS private: void assign(const char *reason); }; + + class SALOMESDS_EXPORT NotSameException : public Exception + { + public: + NotSameException(const std::string& reason):Exception(reason) { } + NotSameException(const char *reason):Exception(reason) { } + }; } #endif diff --git a/src/SALOMESDS/SALOMESDS_Sha1Keeper.cxx b/src/SALOMESDS/SALOMESDS_Sha1Keeper.cxx index 8f63555db..4513da931 100644 --- a/src/SALOMESDS/SALOMESDS_Sha1Keeper.cxx +++ b/src/SALOMESDS/SALOMESDS_Sha1Keeper.cxx @@ -28,22 +28,22 @@ void SALOMESDS::Sha1Keeper::checkSame(const std::string& varName,const std::stri if(compareFuncContent!=_cmp_func_content) { std::ostringstream oss; oss << "PickelizedPyObjRdExtFreeStyleServer::checkSame : content of compare func are not exactly the same ! It should !"; - throw Exception(oss.str()); + throw NotSameException(oss.str()); } SALOME::AutoPyRef resu(PyObject_CallFunctionObjArgs(_cmp_func,oldObj,newObj,nullptr)); if(resu.isNull()) { std::ostringstream oss; oss << "PickelizedPyObjRdExtFreeStyleServer::checkSame : evaluation of function failed !"; - throw Exception(oss.str()); + throw NotSameException(oss.str()); } if(resu.get()!=Py_False && resu.get()!=Py_True) { std::ostringstream oss; oss << "PickelizedPyObjRdExtFreeStyleServer::checkSame : evaluation of function is OK but a boolean is expected !"; - throw Exception(oss.str()); + throw NotSameException(oss.str()); } if(resu.get()==Py_False) { std::ostringstream oss; oss << "PickelizedPyObjRdExtFreeStyleServer::checkSame : comparison function returns False. 2 pybjects are considered different -> createRdExtVarFreeStyleTransac fails !"; - throw Exception(oss.str()); + throw NotSameException(oss.str()); } } diff --git a/src/SALOMESDS/SALOMESDS_Transaction.cxx b/src/SALOMESDS/SALOMESDS_Transaction.cxx index 61e720a3c..cff92a346 100644 --- a/src/SALOMESDS/SALOMESDS_Transaction.cxx +++ b/src/SALOMESDS/SALOMESDS_Transaction.cxx @@ -115,11 +115,25 @@ void TransactionRdExtVarFreeStyleCreate::prepareRollBackInCaseOfFailure() {//nothing it is not a bug } +void TransactionRdExtVarFreeStyleCreate::rollBack() +{// nothing to be done here. Fress style means I don t care. Do not remove var. + if(!_null_rollback) + TransactionRdExtVarCreate::rollBack(); +} + void TransactionRdExtVarFreeStyleCreate::perform() { SALOME::ByteVec data2; FromVBToByteSeq(_data,data2); - _dsct->createRdExtVarFreeStyleInternal(_var_name,data2,std::move(_cmp_func_content),std::move(_cmp_func)); + try + { + _dsct->createRdExtVarFreeStyleInternal(_var_name,data2,std::move(_cmp_func_content),std::move(_cmp_func)); + } + catch(NotSameException& e) + { + _null_rollback = true; + throw e; + } } void TransactionRdExtInitVarCreate::perform() diff --git a/src/SALOMESDS/SALOMESDS_Transaction.hxx b/src/SALOMESDS/SALOMESDS_Transaction.hxx index 3ddbc8204..7c9924677 100644 --- a/src/SALOMESDS/SALOMESDS_Transaction.hxx +++ b/src/SALOMESDS/SALOMESDS_Transaction.hxx @@ -63,9 +63,9 @@ namespace SALOMESDS { public: TransactionVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue); - void prepareRollBackInCaseOfFailure(); - void rollBack(); - void notify(); + void prepareRollBackInCaseOfFailure() override; + void rollBack() override; + void notify() override; protected: std::vector _data; }; @@ -81,16 +81,18 @@ namespace SALOMESDS { public: TransactionRdExtVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):TransactionVarCreate(dsct,varName,constValue) { } - void perform(); + void perform() override; }; class TransactionRdExtVarFreeStyleCreate : public TransactionRdExtVarCreate { public: TransactionRdExtVarFreeStyleCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue, const char *compareFuncContent); - void prepareRollBackInCaseOfFailure(); - void perform(); + void prepareRollBackInCaseOfFailure() override; + void rollBack() override; + void perform() override; protected: + bool _null_rollback = false; std::string _cmp_func_content; SALOME::AutoPyRef _cmp_func; }; @@ -99,24 +101,24 @@ namespace SALOMESDS { public: TransactionRdExtInitVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):TransactionVarCreate(dsct,varName,constValue) { } - void perform(); + void perform() override; }; class TransactionRdWrVarCreate : public TransactionVarCreate { public: TransactionRdWrVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):TransactionVarCreate(dsct,varName,constValue) { } - void perform(); + void perform() override; }; class TransactionKillVar : public Transaction { public: TransactionKillVar(DataScopeServerTransaction *dsct, const std::string& varName); - void prepareRollBackInCaseOfFailure(); - void perform(); - void rollBack(); - void notify(); + void prepareRollBackInCaseOfFailure() override; + void perform() override; + void rollBack() override; + void notify() override; }; class PickelizedPyObjServer; @@ -126,8 +128,8 @@ namespace SALOMESDS public: TransactionDictModify(DataScopeServerTransaction *dsct, const std::string& varName); PickelizedPyObjServer *checkVarExistingAndDict() { return _dsct->checkVarExistingAndDict(_var_name); } - void prepareRollBackInCaseOfFailure(); - void rollBack(); + void prepareRollBackInCaseOfFailure() override; + void rollBack() override; protected: std::string _zeDataBefore; PickelizedPyObjServer *_varc; @@ -137,8 +139,8 @@ namespace SALOMESDS { public: TransactionAddKeyValue(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value); - void prepareRollBackInCaseOfFailure(); - void notify(); + void prepareRollBackInCaseOfFailure() override; + void notify() override; ~TransactionAddKeyValue(); protected: PyObject *_key; @@ -149,22 +151,22 @@ namespace SALOMESDS { public: TransactionAddKeyValueHard(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value); - void perform(); + void perform() override; }; class TransactionAddKeyValueErrorIfAlreadyExisting : public TransactionAddKeyValue { public: TransactionAddKeyValueErrorIfAlreadyExisting(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value); - void perform(); + void perform() override; }; class TransactionRemoveKeyInVarErrorIfNotAlreadyExisting : public TransactionDictModify { public: TransactionRemoveKeyInVarErrorIfNotAlreadyExisting(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key); - void perform(); - void notify(); + void perform() override; + void notify() override; ~TransactionRemoveKeyInVarErrorIfNotAlreadyExisting(); private: PyObject *_key; @@ -178,9 +180,9 @@ namespace SALOMESDS SALOME::PickelizedPyObjRdWrServer_ptr getVar(); public: void prepareRollBackInCaseOfFailure(); - void perform(); - void rollBack(); - void notify(); + void perform() override; + void rollBack() override; + void notify() override; }; /*! @@ -193,10 +195,10 @@ namespace SALOMESDS public://remotely callable void addKeyValueInVarErrorIfAlreadyExistingNow(const SALOME::ByteVec& key, const SALOME::ByteVec& value); public: - void prepareRollBackInCaseOfFailure(); - void perform(); - void rollBack(); - void notify(); + void prepareRollBackInCaseOfFailure() override; + void perform() override; + void rollBack() override; + void notify() override; }; } diff --git a/src/SALOMESDS/TestSalomeSDS.py b/src/SALOMESDS/TestSalomeSDS.py index a9458376a..d0d5b9905 100644 --- a/src/SALOMESDS/TestSalomeSDS.py +++ b/src/SALOMESDS/TestSalomeSDS.py @@ -382,7 +382,7 @@ class SalomeSDSTest(unittest.TestCase): self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value3) t4=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),funcContent) self.assertRaises(SALOME.SALOME_Exception,dss.atomicApply,[t4]) # d is in dict pointed by var. Func returns false -> rejected - self.assertRaises(SALOME.SALOME_Exception,dss.fetchSerializedContent,varName) # creation in the previous line fails -> the var has been removed + self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value3) pass def testTransaction9(self): -- 2.39.2