comparison Framework/Common/ImplicitTransaction.cpp @ 28:c0cb5d2cd696

checks depending on Orthanc version
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 16 Jul 2018 14:48:43 +0200
parents 69a94267cdea
children 714c5d2bee76
comparison
equal deleted inserted replaced
27:173176f8cef2 28:c0cb5d2cd696
26 26
27 #include <memory> 27 #include <memory>
28 28
29 namespace OrthancDatabases 29 namespace OrthancDatabases
30 { 30 {
31 static bool isErrorOnDoubleExecution_ = false;
32
33
31 ImplicitTransaction::ImplicitTransaction() : 34 ImplicitTransaction::ImplicitTransaction() :
32 state_(State_Ready), 35 state_(State_Ready),
33 readOnly_(true) 36 readOnly_(true)
34 { 37 {
35 } 38 }
90 case State_Ready: 93 case State_Ready:
91 // OK 94 // OK
92 break; 95 break;
93 96
94 case State_Executed: 97 case State_Executed:
95 #if defined(NDEBUG) 98 if (isErrorOnDoubleExecution_)
96 // Release build. Ignore such errors. 99 {
97 LOG(INFO) << "Cannot execute more than one statement in an implicit transaction"; 100 /**
101 * This allows to detect errors wrt. the handling of
102 * transactions in the Orthanc core.
103 *
104 * In Orthanc <= 1.3.2: problems in "/changes" (a transaction
105 * was missing because of GetPublicId()).
106 **/
107 LOG(ERROR) << "Cannot execute more than one statement in an implicit transaction";
108 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
109 }
110
98 break; 111 break;
99 #else 112
100 /**
101 * Debug build. This allows to detect errors wrt. the handling
102 * of transactions in the Orthanc core.
103 *
104 * In Orthanc <= 1.3.2: problems in "/changes" (a transaction
105 * was missing because of GetPublicId()).
106 **/
107 LOG(ERROR) << "Cannot execute more than one statement in an implicit transaction";
108 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
109 #endif
110
111 case State_Committed: 113 case State_Committed:
112 LOG(ERROR) << "Cannot commit twice an implicit transaction"; 114 LOG(ERROR) << "Cannot commit twice an implicit transaction";
113 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); 115 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
114 116
115 default: 117 default:
145 readOnly_ = false; 147 readOnly_ = false;
146 } 148 }
147 149
148 state_ = State_Executed; 150 state_ = State_Executed;
149 } 151 }
152
153
154 void ImplicitTransaction::SetErrorOnDoubleExecution(bool isError)
155 {
156 isErrorOnDoubleExecution_ = isError;
157 }
158
159
160 bool ImplicitTransaction::IsErrorOnDoubleExecution()
161 {
162 return isErrorOnDoubleExecution_;
163 }
150 } 164 }
151 165