diff options
Diffstat (limited to 'common/storage_lmdb.cpp')
-rw-r--r-- | common/storage_lmdb.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index 8e9b05c..7e23fd3 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp | |||
@@ -14,7 +14,7 @@ | |||
14 | class Storage::Private | 14 | class Storage::Private |
15 | { | 15 | { |
16 | public: | 16 | public: |
17 | Private(const QString &s, const QString &name); | 17 | Private(const QString &s, const QString &name, AccessMode m); |
18 | ~Private(); | 18 | ~Private(); |
19 | 19 | ||
20 | QString storageRoot; | 20 | QString storageRoot; |
@@ -23,14 +23,16 @@ public: | |||
23 | MDB_dbi dbi; | 23 | MDB_dbi dbi; |
24 | MDB_env *env; | 24 | MDB_env *env; |
25 | MDB_txn *transaction; | 25 | MDB_txn *transaction; |
26 | AccessMode mode; | ||
26 | bool readTransaction; | 27 | bool readTransaction; |
27 | bool firstOpen; | 28 | bool firstOpen; |
28 | }; | 29 | }; |
29 | 30 | ||
30 | Storage::Private::Private(const QString &s, const QString &n) | 31 | Storage::Private::Private(const QString &s, const QString &n, AccessMode m) |
31 | : storageRoot(s), | 32 | : storageRoot(s), |
32 | name(n), | 33 | name(n), |
33 | transaction(0), | 34 | transaction(0), |
35 | mode(m), | ||
34 | readTransaction(false), | 36 | readTransaction(false), |
35 | firstOpen(true) | 37 | firstOpen(true) |
36 | { | 38 | { |
@@ -65,8 +67,8 @@ Storage::Private::~Private() | |||
65 | mdb_env_close(env); | 67 | mdb_env_close(env); |
66 | } | 68 | } |
67 | 69 | ||
68 | Storage::Storage(const QString &storageRoot, const QString &name) | 70 | Storage::Storage(const QString &storageRoot, const QString &name, AccessMode mode) |
69 | : d(new Private(storageRoot, name)) | 71 | : d(new Private(storageRoot, name, mode)) |
70 | { | 72 | { |
71 | } | 73 | } |
72 | 74 | ||
@@ -80,13 +82,18 @@ bool Storage::isInTransaction() const | |||
80 | return d->transaction; | 82 | return d->transaction; |
81 | } | 83 | } |
82 | 84 | ||
83 | bool Storage::startTransaction(TransactionType type) | 85 | bool Storage::startTransaction(AccessMode type) |
84 | { | 86 | { |
85 | if (!d->env) { | 87 | if (!d->env) { |
86 | return false; | 88 | return false; |
87 | } | 89 | } |
88 | 90 | ||
89 | bool requestedRead = type == ReadOnly; | 91 | bool requestedRead = type == ReadOnly; |
92 | |||
93 | if (d->mode == ReadOnly && !requestedRead) { | ||
94 | return false; | ||
95 | } | ||
96 | |||
90 | if (d->transaction && (!d->readTransaction || requestedRead)) { | 97 | if (d->transaction && (!d->readTransaction || requestedRead)) { |
91 | return true; | 98 | return true; |
92 | } | 99 | } |