project name change

This commit is contained in:
Blue 2023-03-21 14:05:54 +03:00
parent 19229f6c26
commit 7377f13534
Signed by: blue
GPG Key ID: 9B203B252A63EE38
29 changed files with 316 additions and 310 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(storage VERSION 0.0.1 LANGUAGES CXX) project(lmdbal VERSION 0.2.0 LANGUAGES CXX)
cmake_policy(SET CMP0076 NEW) cmake_policy(SET CMP0076 NEW)
cmake_policy(SET CMP0079 NEW) cmake_policy(SET CMP0079 NEW)
@ -28,63 +28,32 @@ if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug) set(CMAKE_BUILD_TYPE Debug)
endif () endif ()
set(SOURCES
exceptions.cpp
storage.cpp
database.cpp
)
set(HEADERS
database.h
exceptions.h
storage.h
storage.hpp
cache.h
cache.hpp
serializer.h
serializer.hpp
serializer_uint8.hpp
serializer_uint16.hpp
serializer_uint32.hpp
serializer_uint64.hpp
serializer_int8.hpp
serializer_int16.hpp
serializer_int32.hpp
serializer_int64.hpp
serializer_float.hpp
serializer_double.hpp
serializer_stdstring.hpp
serializer_qstring.hpp
serializer_qbytearray.hpp
operators.hpp
)
if (BUILD_STATIC) if (BUILD_STATIC)
add_library(storage STATIC ${SOURCES}) add_library(lmdbal STATIC ${SOURCES})
else () else ()
add_library(storage SHARED ${SOURCES}) add_library(lmdbal SHARED ${SOURCES})
endif() endif()
add_subdirectory(src)
if (BUILD_TESTS) if (BUILD_TESTS)
add_subdirectory(test) add_subdirectory(test)
endif () endif ()
set_target_properties(storage PROPERTIES PUBLIC_HEADER "${HEADERS}") target_include_directories(lmdbal PUBLIC ${CMAKE_SOURCE_DIR}/src)
target_include_directories(lmdbal PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(lmdbal PRIVATE ${Qt${QT_VERSION_MAJOR}_INCLUDE_DIRS})
target_include_directories(lmdbal PRIVATE ${Qt${QT_VERSION_MAJOR}Core_INCLUDE_DIRS})
target_include_directories(storage PUBLIC ${CMAKE_SOURCE_DIR}) target_link_libraries(lmdbal
target_include_directories(storage PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(storage PRIVATE ${Qt${QT_VERSION_MAJOR}_INCLUDE_DIRS})
target_include_directories(storage PRIVATE ${Qt${QT_VERSION_MAJOR}Core_INCLUDE_DIRS})
target_link_libraries(storage
PRIVATE PRIVATE
Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Core
) )
target_link_libraries(storage PRIVATE lmdb) target_link_libraries(lmdbal PRIVATE lmdb)
install(TARGETS storage install(TARGETS lmdbal
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/storage LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/lmdbal
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/storage PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lmdbal
) )

37
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,37 @@
set(SOURCES
exceptions.cpp
storage.cpp
base.cpp
)
set(HEADERS
base.h
exceptions.h
storage.h
storage.hpp
cache.h
cache.hpp
serializer.h
serializer.hpp
serializer_uint8.hpp
serializer_uint16.hpp
serializer_uint32.hpp
serializer_uint64.hpp
serializer_int8.hpp
serializer_int16.hpp
serializer_int32.hpp
serializer_int64.hpp
serializer_float.hpp
serializer_double.hpp
serializer_stdstring.hpp
serializer_qstring.hpp
serializer_qbytearray.hpp
operators.hpp
)
target_sources(lmdbal PRIVATE
${SOURCES}
${HEADERS}
)
set_target_properties(lmdbal PROPERTIES PUBLIC_HEADER "${HEADERS}")

View File

@ -14,11 +14,11 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "database.h" #include "base.h"
#include "exceptions.h" #include "exceptions.h"
#include "storage.h" #include "storage.h"
LMDBDataBase::DataBase::DataBase(const QString& p_name, uint16_t mapSize): LMDBAL::Base::Base(const QString& p_name, uint16_t mapSize):
name(p_name.toStdString()), name(p_name.toStdString()),
opened(false), opened(false),
size(mapSize), size(mapSize),
@ -27,19 +27,19 @@ LMDBDataBase::DataBase::DataBase(const QString& p_name, uint16_t mapSize):
transactions(new Transactions()) transactions(new Transactions())
{} {}
LMDBDataBase::DataBase::~DataBase() { LMDBAL::Base::~Base() {
close(); close();
delete transactions; delete transactions;
for (const std::pair<const std::string, StorageBase*>& pair : tables) for (const std::pair<const std::string, iStorage*>& pair : tables)
delete pair.second; delete pair.second;
} }
void LMDBDataBase::DataBase::close() { void LMDBAL::Base::close() {
if (opened) { if (opened) {
for (const std::pair<const std::string, StorageBase*>& pair : tables) { for (const std::pair<const std::string, iStorage*>& pair : tables) {
StorageBase* table = pair.second; iStorage* table = pair.second;
mdb_dbi_close(environment, table->dbi); mdb_dbi_close(environment, table->dbi);
} }
mdb_env_close(environment); mdb_env_close(environment);
@ -47,7 +47,7 @@ void LMDBDataBase::DataBase::close() {
} }
} }
void LMDBDataBase::DataBase::open() { void LMDBAL::Base::open() {
if (!opened) { if (!opened) {
mdb_env_create(&environment); mdb_env_create(&environment);
QString path = createDirectory(); QString path = createDirectory();
@ -59,8 +59,8 @@ void LMDBDataBase::DataBase::open() {
MDB_txn *txn; MDB_txn *txn;
mdb_txn_begin(environment, NULL, 0, &txn); mdb_txn_begin(environment, NULL, 0, &txn);
for (const std::pair<const std::string, StorageBase*>& pair : tables) { for (const std::pair<const std::string, iStorage*>& pair : tables) {
StorageBase* table = pair.second; iStorage* table = pair.second;
int rc = table->createTable(txn); int rc = table->createTable(txn);
if (rc) if (rc)
throw Unknown(name, mdb_strerror(rc)); throw Unknown(name, mdb_strerror(rc));
@ -70,7 +70,7 @@ void LMDBDataBase::DataBase::open() {
} }
} }
bool LMDBDataBase::DataBase::removeDirectory() { bool LMDBAL::Base::removeDirectory() {
if (opened) if (opened)
throw Opened(name, "remove database directory"); throw Opened(name, "remove database directory");
@ -84,7 +84,7 @@ bool LMDBDataBase::DataBase::removeDirectory() {
return true; return true;
} }
QString LMDBDataBase::DataBase::createDirectory() { QString LMDBAL::Base::createDirectory() {
if (opened) if (opened)
throw Opened(name, "create database directory"); throw Opened(name, "create database directory");
@ -101,13 +101,13 @@ QString LMDBDataBase::DataBase::createDirectory() {
return path; return path;
} }
QString LMDBDataBase::DataBase::getName() const { QString LMDBAL::Base::getName() const {
return QString::fromStdString(name);} return QString::fromStdString(name);}
bool LMDBDataBase::DataBase::ready() const { bool LMDBAL::Base::ready() const {
return opened;} return opened;}
void LMDBDataBase::DataBase::drop() { void LMDBAL::Base::drop() {
if (!opened) if (!opened)
throw Closed("drop", name); throw Closed("drop", name);
@ -116,7 +116,7 @@ void LMDBDataBase::DataBase::drop() {
if (rc) if (rc)
throw Unknown(name, mdb_strerror(rc)); throw Unknown(name, mdb_strerror(rc));
for (const std::pair<const std::string, StorageBase*>& pair : tables) { for (const std::pair<const std::string, iStorage*>& pair : tables) {
rc = pair.second->drop(txn); rc = pair.second->drop(txn);
if (rc) if (rc)
throw Unknown(name, mdb_strerror(rc), pair.first); throw Unknown(name, mdb_strerror(rc), pair.first);
@ -125,20 +125,20 @@ void LMDBDataBase::DataBase::drop() {
mdb_txn_commit(txn); mdb_txn_commit(txn);
} }
LMDBDataBase::TransactionID LMDBDataBase::DataBase::beginReadOnlyTransaction() const { LMDBAL::TransactionID LMDBAL::Base::beginReadOnlyTransaction() const {
return beginReadOnlyTransaction(emptyName);} return beginReadOnlyTransaction(emptyName);}
LMDBDataBase::TransactionID LMDBDataBase::DataBase::beginTransaction() const { LMDBAL::TransactionID LMDBAL::Base::beginTransaction() const {
return beginTransaction(emptyName);} return beginTransaction(emptyName);}
void LMDBDataBase::DataBase::abortTransaction(LMDBDataBase::TransactionID id) const { void LMDBAL::Base::abortTransaction(LMDBAL::TransactionID id) const {
return abortTransaction(id, emptyName);} return abortTransaction(id, emptyName);}
void LMDBDataBase::DataBase::commitTransaction(LMDBDataBase::TransactionID id) const { void LMDBAL::Base::commitTransaction(LMDBAL::TransactionID id) const {
return commitTransaction(id, emptyName);} return commitTransaction(id, emptyName);}
LMDBDataBase::TransactionID LMDBDataBase::DataBase::beginReadOnlyTransaction(const std::string& storageName) const { LMDBAL::TransactionID LMDBAL::Base::beginReadOnlyTransaction(const std::string& storageName) const {
if (!opened) if (!opened)
throw Closed("beginReadOnlyTransaction", name, storageName); throw Closed("beginReadOnlyTransaction", name, storageName);
@ -152,7 +152,7 @@ LMDBDataBase::TransactionID LMDBDataBase::DataBase::beginReadOnlyTransaction(con
return txn; return txn;
} }
LMDBDataBase::TransactionID LMDBDataBase::DataBase::beginTransaction(const std::string& storageName) const { LMDBAL::TransactionID LMDBAL::Base::beginTransaction(const std::string& storageName) const {
if (!opened) if (!opened)
throw Closed("beginTransaction", name, storageName); throw Closed("beginTransaction", name, storageName);
@ -166,7 +166,7 @@ LMDBDataBase::TransactionID LMDBDataBase::DataBase::beginTransaction(const std::
return txn; return txn;
} }
void LMDBDataBase::DataBase::abortTransaction(LMDBDataBase::TransactionID id, const std::string& storageName) const { void LMDBAL::Base::abortTransaction(LMDBAL::TransactionID id, const std::string& storageName) const {
if (!opened) if (!opened)
throw Closed("abortTransaction", name, storageName); throw Closed("abortTransaction", name, storageName);
@ -178,7 +178,7 @@ void LMDBDataBase::DataBase::abortTransaction(LMDBDataBase::TransactionID id, co
transactions->erase(itr); transactions->erase(itr);
} }
void LMDBDataBase::DataBase::commitTransaction(LMDBDataBase::TransactionID id, const std::string& storageName) const { void LMDBAL::Base::commitTransaction(LMDBAL::TransactionID id, const std::string& storageName) const {
if (!opened) if (!opened)
throw Closed("abortTransaction", name, storageName); throw Closed("abortTransaction", name, storageName);

View File

@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LMDBDATABASE_DATABASE_H #ifndef LMDBAL_BASE_H
#define LMDBDATABASE_DATABASE_H #define LMDBAL_BASE_H
#include <map> #include <map>
#include <set> #include <set>
@ -31,9 +31,9 @@
#include "exceptions.h" #include "exceptions.h"
namespace LMDBDataBase { namespace LMDBAL {
class StorageBase; class iStorage;
template<class T> template<class T>
class Serializer; class Serializer;
@ -46,12 +46,12 @@ class Cache;
typedef MDB_txn* TransactionID; typedef MDB_txn* TransactionID;
class DataBase { class Base {
friend class StorageBase; friend class iStorage;
public: public:
DataBase(const QString& name, uint16_t mapSize = 10); Base(const QString& name, uint16_t mapSize = 10);
~DataBase(); ~Base();
void open(); void open();
void close(); void close();
@ -79,7 +79,7 @@ public:
Cache<K, V>* getCache(const std::string& name); Cache<K, V>* getCache(const std::string& name);
private: private:
typedef std::map<std::string, StorageBase*> Tables; typedef std::map<std::string, iStorage*> Tables;
typedef std::set<TransactionID> Transactions; typedef std::set<TransactionID> Transactions;
TransactionID beginReadOnlyTransaction(const std::string& storageName) const; TransactionID beginReadOnlyTransaction(const std::string& storageName) const;
@ -102,33 +102,33 @@ private:
#include "operators.hpp" #include "operators.hpp"
template <class K, class V> template <class K, class V>
LMDBDataBase::Storage<K, V>* LMDBDataBase::DataBase::addTable(const std::string& p_name) { LMDBAL::Storage<K, V>* LMDBAL::Base::addTable(const std::string& p_name) {
if (opened) { if (opened) {
throw Opened(name, "add table " + p_name); throw Opened(name, "add table " + p_name);
} }
Storage<K, V>* table = new Storage<K, V>(p_name, this); Storage<K, V>* table = new Storage<K, V>(p_name, this);
tables.insert(std::make_pair(p_name, (StorageBase*)table)); tables.insert(std::make_pair(p_name, (iStorage*)table));
return table; return table;
} }
template<class K, class V> template<class K, class V>
LMDBDataBase::Cache<K, V> * LMDBDataBase::DataBase::addCache(const std::string& p_name) { LMDBAL::Cache<K, V> * LMDBAL::Base::addCache(const std::string& p_name) {
if (opened) { if (opened) {
throw Opened(name, "add cache " + p_name); throw Opened(name, "add cache " + p_name);
} }
Cache<K, V>* cache = new Cache<K, V>(p_name, this); Cache<K, V>* cache = new Cache<K, V>(p_name, this);
tables.insert(std::make_pair(p_name, (StorageBase*)cache)); tables.insert(std::make_pair(p_name, (iStorage*)cache));
return cache; return cache;
} }
template <class K, class V> template <class K, class V>
LMDBDataBase::Storage<K, V>* LMDBDataBase::DataBase::getTable(const std::string& p_name) { LMDBAL::Storage<K, V>* LMDBAL::Base::getTable(const std::string& p_name) {
return static_cast<Storage<K, V>*>(tables.at(p_name)); return static_cast<Storage<K, V>*>(tables.at(p_name));
} }
template <class K, class V> template <class K, class V>
LMDBDataBase::Cache<K, V>* LMDBDataBase::DataBase::getCache(const std::string& p_name) { LMDBAL::Cache<K, V>* LMDBAL::Base::getCache(const std::string& p_name) {
return static_cast<Cache<K, V>*>(tables.at(p_name)); return static_cast<Cache<K, V>*>(tables.at(p_name));
} }
#endif // LMDBDATABASE_DATABASE_H #endif //LMDBAL_BASE_H

View File

@ -14,26 +14,26 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LMDBDATABASE_CACHE_H #ifndef LMDBAL_CACHE_H
#define LMDBDATABASE_CACHE_H #define LMDBAL_CACHE_H
#include <map> #include <map>
#include <set> #include <set>
#include "storage.h" #include "storage.h"
namespace LMDBDataBase { namespace LMDBAL {
template <class K, class V> template <class K, class V>
class Cache : public Storage<K, V> { class Cache : public Storage<K, V> {
friend class DataBase; friend class Base;
enum class Mode { //it's a cache state when we: enum class Mode { //it's a cache state when we:
nothing, // - know nothing about records in database on disk nothing, // - know nothing about records in database on disk
size, // - know just an amount of records size, // - know just an amount of records
full // - shure that our cache is equal to the database on disk full // - shure that our cache is equal to the database on disk
}; };
protected: protected:
Cache(const std::string& name, DataBase* parent); Cache(const std::string& name, Base* parent);
~Cache() override; ~Cache() override;
private: private:
@ -65,4 +65,4 @@ protected:
#include "cache.hpp" #include "cache.hpp"
#endif // LMDBDATABASE_CACHE_H #endif // LMDBAL_CACHE_H

View File

@ -14,14 +14,14 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LMDBDATABASE_CACHE_HPP #ifndef LMDBAL_CACHE_HPP
#define LMDBDATABASE_CACHE_HPP #define LMDBAL_CACHE_HPP
#include "cache.h" #include "cache.h"
#include "exceptions.h" #include "exceptions.h"
template<class K, class V> template<class K, class V>
LMDBDataBase::Cache<K, V>::Cache(const std::string& p_name, DataBase* parent): LMDBAL::Cache<K, V>::Cache(const std::string& p_name, Base* parent):
Storage<K, V>(p_name, parent), Storage<K, V>(p_name, parent),
mode(new Mode), mode(new Mode),
cache(new std::map<K, V>()), cache(new std::map<K, V>()),
@ -33,7 +33,7 @@ LMDBDataBase::Cache<K, V>::Cache(const std::string& p_name, DataBase* parent):
} }
template<class K, class V> template<class K, class V>
LMDBDataBase::Cache<K, V>::~Cache() { LMDBAL::Cache<K, V>::~Cache() {
delete sizeDifference; delete sizeDifference;
delete mode; delete mode;
delete cache; delete cache;
@ -41,11 +41,11 @@ LMDBDataBase::Cache<K, V>::~Cache() {
} }
template<class K, class V> template<class K, class V>
void LMDBDataBase::Cache<K, V>::addRecord(const K& key, const V& value) { void LMDBAL::Cache<K, V>::addRecord(const K& key, const V& value) {
StorageBase::ensureOpened(StorageBase::addRecordMethodName); iStorage::ensureOpened(iStorage::addRecordMethodName);
if (cache->count(key) > 0) if (cache->count(key) > 0)
StorageBase::throwDuplicate(StorageBase::toString(key)); iStorage::throwDuplicate(iStorage::toString(key));
Storage<K, V>::addRecord(key, value); Storage<K, V>::addRecord(key, value);
cache->insert(std::make_pair(key, value)); cache->insert(std::make_pair(key, value));
@ -55,8 +55,8 @@ void LMDBDataBase::Cache<K, V>::addRecord(const K& key, const V& value) {
} }
template<class K, class V> template<class K, class V>
bool LMDBDataBase::Cache<K, V>::forceRecord(const K& key, const V& value) { bool LMDBAL::Cache<K, V>::forceRecord(const K& key, const V& value) {
StorageBase::ensureOpened(StorageBase::forceRecordMethodName); iStorage::ensureOpened(iStorage::forceRecordMethodName);
bool added = Storage<K, V>::forceRecord(key, value); bool added = Storage<K, V>::forceRecord(key, value);
if (*mode == Mode::full) { if (*mode == Mode::full) {
@ -76,19 +76,19 @@ bool LMDBDataBase::Cache<K, V>::forceRecord(const K& key, const V& value) {
} }
template<class K, class V> template<class K, class V>
void LMDBDataBase::Cache<K, V>::changeRecord(const K& key, const V& value) { void LMDBAL::Cache<K, V>::changeRecord(const K& key, const V& value) {
StorageBase::ensureOpened(StorageBase::changeRecordMethodName); iStorage::ensureOpened(iStorage::changeRecordMethodName);
if (*mode == Mode::full) { if (*mode == Mode::full) {
typename std::map<K, V>::iterator itr = cache->find(key); typename std::map<K, V>::iterator itr = cache->find(key);
if (itr == cache->end()) if (itr == cache->end())
StorageBase::throwNotFound(StorageBase::toString(key)); iStorage::throwNotFound(iStorage::toString(key));
Storage<K, V>::changeRecord(key, value); Storage<K, V>::changeRecord(key, value);
itr->second = value; itr->second = value;
} else { } else {
if (abscent->count(key) > 0) if (abscent->count(key) > 0)
StorageBase::throwNotFound(StorageBase::toString(key)); iStorage::throwNotFound(iStorage::toString(key));
try { try {
Storage<K, V>::changeRecord(key, value); Storage<K, V>::changeRecord(key, value);
@ -105,15 +105,15 @@ void LMDBDataBase::Cache<K, V>::changeRecord(const K& key, const V& value) {
} }
template<class K, class V> template<class K, class V>
V LMDBDataBase::Cache<K, V>::getRecord(const K& key) const { V LMDBAL::Cache<K, V>::getRecord(const K& key) const {
StorageBase::ensureOpened(StorageBase::getRecordMethodName); iStorage::ensureOpened(iStorage::getRecordMethodName);
typename std::map<K, V>::const_iterator itr = cache->find(key); typename std::map<K, V>::const_iterator itr = cache->find(key);
if (itr != cache->end()) if (itr != cache->end())
return itr->second; return itr->second;
if (*mode == Mode::full || abscent->count(key) != 0) if (*mode == Mode::full || abscent->count(key) != 0)
StorageBase::throwNotFound(StorageBase::toString(key)); iStorage::throwNotFound(iStorage::toString(key));
try { try {
V value = Storage<K, V>::getRecord(key); V value = Storage<K, V>::getRecord(key);
@ -129,8 +129,8 @@ V LMDBDataBase::Cache<K, V>::getRecord(const K& key) const {
} }
template<class K, class V> template<class K, class V>
bool LMDBDataBase::Cache<K, V>::checkRecord(const K& key) const { bool LMDBAL::Cache<K, V>::checkRecord(const K& key) const {
StorageBase::ensureOpened(StorageBase::checkRecordMethodName); iStorage::ensureOpened(iStorage::checkRecordMethodName);
typename std::map<K, V>::const_iterator itr = cache->find(key); typename std::map<K, V>::const_iterator itr = cache->find(key);
if (itr != cache->end()) if (itr != cache->end())
@ -153,8 +153,8 @@ bool LMDBDataBase::Cache<K, V>::checkRecord(const K& key) const {
} }
template<class K, class V> template<class K, class V>
std::map<K, V> LMDBDataBase::Cache<K, V>::readAll() const { std::map<K, V> LMDBAL::Cache<K, V>::readAll() const {
StorageBase::ensureOpened(StorageBase::readAllMethodName); iStorage::ensureOpened(iStorage::readAllMethodName);
if (*mode != Mode::full) { //there is a room for optimization if (*mode != Mode::full) { //there is a room for optimization
*mode = Mode::full; //I can read and deserialize only those values *mode = Mode::full; //I can read and deserialize only those values
@ -167,7 +167,7 @@ std::map<K, V> LMDBDataBase::Cache<K, V>::readAll() const {
} }
template<class K, class V> template<class K, class V>
void LMDBDataBase::Cache<K, V>::replaceAll(const std::map<K, V>& data) { void LMDBAL::Cache<K, V>::replaceAll(const std::map<K, V>& data) {
Storage<K, V>::replaceAll(data); Storage<K, V>::replaceAll(data);
*cache = data; *cache = data;
@ -179,7 +179,7 @@ void LMDBDataBase::Cache<K, V>::replaceAll(const std::map<K, V>& data) {
} }
template<class K, class V> template<class K, class V>
uint32_t LMDBDataBase::Cache<K, V>::addRecords(const std::map<K, V>& data, bool overwrite) { uint32_t LMDBAL::Cache<K, V>::addRecords(const std::map<K, V>& data, bool overwrite) {
uint32_t newSize = Storage<K, V>::addRecords(data, overwrite); uint32_t newSize = Storage<K, V>::addRecords(data, overwrite);
Mode& m = *mode; Mode& m = *mode;
@ -210,12 +210,12 @@ uint32_t LMDBDataBase::Cache<K, V>::addRecords(const std::map<K, V>& data, bool
} }
template<class K, class V> template<class K, class V>
void LMDBDataBase::Cache<K, V>::removeRecord(const K& key) { void LMDBAL::Cache<K, V>::removeRecord(const K& key) {
StorageBase::ensureOpened(StorageBase::removeRecordMethodName); iStorage::ensureOpened(iStorage::removeRecordMethodName);
typename std::pair<typename std::set<K>::const_iterator, bool> pair = abscent->insert(key); typename std::pair<typename std::set<K>::const_iterator, bool> pair = abscent->insert(key);
if (!pair.second) if (!pair.second)
StorageBase::throwNotFound(StorageBase::toString(key)); iStorage::throwNotFound(iStorage::toString(key));
Storage<K, V>::removeRecord(key); Storage<K, V>::removeRecord(key);
if (cache->erase(key) == 0) //if it was not cached and we are now in size mode then the sizeDifference would decrease if (cache->erase(key) == 0) //if it was not cached and we are now in size mode then the sizeDifference would decrease
@ -226,7 +226,7 @@ void LMDBDataBase::Cache<K, V>::removeRecord(const K& key) {
} }
template<class K, class V> template<class K, class V>
uint32_t LMDBDataBase::Cache<K, V>::count() const { uint32_t LMDBAL::Cache<K, V>::count() const {
switch (*mode) { switch (*mode) {
case Mode::nothing: case Mode::nothing:
{ {
@ -250,7 +250,7 @@ uint32_t LMDBDataBase::Cache<K, V>::count() const {
} }
template<class K, class V> template<class K, class V>
void LMDBDataBase::Cache<K, V>::handleMode() const { void LMDBAL::Cache<K, V>::handleMode() const {
if (*mode == Mode::size) { if (*mode == Mode::size) {
--(*sizeDifference); --(*sizeDifference);
if (*sizeDifference == 0) { if (*sizeDifference == 0) {
@ -261,7 +261,7 @@ void LMDBDataBase::Cache<K, V>::handleMode() const {
} }
template<class K, class V> template<class K, class V>
int LMDBDataBase::Cache<K, V>::drop(MDB_txn * transaction) { int LMDBAL::Cache<K, V>::drop(MDB_txn * transaction) {
int res = Storage<K, V>::drop(transaction); int res = Storage<K, V>::drop(transaction);
cache->clear(); cache->clear();
abscent->clear(); abscent->clear();
@ -270,4 +270,4 @@ int LMDBDataBase::Cache<K, V>::drop(MDB_txn * transaction) {
return res; return res;
} }
#endif //LMDBDATABASE_CACHE_HPP #endif //LMDBAL_CACHE_HPP

View File

@ -16,25 +16,25 @@
#include "exceptions.h" #include "exceptions.h"
LMDBDataBase::Exception::Exception(): LMDBAL::Exception::Exception():
std::exception() std::exception()
{} {}
LMDBDataBase::Exception::~Exception() {} LMDBAL::Exception::~Exception() {}
const char* LMDBDataBase::Exception::what() const noexcept( true ) { const char* LMDBAL::Exception::what() const noexcept( true ) {
std::string* msg = new std::string(getMessage()); std::string* msg = new std::string(getMessage());
return msg->c_str(); return msg->c_str();
} }
LMDBDataBase::Directory::Directory(const std::string& p_path): LMDBAL::Directory::Directory(const std::string& p_path):
Exception(), Exception(),
path(p_path) {} path(p_path) {}
std::string LMDBDataBase::Directory::getMessage() const { std::string LMDBAL::Directory::getMessage() const {
return "Can't create directory for database at " + path;} return "Can't create directory for database at " + path;}
LMDBDataBase::Closed::Closed( LMDBAL::Closed::Closed(
const std::string& p_operation, const std::string& p_operation,
const std::string& p_dbName, const std::string& p_dbName,
const std::optional<std::string>& p_tableName const std::optional<std::string>& p_tableName
@ -44,7 +44,7 @@ LMDBDataBase::Closed::Closed(
dbName(p_dbName), dbName(p_dbName),
tableName(p_tableName) {} tableName(p_tableName) {}
std::string LMDBDataBase::Closed::getMessage() const { std::string LMDBAL::Closed::getMessage() const {
std::string msg = "An attempt to perform operation " + operation std::string msg = "An attempt to perform operation " + operation
+ " on closed database " + dbName; + " on closed database " + dbName;
if (tableName.has_value()) if (tableName.has_value())
@ -53,19 +53,19 @@ std::string LMDBDataBase::Closed::getMessage() const {
return msg; return msg;
} }
LMDBDataBase::Opened::Opened(const std::string& p_dbName, const std::string& p_action): LMDBAL::Opened::Opened(const std::string& p_dbName, const std::string& p_action):
Exception(), Exception(),
dbName(p_dbName), dbName(p_dbName),
action(p_action) {} action(p_action) {}
std::string LMDBDataBase::Opened::getMessage() const { std::string LMDBAL::Opened::getMessage() const {
return "An attempt to " + action return "An attempt to " + action
+ " (the database " + dbName + " (the database " + dbName
+ ") but it's can't be done because the DataBase is already opened"; + ") but it's can't be done because the Base is already opened";
} }
LMDBDataBase::NotFound::NotFound( LMDBAL::NotFound::NotFound(
const std::string& p_key, const std::string& p_key,
const std::string& p_dbName, const std::string& p_dbName,
const std::string& p_tableName const std::string& p_tableName
@ -75,12 +75,12 @@ LMDBDataBase::NotFound::NotFound(
dbName(p_dbName), dbName(p_dbName),
tableName(p_tableName) {} tableName(p_tableName) {}
std::string LMDBDataBase::NotFound::getMessage() const { std::string LMDBAL::NotFound::getMessage() const {
return "Element for id " + key + " wasn't found " return "Element for id " + key + " wasn't found "
+ " in database " + dbName + " in database " + dbName
+ " in table " + tableName;} + " in table " + tableName;}
LMDBDataBase::Exist::Exist( LMDBAL::Exist::Exist(
const std::string& p_key, const std::string& p_key,
const std::string& p_dbName, const std::string& p_dbName,
const std::string& p_tableName const std::string& p_tableName
@ -90,14 +90,14 @@ LMDBDataBase::Exist::Exist(
dbName(p_dbName), dbName(p_dbName),
tableName(p_tableName) {} tableName(p_tableName) {}
std::string LMDBDataBase::Exist::getMessage() const { std::string LMDBAL::Exist::getMessage() const {
return "An attempt to insert element with key " + key return "An attempt to insert element with key " + key
+ " to database " + dbName + " to database " + dbName
+ " to table " + tableName + " to table " + tableName
+ " but it already has an element with given id"; + " but it already has an element with given id";
} }
LMDBDataBase::Unknown::Unknown( LMDBAL::Unknown::Unknown(
const std::string& p_dbName, const std::string& p_dbName,
const std::string& message, const std::string& message,
const std::optional<std::string>& p_tableName const std::optional<std::string>& p_tableName
@ -107,7 +107,7 @@ LMDBDataBase::Unknown::Unknown(
tableName(p_tableName), tableName(p_tableName),
msg(message) {} msg(message) {}
std::string LMDBDataBase::Unknown::getMessage() const { std::string LMDBAL::Unknown::getMessage() const {
std::string result = "Unknown error in database " + dbName; std::string result = "Unknown error in database " + dbName;
if (tableName.has_value()) if (tableName.has_value())
result += " in table " + tableName.value(); result += " in table " + tableName.value();

View File

@ -14,14 +14,14 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LMDBDATABASE_EXCEPTIONS_H #ifndef LMDBAL_EXCEPTIONS_H
#define LMDBDATABASE_EXCEPTIONS_H #define LMDBAL_EXCEPTIONS_H
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <optional> #include <optional>
namespace LMDBDataBase { namespace LMDBAL {
class Exception : public std::exception { class Exception : public std::exception {
public: public:
@ -98,4 +98,4 @@ private:
} }
#endif //LMDBDATABASE_EXCEPTIONS_H #endif //LMDBAL_EXCEPTIONS_H

View File

@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef CORE_OPERATORS_HPP #ifndef LMDBAL_OPERATORS_HPP
#define CORE_OPERATORS_HPP #define LMDBAL_OPERATORS_HPP
#include <map> #include <map>
#include <set> #include <set>
@ -206,4 +206,4 @@ QDataStream& operator >> (QDataStream &in, std::list<K>& container) {
return in; return in;
} }
#endif //CORE_OPERATORS_HPP #endif //LMDBAL_OPERATORS_HPP

View File

@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LMDBDATABASE_SERIALIZER_H #ifndef LMDBAL_SERIALIZER_H
#define LMDBDATABASE_SERIALIZER_H #define LMDBAL_SERIALIZER_H
#include <cstring> #include <cstring>
@ -23,9 +23,9 @@
#include <QBuffer> #include <QBuffer>
#include <QDataStream> #include <QDataStream>
#include "database.h" #include <lmdb.h>
namespace LMDBDataBase { namespace LMDBAL {
template<class T> template<class T>
class Serializer { class Serializer {
@ -66,4 +66,4 @@ private:
#include "serializer_qstring.hpp" #include "serializer_qstring.hpp"
#include "serializer_qbytearray.hpp" #include "serializer_qbytearray.hpp"
#endif // LMDBDATABASE_SERIALIZER_H #endif // LMDBAL_SERIALIZER_H

View File

@ -14,13 +14,13 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LMDBDATABASE_SERIALIZER_HPP #ifndef LMDBAL_SERIALIZER_HPP
#define LMDBDATABASE_SERIALIZER_HPP #define LMDBAL_SERIALIZER_HPP
#include "serializer.h" #include "serializer.h"
template<class T> template<class T>
LMDBDataBase::Serializer<T>::Serializer() : LMDBAL::Serializer<T>::Serializer() :
bytes(), bytes(),
buffer(&bytes), buffer(&bytes),
stream(&buffer) stream(&buffer)
@ -29,7 +29,7 @@ LMDBDataBase::Serializer<T>::Serializer() :
} }
template<class T> template<class T>
LMDBDataBase::Serializer<T>::Serializer(const T& value) : LMDBAL::Serializer<T>::Serializer(const T& value) :
bytes(), bytes(),
buffer(&bytes), buffer(&bytes),
stream(&buffer) stream(&buffer)
@ -39,19 +39,19 @@ LMDBDataBase::Serializer<T>::Serializer(const T& value) :
} }
template<class T> template<class T>
LMDBDataBase::Serializer<T>::~Serializer() { LMDBAL::Serializer<T>::~Serializer() {
buffer.close(); buffer.close();
} }
template<class T> template<class T>
MDB_val LMDBDataBase::Serializer<T>::setData(const T& value) { MDB_val LMDBAL::Serializer<T>::setData(const T& value) {
clear(); clear();
_setData(value); _setData(value);
return getData(); return getData();
} }
template<class T> template<class T>
T LMDBDataBase::Serializer<T>::deserialize(const MDB_val& value) { T LMDBAL::Serializer<T>::deserialize(const MDB_val& value) {
clear(); clear();
bytes.setRawData((char*)value.mv_data, value.mv_size); bytes.setRawData((char*)value.mv_data, value.mv_size);
T result; T result;
@ -61,19 +61,19 @@ T LMDBDataBase::Serializer<T>::deserialize(const MDB_val& value) {
} }
template<class T> template<class T>
void LMDBDataBase::Serializer<T>::_setData(const T& value) { void LMDBAL::Serializer<T>::_setData(const T& value) {
stream << value; stream << value;
} }
template<class T> template<class T>
void LMDBDataBase::Serializer<T>::clear() { void LMDBAL::Serializer<T>::clear() {
if (buffer.pos() > 0) { if (buffer.pos() > 0) {
buffer.seek(0); buffer.seek(0);
} }
} }
template<class T> template<class T>
MDB_val LMDBDataBase::Serializer<T>::getData() { MDB_val LMDBAL::Serializer<T>::getData() {
MDB_val val; MDB_val val;
val.mv_size = buffer.pos(); val.mv_size = buffer.pos();
@ -82,4 +82,4 @@ MDB_val LMDBDataBase::Serializer<T>::getData() {
return val; return val;
} }
#endif //LMDBDATABASE_SERIALIZER_HPP #endif //LMDBAL_SERIALIZER_HPP

View File

@ -14,10 +14,10 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LMDBDATABASE_SERIALIZER_DOUBLE_HPP #ifndef LMDBAL_SERIALIZER_DOUBLE_HPP
#define LMDBDATABASE_SERIALIZER_DOUBLE_HPP #define LMDBAL_SERIALIZER_DOUBLE_HPP
namespace LMDBDataBase { namespace LMDBAL {
template<> template<>
class Serializer<double> { class Serializer<double> {
@ -48,7 +48,7 @@ private:
} }
#endif //LMDBDATABASE_SERIALIZER_DOUBLE_HPP #endif //LMDBAL_SERIALIZER_DOUBLE_HPP

View File

@ -14,10 +14,10 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LMDBDATABASE_SERIALIZER_FLOAT_HPP #ifndef LMDBAL_SERIALIZER_FLOAT_HPP
#define LMDBDATABASE_SERIALIZER_FLOAT_HPP #define LMDBAL_SERIALIZER_FLOAT_HPP
namespace LMDBDataBase { namespace LMDBAL {
template<> template<>
class Serializer<float> { class Serializer<float> {
@ -48,7 +48,7 @@ private:
} }
#endif //LMDBDATABASE_SERIALIZER_FLOAT_HPP #endif //LMDBAL_SERIALIZER_FLOAT_HPP

View File

@ -14,12 +14,12 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LMDBDATABASE_SERIALIZER_INT16_HPP #ifndef LMDBAL_SERIALIZER_INT16_HPP
#define LMDBDATABASE_SERIALIZER_INT16_HPP #define LMDBAL_SERIALIZER_INT16_HPP
#include <stdint.h> #include <stdint.h>
namespace LMDBDataBase { namespace LMDBAL {
template<> template<>
class Serializer<int16_t> { class Serializer<int16_t> {
@ -50,4 +50,4 @@ private:
} }
#endif //LMDBDATABASE_SERIALIZER_INT16_HPP #endif //LMDBAL_SERIALIZER_INT16_HPP

View File

@ -14,12 +14,12 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LMDBDATABASE_SERIALIZER_INT32_HPP #ifndef LMDBAL_SERIALIZER_INT32_HPP
#define LMDBDATABASE_SERIALIZER_INT32_HPP #define LMDBAL_SERIALIZER_INT32_HPP
#include <stdint.h> #include <stdint.h>
namespace LMDBDataBase { namespace LMDBAL {
template<> template<>
class Serializer<int32_t> { class Serializer<int32_t> {
@ -50,7 +50,7 @@ private:
} }
#endif //CORE_DATABASE_SERIALIZER_INT32_HPP #endif //LMDBAL_SERIALIZER_INT32_HPP

View File

@ -14,12 +14,12 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LMDBDATABASE_SERIALIZER_INT64_HPP #ifndef LMDBAL_SERIALIZER_INT64_HPP
#define LMDBDATABASE_SERIALIZER_INT64_HPP #define LMDBAL_SERIALIZER_INT64_HPP
#include <stdint.h> #include <stdint.h>
namespace LMDBDataBase { namespace LMDBAL {
template<> template<>
class Serializer<int64_t> { class Serializer<int64_t> {
@ -50,7 +50,7 @@ private:
} }
#endif //CORE_DATABASE_SERIALIZER_INT64_HPP #endif //LMDBAL_SERIALIZER_INT64_HPP

View File

@ -14,12 +14,12 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LMDBDATABASE_SERIALIZER_INT8_HPP #ifndef LMDBAL_SERIALIZER_INT8_HPP
#define LMDBDATABASE_SERIALIZER_INT8_HPP #define LMDBAL_SERIALIZER_INT8_HPP
#include <stdint.h> #include <stdint.h>
namespace LMDBDataBase { namespace LMDBAL {
template<> template<>
class Serializer<int8_t> { class Serializer<int8_t> {
@ -50,7 +50,7 @@ private:
} }
#endif //LMDBDATABASE_SERIALIZER_INT8_HPP #endif //LMDBAL_SERIALIZER_INT8_HPP

View File

@ -14,12 +14,12 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LMDBDATABASE_SERIALIZER_QBYTEARRAY_HPP #ifndef LMDBAL_SERIALIZER_QBYTEARRAY_HPP
#define LMDBDATABASE_SERIALIZER_QBYTEARRAY_HPP #define LMDBAL_SERIALIZER_QBYTEARRAY_HPP
#include <QByteArray> #include <QByteArray>
namespace LMDBDataBase { namespace LMDBAL {
template<> template<>
class Serializer<QByteArray> { class Serializer<QByteArray> {
@ -52,7 +52,7 @@ private:
} }
#endif //LMDBDATABASE_SERIALIZER_QBYTEARRAY_HPP #endif //LMDBAL_SERIALIZER_QBYTEARRAY_HPP

View File

@ -14,13 +14,13 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LMDBDATABASE_SERIALIZER_QSTRING_HPP #ifndef LMDBAL_SERIALIZER_QSTRING_HPP
#define LMDBDATABASE_SERIALIZER_QSTRING_HPP #define LMDBAL_SERIALIZER_QSTRING_HPP
#include <QString> #include <QString>
#include <QByteArray> #include <QByteArray>
namespace LMDBDataBase { namespace LMDBAL {
template<> template<>
class Serializer<QString> { class Serializer<QString> {
@ -51,7 +51,7 @@ private:
} }
#endif //LMDBDATABASE_SERIALIZER_QSTRING_HPP #endif //LMDBAL_SERIALIZER_QSTRING_HPP

View File

@ -14,12 +14,12 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LMDBDATABASE_SERIALIZER_STDSTRING_HPP #ifndef LMDBAL_SERIALIZER_STDSTRING_HPP
#define LMDBDATABASE_SERIALIZER_STDSTRING_HPP #define LMDBAL_SERIALIZER_STDSTRING_HPP
#include <string> #include <string>
namespace LMDBDataBase { namespace LMDBAL {
template<> template<>
class Serializer<std::string> { class Serializer<std::string> {
@ -50,7 +50,7 @@ private:
} }
#endif //LMDBDATABASE_SERIALIZER_STDSTRING_HPP #endif //LMDBAL_SERIALIZER_STDSTRING_HPP

View File

@ -14,12 +14,12 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LMDBDATABASE_SERIALIZER_UINT16_HPP #ifndef LMDBAL_SERIALIZER_UINT16_HPP
#define LMDBDATABASE_SERIALIZER_UINT16_HPP #define LMDBAL_SERIALIZER_UINT16_HPP
#include <stdint.h> #include <stdint.h>
namespace LMDBDataBase { namespace LMDBAL {
template<> template<>
class Serializer<uint16_t> { class Serializer<uint16_t> {
@ -50,6 +50,6 @@ private:
} }
#endif //LMDBDATABASE_SERIALIZER_UINT16_HPP #endif //LMDBAL_SERIALIZER_UINT16_HPP

View File

@ -14,12 +14,12 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LMDBDATABASE_SERIALIZER_UINT32_HPP #ifndef LMDBAL_SERIALIZER_UINT32_HPP
#define LMDBDATABASE_SERIALIZER_UINT32_HPP #define LMDBAL_SERIALIZER_UINT32_HPP
#include <stdint.h> #include <stdint.h>
namespace LMDBDataBase { namespace LMDBAL {
template<> template<>
class Serializer<uint32_t> { class Serializer<uint32_t> {
@ -50,4 +50,4 @@ private:
} }
#endif //LMDBDATABASE_SERIALIZER_UINT32_HPP #endif //LMDBAL_SERIALIZER_UINT32_HPP

View File

@ -14,12 +14,12 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LMDBDATABASE_SERIALIZER_UINT64_HPP #ifndef LMDBAL_SERIALIZER_UINT64_HPP
#define LMDBDATABASE_SERIALIZER_UINT64_HPP #define LMDBAL_SERIALIZER_UINT64_HPP
#include <stdint.h> #include <stdint.h>
namespace LMDBDataBase { namespace LMDBAL {
template<> template<>
class Serializer<uint64_t> { class Serializer<uint64_t> {
@ -50,5 +50,5 @@ private:
} }
#endif //LMDBDATABASE_SERIALIZER_UINT64_HPP #endif //LMDBAL_SERIALIZER_UINT64_HPP

View File

@ -14,12 +14,12 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LMDBDATABASE_SERIALIZER_UINT8_HPP #ifndef LMDBAL_SERIALIZER_UINT8_HPP
#define LMDBDATABASE_SERIALIZER_UINT8_HPP #define LMDBAL_SERIALIZER_UINT8_HPP
#include <stdint.h> #include <stdint.h>
namespace LMDBDataBase { namespace LMDBAL {
template<> template<>
class Serializer<uint8_t> { class Serializer<uint8_t> {
@ -50,7 +50,7 @@ private:
} }
#endif //LMDBDATABASE_SERIALIZER_UINT8_HPP #endif //LMDBAL_SERIALIZER_UINT8_HPP

View File

@ -16,15 +16,15 @@
#include "storage.h" #include "storage.h"
LMDBDataBase::StorageBase::StorageBase(const std::string& p_name, DataBase* parent): LMDBAL::iStorage::iStorage(const std::string& p_name, Base* parent):
dbi(), dbi(),
db(parent), db(parent),
name(p_name) name(p_name)
{} {}
LMDBDataBase::StorageBase::~StorageBase() {} LMDBAL::iStorage::~iStorage() {}
void LMDBDataBase::StorageBase::drop() { void LMDBAL::iStorage::drop() {
ensureOpened(dropMethodName); ensureOpened(dropMethodName);
MDB_txn *txn; MDB_txn *txn;
@ -42,22 +42,22 @@ void LMDBDataBase::StorageBase::drop() {
mdb_txn_commit(txn); mdb_txn_commit(txn);
} }
int LMDBDataBase::StorageBase::drop(MDB_txn* transaction) { int LMDBAL::iStorage::drop(MDB_txn* transaction) {
return mdb_drop(transaction, dbi, 0); return mdb_drop(transaction, dbi, 0);
} }
const std::string & LMDBDataBase::StorageBase::dbName() const { const std::string & LMDBAL::iStorage::dbName() const {
return db->name;} return db->name;}
bool LMDBDataBase::StorageBase::isDBOpened() const { bool LMDBAL::iStorage::isDBOpened() const {
return db->opened;} return db->opened;}
void LMDBDataBase::StorageBase::ensureOpened(const std::string& methodName) const { void LMDBAL::iStorage::ensureOpened(const std::string& methodName) const {
if (!db->opened) if (!db->opened)
throw Closed(methodName, db->name, name); throw Closed(methodName, db->name, name);
} }
uint32_t LMDBDataBase::StorageBase::count() const { uint32_t LMDBAL::iStorage::count() const {
ensureOpened(countMethodName); ensureOpened(countMethodName);
MDB_txn *txn; MDB_txn *txn;
@ -78,7 +78,7 @@ uint32_t LMDBDataBase::StorageBase::count() const {
return amount; return amount;
} }
void LMDBDataBase::StorageBase::throwDuplicateOrUnknown(int rc, TransactionID txn, const std::string& key) const { void LMDBAL::iStorage::throwDuplicateOrUnknown(int rc, TransactionID txn, const std::string& key) const {
abortTransaction(txn); abortTransaction(txn);
if (rc == MDB_KEYEXIST) if (rc == MDB_KEYEXIST)
throwDuplicate(key); throwDuplicate(key);
@ -86,7 +86,7 @@ void LMDBDataBase::StorageBase::throwDuplicateOrUnknown(int rc, TransactionID tx
throwUnknown(rc); throwUnknown(rc);
} }
void LMDBDataBase::StorageBase::throwNotFoundOrUnknown(int rc, LMDBDataBase::TransactionID txn, const std::string& key) const { void LMDBAL::iStorage::throwNotFoundOrUnknown(int rc, LMDBAL::TransactionID txn, const std::string& key) const {
abortTransaction(txn); abortTransaction(txn);
if (rc == MDB_NOTFOUND) if (rc == MDB_NOTFOUND)
throwNotFound(key); throwNotFound(key);
@ -94,28 +94,28 @@ void LMDBDataBase::StorageBase::throwNotFoundOrUnknown(int rc, LMDBDataBase::Tra
throwUnknown(rc); throwUnknown(rc);
} }
void LMDBDataBase::StorageBase::throwUnknown(int rc, LMDBDataBase::TransactionID txn) const { void LMDBAL::iStorage::throwUnknown(int rc, LMDBAL::TransactionID txn) const {
abortTransaction(txn); abortTransaction(txn);
throwUnknown(rc); throwUnknown(rc);
} }
void LMDBDataBase::StorageBase::throwUnknown(int rc) const { void LMDBAL::iStorage::throwUnknown(int rc) const {
throw Unknown(db->name, mdb_strerror(rc), name);} throw Unknown(db->name, mdb_strerror(rc), name);}
void LMDBDataBase::StorageBase::throwDuplicate(const std::string& key) const { void LMDBAL::iStorage::throwDuplicate(const std::string& key) const {
throw Exist(key, db->name, name);} throw Exist(key, db->name, name);}
void LMDBDataBase::StorageBase::throwNotFound(const std::string& key) const { void LMDBAL::iStorage::throwNotFound(const std::string& key) const {
throw NotFound(key, db->name, name);} throw NotFound(key, db->name, name);}
LMDBDataBase::TransactionID LMDBDataBase::StorageBase::beginReadOnlyTransaction() const { LMDBAL::TransactionID LMDBAL::iStorage::beginReadOnlyTransaction() const {
return db->beginReadOnlyTransaction(name);} return db->beginReadOnlyTransaction(name);}
LMDBDataBase::TransactionID LMDBDataBase::StorageBase::beginTransaction() const { LMDBAL::TransactionID LMDBAL::iStorage::beginTransaction() const {
return db->beginTransaction(name);} return db->beginTransaction(name);}
void LMDBDataBase::StorageBase::abortTransaction(LMDBDataBase::TransactionID id) const { void LMDBAL::iStorage::abortTransaction(LMDBAL::TransactionID id) const {
db->abortTransaction(id);} db->abortTransaction(id);}
void LMDBDataBase::StorageBase::commitTransaction(LMDBDataBase::TransactionID id) const { void LMDBAL::iStorage::commitTransaction(LMDBAL::TransactionID id) const {
db->commitTransaction(id);} db->commitTransaction(id);}

View File

@ -14,19 +14,19 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LMDBDATABASE_STORAGE_H #ifndef LMDBAL_STORAGE_H
#define LMDBDATABASE_STORAGE_H #define LMDBAL_STORAGE_H
#include "database.h" #include "base.h"
#include "serializer.h" #include "serializer.h"
namespace LMDBDataBase { namespace LMDBAL {
class StorageBase { class iStorage {
friend class DataBase; friend class Base;
protected: protected:
StorageBase(const std::string& name, DataBase* parent); iStorage(const std::string& name, Base* parent);
virtual ~StorageBase(); virtual ~iStorage();
virtual int createTable(MDB_txn * transaction) = 0; virtual int createTable(MDB_txn * transaction) = 0;
virtual int drop(MDB_txn * transaction); virtual int drop(MDB_txn * transaction);
@ -53,7 +53,7 @@ public:
protected: protected:
MDB_dbi dbi; MDB_dbi dbi;
DataBase* db; Base* db;
const std::string name; const std::string name;
inline static const std::string dropMethodName = "drop"; inline static const std::string dropMethodName = "drop";
@ -78,14 +78,14 @@ protected:
}; };
template <class K, class V> template <class K, class V>
class Storage : public StorageBase { class Storage : public iStorage {
friend class DataBase; friend class Base;
protected: protected:
Storage(const std::string& name, DataBase* parent); Storage(const std::string& name, Base* parent);
~Storage() override; ~Storage() override;
public: public:
using StorageBase::drop; using iStorage::drop;
virtual void addRecord(const K& key, const V& value); virtual void addRecord(const K& key, const V& value);
virtual bool forceRecord(const K& key, const V& value); //returns true if there was addition, false if change virtual bool forceRecord(const K& key, const V& value); //returns true if there was addition, false if change
virtual void changeRecord(const K& key, const V& value); virtual void changeRecord(const K& key, const V& value);
@ -107,4 +107,4 @@ protected:
#include "storage.hpp" #include "storage.hpp"
#endif // LMDBDATABASE_STORAGE_H #endif //LMDBAL_STORAGE_H

View File

@ -14,27 +14,27 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LMDBDATABASE_STORAGE_HPP #ifndef LMDBAL_STORAGE_HPP
#define LMDBDATABASE_STORAGE_HPP #define LMDBAL_STORAGE_HPP
#include "storage.h" #include "storage.h"
#include "exceptions.h" #include "exceptions.h"
template<class K, class V> template<class K, class V>
LMDBDataBase::Storage<K, V>::Storage(const std::string& p_name, DataBase* parent): LMDBAL::Storage<K, V>::Storage(const std::string& p_name, Base* parent):
StorageBase(p_name, parent), iStorage(p_name, parent),
keySerializer(new Serializer<K>()), keySerializer(new Serializer<K>()),
valueSerializer(new Serializer<V>()) valueSerializer(new Serializer<V>())
{} {}
template<class K, class V> template<class K, class V>
LMDBDataBase::Storage<K, V>::~Storage() { LMDBAL::Storage<K, V>::~Storage() {
delete valueSerializer; delete valueSerializer;
delete keySerializer; delete keySerializer;
} }
template<class K, class V> template<class K, class V>
void LMDBDataBase::Storage<K, V>::addRecord(const K& key, const V& value) { void LMDBAL::Storage<K, V>::addRecord(const K& key, const V& value) {
ensureOpened(addRecordMethodName); ensureOpened(addRecordMethodName);
TransactionID txn = beginTransaction(); TransactionID txn = beginTransaction();
@ -49,7 +49,7 @@ void LMDBDataBase::Storage<K, V>::addRecord(const K& key, const V& value) {
} }
template<class K, class V> template<class K, class V>
bool LMDBDataBase::Storage<K, V>::forceRecord(const K& key, const V& value) { bool LMDBAL::Storage<K, V>::forceRecord(const K& key, const V& value) {
ensureOpened(forceRecordMethodName); ensureOpened(forceRecordMethodName);
bool added; bool added;
@ -81,7 +81,7 @@ bool LMDBDataBase::Storage<K, V>::forceRecord(const K& key, const V& value) {
} }
template<class K, class V> template<class K, class V>
void LMDBDataBase::Storage<K, V>::changeRecord(const K& key, const V& value) { void LMDBAL::Storage<K, V>::changeRecord(const K& key, const V& value) {
ensureOpened(changeRecordMethodName); ensureOpened(changeRecordMethodName);
TransactionID txn = beginTransaction(); TransactionID txn = beginTransaction();
@ -96,7 +96,7 @@ void LMDBDataBase::Storage<K, V>::changeRecord(const K& key, const V& value) {
} }
template<class K, class V> template<class K, class V>
V LMDBDataBase::Storage<K, V>::getRecord(const K& key) const { V LMDBAL::Storage<K, V>::getRecord(const K& key) const {
ensureOpened(getRecordMethodName); ensureOpened(getRecordMethodName);
TransactionID txn = beginReadOnlyTransaction(); TransactionID txn = beginReadOnlyTransaction();
@ -114,7 +114,7 @@ V LMDBDataBase::Storage<K, V>::getRecord(const K& key) const {
} }
template<class K, class V> template<class K, class V>
bool LMDBDataBase::Storage<K, V>::checkRecord(const K& key) const { bool LMDBAL::Storage<K, V>::checkRecord(const K& key) const {
ensureOpened(checkRecordMethodName); ensureOpened(checkRecordMethodName);
TransactionID txn = beginReadOnlyTransaction(); TransactionID txn = beginReadOnlyTransaction();
@ -134,7 +134,7 @@ bool LMDBDataBase::Storage<K, V>::checkRecord(const K& key) const {
} }
template<class K, class V> template<class K, class V>
std::map<K, V> LMDBDataBase::Storage<K, V>::readAll() const { std::map<K, V> LMDBAL::Storage<K, V>::readAll() const {
ensureOpened(readAllMethodName); ensureOpened(readAllMethodName);
TransactionID txn = beginReadOnlyTransaction(); TransactionID txn = beginReadOnlyTransaction();
@ -162,7 +162,7 @@ std::map<K, V> LMDBDataBase::Storage<K, V>::readAll() const {
} }
template<class K, class V> template<class K, class V>
void LMDBDataBase::Storage<K, V>::replaceAll(const std::map<K, V>& data) { void LMDBAL::Storage<K, V>::replaceAll(const std::map<K, V>& data) {
ensureOpened(replaceAllMethodName); ensureOpened(replaceAllMethodName);
TransactionID txn = beginTransaction(); TransactionID txn = beginTransaction();
@ -183,7 +183,7 @@ void LMDBDataBase::Storage<K, V>::replaceAll(const std::map<K, V>& data) {
} }
template<class K, class V> template<class K, class V>
uint32_t LMDBDataBase::Storage<K, V>::addRecords(const std::map<K, V>& data, bool overwrite) { uint32_t LMDBAL::Storage<K, V>::addRecords(const std::map<K, V>& data, bool overwrite) {
ensureOpened(addRecordsMethodName); ensureOpened(addRecordsMethodName);
TransactionID txn = beginTransaction(); TransactionID txn = beginTransaction();
@ -211,7 +211,7 @@ uint32_t LMDBDataBase::Storage<K, V>::addRecords(const std::map<K, V>& data, boo
} }
template<class K, class V> template<class K, class V>
void LMDBDataBase::Storage<K, V>::removeRecord(const K& key) { void LMDBAL::Storage<K, V>::removeRecord(const K& key) {
ensureOpened(removeRecordMethodName); ensureOpened(removeRecordMethodName);
TransactionID txn = beginTransaction(); TransactionID txn = beginTransaction();
@ -224,68 +224,68 @@ void LMDBDataBase::Storage<K, V>::removeRecord(const K& key) {
} }
template<class K, class V> template<class K, class V>
int LMDBDataBase::Storage<K, V>::createTable(MDB_txn* transaction) { int LMDBAL::Storage<K, V>::createTable(MDB_txn* transaction) {
return makeTable<K>(transaction); return makeTable<K>(transaction);
} }
template<class K> template<class K>
inline int LMDBDataBase::StorageBase::makeTable(MDB_txn* transaction) { inline int LMDBAL::iStorage::makeTable(MDB_txn* transaction) {
return mdb_dbi_open(transaction, name.c_str(), MDB_CREATE, &dbi); return mdb_dbi_open(transaction, name.c_str(), MDB_CREATE, &dbi);
} }
template<> template<>
inline int LMDBDataBase::StorageBase::makeTable<uint64_t>(MDB_txn* transaction) { inline int LMDBAL::iStorage::makeTable<uint64_t>(MDB_txn* transaction) {
return mdb_dbi_open(transaction, name.c_str(), MDB_CREATE | MDB_INTEGERKEY, &dbi); return mdb_dbi_open(transaction, name.c_str(), MDB_CREATE | MDB_INTEGERKEY, &dbi);
} }
template<> template<>
inline int LMDBDataBase::StorageBase::makeTable<uint32_t>(MDB_txn* transaction) { inline int LMDBAL::iStorage::makeTable<uint32_t>(MDB_txn* transaction) {
return mdb_dbi_open(transaction, name.c_str(), MDB_CREATE | MDB_INTEGERKEY, &dbi); return mdb_dbi_open(transaction, name.c_str(), MDB_CREATE | MDB_INTEGERKEY, &dbi);
} }
template<> template<>
inline int LMDBDataBase::StorageBase::makeTable<uint16_t>(MDB_txn* transaction) { inline int LMDBAL::iStorage::makeTable<uint16_t>(MDB_txn* transaction) {
return mdb_dbi_open(transaction, name.c_str(), MDB_CREATE | MDB_INTEGERKEY, &dbi); return mdb_dbi_open(transaction, name.c_str(), MDB_CREATE | MDB_INTEGERKEY, &dbi);
} }
template<> template<>
inline int LMDBDataBase::StorageBase::makeTable<uint8_t>(MDB_txn* transaction) { inline int LMDBAL::iStorage::makeTable<uint8_t>(MDB_txn* transaction) {
return mdb_dbi_open(transaction, name.c_str(), MDB_CREATE | MDB_INTEGERKEY, &dbi); return mdb_dbi_open(transaction, name.c_str(), MDB_CREATE | MDB_INTEGERKEY, &dbi);
} }
template<> template<>
inline int LMDBDataBase::StorageBase::makeTable<int64_t>(MDB_txn* transaction) { inline int LMDBAL::iStorage::makeTable<int64_t>(MDB_txn* transaction) {
return mdb_dbi_open(transaction, name.c_str(), MDB_CREATE | MDB_INTEGERKEY, &dbi); return mdb_dbi_open(transaction, name.c_str(), MDB_CREATE | MDB_INTEGERKEY, &dbi);
} }
template<> template<>
inline int LMDBDataBase::StorageBase::makeTable<int32_t>(MDB_txn* transaction) { inline int LMDBAL::iStorage::makeTable<int32_t>(MDB_txn* transaction) {
return mdb_dbi_open(transaction, name.c_str(), MDB_CREATE | MDB_INTEGERKEY, &dbi); return mdb_dbi_open(transaction, name.c_str(), MDB_CREATE | MDB_INTEGERKEY, &dbi);
} }
template<> template<>
inline int LMDBDataBase::StorageBase::makeTable<int16_t>(MDB_txn* transaction) { inline int LMDBAL::iStorage::makeTable<int16_t>(MDB_txn* transaction) {
return mdb_dbi_open(transaction, name.c_str(), MDB_CREATE | MDB_INTEGERKEY, &dbi); return mdb_dbi_open(transaction, name.c_str(), MDB_CREATE | MDB_INTEGERKEY, &dbi);
} }
template<> template<>
inline int LMDBDataBase::StorageBase::makeTable<int8_t>(MDB_txn* transaction) { inline int LMDBAL::iStorage::makeTable<int8_t>(MDB_txn* transaction) {
return mdb_dbi_open(transaction, name.c_str(), MDB_CREATE | MDB_INTEGERKEY, &dbi); return mdb_dbi_open(transaction, name.c_str(), MDB_CREATE | MDB_INTEGERKEY, &dbi);
} }
template<class T> template<class T>
inline std::string LMDBDataBase::StorageBase::toString(const T& value) { inline std::string LMDBAL::iStorage::toString(const T& value) {
return std::to_string(value); return std::to_string(value);
} }
template<> template<>
inline std::string LMDBDataBase::StorageBase::toString(const QString& value) { inline std::string LMDBAL::iStorage::toString(const QString& value) {
return value.toStdString(); return value.toStdString();
} }
template<> template<>
inline std::string LMDBDataBase::StorageBase::toString(const std::string& value) { inline std::string LMDBAL::iStorage::toString(const std::string& value) {
return value; return value;
} }
#endif //LMDBDATABASE_STORAGE_HPP #endif //LMDBAL_STORAGE_HPP

View File

@ -8,14 +8,14 @@ add_executable(runUnitTests
target_compile_options(runUnitTests PRIVATE -fPIC) target_compile_options(runUnitTests PRIVATE -fPIC)
target_include_directories(runUnitTests PRIVATE ${CMAKE_SOURCE_DIR}) target_include_directories(runUnitTests PRIVATE ${CMAKE_SOURCE_DIR}/src)
target_include_directories(runUnitTests PRIVATE ${Qt${QT_VERSION_MAJOR}_INCLUDE_DIRS}) target_include_directories(runUnitTests PRIVATE ${Qt${QT_VERSION_MAJOR}_INCLUDE_DIRS})
target_include_directories(runUnitTests PRIVATE ${Qt${QT_VERSION_MAJOR}Core_INCLUDE_DIRS}) target_include_directories(runUnitTests PRIVATE ${Qt${QT_VERSION_MAJOR}Core_INCLUDE_DIRS})
target_link_libraries( target_link_libraries(
runUnitTests runUnitTests
GTest::gtest_main GTest::gtest_main
storage lmdbal
) )
include(GoogleTest) include(GoogleTest)

View File

@ -1,24 +1,24 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "database.h" #include "base.h"
#include "storage.h" #include "storage.h"
#include "cache.h" #include "cache.h"
#include <QString> #include <QString>
class DataBaseTest : public ::testing::Test { class BaseTest : public ::testing::Test {
protected: protected:
DataBaseTest(): BaseTest():
::testing::Test(), ::testing::Test(),
t1(db->getTable<uint32_t, uint32_t>("table1")), t1(db->getTable<uint32_t, uint32_t>("table1")),
t2(db->getTable<QString, QString>("table2")), t2(db->getTable<QString, QString>("table2")),
c1(db->getCache<int8_t, std::string>("cache1")) {} c1(db->getCache<int8_t, std::string>("cache1")) {}
~DataBaseTest() {} ~BaseTest() {}
static void SetUpTestSuite() { static void SetUpTestSuite() {
if (db == nullptr) { if (db == nullptr) {
db = new LMDBDataBase::DataBase("testBase"); db = new LMDBAL::Base("testBase");
db->addTable<uint32_t, uint32_t>("table1"); db->addTable<uint32_t, uint32_t>("table1");
db->addTable<QString, QString>("table2"); db->addTable<QString, QString>("table2");
db->addCache<int8_t, std::string>("cache1"); db->addCache<int8_t, std::string>("cache1");
@ -32,21 +32,21 @@ protected:
db = nullptr; db = nullptr;
} }
static LMDBDataBase::DataBase* db; static LMDBAL::Base* db;
LMDBDataBase::Storage<uint32_t, uint32_t>* t1; LMDBAL::Storage<uint32_t, uint32_t>* t1;
LMDBDataBase::Storage<QString, QString>* t2; LMDBAL::Storage<QString, QString>* t2;
LMDBDataBase::Cache<int8_t, std::string>* c1; LMDBAL::Cache<int8_t, std::string>* c1;
}; };
LMDBDataBase::DataBase* DataBaseTest::db = nullptr; LMDBAL::Base* BaseTest::db = nullptr;
TEST_F(DataBaseTest, RemovingDirectory) { TEST_F(BaseTest, RemovingDirectory) {
EXPECT_EQ(db->removeDirectory(), true); EXPECT_EQ(db->removeDirectory(), true);
} }
TEST_F(DataBaseTest, OpeningClosingDatabase) { TEST_F(BaseTest, OpeningClosingDatabase) {
EXPECT_EQ(db->ready(), false); EXPECT_EQ(db->ready(), false);
db->open(); db->open();
EXPECT_EQ(db->ready(), true); EXPECT_EQ(db->ready(), true);
@ -56,7 +56,7 @@ TEST_F(DataBaseTest, OpeningClosingDatabase) {
EXPECT_EQ(db->ready(), true); EXPECT_EQ(db->ready(), true);
} }
TEST_F(DataBaseTest, AddingIntegerKey) { TEST_F(BaseTest, AddingIntegerKey) {
EXPECT_EQ(db->ready(), true); EXPECT_EQ(db->ready(), true);
t1->addRecord(1, 2); t1->addRecord(1, 2);
t1->addRecord(2, 2); t1->addRecord(2, 2);
@ -64,7 +64,7 @@ TEST_F(DataBaseTest, AddingIntegerKey) {
EXPECT_EQ(t1->getRecord(1), 2); EXPECT_EQ(t1->getRecord(1), 2);
} }
TEST_F(DataBaseTest, AddingQStringKey) { TEST_F(BaseTest, AddingQStringKey) {
EXPECT_EQ(db->ready(), true); EXPECT_EQ(db->ready(), true);
t2->addRecord("hello", "world"); t2->addRecord("hello", "world");
t2->addRecord("aaa", "gagdfsdf"); t2->addRecord("aaa", "gagdfsdf");
@ -73,7 +73,7 @@ TEST_F(DataBaseTest, AddingQStringKey) {
EXPECT_EQ(t2->getRecord("hello"), "world"); EXPECT_EQ(t2->getRecord("hello"), "world");
} }
TEST_F(DataBaseTest, AddingKeysToCache) { TEST_F(BaseTest, AddingKeysToCache) {
EXPECT_EQ(db->ready(), true); EXPECT_EQ(db->ready(), true);
c1->addRecord(2, "blah balah"); c1->addRecord(2, "blah balah");
c1->addRecord(-4, "testing goes brrr"); c1->addRecord(-4, "testing goes brrr");
@ -83,48 +83,48 @@ TEST_F(DataBaseTest, AddingKeysToCache) {
EXPECT_EQ(c1->getRecord(-116), "whatever"); EXPECT_EQ(c1->getRecord(-116), "whatever");
} }
TEST_F(DataBaseTest, AddingRepeatingIntegerKey) { TEST_F(BaseTest, AddingRepeatingIntegerKey) {
EXPECT_EQ(db->ready(), true); EXPECT_EQ(db->ready(), true);
bool thrown = false; bool thrown = false;
try { try {
t1->addRecord(3, 24); t1->addRecord(3, 24);
} catch (const LMDBDataBase::Exist e) { } catch (const LMDBAL::Exist e) {
thrown = true; thrown = true;
} }
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened"; ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
EXPECT_EQ(t1->getRecord(3), 15); EXPECT_EQ(t1->getRecord(3), 15);
} }
TEST_F(DataBaseTest, AddingRepeatingStringKey) { TEST_F(BaseTest, AddingRepeatingStringKey) {
EXPECT_EQ(db->ready(), true); EXPECT_EQ(db->ready(), true);
bool thrown = false; bool thrown = false;
try { try {
t2->addRecord("sdfhga", "world"); t2->addRecord("sdfhga", "world");
} catch (const LMDBDataBase::Exist e) { } catch (const LMDBAL::Exist e) {
thrown = true; thrown = true;
} }
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened"; ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
EXPECT_EQ(t2->getRecord("sdfhga"), "DSFFDG"); EXPECT_EQ(t2->getRecord("sdfhga"), "DSFFDG");
} }
TEST_F(DataBaseTest, AddingRepeatingCacheKey) { TEST_F(BaseTest, AddingRepeatingCacheKey) {
EXPECT_EQ(db->ready(), true); EXPECT_EQ(db->ready(), true);
bool thrown = false; bool thrown = false;
try { try {
c1->addRecord(-4, "world"); c1->addRecord(-4, "world");
} catch (const LMDBDataBase::Exist e) { } catch (const LMDBAL::Exist e) {
thrown = true; thrown = true;
} }
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened"; ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
EXPECT_EQ(c1->getRecord(-4), "testing goes brrr"); EXPECT_EQ(c1->getRecord(-4), "testing goes brrr");
} }
TEST_F(DataBaseTest, GettingNotExistingKeys) { TEST_F(BaseTest, GettingNotExistingKeys) {
EXPECT_EQ(db->ready(), true); EXPECT_EQ(db->ready(), true);
bool thrown = false; bool thrown = false;
try { try {
QString wrong = t2->getRecord("almonds"); QString wrong = t2->getRecord("almonds");
} catch (const LMDBDataBase::NotFound e) { } catch (const LMDBAL::NotFound e) {
thrown = true; thrown = true;
} }
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened"; ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
@ -132,7 +132,7 @@ TEST_F(DataBaseTest, GettingNotExistingKeys) {
thrown = false; thrown = false;
try { try {
uint32_t wrong = t1->getRecord(64); uint32_t wrong = t1->getRecord(64);
} catch (const LMDBDataBase::NotFound e) { } catch (const LMDBAL::NotFound e) {
thrown = true; thrown = true;
} }
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened"; ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
@ -140,18 +140,18 @@ TEST_F(DataBaseTest, GettingNotExistingKeys) {
thrown = false; thrown = false;
try { try {
std::string wrong = c1->getRecord(21); std::string wrong = c1->getRecord(21);
} catch (const LMDBDataBase::NotFound e) { } catch (const LMDBAL::NotFound e) {
thrown = true; thrown = true;
} }
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened"; ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
} }
TEST_F(DataBaseTest, Persistence) { TEST_F(BaseTest, Persistence) {
EXPECT_EQ(db->ready(), true); EXPECT_EQ(db->ready(), true);
db->close(); db->close();
delete db; delete db;
db = new LMDBDataBase::DataBase("testBase"); db = new LMDBAL::Base("testBase");
t1 = db->addTable<uint32_t, uint32_t>("table1"); t1 = db->addTable<uint32_t, uint32_t>("table1");
t2 = db->addTable<QString, QString>("table2"); t2 = db->addTable<QString, QString>("table2");
c1 = db->addCache<int8_t, std::string>("cache1"); c1 = db->addCache<int8_t, std::string>("cache1");
@ -175,7 +175,7 @@ TEST_F(DataBaseTest, Persistence) {
bool thrown = false; bool thrown = false;
try { try {
QString wrong = t2->getRecord("cats"); QString wrong = t2->getRecord("cats");
} catch (const LMDBDataBase::NotFound e) { } catch (const LMDBAL::NotFound e) {
thrown = true; thrown = true;
} }
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened"; ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
@ -183,7 +183,7 @@ TEST_F(DataBaseTest, Persistence) {
thrown = false; thrown = false;
try { try {
uint32_t wrong = t1->getRecord(7893); uint32_t wrong = t1->getRecord(7893);
} catch (const LMDBDataBase::NotFound e) { } catch (const LMDBAL::NotFound e) {
thrown = true; thrown = true;
} }
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened"; ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
@ -191,13 +191,13 @@ TEST_F(DataBaseTest, Persistence) {
thrown = false; thrown = false;
try { try {
std::string wrong = c1->getRecord(89); std::string wrong = c1->getRecord(89);
} catch (const LMDBDataBase::NotFound e) { } catch (const LMDBAL::NotFound e) {
thrown = true; thrown = true;
} }
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened"; ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
} }
TEST_F(DataBaseTest, CountAndDrop) { TEST_F(BaseTest, CountAndDrop) {
EXPECT_EQ(db->ready(), true); EXPECT_EQ(db->ready(), true);
EXPECT_EQ(t1->count(), 3); EXPECT_EQ(t1->count(), 3);
EXPECT_EQ(t2->count(), 4); EXPECT_EQ(t2->count(), 4);
@ -219,7 +219,7 @@ TEST_F(DataBaseTest, CountAndDrop) {
EXPECT_EQ(c1->count(), 2); EXPECT_EQ(c1->count(), 2);
} }
TEST_F(DataBaseTest, Change) { TEST_F(BaseTest, Change) {
EXPECT_EQ(db->ready(), true); EXPECT_EQ(db->ready(), true);
EXPECT_EQ(t1->count(), 1); EXPECT_EQ(t1->count(), 1);
EXPECT_EQ(t2->count(), 1); EXPECT_EQ(t2->count(), 1);
@ -253,7 +253,7 @@ TEST_F(DataBaseTest, Change) {
EXPECT_EQ(c1->count(), 3); EXPECT_EQ(c1->count(), 3);
} }
TEST_F(DataBaseTest, Force) { TEST_F(BaseTest, Force) {
EXPECT_EQ(db->ready(), true); EXPECT_EQ(db->ready(), true);
t1->forceRecord(58, 35); //changing t1->forceRecord(58, 35); //changing