librime: level_db.h Source File

| 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
19 class LevelDbAccessor : public DbAccessor {
20 public:
21 LevelDbAccessor();
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
35 class 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
54 an<DbAccessor> QueryMetadata() override;
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
72 the<LevelDbWrapper> db_;
73 string db_type_;
74};
75
76} // namespace rime
77
78#endif // RIME_LEVEL_DB_H_
db.h
rime
Definition algebra.cc:12
rime::an
std::shared_ptr< T > an
Definition common.h:60
rime::the
std::unique_ptr< T > the
Definition common.h:58
rime::path
Definition common.h:84
rime::DbAccessor::DbAccessor
DbAccessor()=default
rime::Db::Db
Db(const path &file_path, const string &name)
Definition db.cc:39
rime::Db::file_path
const path & file_path() const
Definition db.h:60
rime::Transactional::Transactional
Transactional()=default
rime::Recoverable
Definition db.h:88
rime::LevelDbCursor
Definition level_db.cc:19
rime::LevelDbWrapper
Definition level_db.cc:50
rime::LevelDbAccessor::exhausted
bool exhausted() override
Definition level_db.cc:136
rime::LevelDbAccessor::GetNextRecord
bool GetNextRecord(string *key, string *value) override
Definition level_db.cc:121
rime::LevelDbAccessor::Jump
bool Jump(const string &key) override
Definition level_db.cc:117
rime::LevelDbAccessor::LevelDbAccessor
LevelDbAccessor()
Definition level_db.cc:100
rime::LevelDbAccessor::Reset
bool Reset() override
Definition level_db.cc:113
rime::LevelDb
Definition level_db.h:35
rime::LevelDb::Remove
bool Remove() override
Definition level_db.cc:229
rime::LevelDb::Backup
bool Backup(const path &snapshot_file) override
Definition level_db.cc:193
rime::LevelDb::MetaFetch
bool MetaFetch(const string &key, string *value) override
Definition level_db.cc:295
rime::LevelDb::Recover
bool Recover() override
Definition level_db.cc:218
rime::LevelDb::Open
bool Open() override
Definition level_db.cc:242
rime::LevelDb::Update
bool Update(const string &key, const string &value) override
Definition level_db.cc:179
rime::LevelDb::Restore
bool Restore(const path &snapshot_file) override
Definition level_db.cc:206
rime::LevelDb::Erase
bool Erase(const string &key) override
Definition level_db.cc:186
rime::LevelDb::CreateMetadata
bool CreateMetadata() override
Definition level_db.cc:291
rime::LevelDb::CommitTransaction
bool CommitTransaction() override
Definition level_db.cc:319
rime::LevelDb::Close
bool Close() override
Definition level_db.cc:278
rime::LevelDb::Fetch
bool Fetch(const string &key, string *value) override
Definition level_db.cc:173
rime::LevelDb::QueryMetadata
an< DbAccessor > QueryMetadata() override
Definition level_db.cc:156
rime::LevelDb::BeginTransaction
bool BeginTransaction() override
Definition level_db.cc:303
rime::LevelDb::OpenReadOnly
bool OpenReadOnly() override
Definition level_db.cc:264
rime::LevelDb::AbortTransaction
bool AbortTransaction() override
Definition level_db.cc:311
rime::LevelDb::LevelDb
LevelDb(const path &file_path, const string &db_name, const string &db_type="")
Definition level_db.cc:142
rime::LevelDb::QueryAll
an< DbAccessor > QueryAll() override
Definition level_db.cc:160
rime::LevelDb::MetaUpdate
bool MetaUpdate(const string &key, const string &value) override
Definition level_db.cc:299
rime::LevelDb::Query
an< DbAccessor > Query(const string &key) override
Definition level_db.cc:167