]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
[EDF17719] : When comparison fails do not loose the content of data
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 7 Sep 2018 07:11:12 +0000 (09:11 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 7 Sep 2018 07:11:12 +0000 (09:11 +0200)
src/SALOMESDS/SALOMESDS_Exception.hxx
src/SALOMESDS/SALOMESDS_Sha1Keeper.cxx
src/SALOMESDS/SALOMESDS_Transaction.cxx
src/SALOMESDS/SALOMESDS_Transaction.hxx
src/SALOMESDS/TestSalomeSDS.py

index 61b77f33a86f5438cbc061207a3aa57769275504..9ad7dc37142c302b0fd5ff19785dc901f97c9ecf 100644 (file)
@@ -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
index 8f63555db49fdffba2ed8c47e8eb29c6cc60a015..4513da931c2a546b079792d637ca558f18c5e937 100644 (file)
@@ -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());
     }
 }
index 61e720a3c3da984a088c640b5d811741ea176bcc..cff92a346264c47ffee6b94cc441ec79c25f9cae 100644 (file)
@@ -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()
index 3ddbc82046a7595931b6580ce95555e160ca3a8e..7c9924677c8b0d363d10c20fe706f55c2b749a1b 100644 (file)
@@ -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<unsigned char> _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;
   };
 }
 
index a9458376a7b0a347388a219326803b7f5bbe72e5..d0d5b990599ec66214fe3be4c8a26505ac3e884a 100644 (file)
@@ -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):