1
+ #include " transaction.h"
2
+
3
+ Transaction::Transaction (TransactionDB *db)
4
+ :db(db) {
5
+
6
+ }
7
+
8
+ Transaction::~Transaction () {
9
+
10
+ }
11
+
12
+ Status Transaction::Put (const WriteOptions& options, const std::string_view& key, const std::string_view& value) {
13
+ HashLock l (db->GetLockMgr (), key);
14
+ return db->GetDB ()->Put (options, key, value);
15
+ }
16
+
17
+ Status Transaction::Delete (const WriteOptions& options, const std::string_view& key) {
18
+ HashLock l (db->GetLockMgr (), key);
19
+ return db->GetDB ()->Delete (options, key);
20
+ }
21
+
22
+ Status Transaction::Get (const ReadOptions& options, const std::string_view& key, std::string* value) {
23
+ HashLock l (db->GetLockMgr (), key);
24
+ return db->GetDB ()->Get (options, key, value);
25
+ }
26
+
27
+ Status Transaction::Commit () {
28
+ return db->Write (WriteOptions (), &writebatch);
29
+ }
30
+
31
+ Status Transaction::Rollback () {
32
+ writebatch.clear ();
33
+ }
34
+
35
+ TransactionDB::TransactionDB (const Options& options, const std::string& path):
36
+ db(new DB(options, path)) {
37
+
38
+ }
39
+
40
+ Status TransactionDB::Open () {
41
+ return db->Open ();
42
+ }
43
+
44
+ TransactionDB::~TransactionDB () {
45
+
46
+ }
47
+
48
+ Status TransactionDB::Put (const WriteOptions& options, const std::string_view& key, const std::string_view& value) {
49
+ WriteSharedHashLock l (&lockmgr, key);
50
+ return db->Put (options, key, value);
51
+ }
52
+
53
+ Status TransactionDB::Delete (const WriteOptions& options, const std::string_view& key) {
54
+ HashLock l (&lockmgr, key);
55
+ return db->Delete (options, key);
56
+ }
57
+
58
+ Status TransactionDB::Write (const WriteOptions& options, WriteBatch* updates) {
59
+ return db->Write (options, updates);
60
+ }
61
+
62
+ Status TransactionDB::Get (const ReadOptions& options, const std::string_view& key, std::string* value) {
63
+ HashLock l (&lockmgr, key);
64
+ return db->Get (options, key, value);
65
+ }
66
+
67
+ std::shared_ptr<Transaction> TransactionDB::BeginTrasaction () {
68
+ std::shared_ptr<Transaction> tran (new Transaction (this ));
69
+ return tran;
70
+ }
0 commit comments