CernVM-FS  2.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
history_sql.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_HISTORY_SQL_H_
6 #define CVMFS_HISTORY_SQL_H_
7 
8 #include <string>
9 
10 #include "history.h"
11 #include "sql.h"
12 
13 namespace history {
14 
20 class HistoryDatabase : public sqlite::Database<HistoryDatabase> {
21  public:
22  static const float kLatestSchema;
23  static const float kLatestSupportedSchema;
24  // backwards-compatible schema changes
25  static const unsigned kLatestSchemaRevision;
26 
27  static const std::string kFqrnKey;
28 
29  bool CreateEmptyDatabase();
30  bool InsertInitialValues(const std::string &repository_name);
31 
32  bool ContainsRecycleBin() const;
33 
36  bool CompactDatabase() const { return true; } // no implementation specific
37  // database compaction.
38  protected:
39  // TODO(rmeusel): C++11 - constructor inheritance
41  HistoryDatabase(const std::string &filename,
42  const OpenMode open_mode) :
43  sqlite::Database<HistoryDatabase>(filename, open_mode) {}
44 
45  private:
46  bool CreateTagsTable();
47  bool CreateRecycleBinTable();
48  bool CreateBranchesTable();
49 
53 };
54 
55 
56 //------------------------------------------------------------------------------
57 
58 
59 class SqlHistory : public sqlite::Sql {};
60 
61 
95 template <class MixinT>
96 class SqlRetrieveTag : public MixinT {
97  public:
105  History::Tag result;
106  result.name = MixinT::RetrieveString(0);
108  shash::HexPtr(MixinT::RetrieveString(1)),
110  result.revision = MixinT::RetrieveInt64(2);
111  result.timestamp = MixinT::RetrieveInt64(3);
112  result.channel = static_cast<History::UpdateChannel>(
113  MixinT::RetrieveInt64(4));
114  result.description = MixinT::RetrieveString(5);
115  result.size = MixinT::RetrieveInt64(6);
116  result.branch = MixinT::RetrieveString(7);
117  return result;
118  }
119 };
120 
121 
122 class SqlInsertTag : public SqlHistory {
123  private:
124  static const std::string db_placeholders;
125 
126  public:
127  explicit SqlInsertTag(const HistoryDatabase *database);
128  bool BindTag(const History::Tag &tag);
129 };
130 
131 
132 class SqlRemoveTag : public SqlHistory {
133  public:
134  explicit SqlRemoveTag(const HistoryDatabase *database);
135  bool BindName(const std::string &name);
136 };
137 
138 
139 class SqlFindTag : public SqlRetrieveTag<SqlHistory> {
140  public:
141  explicit SqlFindTag(const HistoryDatabase *database);
142  bool BindName(const std::string &name);
143 };
144 
145 
146 class SqlFindTagByDate : public SqlRetrieveTag<SqlHistory> {
147  public:
148  explicit SqlFindTagByDate(const HistoryDatabase *database);
149  bool BindTimestamp(const time_t timestamp);
150 };
151 
152 
153 class SqlFindBranchHead : public SqlRetrieveTag<SqlHistory> {
154  public:
155  explicit SqlFindBranchHead(const HistoryDatabase *database);
156  bool BindBranchName(const std::string &branch_name);
157 };
158 
159 
160 class SqlCountTags : public SqlHistory {
161  public:
162  explicit SqlCountTags(const HistoryDatabase *database);
163  unsigned RetrieveCount() const;
164 };
165 
166 
167 class SqlListTags : public SqlRetrieveTag<SqlHistory> {
168  public:
169  explicit SqlListTags(const HistoryDatabase *database);
170 };
171 
172 
173 class SqlGetChannelTips : public SqlRetrieveTag<SqlHistory> {
174  public:
175  explicit SqlGetChannelTips(const HistoryDatabase *database);
176 };
177 
178 
179 class SqlGetHashes : public SqlHistory {
180  public:
181  explicit SqlGetHashes(const HistoryDatabase *database);
182  shash::Any RetrieveHash() const;
183 };
184 
185 
186 class SqlListBranches : public SqlHistory {
187  public:
188  explicit SqlListBranches(const HistoryDatabase *database);
190 };
191 
192 
193 class SqlInsertBranch : public SqlHistory {
194  public:
195  explicit SqlInsertBranch(const HistoryDatabase *database);
196  bool BindBranch(const History::Branch &branch);
197 };
198 
199 
210 template <class MixinT, int offset = 0>
211 class SqlRollback : public MixinT {
212  public:
213  bool BindTargetTag(const History::Tag &target_tag) {
214  return MixinT::BindInt64(offset + 1, target_tag.revision) &&
215  MixinT::BindText(offset + 2, target_tag.name) &&
216  MixinT::BindInt64(offset + 3, target_tag.channel);
217  }
218 };
219 
220 
221 class SqlRollbackTag : public SqlRollback<SqlHistory> {
222  public:
223  explicit SqlRollbackTag(const HistoryDatabase *database);
224 };
225 
226 
227 class SqlListRollbackTags : public SqlRetrieveTag<SqlRollback<SqlHistory> > {
228  public:
229  explicit SqlListRollbackTags(const HistoryDatabase *database);
230 };
231 
232 
233 class SqlRecycleBin : public SqlHistory {
234  protected:
235  static const unsigned int kFlagCatalog = 1;
236 
237  bool CheckSchema(const HistoryDatabase *database) const;
238 };
239 
240 
242  public:
243  explicit SqlRecycleBinList(const HistoryDatabase *database);
245 };
246 
247 
249  public:
250  explicit SqlRecycleBinFlush(const HistoryDatabase *database);
251 };
252 
253 } // namespace history
254 
255 #endif // CVMFS_HISTORY_SQL_H_
History::Tag RetrieveTag() const
Definition: history_sql.h:104
UpdateChannel channel
Definition: history.h:118
bool BindTimestamp(const time_t timestamp)
Definition: history_sql.cc:295
static const float kLatestSchema
Definition: history_sql.h:22
unsigned RetrieveCount() const
Definition: history_sql.cc:324
SqlFindTag(const HistoryDatabase *database)
Definition: history_sql.cc:270
const std::string & filename() const
Definition: sql.h:148
bool CheckSchema(const HistoryDatabase *database) const
Definition: history_sql.cc:425
static const float kLatestSupportedSchema
Definition: history_sql.h:23
std::string name
Definition: history.h:113
static const std::string db_placeholders
Definition: history_sql.h:124
SqlFindTagByDate(const HistoryDatabase *database)
Definition: history_sql.cc:283
const history::History * history() const
shash::Any RetrieveHash() const
Definition: history_sql.cc:357
Database(const std::string &filename, const OpenMode open_mode)
SqlInsertTag(const HistoryDatabase *database)
Definition: history_sql.cc:236
SqlCountTags(const HistoryDatabase *database)
Definition: history_sql.cc:320
SqlListRollbackTags(const HistoryDatabase *database)
Definition: history_sql.cc:375
bool CompactDatabase() const
Definition: history_sql.h:36
SqlFindBranchHead(const HistoryDatabase *database)
Definition: history_sql.cc:303
bool InsertInitialValues(const std::string &repository_name)
Definition: history_sql.cc:87
std::string description
Definition: history.h:119
bool BindBranchName(const std::string &branch_name)
Definition: history_sql.cc:312
SqlRecycleBinFlush(const HistoryDatabase *database)
Definition: history_sql.cc:454
static const unsigned int kFlagCatalog
Definition: history_sql.h:235
bool BindName(const std::string &name)
Definition: history_sql.cc:275
bool BindTargetTag(const History::Tag &target_tag)
Definition: history_sql.h:213
const char kSuffixCatalog
Definition: hash.h:53
bool BindTag(const History::Tag &tag)
Definition: history_sql.cc:242
SqlListTags(const HistoryDatabase *database)
Definition: history_sql.cc:334
Any MkFromHexPtr(const HexPtr hex, const char suffix)
Definition: hash.cc:83
bool BindBranch(const History::Branch &branch)
Definition: history_sql.cc:414
SqlGetChannelTips(const HistoryDatabase *database)
Definition: history_sql.cc:344
SqlInsertBranch(const HistoryDatabase *database)
Definition: history_sql.cc:407
static const unsigned kLatestSchemaRevision
Definition: history_sql.h:25
SqlGetHashes(const HistoryDatabase *database)
Definition: history_sql.cc:352
HistoryDatabase(const std::string &filename, const OpenMode open_mode)
Definition: history_sql.h:41
static const std::string kFqrnKey
Definition: history_sql.h:27
bool BindName(const std::string &name)
Definition: history_sql.cc:262
shash::Any root_hash
Definition: history.h:114
std::string branch
Definition: history.h:123
SqlRemoveTag(const HistoryDatabase *database)
Definition: history_sql.cc:258
bool ContainsRecycleBin() const
Definition: history_sql.cc:93
History::Branch RetrieveBranch() const
Definition: history_sql.cc:395
SqlRecycleBinList(const HistoryDatabase *database)
Definition: history_sql.cc:434
SqlRollbackTag(const HistoryDatabase *database)
Definition: history_sql.cc:366
SqlListBranches(const HistoryDatabase *database)
Definition: history_sql.cc:386