Line |
Branch |
Exec |
Source |
1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM File System. |
3 |
|
|
*/ |
4 |
|
|
|
5 |
|
|
#ifndef CVMFS_REFLOG_SQL_H_ |
6 |
|
|
#define CVMFS_REFLOG_SQL_H_ |
7 |
|
|
|
8 |
|
|
#include <string> |
9 |
|
|
|
10 |
|
|
#include "crypto/hash.h" |
11 |
|
|
#include "sql.h" |
12 |
|
|
|
13 |
|
|
class ReflogDatabase : public sqlite::Database<ReflogDatabase> { |
14 |
|
|
public: |
15 |
|
|
static const float kLatestSchema; |
16 |
|
|
static const float kLatestSupportedSchema; |
17 |
|
|
// backwards-compatible schema changes |
18 |
|
|
static const unsigned kLatestSchemaRevision; |
19 |
|
|
|
20 |
|
|
static const std::string kFqrnKey; |
21 |
|
|
|
22 |
|
|
bool CreateEmptyDatabase(); |
23 |
|
|
|
24 |
|
|
bool CheckSchemaCompatibility(); |
25 |
|
|
bool LiveSchemaUpgradeIfNecessary(); |
26 |
|
✗ |
bool CompactDatabase() const { return true; } // no implementation specific |
27 |
|
|
// database compaction. |
28 |
|
|
|
29 |
|
|
bool InsertInitialValues(const std::string &repo_name); |
30 |
|
|
|
31 |
|
|
protected: |
32 |
|
|
// TODO(rmeusel): C++11 - constructor inheritance |
33 |
|
|
friend class sqlite::Database<ReflogDatabase>; |
34 |
|
37 |
ReflogDatabase(const std::string &filename, |
35 |
|
37 |
const OpenMode open_mode) : |
36 |
|
37 |
sqlite::Database<ReflogDatabase>(filename, open_mode) {} |
37 |
|
|
}; |
38 |
|
|
|
39 |
|
|
|
40 |
|
|
//------------------------------------------------------------------------------ |
41 |
|
|
|
42 |
|
|
|
43 |
|
|
class SqlReflog : public sqlite::Sql { |
44 |
|
|
public: |
45 |
|
|
enum ReferenceType { |
46 |
|
|
kRefCatalog, |
47 |
|
|
kRefCertificate, |
48 |
|
|
kRefHistory, |
49 |
|
|
kRefMetainfo |
50 |
|
|
}; |
51 |
|
|
|
52 |
|
|
static shash::Suffix ToSuffix(const ReferenceType type); |
53 |
|
|
}; |
54 |
|
|
|
55 |
|
|
|
56 |
|
|
class SqlInsertReference : public SqlReflog { |
57 |
|
|
public: |
58 |
|
|
explicit SqlInsertReference(const ReflogDatabase *database); |
59 |
|
|
bool BindReference(const shash::Any &reference_hash, |
60 |
|
|
const ReferenceType type); |
61 |
|
|
}; |
62 |
|
|
|
63 |
|
|
|
64 |
|
|
class SqlCountReferences : public SqlReflog { |
65 |
|
|
public: |
66 |
|
|
explicit SqlCountReferences(const ReflogDatabase *database); |
67 |
|
|
uint64_t RetrieveCount(); |
68 |
|
|
}; |
69 |
|
|
|
70 |
|
|
|
71 |
|
|
class SqlListReferences : public SqlReflog { |
72 |
|
|
public: |
73 |
|
|
explicit SqlListReferences(const ReflogDatabase *database); |
74 |
|
|
bool BindType(const ReferenceType type); |
75 |
|
|
bool BindOlderThan(const uint64_t timestamp); |
76 |
|
|
shash::Any RetrieveHash() const; |
77 |
|
|
}; |
78 |
|
|
|
79 |
|
|
|
80 |
|
|
class SqlRemoveReference : public SqlReflog { |
81 |
|
|
public: |
82 |
|
|
explicit SqlRemoveReference(const ReflogDatabase *database); |
83 |
|
|
bool BindReference(const shash::Any &reference_hash, |
84 |
|
|
const ReferenceType type); |
85 |
|
|
}; |
86 |
|
|
|
87 |
|
|
|
88 |
|
|
class SqlContainsReference : public SqlReflog { |
89 |
|
|
public: |
90 |
|
|
explicit SqlContainsReference(const ReflogDatabase *database); |
91 |
|
|
bool BindReference(const shash::Any &reference_hash, |
92 |
|
|
const ReferenceType type); |
93 |
|
|
bool RetrieveAnswer(); |
94 |
|
|
}; |
95 |
|
|
|
96 |
|
|
|
97 |
|
|
class SqlGetTimestamp : public SqlReflog { |
98 |
|
|
public: |
99 |
|
|
explicit SqlGetTimestamp(const ReflogDatabase *database); |
100 |
|
|
bool BindReference(const shash::Any &reference_hash, |
101 |
|
|
const ReferenceType type); |
102 |
|
|
uint64_t RetrieveTimestamp(); |
103 |
|
|
}; |
104 |
|
|
|
105 |
|
|
#endif // CVMFS_REFLOG_SQL_H_ |
106 |
|
|
|