comparison Framework/PostgreSQL/PostgreSQLTransaction.cpp @ 216:fbb52129158a

TransactionType given to PostgreSQLTransaction constructor
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 26 Mar 2021 17:47:56 +0100
parents ab96698c73a3
children d1b124d116c1
comparison
equal deleted inserted replaced
215:b40b30075c51 216:fbb52129158a
27 #include <Logging.h> 27 #include <Logging.h>
28 #include <OrthancException.h> 28 #include <OrthancException.h>
29 29
30 namespace OrthancDatabases 30 namespace OrthancDatabases
31 { 31 {
32 PostgreSQLTransaction::PostgreSQLTransaction(PostgreSQLDatabase& database) : 32 PostgreSQLTransaction::PostgreSQLTransaction(PostgreSQLDatabase& database,
33 TransactionType type) :
33 database_(database), 34 database_(database),
34 isOpen_(false) 35 isOpen_(false)
35 { 36 {
36 Begin(); 37 Begin(type);
37 } 38 }
38 39
39 40
40 PostgreSQLTransaction::~PostgreSQLTransaction() 41 PostgreSQLTransaction::~PostgreSQLTransaction()
41 { 42 {
53 } 54 }
54 } 55 }
55 } 56 }
56 57
57 58
58 void PostgreSQLTransaction::Begin() 59 void PostgreSQLTransaction::Begin(TransactionType type)
59 { 60 {
60 if (isOpen_) 61 if (isOpen_)
61 { 62 {
62 LOG(ERROR) << "PostgreSQL: Beginning a transaction twice!"; 63 LOG(ERROR) << "PostgreSQL: Beginning a transaction twice!";
63 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); 64 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
64 } 65 }
65 66
66 database_.Execute("BEGIN"); 67 database_.Execute("BEGIN");
67 database_.Execute("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE"); 68
69 switch (type)
70 {
71 case TransactionType_ReadWrite:
72 database_.Execute("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ WRITE");
73 break;
74
75 case TransactionType_ReadOnly:
76 database_.Execute("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY");
77 break;
78
79 default:
80 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
81 }
82
68 isOpen_ = true; 83 isOpen_ = true;
69 } 84 }
70 85
71 86
72 void PostgreSQLTransaction::Rollback() 87 void PostgreSQLTransaction::Rollback()