CernVM-FS  2.12.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 "crypto/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 
99  virtual bool GetBranchHead(const std::string &branch_name, Tag *tag) const;
100  virtual bool ExistsBranch(const std::string &branch_name) const;
101  virtual bool InsertBranch(const Branch &branch);
102  virtual bool PruneBranches();
103  virtual bool ListBranches(std::vector<Branch> *branches) const;
104 
105  bool ListRecycleBin(std::vector<shash::Any> *hashes) const;
106  bool EmptyRecycleBin();
107 
118  bool Rollback(const Tag &updated_target_tag);
119 
130  bool ListTagsAffectedByRollback(const std::string &target_tag_name,
131  std::vector<Tag> *tags) const;
132 
140  bool GetHashes(std::vector<shash::Any> *hashes) const;
141 
142  // database file management controls
145  bool OwnsDatabaseFile() const {
146  return database_.IsValid() && database_->OwnsFile();
147  }
148  std::string filename() const { return database_->filename(); }
149 
150  protected:
151  static SqliteHistory* Open(const std::string &file_name,
152  const bool read_write);
153  bool OpenDatabase(const std::string &file_name, const bool read_write);
154  bool CreateDatabase(const std::string &file_name, const std::string &fqrn);
155  void PrepareQueries();
156 
157  private:
158  template <class SqlListingT>
159  bool RunListing(std::vector<Tag> *list, SqlListingT *sql) const;
160 
161  private:
163 
178 };
179 
180 } // namespace history
181 
182 #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)
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:193
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 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_