0031013: Application Framework - Storage status is wrong after a failure
[occt.git] / src / CDF / CDF_StoreList.cxx
index 619af20..91149ae 100644 (file)
@@ -20,7 +20,6 @@
 #include <CDF_MetaDataDriverError.hxx>
 #include <CDF_Session.hxx>
 #include <CDF_StoreList.hxx>
-#include <CDF_Timer.hxx>
 #include <CDM_Document.hxx>
 #include <CDM_MetaData.hxx>
 #include <CDM_ReferenceIterator.hxx>
 #include <PCDM_Document.hxx>
 #include <PCDM_StorageDriver.hxx>
 #include <Standard_ErrorHandler.hxx>
-#include <Standard_Macro.hxx>
 #include <Standard_NoSuchObject.hxx>
-#include <Standard_Type.hxx>
 #include <TCollection_ExtendedString.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(CDF_StoreList,Standard_Transient)
 
-static void CAUGHT(TCollection_ExtendedString& status,const TCollection_ExtendedString& what) {
-  Handle(Standard_Failure) F = Standard_Failure::Caught();
+static void CAUGHT(const Standard_Failure& theException,TCollection_ExtendedString& status,const TCollection_ExtendedString& what) {
   status += what;
-  status += F->GetMessageString();
+  status += theException.GetMessageString();
 }
 
 CDF_StoreList::CDF_StoreList(const Handle(CDM_Document)& aDocument) {
@@ -94,7 +90,7 @@ PCDM_StoreStatus CDF_StoreList::Store (Handle(CDM_MetaData)& aMetaData, TCollect
           Handle(CDF_Application) anApp = Handle(CDF_Application)::DownCast (theDocument->Application());
           if (anApp.IsNull())
           {
-            Standard_Failure::Raise("Document has no application, cannot save!");
+            throw Standard_Failure("Document has no application, cannot save!");
           }
           Handle(PCDM_StorageDriver) aDocumentStorageDriver = 
             anApp->WriterFromFormat(theDocument->StorageFormat());
@@ -102,25 +98,23 @@ PCDM_StoreStatus CDF_StoreList::Store (Handle(CDM_MetaData)& aMetaData, TCollect
           {
             Standard_SStream aMsg;
             aMsg <<"No storage driver does exist for this format: " << theDocument->StorageFormat() << (char)0;
-            Standard_Failure::Raise(aMsg);
+            throw Standard_Failure(aMsg.str().c_str());
           }
 
+          // Reset the store-status.
+          // It has sense in multi-threaded access to the storage driver - this way we reset the status for each call.
+          aDocumentStorageDriver->SetStoreStatus(PCDM_SS_OK);
+
           if(!theMetaDataDriver->FindFolder(theDocument->RequestedFolder())) {
             Standard_SStream aMsg; aMsg << "could not find the active dbunit";
             aMsg << TCollection_ExtendedString(theDocument->RequestedFolder())<< (char)0;
-            Standard_NoSuchObject::Raise(aMsg);
+            throw Standard_NoSuchObject(aMsg.str().c_str());
           }
           TCollection_ExtendedString theName=theMetaDataDriver->BuildFileName(theDocument);
 
-          CDF_Timer theTimer;
           aDocumentStorageDriver->Write(theDocument,theName);
           status = aDocumentStorageDriver->GetStoreStatus();
-
-          theTimer.ShowAndRestart("Driver->Write: ");
-
           aMetaData = theMetaDataDriver->CreateMetaData(theDocument,theName);
-          theTimer.ShowAndStop("metadata creating: ");
-
           theDocument->SetMetaData(aMetaData);
 
           CDM_ReferenceIterator it(theDocument);
@@ -131,12 +125,12 @@ PCDM_StoreStatus CDF_StoreList::Store (Handle(CDM_MetaData)& aMetaData, TCollect
       }
     }
 
-    catch (CDF_MetaDataDriverError) {
-      CAUGHT(aStatusAssociatedText,TCollection_ExtendedString("metadatadriver failed; reason:"));
+    catch (CDF_MetaDataDriverError const& anException) {
+      CAUGHT(anException, aStatusAssociatedText, TCollection_ExtendedString("metadatadriver failed; reason:"));
       status = PCDM_SS_DriverFailure;
     }
-    catch (Standard_Failure) {
-      CAUGHT(aStatusAssociatedText,TCollection_ExtendedString("driver failed; reason:"));
+    catch (Standard_Failure const& anException) {
+      CAUGHT(anException, aStatusAssociatedText, TCollection_ExtendedString("driver failed; reason:"));
       status = PCDM_SS_Failure; 
     }
   }