CernVM-FS  2.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
history_sqlite.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_HISTORY_SQLITE_H_
6 #define CVMFS_HISTORY_SQLITE_H_
7 
8 #include <stdint.h>
9 #include <time.h>
10 
11 #include <string>
12 #include <vector>
13 
14 #include "hash.h"
15 #include "history.h"
16 #include "history_sql.h"
17 
18 namespace history {
19 
25 class SqliteHistory : public History {
26  protected:
27  static const std::string kPreviousRevisionKey;
28 
29  public:
30  virtual ~SqliteHistory() { }
31 
41  static SqliteHistory* Open(const std::string &file_name);
42 
51  static SqliteHistory* OpenWritable(const std::string &file_name);
52 
63  static SqliteHistory* Create(const std::string &file_name,
64  const std::string &fqrn);
65 
66  bool IsWritable() const;
67  unsigned GetNumberOfTags() const;
68 
74  bool BeginTransaction() const;
75 
79  bool CommitTransaction() const;
80 
81  virtual bool Vacuum() { return database_->Vacuum(); }
82 
89  bool SetPreviousRevision(const shash::Any &history_hash);
91 
92  bool Insert(const Tag &tag);
93  bool Remove(const std::string &name);
94  bool Exists(const std::string &name) const;
95  bool GetByName(const std::string &name, Tag *tag) const;
96  bool GetByDate(const time_t timestamp, Tag *tag) const;
97  bool List(std::vector<Tag> *tags) const;
98  bool Tips(std::vector<Tag> *channel_tips) const;
99 
100  virtual bool GetBranchHead(const std::string &branch_name, Tag *tag) const;
101  virtual bool ExistsBranch(const std::string &branch_name) const;
102  virtual bool InsertBranch(const Branch &branch);
103  virtual bool PruneBranches();
104  virtual bool ListBranches(std::vector<Branch> *branches) const;
105 
106  bool ListRecycleBin(std::vector<shash::Any> *hashes) const;
107  bool EmptyRecycleBin();
108 
119  bool Rollback(const Tag &updated_target_tag);
120 
131  bool ListTagsAffectedByRollback(const std::string &target_tag_name,
132  std::vector<Tag> *tags) const;
133 
141  bool GetHashes(std::vector<shash::Any> *hashes) const;
142 
143  // database file management controls
146  bool OwnsDatabaseFile() const {
147  return database_.IsValid() && database_->OwnsFile();
148  }
149  std::string filename() const { return database_->filename(); }
150 
151  protected:
152  static SqliteHistory* Open(const std::string &file_name,
153  const bool read_write);
154  bool OpenDatabase(const std::string &file_name, const bool read_write);
155  bool CreateDatabase(const std::string &file_name, const std::string &fqrn);
156  void PrepareQueries();
157 
158  private:
159  template <class SqlListingT>
160  bool RunListing(std::vector<Tag> *list, SqlListingT *sql) const;
161 
162  private:
164 
180 };
181 
182 } // namespace history
183 
184 #endif // CVMFS_HISTORY_SQLITE_H_
UniquePtr< SqlCountTags > count_tags_
UniquePtr< SqlListRollbackTags > list_rollback_tags_
static SqliteHistory * Open(const std::string &file_name)
UniquePtr< SqlListTags > list_tags_
UniquePtr< SqlGetHashes > get_hashes_
bool Rollback(const Tag &updated_target_tag)
UniquePtr< SqlGetChannelTips > channel_tips_
const history::History * history() const
virtual bool ListBranches(std::vector< Branch > *branches) const
virtual bool PruneBranches()
bool CommitTransaction() const
const std::string & fqrn() const
Definition: history.h:220
bool Remove(const std::string &name)
bool List(std::vector< Tag > *tags) const
bool Exists(const std::string &name) const
static SqliteHistory * OpenWritable(const std::string &file_name)
bool BeginTransaction() const
bool OpenDatabase(const std::string &file_name, const bool read_write)
bool GetByDate(const time_t timestamp, Tag *tag) const
UniquePtr< SqlInsertBranch > insert_branch_
UniquePtr< SqlRemoveTag > remove_tag_
UniquePtr< SqlFindTag > find_tag_
bool GetByName(const std::string &name, Tag *tag) const
bool CreateDatabase(const std::string &file_name, const std::string &fqrn)
UniquePtr< SqlRecycleBinFlush > recycle_empty_
bool RunListing(std::vector< Tag > *list, SqlListingT *sql) const
UniquePtr< SqlFindBranchHead > find_branch_head_
bool Insert(const Tag &tag)
virtual bool Vacuum()
bool OwnsDatabaseFile() const
UniquePtr< SqlListBranches > list_branches_
shash::Any previous_revision() const
bool SetPreviousRevision(const shash::Any &history_hash)
UniquePtr< SqlFindTagByDate > find_tag_by_date_
std::string filename() const
bool Tips(std::vector< Tag > *channel_tips) const
bool ListTagsAffectedByRollback(const std::string &target_tag_name, std::vector< Tag > *tags) const
virtual bool GetBranchHead(const std::string &branch_name, Tag *tag) const
UniquePtr< SqlInsertTag > insert_tag_
bool ListRecycleBin(std::vector< shash::Any > *hashes) const
static SqliteHistory * Create(const std::string &file_name, const std::string &fqrn)
virtual bool ExistsBranch(const std::string &branch_name) const
UniquePtr< HistoryDatabase > database_
UniquePtr< SqlRollbackTag > rollback_tag_
bool GetHashes(std::vector< shash::Any > *hashes) const
static const std::string kPreviousRevisionKey
virtual bool InsertBranch(const Branch &branch)
unsigned GetNumberOfTags() const
UniquePtr< SqlRecycleBinList > recycle_list_