diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-05-06 12:37:30 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-05-06 12:37:30 +0200 |
commit | f52ed4fd64994985f1061c5fcd20dccaa61fbc67 (patch) | |
tree | 037ab2cff55452dfcfb1eae772458ebab020d749 /common/storage_lmdb.cpp | |
parent | 8eab2b67fdf83c657f996debfc238703a78b337b (diff) | |
download | sink-f52ed4fd64994985f1061c5fcd20dccaa61fbc67.tar.gz sink-f52ed4fd64994985f1061c5fcd20dccaa61fbc67.zip |
A defined table layout
Diffstat (limited to 'common/storage_lmdb.cpp')
-rw-r--r-- | common/storage_lmdb.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index cb7bca4..ef4bd17 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp | |||
@@ -711,7 +711,7 @@ QList<QByteArray> DataStore::Transaction::getDatabaseNames() const | |||
711 | class DataStore::Private | 711 | class DataStore::Private |
712 | { | 712 | { |
713 | public: | 713 | public: |
714 | Private(const QString &s, const QString &n, AccessMode m); | 714 | Private(const QString &s, const QString &n, AccessMode m, const DbLayout &layout = {}); |
715 | ~Private(); | 715 | ~Private(); |
716 | 716 | ||
717 | QString storageRoot; | 717 | QString storageRoot; |
@@ -721,7 +721,7 @@ public: | |||
721 | AccessMode mode; | 721 | AccessMode mode; |
722 | }; | 722 | }; |
723 | 723 | ||
724 | DataStore::Private::Private(const QString &s, const QString &n, AccessMode m) : storageRoot(s), name(n), env(0), mode(m) | 724 | DataStore::Private::Private(const QString &s, const QString &n, AccessMode m, const DbLayout &layout) : storageRoot(s), name(n), env(0), mode(m) |
725 | { | 725 | { |
726 | const QString fullPath(storageRoot + '/' + name); | 726 | const QString fullPath(storageRoot + '/' + name); |
727 | QFileInfo dirInfo(fullPath); | 727 | QFileInfo dirInfo(fullPath); |
@@ -772,9 +772,16 @@ DataStore::Private::Private(const QString &s, const QString &n, AccessMode m) : | |||
772 | bool noLock = true; | 772 | bool noLock = true; |
773 | bool requestedRead = m == ReadOnly; | 773 | bool requestedRead = m == ReadOnly; |
774 | auto t = Transaction(new Transaction::Private(requestedRead, nullptr, name, env, noLock)); | 774 | auto t = Transaction(new Transaction::Private(requestedRead, nullptr, name, env, noLock)); |
775 | for (const auto &db : t.getDatabaseNames()) { | 775 | if (!layout.tables.isEmpty()) { |
776 | //Get dbi to store for future use. | 776 | for (auto it = layout.tables.constBegin(); it != layout.tables.constEnd(); it++) { |
777 | t.openDatabase(db); | 777 | bool allowDuplicates = it.value(); |
778 | t.openDatabase(it.key(), {}, allowDuplicates); | ||
779 | } | ||
780 | } else { | ||
781 | for (const auto &db : t.getDatabaseNames()) { | ||
782 | //Get dbi to store for future use. | ||
783 | t.openDatabase(db); | ||
784 | } | ||
778 | } | 785 | } |
779 | //To persist the dbis (this is also necessary for read-only transactions) | 786 | //To persist the dbis (this is also necessary for read-only transactions) |
780 | t.commit(); | 787 | t.commit(); |
@@ -794,6 +801,10 @@ DataStore::DataStore(const QString &storageRoot, const QString &name, AccessMode | |||
794 | { | 801 | { |
795 | } | 802 | } |
796 | 803 | ||
804 | DataStore::DataStore(const QString &storageRoot, const DbLayout &dbLayout, AccessMode mode) : d(new Private(storageRoot, dbLayout.name, mode, dbLayout)) | ||
805 | { | ||
806 | } | ||
807 | |||
797 | DataStore::~DataStore() | 808 | DataStore::~DataStore() |
798 | { | 809 | { |
799 | delete d; | 810 | delete d; |