crawlserv++  [under development]
Application for crawling and analyzing textual content of websites.
crawlservpp::Wrapper::DatabaseTryLock< DB > Class Template Reference

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

The class is not copyable, only moveable.

 DatabaseTryLock (DatabaseTryLock &)=delete
 Deleted copy constructor. More...
 
DatabaseTryLockoperator= (DatabaseTryLock &)=delete
 Deleted copy assignment operator. More...
 
 DatabaseTryLock (DatabaseTryLock &&other) noexcept
 Move constructor. More...
 
DatabaseTryLockoperator= (DatabaseTryLock &&other) noexcept
 Move assignment operator. More...
 

Detailed Description

template<class DB>
class crawlservpp::Wrapper::DatabaseTryLock< DB >

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.

Template Parameters
DBDatabase connection to be used for the lock. Must implement the member functions tryDatabaseLock() and removeDatabaseLock(), i.e. inherit from Main::Database.

Constructor & Destructor Documentation

◆ DatabaseTryLock() [1/3]

template<class DB >
crawlservpp::Wrapper::DatabaseTryLock< DB >::DatabaseTryLock ( DB &  db,
const std::string &  lockName 
)
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.

Parameters
dbThe database connection to use.
lockNameThe 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().

◆ ~DatabaseTryLock()

template<class DB >
virtual crawlservpp::Wrapper::DatabaseTryLock< DB >::~DatabaseTryLock ( )
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.

◆ DatabaseTryLock() [2/3]

template<class DB >
crawlservpp::Wrapper::DatabaseTryLock< DB >::DatabaseTryLock ( DatabaseTryLock< DB > &  )
delete

Deleted copy constructor.

◆ DatabaseTryLock() [3/3]

template<class DB >
crawlservpp::Wrapper::DatabaseTryLock< DB >::DatabaseTryLock ( DatabaseTryLock< DB > &&  other)
inlinenoexcept

Move constructor.

Moves the database lock from the specified location into this instance of the class.

Note
The other lock will be invalidated by this move.
Parameters
otherThe database lock to move from.

Member Function Documentation

◆ isActive()

template<class DB >
bool crawlservpp::Wrapper::DatabaseTryLock< DB >::isActive ( ) const
inlinenoexcept

Checks the status of the database lock.

Returns
True if the lock is active. False if not.

References crawlservpp::Wrapper::DatabaseTryLock< DB >::DatabaseTryLock(), and crawlservpp::Wrapper::DatabaseTryLock< DB >::operator=().

Referenced by crawlservpp::Module::Crawler::Thread::onReset().

◆ operator=() [1/2]

template<class DB >
DatabaseTryLock& crawlservpp::Wrapper::DatabaseTryLock< DB >::operator= ( DatabaseTryLock< DB > &  )
delete

Deleted copy assignment operator.

Referenced by crawlservpp::Wrapper::DatabaseTryLock< DB >::isActive().

◆ operator=() [2/2]

template<class DB >
DatabaseTryLock& crawlservpp::Wrapper::DatabaseTryLock< DB >::operator= ( DatabaseTryLock< DB > &&  other)
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.

Note
The other lock will be invalidated by this move.
Nothing will be done if used on itself.
Parameters
otherThe database lock to move from.
Returns
A reference to the instance containing the database lock after moving (i.e. *this).

The documentation for this class was generated from the following file: