# HG changeset patch # User Alain Mazy # Date 1687523218 -7200 # Node ID 15bfd9a76f8df57548ca081b9e898caff3eb7dba # Parent d2b5d9c922144ce5e96f1a1234cc09003564d548# Parent 6b16914b6655db564fefe52959df65bfe61b74b6 merge diff -r 6b16914b6655 -r 15bfd9a76f8d Framework/PostgreSQL/PostgreSQLDatabase.h --- a/Framework/PostgreSQL/PostgreSQLDatabase.h Thu Jun 22 21:15:50 2023 +0200 +++ b/Framework/PostgreSQL/PostgreSQLDatabase.h Fri Jun 23 14:26:58 2023 +0200 @@ -36,6 +36,7 @@ private: friend class PostgreSQLStatement; friend class PostgreSQLLargeObject; + friend class PostgreSQLTransaction; class Factory; @@ -99,5 +100,17 @@ static IDatabaseFactory* CreateDatabaseFactory(const PostgreSQLParameters& parameters); static PostgreSQLDatabase* CreateDatabaseConnection(const PostgreSQLParameters& parameters); + + protected: + const std::string& GetReadWriteTransactionStatement() const + { + return parameters_.GetReadWriteTransactionStatement(); + } + + const std::string& GetReadOnlyTransactionStatement() const + { + return parameters_.GetReadOnlyTransactionStatement(); + } + }; } diff -r 6b16914b6655 -r 15bfd9a76f8d Framework/PostgreSQL/PostgreSQLParameters.cpp --- a/Framework/PostgreSQL/PostgreSQLParameters.cpp Thu Jun 22 21:15:50 2023 +0200 +++ b/Framework/PostgreSQL/PostgreSQLParameters.cpp Fri Jun 23 14:26:58 2023 +0200 @@ -42,6 +42,8 @@ lock_ = true; maxConnectionRetries_ = 10; connectionRetryInterval_ = 5; + readWriteTransactionStatement_ = "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ WRITE"; + readOnlyTransactionStatement_ = "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY"; } @@ -96,6 +98,17 @@ maxConnectionRetries_ = configuration.GetUnsignedIntegerValue("MaximumConnectionRetries", 10); connectionRetryInterval_ = configuration.GetUnsignedIntegerValue("ConnectionRetryInterval", 5); + + if (configuration.LookupStringValue(s, "ReadWriteTransactionStatement")) + { + SetReadWriteTransactionStatement(s); + } + + if (configuration.LookupStringValue(s, "ReadOnlyTransactionStatement")) + { + SetReadOnlyTransactionStatement(s); + } + } diff -r 6b16914b6655 -r 15bfd9a76f8d Framework/PostgreSQL/PostgreSQLParameters.h --- a/Framework/PostgreSQL/PostgreSQLParameters.h Thu Jun 22 21:15:50 2023 +0200 +++ b/Framework/PostgreSQL/PostgreSQLParameters.h Fri Jun 23 14:26:58 2023 +0200 @@ -43,6 +43,8 @@ bool lock_; unsigned int maxConnectionRetries_; unsigned int connectionRetryInterval_; + std::string readWriteTransactionStatement_; + std::string readOnlyTransactionStatement_; void Reset(); @@ -125,6 +127,26 @@ return connectionRetryInterval_; } + void SetReadWriteTransactionStatement(const std::string& statement) + { + readWriteTransactionStatement_ = statement; + } + + void SetReadOnlyTransactionStatement(const std::string& statement) + { + readOnlyTransactionStatement_ = statement; + } + + const std::string& GetReadWriteTransactionStatement() const + { + return readWriteTransactionStatement_; + } + + const std::string& GetReadOnlyTransactionStatement() const + { + return readOnlyTransactionStatement_; + } + void Format(std::string& target) const; }; } diff -r 6b16914b6655 -r 15bfd9a76f8d Framework/PostgreSQL/PostgreSQLTransaction.cpp --- a/Framework/PostgreSQL/PostgreSQLTransaction.cpp Thu Jun 22 21:15:50 2023 +0200 +++ b/Framework/PostgreSQL/PostgreSQLTransaction.cpp Fri Jun 23 14:26:58 2023 +0200 @@ -70,12 +70,22 @@ switch (type) { case TransactionType_ReadWrite: - database_.ExecuteMultiLines("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ WRITE"); - break; + { + const std::string& statement = database_.GetReadWriteTransactionStatement(); + if (!statement.empty()) // if not defined, will use the default DB transaction isolation level + { + database_.ExecuteMultiLines(statement); + } + }; break; case TransactionType_ReadOnly: - database_.ExecuteMultiLines("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY"); - break; + { + const std::string& statement = database_.GetReadOnlyTransactionStatement(); + if (!statement.empty()) // if not defined, will use the default DB transaction isolation level + { + database_.ExecuteMultiLines(statement); + } + }; break; default: throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); diff -r 6b16914b6655 -r 15bfd9a76f8d PostgreSQL/NEWS --- a/PostgreSQL/NEWS Thu Jun 22 21:15:50 2023 +0200 +++ b/PostgreSQL/NEWS Fri Jun 23 14:26:58 2023 +0200 @@ -13,6 +13,13 @@ * Upgraded dependencies for static builds (notably on Windows and LSB): - openssl 3.1.0 +* Experimental debug feature: + Introduced 2 new configurations with these default values: + "ReadOnlyTransactionStatement": "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY" + "ReadWriteTransactionStatement": "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ WRITE" + You can now customize the transaction isolation level. + If setting these values to "", no statement is run and therefore, the default DB or server + isolation level is used. Release 4.0 (2021-04-22) ========================