some more ideas about duplicates
This commit is contained in:
parent
f0727aa73d
commit
06e1aca45a
8 changed files with 139 additions and 24 deletions
21
src/base.h
21
src/base.h
|
@ -48,6 +48,12 @@ class Cache;
|
|||
|
||||
typedef MDB_txn* TransactionID; /**<I'm going to use transaction pointers as transaction IDs*/
|
||||
|
||||
enum Duplicates { /**<Duplicates mode:*/
|
||||
uniqueKey, /** - no duplicate keys allowed*/
|
||||
uniquePair, /** - no duplicate key <b>AND</b> value pairs allowed*/
|
||||
full /** - any configuration of duplicates goes*/
|
||||
};
|
||||
|
||||
class Base {
|
||||
friend class iStorage;
|
||||
public:
|
||||
|
@ -69,7 +75,7 @@ public:
|
|||
void abortTransaction(TransactionID id) const;
|
||||
|
||||
template <class K, class V>
|
||||
LMDBAL::Storage<K, V>* addStorage(const std::string& storageName, bool duplicates = false);
|
||||
LMDBAL::Storage<K, V>* addStorage(const std::string& storageName, Duplicates duplicates = uniqueKey);
|
||||
|
||||
template <class K, class V>
|
||||
LMDBAL::Cache<K, V>* addCache(const std::string& storageName);
|
||||
|
@ -115,6 +121,7 @@ private:
|
|||
* The LMDBAL::Base must be closed
|
||||
*
|
||||
* \param[in] storageName - storage name
|
||||
* \param[in] duplicates - LMDBAL::Duplicates duplicates mode (uniqueKey by default)
|
||||
*
|
||||
* \returns storage pointer. LMDBAL::Base keeps the ownership of the added storage, you don't need to destoroy it
|
||||
*
|
||||
|
@ -125,10 +132,10 @@ private:
|
|||
* \exception LMDBAL::StorageDuplicate thrown if somebody tries to add storage with repeating name
|
||||
*/
|
||||
template <class K, class V>
|
||||
LMDBAL::Storage<K, V>* LMDBAL::Base::addStorage(const std::string& storageName, bool duplicates) {
|
||||
if (opened) {
|
||||
LMDBAL::Storage<K, V>* LMDBAL::Base::addStorage(const std::string& storageName, Duplicates duplicates) {
|
||||
if (opened)
|
||||
throw Opened(name, "add storage " + storageName);
|
||||
}
|
||||
|
||||
Storage<K, V>* storage = new Storage<K, V>(this, storageName, duplicates);
|
||||
std::pair<Storages::const_iterator, bool> pair = storages.insert(std::make_pair(storageName, (iStorage*)storage));
|
||||
if (!pair.second)
|
||||
|
@ -154,10 +161,10 @@ LMDBAL::Storage<K, V>* LMDBAL::Base::addStorage(const std::string& storageName,
|
|||
*/
|
||||
template<class K, class V>
|
||||
LMDBAL::Cache<K, V> * LMDBAL::Base::addCache(const std::string& storageName) {
|
||||
if (opened) {
|
||||
if (opened)
|
||||
throw Opened(name, "add cache " + storageName);
|
||||
}
|
||||
Cache<K, V>* cache = new Cache<K, V>(this, storageName, false);
|
||||
|
||||
Cache<K, V>* cache = new Cache<K, V>(this, storageName, uniqueKey);
|
||||
std::pair<Storages::const_iterator, bool> pair = storages.insert(std::make_pair(storageName, (iStorage*)cache));
|
||||
if (!pair.second)
|
||||
throw StorageDuplicate(name, storageName);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue