From 7377f135349ddb3aaa1aeda1aeced15b76c4429f Mon Sep 17 00:00:00 2001 From: blue Date: Tue, 21 Mar 2023 14:05:54 +0300 Subject: [PATCH] project name change --- CMakeLists.txt | 59 ++++------------- src/CMakeLists.txt | 37 +++++++++++ database.cpp => src/base.cpp | 48 +++++++------- database.h => src/base.h | 40 +++++------ cache.h => src/cache.h | 12 ++-- cache.hpp => src/cache.hpp | 58 ++++++++-------- exceptions.cpp => src/exceptions.cpp | 32 ++++----- exceptions.h => src/exceptions.h | 8 +-- operators.hpp => src/operators.hpp | 6 +- serializer.h => src/serializer.h | 10 +-- serializer.hpp => src/serializer.hpp | 22 +++---- .../serializer_double.hpp | 8 +-- .../serializer_float.hpp | 8 +-- .../serializer_int16.hpp | 8 +-- .../serializer_int32.hpp | 8 +-- .../serializer_int64.hpp | 8 +-- .../serializer_int8.hpp | 8 +-- .../serializer_qbytearray.hpp | 8 +-- .../serializer_qstring.hpp | 8 +-- .../serializer_stdstring.hpp | 8 +-- .../serializer_uint16.hpp | 8 +-- .../serializer_uint32.hpp | 8 +-- .../serializer_uint64.hpp | 8 +-- .../serializer_uint8.hpp | 8 +-- storage.cpp => src/storage.cpp | 36 +++++----- storage.h => src/storage.h | 28 ++++---- storage.hpp => src/storage.hpp | 56 ++++++++-------- test/CMakeLists.txt | 4 +- test/basic.cpp | 66 +++++++++---------- 29 files changed, 316 insertions(+), 310 deletions(-) create mode 100644 src/CMakeLists.txt rename database.cpp => src/base.cpp (73%) rename database.h => src/base.h (77%) rename cache.h => src/cache.h (91%) rename cache.hpp => src/cache.hpp (77%) rename exceptions.cpp => src/exceptions.cpp (76%) rename exceptions.h => src/exceptions.h (95%) rename operators.hpp => src/operators.hpp (98%) rename serializer.h => src/serializer.h (91%) rename serializer.hpp => src/serializer.hpp (73%) rename serializer_double.hpp => src/serializer_double.hpp (89%) rename serializer_float.hpp => src/serializer_float.hpp (89%) rename serializer_int16.hpp => src/serializer_int16.hpp (89%) rename serializer_int32.hpp => src/serializer_int32.hpp (89%) rename serializer_int64.hpp => src/serializer_int64.hpp (89%) rename serializer_int8.hpp => src/serializer_int8.hpp (89%) rename serializer_qbytearray.hpp => src/serializer_qbytearray.hpp (89%) rename serializer_qstring.hpp => src/serializer_qstring.hpp (90%) rename serializer_stdstring.hpp => src/serializer_stdstring.hpp (89%) rename serializer_uint16.hpp => src/serializer_uint16.hpp (89%) rename serializer_uint32.hpp => src/serializer_uint32.hpp (89%) rename serializer_uint64.hpp => src/serializer_uint64.hpp (89%) rename serializer_uint8.hpp => src/serializer_uint8.hpp (89%) rename storage.cpp => src/storage.cpp (63%) rename storage.h => src/storage.h (88%) rename storage.hpp => src/storage.hpp (77%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1eb24f6..61b7919 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ 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 CMP0079 NEW) @@ -28,63 +28,32 @@ if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug) 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) - add_library(storage STATIC ${SOURCES}) + add_library(lmdbal STATIC ${SOURCES}) else () - add_library(storage SHARED ${SOURCES}) + add_library(lmdbal SHARED ${SOURCES}) endif() +add_subdirectory(src) + if (BUILD_TESTS) add_subdirectory(test) 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_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 +target_link_libraries(lmdbal PRIVATE 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} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/storage - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/storage + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/lmdbal + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lmdbal ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..f5ca470 --- /dev/null +++ b/src/CMakeLists.txt @@ -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}") diff --git a/database.cpp b/src/base.cpp similarity index 73% rename from database.cpp rename to src/base.cpp index 87f4419..1f9003a 100644 --- a/database.cpp +++ b/src/base.cpp @@ -14,11 +14,11 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include "database.h" +#include "base.h" #include "exceptions.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()), opened(false), size(mapSize), @@ -27,19 +27,19 @@ LMDBDataBase::DataBase::DataBase(const QString& p_name, uint16_t mapSize): transactions(new Transactions()) {} -LMDBDataBase::DataBase::~DataBase() { +LMDBAL::Base::~Base() { close(); delete transactions; - for (const std::pair& pair : tables) + for (const std::pair& pair : tables) delete pair.second; } -void LMDBDataBase::DataBase::close() { +void LMDBAL::Base::close() { if (opened) { - for (const std::pair& pair : tables) { - StorageBase* table = pair.second; + for (const std::pair& pair : tables) { + iStorage* table = pair.second; mdb_dbi_close(environment, table->dbi); } mdb_env_close(environment); @@ -47,7 +47,7 @@ void LMDBDataBase::DataBase::close() { } } -void LMDBDataBase::DataBase::open() { +void LMDBAL::Base::open() { if (!opened) { mdb_env_create(&environment); QString path = createDirectory(); @@ -59,8 +59,8 @@ void LMDBDataBase::DataBase::open() { MDB_txn *txn; mdb_txn_begin(environment, NULL, 0, &txn); - for (const std::pair& pair : tables) { - StorageBase* table = pair.second; + for (const std::pair& pair : tables) { + iStorage* table = pair.second; int rc = table->createTable(txn); if (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) throw Opened(name, "remove database directory"); @@ -84,7 +84,7 @@ bool LMDBDataBase::DataBase::removeDirectory() { return true; } -QString LMDBDataBase::DataBase::createDirectory() { +QString LMDBAL::Base::createDirectory() { if (opened) throw Opened(name, "create database directory"); @@ -101,13 +101,13 @@ QString LMDBDataBase::DataBase::createDirectory() { return path; } -QString LMDBDataBase::DataBase::getName() const { +QString LMDBAL::Base::getName() const { return QString::fromStdString(name);} -bool LMDBDataBase::DataBase::ready() const { +bool LMDBAL::Base::ready() const { return opened;} -void LMDBDataBase::DataBase::drop() { +void LMDBAL::Base::drop() { if (!opened) throw Closed("drop", name); @@ -116,7 +116,7 @@ void LMDBDataBase::DataBase::drop() { if (rc) throw Unknown(name, mdb_strerror(rc)); - for (const std::pair& pair : tables) { + for (const std::pair& pair : tables) { rc = pair.second->drop(txn); if (rc) throw Unknown(name, mdb_strerror(rc), pair.first); @@ -125,20 +125,20 @@ void LMDBDataBase::DataBase::drop() { mdb_txn_commit(txn); } -LMDBDataBase::TransactionID LMDBDataBase::DataBase::beginReadOnlyTransaction() const { +LMDBAL::TransactionID LMDBAL::Base::beginReadOnlyTransaction() const { return beginReadOnlyTransaction(emptyName);} -LMDBDataBase::TransactionID LMDBDataBase::DataBase::beginTransaction() const { +LMDBAL::TransactionID LMDBAL::Base::beginTransaction() const { return beginTransaction(emptyName);} -void LMDBDataBase::DataBase::abortTransaction(LMDBDataBase::TransactionID id) const { +void LMDBAL::Base::abortTransaction(LMDBAL::TransactionID id) const { return abortTransaction(id, emptyName);} -void LMDBDataBase::DataBase::commitTransaction(LMDBDataBase::TransactionID id) const { +void LMDBAL::Base::commitTransaction(LMDBAL::TransactionID id) const { 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) throw Closed("beginReadOnlyTransaction", name, storageName); @@ -152,7 +152,7 @@ LMDBDataBase::TransactionID LMDBDataBase::DataBase::beginReadOnlyTransaction(con return txn; } -LMDBDataBase::TransactionID LMDBDataBase::DataBase::beginTransaction(const std::string& storageName) const { +LMDBAL::TransactionID LMDBAL::Base::beginTransaction(const std::string& storageName) const { if (!opened) throw Closed("beginTransaction", name, storageName); @@ -166,7 +166,7 @@ LMDBDataBase::TransactionID LMDBDataBase::DataBase::beginTransaction(const std:: 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) throw Closed("abortTransaction", name, storageName); @@ -178,7 +178,7 @@ void LMDBDataBase::DataBase::abortTransaction(LMDBDataBase::TransactionID id, co 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) throw Closed("abortTransaction", name, storageName); diff --git a/database.h b/src/base.h similarity index 77% rename from database.h rename to src/base.h index 27f318e..42cc26c 100644 --- a/database.h +++ b/src/base.h @@ -1,21 +1,21 @@ -// Squawk messenger. +// Squawk messenger. // Copyright (C) 2019 Yury Gubich -// +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef LMDBDATABASE_DATABASE_H -#define LMDBDATABASE_DATABASE_H +#ifndef LMDBAL_BASE_H +#define LMDBAL_BASE_H #include #include @@ -31,9 +31,9 @@ #include "exceptions.h" -namespace LMDBDataBase { +namespace LMDBAL { -class StorageBase; +class iStorage; template class Serializer; @@ -46,12 +46,12 @@ class Cache; typedef MDB_txn* TransactionID; -class DataBase { - friend class StorageBase; +class Base { + friend class iStorage; public: - DataBase(const QString& name, uint16_t mapSize = 10); - ~DataBase(); + Base(const QString& name, uint16_t mapSize = 10); + ~Base(); void open(); void close(); @@ -79,7 +79,7 @@ public: Cache* getCache(const std::string& name); private: - typedef std::map Tables; + typedef std::map Tables; typedef std::set Transactions; TransactionID beginReadOnlyTransaction(const std::string& storageName) const; @@ -102,33 +102,33 @@ private: #include "operators.hpp" template -LMDBDataBase::Storage* LMDBDataBase::DataBase::addTable(const std::string& p_name) { +LMDBAL::Storage* LMDBAL::Base::addTable(const std::string& p_name) { if (opened) { throw Opened(name, "add table " + p_name); } Storage* table = new Storage(p_name, this); - tables.insert(std::make_pair(p_name, (StorageBase*)table)); + tables.insert(std::make_pair(p_name, (iStorage*)table)); return table; } template -LMDBDataBase::Cache * LMDBDataBase::DataBase::addCache(const std::string& p_name) { +LMDBAL::Cache * LMDBAL::Base::addCache(const std::string& p_name) { if (opened) { throw Opened(name, "add cache " + p_name); } Cache* cache = new Cache(p_name, this); - tables.insert(std::make_pair(p_name, (StorageBase*)cache)); + tables.insert(std::make_pair(p_name, (iStorage*)cache)); return cache; } template -LMDBDataBase::Storage* LMDBDataBase::DataBase::getTable(const std::string& p_name) { +LMDBAL::Storage* LMDBAL::Base::getTable(const std::string& p_name) { return static_cast*>(tables.at(p_name)); } template -LMDBDataBase::Cache* LMDBDataBase::DataBase::getCache(const std::string& p_name) { +LMDBAL::Cache* LMDBAL::Base::getCache(const std::string& p_name) { return static_cast*>(tables.at(p_name)); } -#endif // LMDBDATABASE_DATABASE_H +#endif //LMDBAL_BASE_H diff --git a/cache.h b/src/cache.h similarity index 91% rename from cache.h rename to src/cache.h index ba72f46..52dd88a 100644 --- a/cache.h +++ b/src/cache.h @@ -14,26 +14,26 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef LMDBDATABASE_CACHE_H -#define LMDBDATABASE_CACHE_H +#ifndef LMDBAL_CACHE_H +#define LMDBAL_CACHE_H #include #include #include "storage.h" -namespace LMDBDataBase { +namespace LMDBAL { template class Cache : public Storage { - friend class DataBase; + friend class Base; enum class Mode { //it's a cache state when we: nothing, // - know nothing about records in database on disk size, // - know just an amount of records full // - shure that our cache is equal to the database on disk }; protected: - Cache(const std::string& name, DataBase* parent); + Cache(const std::string& name, Base* parent); ~Cache() override; private: @@ -65,4 +65,4 @@ protected: #include "cache.hpp" -#endif // LMDBDATABASE_CACHE_H +#endif // LMDBAL_CACHE_H diff --git a/cache.hpp b/src/cache.hpp similarity index 77% rename from cache.hpp rename to src/cache.hpp index 1212f4e..e0cc1d0 100644 --- a/cache.hpp +++ b/src/cache.hpp @@ -14,14 +14,14 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef LMDBDATABASE_CACHE_HPP -#define LMDBDATABASE_CACHE_HPP +#ifndef LMDBAL_CACHE_HPP +#define LMDBAL_CACHE_HPP #include "cache.h" #include "exceptions.h" template -LMDBDataBase::Cache::Cache(const std::string& p_name, DataBase* parent): +LMDBAL::Cache::Cache(const std::string& p_name, Base* parent): Storage(p_name, parent), mode(new Mode), cache(new std::map()), @@ -33,7 +33,7 @@ LMDBDataBase::Cache::Cache(const std::string& p_name, DataBase* parent): } template -LMDBDataBase::Cache::~Cache() { +LMDBAL::Cache::~Cache() { delete sizeDifference; delete mode; delete cache; @@ -41,11 +41,11 @@ LMDBDataBase::Cache::~Cache() { } template -void LMDBDataBase::Cache::addRecord(const K& key, const V& value) { - StorageBase::ensureOpened(StorageBase::addRecordMethodName); +void LMDBAL::Cache::addRecord(const K& key, const V& value) { + iStorage::ensureOpened(iStorage::addRecordMethodName); if (cache->count(key) > 0) - StorageBase::throwDuplicate(StorageBase::toString(key)); + iStorage::throwDuplicate(iStorage::toString(key)); Storage::addRecord(key, value); cache->insert(std::make_pair(key, value)); @@ -55,8 +55,8 @@ void LMDBDataBase::Cache::addRecord(const K& key, const V& value) { } template -bool LMDBDataBase::Cache::forceRecord(const K& key, const V& value) { - StorageBase::ensureOpened(StorageBase::forceRecordMethodName); +bool LMDBAL::Cache::forceRecord(const K& key, const V& value) { + iStorage::ensureOpened(iStorage::forceRecordMethodName); bool added = Storage::forceRecord(key, value); if (*mode == Mode::full) { @@ -76,19 +76,19 @@ bool LMDBDataBase::Cache::forceRecord(const K& key, const V& value) { } template -void LMDBDataBase::Cache::changeRecord(const K& key, const V& value) { - StorageBase::ensureOpened(StorageBase::changeRecordMethodName); +void LMDBAL::Cache::changeRecord(const K& key, const V& value) { + iStorage::ensureOpened(iStorage::changeRecordMethodName); if (*mode == Mode::full) { typename std::map::iterator itr = cache->find(key); if (itr == cache->end()) - StorageBase::throwNotFound(StorageBase::toString(key)); + iStorage::throwNotFound(iStorage::toString(key)); Storage::changeRecord(key, value); itr->second = value; } else { if (abscent->count(key) > 0) - StorageBase::throwNotFound(StorageBase::toString(key)); + iStorage::throwNotFound(iStorage::toString(key)); try { Storage::changeRecord(key, value); @@ -105,15 +105,15 @@ void LMDBDataBase::Cache::changeRecord(const K& key, const V& value) { } template -V LMDBDataBase::Cache::getRecord(const K& key) const { - StorageBase::ensureOpened(StorageBase::getRecordMethodName); +V LMDBAL::Cache::getRecord(const K& key) const { + iStorage::ensureOpened(iStorage::getRecordMethodName); typename std::map::const_iterator itr = cache->find(key); if (itr != cache->end()) return itr->second; if (*mode == Mode::full || abscent->count(key) != 0) - StorageBase::throwNotFound(StorageBase::toString(key)); + iStorage::throwNotFound(iStorage::toString(key)); try { V value = Storage::getRecord(key); @@ -129,8 +129,8 @@ V LMDBDataBase::Cache::getRecord(const K& key) const { } template -bool LMDBDataBase::Cache::checkRecord(const K& key) const { - StorageBase::ensureOpened(StorageBase::checkRecordMethodName); +bool LMDBAL::Cache::checkRecord(const K& key) const { + iStorage::ensureOpened(iStorage::checkRecordMethodName); typename std::map::const_iterator itr = cache->find(key); if (itr != cache->end()) @@ -153,8 +153,8 @@ bool LMDBDataBase::Cache::checkRecord(const K& key) const { } template -std::map LMDBDataBase::Cache::readAll() const { - StorageBase::ensureOpened(StorageBase::readAllMethodName); +std::map LMDBAL::Cache::readAll() const { + iStorage::ensureOpened(iStorage::readAllMethodName); if (*mode != Mode::full) { //there is a room for optimization *mode = Mode::full; //I can read and deserialize only those values @@ -167,7 +167,7 @@ std::map LMDBDataBase::Cache::readAll() const { } template -void LMDBDataBase::Cache::replaceAll(const std::map& data) { +void LMDBAL::Cache::replaceAll(const std::map& data) { Storage::replaceAll(data); *cache = data; @@ -179,7 +179,7 @@ void LMDBDataBase::Cache::replaceAll(const std::map& data) { } template -uint32_t LMDBDataBase::Cache::addRecords(const std::map& data, bool overwrite) { +uint32_t LMDBAL::Cache::addRecords(const std::map& data, bool overwrite) { uint32_t newSize = Storage::addRecords(data, overwrite); Mode& m = *mode; @@ -210,12 +210,12 @@ uint32_t LMDBDataBase::Cache::addRecords(const std::map& data, bool } template -void LMDBDataBase::Cache::removeRecord(const K& key) { - StorageBase::ensureOpened(StorageBase::removeRecordMethodName); +void LMDBAL::Cache::removeRecord(const K& key) { + iStorage::ensureOpened(iStorage::removeRecordMethodName); typename std::pair::const_iterator, bool> pair = abscent->insert(key); if (!pair.second) - StorageBase::throwNotFound(StorageBase::toString(key)); + iStorage::throwNotFound(iStorage::toString(key)); Storage::removeRecord(key); 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::removeRecord(const K& key) { } template -uint32_t LMDBDataBase::Cache::count() const { +uint32_t LMDBAL::Cache::count() const { switch (*mode) { case Mode::nothing: { @@ -250,7 +250,7 @@ uint32_t LMDBDataBase::Cache::count() const { } template -void LMDBDataBase::Cache::handleMode() const { +void LMDBAL::Cache::handleMode() const { if (*mode == Mode::size) { --(*sizeDifference); if (*sizeDifference == 0) { @@ -261,7 +261,7 @@ void LMDBDataBase::Cache::handleMode() const { } template -int LMDBDataBase::Cache::drop(MDB_txn * transaction) { +int LMDBAL::Cache::drop(MDB_txn * transaction) { int res = Storage::drop(transaction); cache->clear(); abscent->clear(); @@ -270,4 +270,4 @@ int LMDBDataBase::Cache::drop(MDB_txn * transaction) { return res; } -#endif //LMDBDATABASE_CACHE_HPP +#endif //LMDBAL_CACHE_HPP diff --git a/exceptions.cpp b/src/exceptions.cpp similarity index 76% rename from exceptions.cpp rename to src/exceptions.cpp index 16a8010..49ca0a4 100644 --- a/exceptions.cpp +++ b/src/exceptions.cpp @@ -16,25 +16,25 @@ #include "exceptions.h" -LMDBDataBase::Exception::Exception(): +LMDBAL::Exception::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()); return msg->c_str(); } -LMDBDataBase::Directory::Directory(const std::string& p_path): +LMDBAL::Directory::Directory(const std::string& p_path): Exception(), path(p_path) {} -std::string LMDBDataBase::Directory::getMessage() const { +std::string LMDBAL::Directory::getMessage() const { return "Can't create directory for database at " + path;} -LMDBDataBase::Closed::Closed( +LMDBAL::Closed::Closed( const std::string& p_operation, const std::string& p_dbName, const std::optional& p_tableName @@ -44,7 +44,7 @@ LMDBDataBase::Closed::Closed( dbName(p_dbName), tableName(p_tableName) {} -std::string LMDBDataBase::Closed::getMessage() const { +std::string LMDBAL::Closed::getMessage() const { std::string msg = "An attempt to perform operation " + operation + " on closed database " + dbName; if (tableName.has_value()) @@ -53,19 +53,19 @@ std::string LMDBDataBase::Closed::getMessage() const { 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(), dbName(p_dbName), action(p_action) {} -std::string LMDBDataBase::Opened::getMessage() const { +std::string LMDBAL::Opened::getMessage() const { return "An attempt to " + action + " (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_dbName, const std::string& p_tableName @@ -75,12 +75,12 @@ LMDBDataBase::NotFound::NotFound( dbName(p_dbName), tableName(p_tableName) {} -std::string LMDBDataBase::NotFound::getMessage() const { +std::string LMDBAL::NotFound::getMessage() const { return "Element for id " + key + " wasn't found " + " in database " + dbName + " in table " + tableName;} -LMDBDataBase::Exist::Exist( +LMDBAL::Exist::Exist( const std::string& p_key, const std::string& p_dbName, const std::string& p_tableName @@ -90,14 +90,14 @@ LMDBDataBase::Exist::Exist( dbName(p_dbName), tableName(p_tableName) {} -std::string LMDBDataBase::Exist::getMessage() const { +std::string LMDBAL::Exist::getMessage() const { return "An attempt to insert element with key " + key + " to database " + dbName + " to table " + tableName + " but it already has an element with given id"; } -LMDBDataBase::Unknown::Unknown( +LMDBAL::Unknown::Unknown( const std::string& p_dbName, const std::string& message, const std::optional& p_tableName @@ -107,7 +107,7 @@ LMDBDataBase::Unknown::Unknown( tableName(p_tableName), msg(message) {} -std::string LMDBDataBase::Unknown::getMessage() const { +std::string LMDBAL::Unknown::getMessage() const { std::string result = "Unknown error in database " + dbName; if (tableName.has_value()) result += " in table " + tableName.value(); diff --git a/exceptions.h b/src/exceptions.h similarity index 95% rename from exceptions.h rename to src/exceptions.h index 87dc438..98db230 100644 --- a/exceptions.h +++ b/src/exceptions.h @@ -14,14 +14,14 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef LMDBDATABASE_EXCEPTIONS_H -#define LMDBDATABASE_EXCEPTIONS_H +#ifndef LMDBAL_EXCEPTIONS_H +#define LMDBAL_EXCEPTIONS_H #include #include #include -namespace LMDBDataBase { +namespace LMDBAL { class Exception : public std::exception { public: @@ -98,4 +98,4 @@ private: } -#endif //LMDBDATABASE_EXCEPTIONS_H +#endif //LMDBAL_EXCEPTIONS_H diff --git a/operators.hpp b/src/operators.hpp similarity index 98% rename from operators.hpp rename to src/operators.hpp index c4010ff..352534a 100644 --- a/operators.hpp +++ b/src/operators.hpp @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef CORE_OPERATORS_HPP -#define CORE_OPERATORS_HPP +#ifndef LMDBAL_OPERATORS_HPP +#define LMDBAL_OPERATORS_HPP #include #include @@ -206,4 +206,4 @@ QDataStream& operator >> (QDataStream &in, std::list& container) { return in; } -#endif //CORE_OPERATORS_HPP +#endif //LMDBAL_OPERATORS_HPP diff --git a/serializer.h b/src/serializer.h similarity index 91% rename from serializer.h rename to src/serializer.h index 8f00db9..145fe5e 100644 --- a/serializer.h +++ b/src/serializer.h @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef LMDBDATABASE_SERIALIZER_H -#define LMDBDATABASE_SERIALIZER_H +#ifndef LMDBAL_SERIALIZER_H +#define LMDBAL_SERIALIZER_H #include @@ -23,9 +23,9 @@ #include #include -#include "database.h" +#include -namespace LMDBDataBase { +namespace LMDBAL { template class Serializer { @@ -66,4 +66,4 @@ private: #include "serializer_qstring.hpp" #include "serializer_qbytearray.hpp" -#endif // LMDBDATABASE_SERIALIZER_H +#endif // LMDBAL_SERIALIZER_H diff --git a/serializer.hpp b/src/serializer.hpp similarity index 73% rename from serializer.hpp rename to src/serializer.hpp index a580a88..a03a32d 100644 --- a/serializer.hpp +++ b/src/serializer.hpp @@ -14,13 +14,13 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef LMDBDATABASE_SERIALIZER_HPP -#define LMDBDATABASE_SERIALIZER_HPP +#ifndef LMDBAL_SERIALIZER_HPP +#define LMDBAL_SERIALIZER_HPP #include "serializer.h" template -LMDBDataBase::Serializer::Serializer() : +LMDBAL::Serializer::Serializer() : bytes(), buffer(&bytes), stream(&buffer) @@ -29,7 +29,7 @@ LMDBDataBase::Serializer::Serializer() : } template -LMDBDataBase::Serializer::Serializer(const T& value) : +LMDBAL::Serializer::Serializer(const T& value) : bytes(), buffer(&bytes), stream(&buffer) @@ -39,19 +39,19 @@ LMDBDataBase::Serializer::Serializer(const T& value) : } template -LMDBDataBase::Serializer::~Serializer() { +LMDBAL::Serializer::~Serializer() { buffer.close(); } template -MDB_val LMDBDataBase::Serializer::setData(const T& value) { +MDB_val LMDBAL::Serializer::setData(const T& value) { clear(); _setData(value); return getData(); } template -T LMDBDataBase::Serializer::deserialize(const MDB_val& value) { +T LMDBAL::Serializer::deserialize(const MDB_val& value) { clear(); bytes.setRawData((char*)value.mv_data, value.mv_size); T result; @@ -61,19 +61,19 @@ T LMDBDataBase::Serializer::deserialize(const MDB_val& value) { } template -void LMDBDataBase::Serializer::_setData(const T& value) { +void LMDBAL::Serializer::_setData(const T& value) { stream << value; } template -void LMDBDataBase::Serializer::clear() { +void LMDBAL::Serializer::clear() { if (buffer.pos() > 0) { buffer.seek(0); } } template -MDB_val LMDBDataBase::Serializer::getData() { +MDB_val LMDBAL::Serializer::getData() { MDB_val val; val.mv_size = buffer.pos(); @@ -82,4 +82,4 @@ MDB_val LMDBDataBase::Serializer::getData() { return val; } -#endif //LMDBDATABASE_SERIALIZER_HPP +#endif //LMDBAL_SERIALIZER_HPP diff --git a/serializer_double.hpp b/src/serializer_double.hpp similarity index 89% rename from serializer_double.hpp rename to src/serializer_double.hpp index 6cdbf01..8a165fe 100644 --- a/serializer_double.hpp +++ b/src/serializer_double.hpp @@ -14,10 +14,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef LMDBDATABASE_SERIALIZER_DOUBLE_HPP -#define LMDBDATABASE_SERIALIZER_DOUBLE_HPP +#ifndef LMDBAL_SERIALIZER_DOUBLE_HPP +#define LMDBAL_SERIALIZER_DOUBLE_HPP -namespace LMDBDataBase { +namespace LMDBAL { template<> class Serializer { @@ -48,7 +48,7 @@ private: } -#endif //LMDBDATABASE_SERIALIZER_DOUBLE_HPP +#endif //LMDBAL_SERIALIZER_DOUBLE_HPP diff --git a/serializer_float.hpp b/src/serializer_float.hpp similarity index 89% rename from serializer_float.hpp rename to src/serializer_float.hpp index 29ce0e0..223968b 100644 --- a/serializer_float.hpp +++ b/src/serializer_float.hpp @@ -14,10 +14,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef LMDBDATABASE_SERIALIZER_FLOAT_HPP -#define LMDBDATABASE_SERIALIZER_FLOAT_HPP +#ifndef LMDBAL_SERIALIZER_FLOAT_HPP +#define LMDBAL_SERIALIZER_FLOAT_HPP -namespace LMDBDataBase { +namespace LMDBAL { template<> class Serializer { @@ -48,7 +48,7 @@ private: } -#endif //LMDBDATABASE_SERIALIZER_FLOAT_HPP +#endif //LMDBAL_SERIALIZER_FLOAT_HPP diff --git a/serializer_int16.hpp b/src/serializer_int16.hpp similarity index 89% rename from serializer_int16.hpp rename to src/serializer_int16.hpp index ff07821..81f4c62 100644 --- a/serializer_int16.hpp +++ b/src/serializer_int16.hpp @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef LMDBDATABASE_SERIALIZER_INT16_HPP -#define LMDBDATABASE_SERIALIZER_INT16_HPP +#ifndef LMDBAL_SERIALIZER_INT16_HPP +#define LMDBAL_SERIALIZER_INT16_HPP #include -namespace LMDBDataBase { +namespace LMDBAL { template<> class Serializer { @@ -50,4 +50,4 @@ private: } -#endif //LMDBDATABASE_SERIALIZER_INT16_HPP +#endif //LMDBAL_SERIALIZER_INT16_HPP diff --git a/serializer_int32.hpp b/src/serializer_int32.hpp similarity index 89% rename from serializer_int32.hpp rename to src/serializer_int32.hpp index 28da663..cc0e352 100644 --- a/serializer_int32.hpp +++ b/src/serializer_int32.hpp @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef LMDBDATABASE_SERIALIZER_INT32_HPP -#define LMDBDATABASE_SERIALIZER_INT32_HPP +#ifndef LMDBAL_SERIALIZER_INT32_HPP +#define LMDBAL_SERIALIZER_INT32_HPP #include -namespace LMDBDataBase { +namespace LMDBAL { template<> class Serializer { @@ -50,7 +50,7 @@ private: } -#endif //CORE_DATABASE_SERIALIZER_INT32_HPP +#endif //LMDBAL_SERIALIZER_INT32_HPP diff --git a/serializer_int64.hpp b/src/serializer_int64.hpp similarity index 89% rename from serializer_int64.hpp rename to src/serializer_int64.hpp index 14c7426..7ef667e 100644 --- a/serializer_int64.hpp +++ b/src/serializer_int64.hpp @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef LMDBDATABASE_SERIALIZER_INT64_HPP -#define LMDBDATABASE_SERIALIZER_INT64_HPP +#ifndef LMDBAL_SERIALIZER_INT64_HPP +#define LMDBAL_SERIALIZER_INT64_HPP #include -namespace LMDBDataBase { +namespace LMDBAL { template<> class Serializer { @@ -50,7 +50,7 @@ private: } -#endif //CORE_DATABASE_SERIALIZER_INT64_HPP +#endif //LMDBAL_SERIALIZER_INT64_HPP diff --git a/serializer_int8.hpp b/src/serializer_int8.hpp similarity index 89% rename from serializer_int8.hpp rename to src/serializer_int8.hpp index d6df4c1..0656d7a 100644 --- a/serializer_int8.hpp +++ b/src/serializer_int8.hpp @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef LMDBDATABASE_SERIALIZER_INT8_HPP -#define LMDBDATABASE_SERIALIZER_INT8_HPP +#ifndef LMDBAL_SERIALIZER_INT8_HPP +#define LMDBAL_SERIALIZER_INT8_HPP #include -namespace LMDBDataBase { +namespace LMDBAL { template<> class Serializer { @@ -50,7 +50,7 @@ private: } -#endif //LMDBDATABASE_SERIALIZER_INT8_HPP +#endif //LMDBAL_SERIALIZER_INT8_HPP diff --git a/serializer_qbytearray.hpp b/src/serializer_qbytearray.hpp similarity index 89% rename from serializer_qbytearray.hpp rename to src/serializer_qbytearray.hpp index bbb8050..86e72d6 100644 --- a/serializer_qbytearray.hpp +++ b/src/serializer_qbytearray.hpp @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef LMDBDATABASE_SERIALIZER_QBYTEARRAY_HPP -#define LMDBDATABASE_SERIALIZER_QBYTEARRAY_HPP +#ifndef LMDBAL_SERIALIZER_QBYTEARRAY_HPP +#define LMDBAL_SERIALIZER_QBYTEARRAY_HPP #include -namespace LMDBDataBase { +namespace LMDBAL { template<> class Serializer { @@ -52,7 +52,7 @@ private: } -#endif //LMDBDATABASE_SERIALIZER_QBYTEARRAY_HPP +#endif //LMDBAL_SERIALIZER_QBYTEARRAY_HPP diff --git a/serializer_qstring.hpp b/src/serializer_qstring.hpp similarity index 90% rename from serializer_qstring.hpp rename to src/serializer_qstring.hpp index 6073435..67f3bdf 100644 --- a/serializer_qstring.hpp +++ b/src/serializer_qstring.hpp @@ -14,13 +14,13 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef LMDBDATABASE_SERIALIZER_QSTRING_HPP -#define LMDBDATABASE_SERIALIZER_QSTRING_HPP +#ifndef LMDBAL_SERIALIZER_QSTRING_HPP +#define LMDBAL_SERIALIZER_QSTRING_HPP #include #include -namespace LMDBDataBase { +namespace LMDBAL { template<> class Serializer { @@ -51,7 +51,7 @@ private: } -#endif //LMDBDATABASE_SERIALIZER_QSTRING_HPP +#endif //LMDBAL_SERIALIZER_QSTRING_HPP diff --git a/serializer_stdstring.hpp b/src/serializer_stdstring.hpp similarity index 89% rename from serializer_stdstring.hpp rename to src/serializer_stdstring.hpp index 9fdc152..c056469 100644 --- a/serializer_stdstring.hpp +++ b/src/serializer_stdstring.hpp @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef LMDBDATABASE_SERIALIZER_STDSTRING_HPP -#define LMDBDATABASE_SERIALIZER_STDSTRING_HPP +#ifndef LMDBAL_SERIALIZER_STDSTRING_HPP +#define LMDBAL_SERIALIZER_STDSTRING_HPP #include -namespace LMDBDataBase { +namespace LMDBAL { template<> class Serializer { @@ -50,7 +50,7 @@ private: } -#endif //LMDBDATABASE_SERIALIZER_STDSTRING_HPP +#endif //LMDBAL_SERIALIZER_STDSTRING_HPP diff --git a/serializer_uint16.hpp b/src/serializer_uint16.hpp similarity index 89% rename from serializer_uint16.hpp rename to src/serializer_uint16.hpp index ea3324c..41bef80 100644 --- a/serializer_uint16.hpp +++ b/src/serializer_uint16.hpp @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef LMDBDATABASE_SERIALIZER_UINT16_HPP -#define LMDBDATABASE_SERIALIZER_UINT16_HPP +#ifndef LMDBAL_SERIALIZER_UINT16_HPP +#define LMDBAL_SERIALIZER_UINT16_HPP #include -namespace LMDBDataBase { +namespace LMDBAL { template<> class Serializer { @@ -50,6 +50,6 @@ private: } -#endif //LMDBDATABASE_SERIALIZER_UINT16_HPP +#endif //LMDBAL_SERIALIZER_UINT16_HPP diff --git a/serializer_uint32.hpp b/src/serializer_uint32.hpp similarity index 89% rename from serializer_uint32.hpp rename to src/serializer_uint32.hpp index bd07534..8e4c763 100644 --- a/serializer_uint32.hpp +++ b/src/serializer_uint32.hpp @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef LMDBDATABASE_SERIALIZER_UINT32_HPP -#define LMDBDATABASE_SERIALIZER_UINT32_HPP +#ifndef LMDBAL_SERIALIZER_UINT32_HPP +#define LMDBAL_SERIALIZER_UINT32_HPP #include -namespace LMDBDataBase { +namespace LMDBAL { template<> class Serializer { @@ -50,4 +50,4 @@ private: } -#endif //LMDBDATABASE_SERIALIZER_UINT32_HPP +#endif //LMDBAL_SERIALIZER_UINT32_HPP diff --git a/serializer_uint64.hpp b/src/serializer_uint64.hpp similarity index 89% rename from serializer_uint64.hpp rename to src/serializer_uint64.hpp index 9015378..6ea39d6 100644 --- a/serializer_uint64.hpp +++ b/src/serializer_uint64.hpp @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef LMDBDATABASE_SERIALIZER_UINT64_HPP -#define LMDBDATABASE_SERIALIZER_UINT64_HPP +#ifndef LMDBAL_SERIALIZER_UINT64_HPP +#define LMDBAL_SERIALIZER_UINT64_HPP #include -namespace LMDBDataBase { +namespace LMDBAL { template<> class Serializer { @@ -50,5 +50,5 @@ private: } -#endif //LMDBDATABASE_SERIALIZER_UINT64_HPP +#endif //LMDBAL_SERIALIZER_UINT64_HPP diff --git a/serializer_uint8.hpp b/src/serializer_uint8.hpp similarity index 89% rename from serializer_uint8.hpp rename to src/serializer_uint8.hpp index ba2526c..4c77a25 100644 --- a/serializer_uint8.hpp +++ b/src/serializer_uint8.hpp @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef LMDBDATABASE_SERIALIZER_UINT8_HPP -#define LMDBDATABASE_SERIALIZER_UINT8_HPP +#ifndef LMDBAL_SERIALIZER_UINT8_HPP +#define LMDBAL_SERIALIZER_UINT8_HPP #include -namespace LMDBDataBase { +namespace LMDBAL { template<> class Serializer { @@ -50,7 +50,7 @@ private: } -#endif //LMDBDATABASE_SERIALIZER_UINT8_HPP +#endif //LMDBAL_SERIALIZER_UINT8_HPP diff --git a/storage.cpp b/src/storage.cpp similarity index 63% rename from storage.cpp rename to src/storage.cpp index 213a0f2..3ce6c25 100644 --- a/storage.cpp +++ b/src/storage.cpp @@ -16,15 +16,15 @@ #include "storage.h" -LMDBDataBase::StorageBase::StorageBase(const std::string& p_name, DataBase* parent): +LMDBAL::iStorage::iStorage(const std::string& p_name, Base* parent): dbi(), db(parent), name(p_name) {} -LMDBDataBase::StorageBase::~StorageBase() {} +LMDBAL::iStorage::~iStorage() {} -void LMDBDataBase::StorageBase::drop() { +void LMDBAL::iStorage::drop() { ensureOpened(dropMethodName); MDB_txn *txn; @@ -42,22 +42,22 @@ void LMDBDataBase::StorageBase::drop() { mdb_txn_commit(txn); } -int LMDBDataBase::StorageBase::drop(MDB_txn* transaction) { +int LMDBAL::iStorage::drop(MDB_txn* transaction) { return mdb_drop(transaction, dbi, 0); } -const std::string & LMDBDataBase::StorageBase::dbName() const { +const std::string & LMDBAL::iStorage::dbName() const { return db->name;} -bool LMDBDataBase::StorageBase::isDBOpened() const { +bool LMDBAL::iStorage::isDBOpened() const { return db->opened;} -void LMDBDataBase::StorageBase::ensureOpened(const std::string& methodName) const { +void LMDBAL::iStorage::ensureOpened(const std::string& methodName) const { if (!db->opened) throw Closed(methodName, db->name, name); } -uint32_t LMDBDataBase::StorageBase::count() const { +uint32_t LMDBAL::iStorage::count() const { ensureOpened(countMethodName); MDB_txn *txn; @@ -78,7 +78,7 @@ uint32_t LMDBDataBase::StorageBase::count() const { 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); if (rc == MDB_KEYEXIST) throwDuplicate(key); @@ -86,7 +86,7 @@ void LMDBDataBase::StorageBase::throwDuplicateOrUnknown(int rc, TransactionID tx 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); if (rc == MDB_NOTFOUND) throwNotFound(key); @@ -94,28 +94,28 @@ void LMDBDataBase::StorageBase::throwNotFoundOrUnknown(int rc, LMDBDataBase::Tra throwUnknown(rc); } -void LMDBDataBase::StorageBase::throwUnknown(int rc, LMDBDataBase::TransactionID txn) const { +void LMDBAL::iStorage::throwUnknown(int rc, LMDBAL::TransactionID txn) const { abortTransaction(txn); throwUnknown(rc); } -void LMDBDataBase::StorageBase::throwUnknown(int rc) const { +void LMDBAL::iStorage::throwUnknown(int rc) const { 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);} -void LMDBDataBase::StorageBase::throwNotFound(const std::string& key) const { +void LMDBAL::iStorage::throwNotFound(const std::string& key) const { throw NotFound(key, db->name, name);} -LMDBDataBase::TransactionID LMDBDataBase::StorageBase::beginReadOnlyTransaction() const { +LMDBAL::TransactionID LMDBAL::iStorage::beginReadOnlyTransaction() const { return db->beginReadOnlyTransaction(name);} -LMDBDataBase::TransactionID LMDBDataBase::StorageBase::beginTransaction() const { +LMDBAL::TransactionID LMDBAL::iStorage::beginTransaction() const { return db->beginTransaction(name);} -void LMDBDataBase::StorageBase::abortTransaction(LMDBDataBase::TransactionID id) const { +void LMDBAL::iStorage::abortTransaction(LMDBAL::TransactionID id) const { db->abortTransaction(id);} -void LMDBDataBase::StorageBase::commitTransaction(LMDBDataBase::TransactionID id) const { +void LMDBAL::iStorage::commitTransaction(LMDBAL::TransactionID id) const { db->commitTransaction(id);} diff --git a/storage.h b/src/storage.h similarity index 88% rename from storage.h rename to src/storage.h index 19990c1..af2d77e 100644 --- a/storage.h +++ b/src/storage.h @@ -14,19 +14,19 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef LMDBDATABASE_STORAGE_H -#define LMDBDATABASE_STORAGE_H +#ifndef LMDBAL_STORAGE_H +#define LMDBAL_STORAGE_H -#include "database.h" +#include "base.h" #include "serializer.h" -namespace LMDBDataBase { +namespace LMDBAL { -class StorageBase { - friend class DataBase; +class iStorage { + friend class Base; protected: - StorageBase(const std::string& name, DataBase* parent); - virtual ~StorageBase(); + iStorage(const std::string& name, Base* parent); + virtual ~iStorage(); virtual int createTable(MDB_txn * transaction) = 0; virtual int drop(MDB_txn * transaction); @@ -53,7 +53,7 @@ public: protected: MDB_dbi dbi; - DataBase* db; + Base* db; const std::string name; inline static const std::string dropMethodName = "drop"; @@ -78,14 +78,14 @@ protected: }; template -class Storage : public StorageBase { - friend class DataBase; +class Storage : public iStorage { + friend class Base; protected: - Storage(const std::string& name, DataBase* parent); + Storage(const std::string& name, Base* parent); ~Storage() override; public: - using StorageBase::drop; + using iStorage::drop; 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 void changeRecord(const K& key, const V& value); @@ -107,4 +107,4 @@ protected: #include "storage.hpp" -#endif // LMDBDATABASE_STORAGE_H +#endif //LMDBAL_STORAGE_H diff --git a/storage.hpp b/src/storage.hpp similarity index 77% rename from storage.hpp rename to src/storage.hpp index 198fcf1..bfecd4d 100644 --- a/storage.hpp +++ b/src/storage.hpp @@ -14,27 +14,27 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef LMDBDATABASE_STORAGE_HPP -#define LMDBDATABASE_STORAGE_HPP +#ifndef LMDBAL_STORAGE_HPP +#define LMDBAL_STORAGE_HPP #include "storage.h" #include "exceptions.h" template -LMDBDataBase::Storage::Storage(const std::string& p_name, DataBase* parent): - StorageBase(p_name, parent), +LMDBAL::Storage::Storage(const std::string& p_name, Base* parent): + iStorage(p_name, parent), keySerializer(new Serializer()), valueSerializer(new Serializer()) {} template -LMDBDataBase::Storage::~Storage() { +LMDBAL::Storage::~Storage() { delete valueSerializer; delete keySerializer; } template -void LMDBDataBase::Storage::addRecord(const K& key, const V& value) { +void LMDBAL::Storage::addRecord(const K& key, const V& value) { ensureOpened(addRecordMethodName); TransactionID txn = beginTransaction(); @@ -49,7 +49,7 @@ void LMDBDataBase::Storage::addRecord(const K& key, const V& value) { } template -bool LMDBDataBase::Storage::forceRecord(const K& key, const V& value) { +bool LMDBAL::Storage::forceRecord(const K& key, const V& value) { ensureOpened(forceRecordMethodName); bool added; @@ -81,7 +81,7 @@ bool LMDBDataBase::Storage::forceRecord(const K& key, const V& value) { } template -void LMDBDataBase::Storage::changeRecord(const K& key, const V& value) { +void LMDBAL::Storage::changeRecord(const K& key, const V& value) { ensureOpened(changeRecordMethodName); TransactionID txn = beginTransaction(); @@ -96,7 +96,7 @@ void LMDBDataBase::Storage::changeRecord(const K& key, const V& value) { } template -V LMDBDataBase::Storage::getRecord(const K& key) const { +V LMDBAL::Storage::getRecord(const K& key) const { ensureOpened(getRecordMethodName); TransactionID txn = beginReadOnlyTransaction(); @@ -114,7 +114,7 @@ V LMDBDataBase::Storage::getRecord(const K& key) const { } template -bool LMDBDataBase::Storage::checkRecord(const K& key) const { +bool LMDBAL::Storage::checkRecord(const K& key) const { ensureOpened(checkRecordMethodName); TransactionID txn = beginReadOnlyTransaction(); @@ -134,7 +134,7 @@ bool LMDBDataBase::Storage::checkRecord(const K& key) const { } template -std::map LMDBDataBase::Storage::readAll() const { +std::map LMDBAL::Storage::readAll() const { ensureOpened(readAllMethodName); TransactionID txn = beginReadOnlyTransaction(); @@ -162,7 +162,7 @@ std::map LMDBDataBase::Storage::readAll() const { } template -void LMDBDataBase::Storage::replaceAll(const std::map& data) { +void LMDBAL::Storage::replaceAll(const std::map& data) { ensureOpened(replaceAllMethodName); TransactionID txn = beginTransaction(); @@ -183,7 +183,7 @@ void LMDBDataBase::Storage::replaceAll(const std::map& data) { } template -uint32_t LMDBDataBase::Storage::addRecords(const std::map& data, bool overwrite) { +uint32_t LMDBAL::Storage::addRecords(const std::map& data, bool overwrite) { ensureOpened(addRecordsMethodName); TransactionID txn = beginTransaction(); @@ -211,7 +211,7 @@ uint32_t LMDBDataBase::Storage::addRecords(const std::map& data, boo } template -void LMDBDataBase::Storage::removeRecord(const K& key) { +void LMDBAL::Storage::removeRecord(const K& key) { ensureOpened(removeRecordMethodName); TransactionID txn = beginTransaction(); @@ -224,68 +224,68 @@ void LMDBDataBase::Storage::removeRecord(const K& key) { } template -int LMDBDataBase::Storage::createTable(MDB_txn* transaction) { +int LMDBAL::Storage::createTable(MDB_txn* transaction) { return makeTable(transaction); } template -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); } template<> -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 | MDB_INTEGERKEY, &dbi); } template<> -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 | MDB_INTEGERKEY, &dbi); } template<> -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 | MDB_INTEGERKEY, &dbi); } template<> -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 | MDB_INTEGERKEY, &dbi); } template<> -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 | MDB_INTEGERKEY, &dbi); } template<> -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 | MDB_INTEGERKEY, &dbi); } template<> -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 | MDB_INTEGERKEY, &dbi); } template<> -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 | MDB_INTEGERKEY, &dbi); } template -inline std::string LMDBDataBase::StorageBase::toString(const T& value) { +inline std::string LMDBAL::iStorage::toString(const T& value) { return std::to_string(value); } template<> -inline std::string LMDBDataBase::StorageBase::toString(const QString& value) { +inline std::string LMDBAL::iStorage::toString(const QString& value) { return value.toStdString(); } template<> -inline std::string LMDBDataBase::StorageBase::toString(const std::string& value) { +inline std::string LMDBAL::iStorage::toString(const std::string& value) { return value; } -#endif //LMDBDATABASE_STORAGE_HPP +#endif //LMDBAL_STORAGE_HPP diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d35802f..0b5208c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,14 +8,14 @@ add_executable(runUnitTests 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}Core_INCLUDE_DIRS}) target_link_libraries( runUnitTests GTest::gtest_main - storage + lmdbal ) include(GoogleTest) diff --git a/test/basic.cpp b/test/basic.cpp index cc92a5f..9c9ad62 100644 --- a/test/basic.cpp +++ b/test/basic.cpp @@ -1,24 +1,24 @@ #include -#include "database.h" +#include "base.h" #include "storage.h" #include "cache.h" #include -class DataBaseTest : public ::testing::Test { +class BaseTest : public ::testing::Test { protected: - DataBaseTest(): + BaseTest(): ::testing::Test(), t1(db->getTable("table1")), t2(db->getTable("table2")), c1(db->getCache("cache1")) {} - ~DataBaseTest() {} + ~BaseTest() {} static void SetUpTestSuite() { if (db == nullptr) { - db = new LMDBDataBase::DataBase("testBase"); + db = new LMDBAL::Base("testBase"); db->addTable("table1"); db->addTable("table2"); db->addCache("cache1"); @@ -32,21 +32,21 @@ protected: db = nullptr; } - static LMDBDataBase::DataBase* db; + static LMDBAL::Base* db; - LMDBDataBase::Storage* t1; - LMDBDataBase::Storage* t2; - LMDBDataBase::Cache* c1; + LMDBAL::Storage* t1; + LMDBAL::Storage* t2; + LMDBAL::Cache* c1; }; -LMDBDataBase::DataBase* DataBaseTest::db = nullptr; +LMDBAL::Base* BaseTest::db = nullptr; -TEST_F(DataBaseTest, RemovingDirectory) { +TEST_F(BaseTest, RemovingDirectory) { EXPECT_EQ(db->removeDirectory(), true); } -TEST_F(DataBaseTest, OpeningClosingDatabase) { +TEST_F(BaseTest, OpeningClosingDatabase) { EXPECT_EQ(db->ready(), false); db->open(); EXPECT_EQ(db->ready(), true); @@ -56,7 +56,7 @@ TEST_F(DataBaseTest, OpeningClosingDatabase) { EXPECT_EQ(db->ready(), true); } -TEST_F(DataBaseTest, AddingIntegerKey) { +TEST_F(BaseTest, AddingIntegerKey) { EXPECT_EQ(db->ready(), true); t1->addRecord(1, 2); t1->addRecord(2, 2); @@ -64,7 +64,7 @@ TEST_F(DataBaseTest, AddingIntegerKey) { EXPECT_EQ(t1->getRecord(1), 2); } -TEST_F(DataBaseTest, AddingQStringKey) { +TEST_F(BaseTest, AddingQStringKey) { EXPECT_EQ(db->ready(), true); t2->addRecord("hello", "world"); t2->addRecord("aaa", "gagdfsdf"); @@ -73,7 +73,7 @@ TEST_F(DataBaseTest, AddingQStringKey) { EXPECT_EQ(t2->getRecord("hello"), "world"); } -TEST_F(DataBaseTest, AddingKeysToCache) { +TEST_F(BaseTest, AddingKeysToCache) { EXPECT_EQ(db->ready(), true); c1->addRecord(2, "blah balah"); c1->addRecord(-4, "testing goes brrr"); @@ -83,48 +83,48 @@ TEST_F(DataBaseTest, AddingKeysToCache) { EXPECT_EQ(c1->getRecord(-116), "whatever"); } -TEST_F(DataBaseTest, AddingRepeatingIntegerKey) { +TEST_F(BaseTest, AddingRepeatingIntegerKey) { EXPECT_EQ(db->ready(), true); bool thrown = false; try { t1->addRecord(3, 24); - } catch (const LMDBDataBase::Exist e) { + } catch (const LMDBAL::Exist e) { thrown = true; } ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened"; EXPECT_EQ(t1->getRecord(3), 15); } -TEST_F(DataBaseTest, AddingRepeatingStringKey) { +TEST_F(BaseTest, AddingRepeatingStringKey) { EXPECT_EQ(db->ready(), true); bool thrown = false; try { t2->addRecord("sdfhga", "world"); - } catch (const LMDBDataBase::Exist e) { + } catch (const LMDBAL::Exist e) { thrown = true; } ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened"; EXPECT_EQ(t2->getRecord("sdfhga"), "DSFFDG"); } -TEST_F(DataBaseTest, AddingRepeatingCacheKey) { +TEST_F(BaseTest, AddingRepeatingCacheKey) { EXPECT_EQ(db->ready(), true); bool thrown = false; try { c1->addRecord(-4, "world"); - } catch (const LMDBDataBase::Exist e) { + } catch (const LMDBAL::Exist e) { thrown = true; } 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"); } -TEST_F(DataBaseTest, GettingNotExistingKeys) { +TEST_F(BaseTest, GettingNotExistingKeys) { EXPECT_EQ(db->ready(), true); bool thrown = false; try { QString wrong = t2->getRecord("almonds"); - } catch (const LMDBDataBase::NotFound e) { + } catch (const LMDBAL::NotFound e) { thrown = true; } 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; try { uint32_t wrong = t1->getRecord(64); - } catch (const LMDBDataBase::NotFound e) { + } catch (const LMDBAL::NotFound e) { thrown = true; } 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; try { std::string wrong = c1->getRecord(21); - } catch (const LMDBDataBase::NotFound e) { + } catch (const LMDBAL::NotFound e) { thrown = true; } 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); db->close(); delete db; - db = new LMDBDataBase::DataBase("testBase"); + db = new LMDBAL::Base("testBase"); t1 = db->addTable("table1"); t2 = db->addTable("table2"); c1 = db->addCache("cache1"); @@ -175,7 +175,7 @@ TEST_F(DataBaseTest, Persistence) { bool thrown = false; try { QString wrong = t2->getRecord("cats"); - } catch (const LMDBDataBase::NotFound e) { + } catch (const LMDBAL::NotFound e) { thrown = true; } 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; try { uint32_t wrong = t1->getRecord(7893); - } catch (const LMDBDataBase::NotFound e) { + } catch (const LMDBAL::NotFound e) { thrown = true; } 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; try { std::string wrong = c1->getRecord(89); - } catch (const LMDBDataBase::NotFound e) { + } catch (const LMDBAL::NotFound e) { thrown = true; } 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(t1->count(), 3); EXPECT_EQ(t2->count(), 4); @@ -219,7 +219,7 @@ TEST_F(DataBaseTest, CountAndDrop) { EXPECT_EQ(c1->count(), 2); } -TEST_F(DataBaseTest, Change) { +TEST_F(BaseTest, Change) { EXPECT_EQ(db->ready(), true); EXPECT_EQ(t1->count(), 1); EXPECT_EQ(t2->count(), 1); @@ -253,7 +253,7 @@ TEST_F(DataBaseTest, Change) { EXPECT_EQ(c1->count(), 3); } -TEST_F(DataBaseTest, Force) { +TEST_F(BaseTest, Force) { EXPECT_EQ(db->ready(), true); t1->forceRecord(58, 35); //changing