librime 1.2
Rime Input Method Engine, the core library
level_db.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5// 2014-12-04 Chen Gong <chen.sst@gmail.com>
6//
7#ifndef RIME_LEVEL_DB_H_
8#define RIME_LEVEL_DB_H_
9
10#include <rime/dict/db.h>
11
12namespace rime {
13
14struct LevelDbCursor;
15struct LevelDbWrapper;
16
17class LevelDb;
18
20 public:
22 LevelDbAccessor(LevelDbCursor* cursor, const string& prefix);
23 virtual ~LevelDbAccessor();
24
25 bool Reset() override;
26 bool Jump(const string& key) override;
27 bool GetNextRecord(string* key, string* value) override;
28 bool exhausted() override;
29
30 private:
31 the<LevelDbCursor> cursor_;
32 bool is_metadata_query_ = false;
33};
34
35class LevelDb : public Db, public Recoverable, public Transactional {
36 public:
37 LevelDb(const path& file_path,
38 const string& db_name,
39 const string& db_type = "");
40 virtual ~LevelDb();
41
42 bool Remove() override;
43 bool Open() override;
44 bool OpenReadOnly() override;
45 bool Close() override;
46
47 bool Backup(const path& snapshot_file) override;
48 bool Restore(const path& snapshot_file) override;
49
50 bool CreateMetadata() override;
51 bool MetaFetch(const string& key, string* value) override;
52 bool MetaUpdate(const string& key, const string& value) override;
53
55 an<DbAccessor> QueryAll() override;
56 an<DbAccessor> Query(const string& key) override;
57 bool Fetch(const string& key, string* value) override;
58 bool Update(const string& key, const string& value) override;
59 bool Erase(const string& key) override;
60
61 // Recoverable
62 bool Recover() override;
63
64 // Transactional
65 bool BeginTransaction() override;
66 bool AbortTransaction() override;
67 bool CommitTransaction() override;
68
69 private:
70 void Initialize();
71
73 string db_type_;
74};
75
76} // namespace rime
77
78#endif // RIME_LEVEL_DB_H_
Definition algebra.cc:12
std::shared_ptr< T > an
Definition common.h:60
std::unique_ptr< T > the
Definition common.h:58
Definition common.h:84
DbAccessor()=default
Db(const path &file_path, const string &name)
Definition db.cc:39
const path & file_path() const
Definition db.h:60
Transactional()=default
Definition db.h:88
Definition level_db.cc:19
Definition level_db.cc:50
bool exhausted() override
Definition level_db.cc:136
bool GetNextRecord(string *key, string *value) override
Definition level_db.cc:121
bool Jump(const string &key) override
Definition level_db.cc:117
LevelDbAccessor()
Definition level_db.cc:100
bool Reset() override
Definition level_db.cc:113
Definition level_db.h:35
bool Remove() override
Definition level_db.cc:229
bool Backup(const path &snapshot_file) override
Definition level_db.cc:193
bool MetaFetch(const string &key, string *value) override
Definition level_db.cc:295
bool Recover() override
Definition level_db.cc:218
bool Open() override
Definition level_db.cc:242
bool Update(const string &key, const string &value) override
Definition level_db.cc:179
bool Restore(const path &snapshot_file) override
Definition level_db.cc:206
bool Erase(const string &key) override
Definition level_db.cc:186
bool CreateMetadata() override
Definition level_db.cc:291
bool CommitTransaction() override
Definition level_db.cc:319
bool Close() override
Definition level_db.cc:278
bool Fetch(const string &key, string *value) override
Definition level_db.cc:173
an< DbAccessor > QueryMetadata() override
Definition level_db.cc:156
bool BeginTransaction() override
Definition level_db.cc:303
bool OpenReadOnly() override
Definition level_db.cc:264
bool AbortTransaction() override
Definition level_db.cc:311
LevelDb(const path &file_path, const string &db_name, const string &db_type="")
Definition level_db.cc:142
an< DbAccessor > QueryAll() override
Definition level_db.cc:160
bool MetaUpdate(const string &key, const string &value) override
Definition level_db.cc:299
an< DbAccessor > Query(const string &key) override
Definition level_db.cc:167