UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
qsql_impl.hpp
1 /* qsql_impl.hpp */
2 /* $Id$ */
3 #ifndef __hds_db_qsql_impl_hpp
4 #define __hds_db_qsql_impl_hpp
5 
6 #include <hds_db/base/seismic.hpp>
7 #include <hds_db/qsql/dbcontext_qsql.hpp>
8 #include <QSqlDatabase>
9 
10 class QMutex;
11 
13 namespace hds
14 {
16  namespace db
17  {
19  class QSqlImpl
20  {
21  public:
22 
25  {
26  TLT_READ = 0,
28  };
29 
30 
33  {
35  type(TLT_READ)
36  { /* nothing to do */}
37 
38  TableLockDescr(const TableLockType &i_type,
39  const std::string &i_table_name):
40  type(i_type), table_name(i_table_name)
41  { /* nothing to do */}
42 
44  std::string table_name;
45  };
46 
48  typedef std::vector<TableLockDescr> TLDVec;
49 
50 
52  QSqlImpl();
53 
55  QSqlImpl(const ContextQSql &dbc);
56 
58  virtual ~QSqlImpl();
59 
60 
62  const ContextQSql& getDbContext() const {return m_dbc;}
63 
65  QSqlDatabase& getDb() {return m_db;}
66 
68  bool supportTransactionsFlag() const;
69 
72  ErrCode dbConnect() const;
73 
74 
76  QMutex& getDefaultMutex() const;
77 
78  protected:
79 
81  mutable QSqlDatabase m_db;
82 
85 
87  mutable bool m_is_transaction_started;
88 
89 
92  ErrCode db_init(const hds::db::ContextQSql &context);
93 
96  ErrCode db_close(const hds::db::ContextQSql &context);
97 
98 
100  ErrCode db_lock_tables(const TLDVec &tld_vec);
101 
104 
105 
110  ErrCode db_get_lock(const std::string &lock_name,
111  const size_t timeout = 3) const;
112 
116  ErrCode db_release_lock(const std::string &lock_name) const;
117 
120  ErrCode db_set_item_value(const std::string &table_name,
121  const std::string &field_name,
122  const std::string &key_name,
123  const DbIndex &key_id,
124  const std::string &value);
125 
128  ErrCode db_get_item_value(const std::string &table_name,
129  const std::string &field_name,
130  const std::string &key_name,
131  const DbIndex &key_id,
132  std::string &value) const;
133 
139  time_t db_table_creation_time(const std::string &table_name,
140  ErrCode *prc = NULL) const;
141 
147  time_t db_table_modification_time(const std::string &table_name,
148  ErrCode *prc = NULL) const;
149 
155  quint64 db_table_size(const std::string &table_name, ErrCode *prc = NULL) const;
156 
161  size_t db_table_rows_num(const std::string &table_name, ErrCode *prc = NULL) const;
162 
168 
174 
180 
181 
183  QString get_db_name_hash(const hds::db::ContextQSql &context) const;
184  };
185  };
186 };
187 
188 #endif /* __hds_db_qsql_impl_hpp */
ErrCode db_get_item_value(const std::string &table_name, const std::string &field_name, const std::string &key_name, const DbIndex &key_id, std::string &value) const
time_t db_table_modification_time(const std::string &table_name, ErrCode *prc=NULL) const
time_t db_table_creation_time(const std::string &table_name, ErrCode *prc=NULL) const
Definition: qsql_impl.hpp:26
virtual ~QSqlImpl()
ErrCode db_transaction_rollback()
size_t db_table_rows_num(const std::string &table_name, ErrCode *prc=NULL) const
Definition: dbcontext_qsql.hpp:15
uint64_t DbIndex
Definition: defines.hpp:26
ErrCode db_transaction_commit()
TableLockType
Definition: qsql_impl.hpp:24
ErrCode db_lock_tables(const TLDVec &tld_vec)
ErrCode db_set_item_value(const std::string &table_name, const std::string &field_name, const std::string &key_name, const DbIndex &key_id, const std::string &value)
ContextQSql m_dbc
Definition: qsql_impl.hpp:84
Definition: qsql_impl.hpp:32
ErrCode
Definition: defines.hpp:46
quint64 db_table_size(const std::string &table_name, ErrCode *prc=NULL) const
ErrCode db_release_lock(const std::string &lock_name) const
ErrCode db_close(const hds::db::ContextQSql &context)
std::string table_name
Definition: qsql_impl.hpp:44
const ContextQSql & getDbContext() const
Definition: qsql_impl.hpp:62
std::vector< TableLockDescr > TLDVec
Definition: qsql_impl.hpp:48
QSqlDatabase m_db
Definition: qsql_impl.hpp:81
TableLockType type
Definition: qsql_impl.hpp:43
ErrCode db_init(const hds::db::ContextQSql &context)
QSqlDatabase & getDb()
Definition: qsql_impl.hpp:65
QMutex & getDefaultMutex() const
Definition: qsql_impl.hpp:19
ErrCode db_transaction_begin() const
QString get_db_name_hash(const hds::db::ContextQSql &context) const
bool supportTransactionsFlag() const
ErrCode db_get_lock(const std::string &lock_name, const size_t timeout=3) const
ErrCode dbConnect() const
Definition: qsql_impl.hpp:27
ErrCode db_release_tables_locks()