forked from blue/lmdbal
big refactoring part 1
This commit is contained in:
parent
6a8f67ac34
commit
19229f6c26
28 changed files with 867 additions and 795 deletions
|
@ -16,26 +16,25 @@
|
|||
|
||||
#include "exceptions.h"
|
||||
|
||||
DataBase::Exception::Exception():
|
||||
std::exception()
|
||||
LMDBDataBase::Exception::Exception():
|
||||
std::exception()
|
||||
{}
|
||||
|
||||
DataBase::Exception::~Exception() {}
|
||||
LMDBDataBase::Exception::~Exception() {}
|
||||
|
||||
const char* DataBase::Exception::what() const noexcept( true )
|
||||
{
|
||||
const char* LMDBDataBase::Exception::what() const noexcept( true ) {
|
||||
std::string* msg = new std::string(getMessage());
|
||||
return msg->c_str();
|
||||
}
|
||||
|
||||
DataBase::Directory::Directory(const std::string& p_path):
|
||||
LMDBDataBase::Directory::Directory(const std::string& p_path):
|
||||
Exception(),
|
||||
path(p_path) {}
|
||||
|
||||
std::string DataBase::Directory::getMessage() const {
|
||||
std::string LMDBDataBase::Directory::getMessage() const {
|
||||
return "Can't create directory for database at " + path;}
|
||||
|
||||
DataBase::Closed::Closed(
|
||||
LMDBDataBase::Closed::Closed(
|
||||
const std::string& p_operation,
|
||||
const std::string& p_dbName,
|
||||
const std::optional<std::string>& p_tableName
|
||||
|
@ -45,29 +44,28 @@ DataBase::Closed::Closed(
|
|||
dbName(p_dbName),
|
||||
tableName(p_tableName) {}
|
||||
|
||||
std::string DataBase::Closed::getMessage() const {
|
||||
std::string LMDBDataBase::Closed::getMessage() const {
|
||||
std::string msg = "An attempt to perform operation " + operation
|
||||
+ " on closed database " + dbName;
|
||||
if (tableName.has_value()) {
|
||||
if (tableName.has_value())
|
||||
msg += + " on table " + tableName.value();
|
||||
}
|
||||
return msg;
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
DataBase::Opened::Opened(const std::string& p_dbName, const std::string& p_action):
|
||||
LMDBDataBase::Opened::Opened(const std::string& p_dbName, const std::string& p_action):
|
||||
Exception(),
|
||||
dbName(p_dbName),
|
||||
action(p_action) {}
|
||||
|
||||
|
||||
std::string DataBase::Opened::getMessage() const {
|
||||
std::string LMDBDataBase::Opened::getMessage() const {
|
||||
return "An attempt to " + action
|
||||
+ " (the database " + dbName
|
||||
+ ") but it's can't be done because the DataBase is already opened";
|
||||
}
|
||||
|
||||
DataBase::NotFound::NotFound(
|
||||
LMDBDataBase::NotFound::NotFound(
|
||||
const std::string& p_key,
|
||||
const std::string& p_dbName,
|
||||
const std::string& p_tableName
|
||||
|
@ -77,12 +75,12 @@ DataBase::NotFound::NotFound(
|
|||
dbName(p_dbName),
|
||||
tableName(p_tableName) {}
|
||||
|
||||
std::string DataBase::NotFound::getMessage() const {
|
||||
std::string LMDBDataBase::NotFound::getMessage() const {
|
||||
return "Element for id " + key + " wasn't found "
|
||||
+ " in database " + dbName
|
||||
+ " in table " + tableName;}
|
||||
|
||||
DataBase::Exist::Exist(
|
||||
LMDBDataBase::Exist::Exist(
|
||||
const std::string& p_key,
|
||||
const std::string& p_dbName,
|
||||
const std::string& p_tableName
|
||||
|
@ -92,14 +90,14 @@ DataBase::Exist::Exist(
|
|||
dbName(p_dbName),
|
||||
tableName(p_tableName) {}
|
||||
|
||||
std::string DataBase::Exist::getMessage() const {
|
||||
std::string LMDBDataBase::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";
|
||||
}
|
||||
|
||||
DataBase::Unknown::Unknown(
|
||||
LMDBDataBase::Unknown::Unknown(
|
||||
const std::string& p_dbName,
|
||||
const std::string& message,
|
||||
const std::optional<std::string>& p_tableName
|
||||
|
@ -109,12 +107,11 @@ DataBase::Unknown::Unknown(
|
|||
tableName(p_tableName),
|
||||
msg(message) {}
|
||||
|
||||
std::string DataBase::Unknown::getMessage() const
|
||||
{
|
||||
std::string LMDBDataBase::Unknown::getMessage() const {
|
||||
std::string result = "Unknown error in database " + dbName;
|
||||
if (tableName.has_value()) {
|
||||
if (tableName.has_value())
|
||||
result += " in table " + tableName.value();
|
||||
}
|
||||
|
||||
result += ": " + msg;
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue