UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
locker_qsql.hpp
1 /* qsql_locker.hpp */
2 /* $Id$ */
3 #ifndef __locker_qsql_hpp
4 #define __locker_qsql_hpp
5 
6 #include <QSqlQuery>
7 #include <hds_db/base/locker.hpp>
8 #include <hds_db/qsql/qsql_impl.hpp>
9 
11 namespace hds
12 {
14  namespace db
15  {
17  class LockerQSql : public Locker, public QSqlImpl
18  {
19  public:
20 
31  LockerQSql(const QSqlDatabase &db,
32  const std::string &name = "hds_db_locker",
33  const size_t timeout = 1);
34 
46  LockerQSql(const ContextQSql &dbc,
47  const std::string &name = "hds_db_locker",
48  const size_t timeout = 1);
49 
51  virtual ~LockerQSql();
52 
61  virtual DbIndex lock(const LockDescription &ld);
62 
67  virtual void release(const DbIndex &id);
68 
74  virtual size_t releaseAll();
75 
81  virtual void list(LockDescriptionVec &locks);
82 
83 
85  virtual ErrCode lastError() const;
86 
87  protected:
88 
94  ErrCode init(const std::string &mutex_name,
95  const size_t timeout);
96 
100 
106  ErrCode db_get_locks_num(const std::string &name,
107  const LockType &lt,
108  unsigned int &locks_num) const;
109 
113 
114  private:
115 
117  std::string m_mutex_name;
118 
120  QSqlQuery m_client_connected_query;
121 
123  QSqlQuery m_del_lock_by_cid_query;
124 
126  QSqlQuery m_locks_list_query;
127 
129  mutable ErrCode m_last_error;
130  };
131  };
132 };
133 
134 #endif /* locker_qsql.hpp */
ErrCode init(const std::string &mutex_name, const size_t timeout)
virtual void list(LockDescriptionVec &locks)
ErrCode db_clear_invalid_locks()
virtual void release(const DbIndex &id)
Definition: dbcontext_qsql.hpp:15
uint64_t DbIndex
Definition: defines.hpp:26
Definition: locker.hpp:50
ErrCode
Definition: defines.hpp:46
virtual ErrCode lastError() const
LockType
Definition: locker.hpp:17
LockerQSql(const QSqlDatabase &db, const std::string &name="hds_db_locker", const size_t timeout=1)
ErrCode db_get_locks_num(const std::string &name, const LockType &lt, unsigned int &locks_num) const
std::vector< LockDescription > LockDescriptionVec
Definition: locker.hpp:47
virtual size_t releaseAll()
Definition: qsql_impl.hpp:19
virtual DbIndex lock(const LockDescription &ld)
Definition: locker.hpp:24
Definition: locker_qsql.hpp:17
ErrCode db_create_locks_table() const