Mercurial > hg > orthanc-databases
diff Framework/PostgreSQL/PostgreSQLDatabase.cpp @ 12:41543239072d
transactions for storage area
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 09 Jul 2018 18:34:56 +0200 |
parents | 7cea966b6829 |
children | b2ff1cd2907a |
line wrap: on
line diff
--- a/Framework/PostgreSQL/PostgreSQLDatabase.cpp Mon Jul 09 11:45:52 2018 +0200 +++ b/Framework/PostgreSQL/PostgreSQLDatabase.cpp Mon Jul 09 18:34:56 2018 +0200 @@ -96,26 +96,25 @@ LOG(ERROR) << "PostgreSQL error: " << message; throw Orthanc::OrthancException(Orthanc::ErrorCode_DatabaseUnavailable); } + } - if (parameters_.HasLock()) - { - PostgreSQLTransaction transaction(*this); - int32_t lock = 42; // Some arbitrary constant + void PostgreSQLDatabase::AdvisoryLock(int32_t lock) + { + PostgreSQLTransaction transaction(*this); - PostgreSQLStatement s(*this, "select pg_try_advisory_lock(" + - boost::lexical_cast<std::string>(lock) + ");"); + PostgreSQLStatement s(*this, "select pg_try_advisory_lock(" + + boost::lexical_cast<std::string>(lock) + ");"); - PostgreSQLResult result(s); - if (result.IsDone() || - !result.GetBoolean(0)) - { - LOG(ERROR) << "The PostgreSQL database is locked by another instance of Orthanc"; - throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); - } + PostgreSQLResult result(s); + if (result.IsDone() || + !result.GetBoolean(0)) + { + LOG(ERROR) << "The PostgreSQL database is locked by another instance of Orthanc"; + throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); + } - transaction.Commit(); - } + transaction.Commit(); }