crawlserv++
[under development]
Application for crawling and analyzing textual content of websites.
|
Template class for safe in-scope database locks. More...
#include <DatabaseTryLock.hpp>
Construction and Destruction | |
DatabaseTryLock (DB &db, const std::string &lockName) | |
Constructor locking the database if it is not already locked. More... | |
virtual | ~DatabaseTryLock () |
Destructor unlocking the database if necessary. More... | |
Getter | |
bool | isActive () const noexcept |
Checks the status of the database lock. More... | |
Copy and Move | |
DatabaseTryLock (DatabaseTryLock &)=delete | |
Deleted copy constructor. More... | |
DatabaseTryLock & | operator= (DatabaseTryLock &)=delete |
Deleted copy assignment operator. More... | |
DatabaseTryLock (DatabaseTryLock &&other) noexcept | |
Move constructor. More... | |
DatabaseTryLock & | operator= (DatabaseTryLock &&other) noexcept |
Move assignment operator. More... | |
Template class for safe in-scope database locks.
Locks the database for specific actions on construction if not locked already, unlocks it on destruction if necessary.
DB | Database connection to be used for the lock. Must implement the member functions tryDatabaseLock() and removeDatabaseLock(), i.e. inherit from Main::Database. |
|
inline |
Constructor locking the database if it is not already locked.
If no other lock with the same name is active, the database will be locked by calling an implementation of Main::Database::tryDatabaseLock.
Otherwise, the constructor will not lock the database. Use isActive() to check whether it was locked or not.
db | The database connection to use. |
lockName | The name of the lock. If there is another DatabaseLock active with the same name, the constructor will wait until it is destructed. |
Referenced by crawlservpp::Wrapper::DatabaseTryLock< DB >::isActive().
|
inlinevirtual |
Destructor unlocking the database if necessary.
If the constructor was successful in locking the database, the lock will be removed by calling an implementation of Main::Database::removeDatabaseLock.
|
delete |
Deleted copy constructor.
|
inlinenoexcept |
Move constructor.
Moves the database lock from the specified location into this instance of the class.
other | The database lock to move from. |
|
inlinenoexcept |
Checks the status of the database lock.
References crawlservpp::Wrapper::DatabaseTryLock< DB >::DatabaseTryLock(), and crawlservpp::Wrapper::DatabaseTryLock< DB >::operator=().
Referenced by crawlservpp::Module::Crawler::Thread::onReset().
|
delete |
Deleted copy assignment operator.
Referenced by crawlservpp::Wrapper::DatabaseTryLock< DB >::isActive().
|
inlinenoexcept |
Move assignment operator.
Moves the database lock from the specified location into this instance of the class.
If the current instance already holds a database lock, it will be released before moving in the other lock.
other | The database lock to move from. |