From b009c773f02b372973e7771c4d00d6195e053e67 Mon Sep 17 00:00:00 2001 From: Steven Murray <Steven.Murray@cern.ch> Date: Tue, 3 Dec 2019 13:28:22 +0100 Subject: [PATCH] Moved rdbms exceptions into the rdbms directory and namespace --- catalogue/MysqlCatalogue.cpp | 6 +++--- catalogue/SqliteCatalogue.cpp | 6 +++--- common/CMakeLists.txt | 4 ---- rdbms/CMakeLists.txt | 6 +++++- .../CheckConstraintError.cpp | 12 ++++++------ .../CheckConstraintError.hpp | 15 +++++++-------- .../ConstraintError.cpp | 10 +++++----- .../ConstraintError.hpp | 14 +++++++------- .../PrimaryKeyError.cpp | 12 ++++++------ .../PrimaryKeyError.hpp | 16 ++++++++-------- rdbms/StmtTest.cpp | 12 ++++++------ .../UniqueError.cpp | 12 ++++++------ .../UniqueError.hpp | 16 ++++++++-------- rdbms/wrapper/MysqlRset.cpp | 4 ++-- rdbms/wrapper/MysqlStmt.cpp | 8 ++++---- rdbms/wrapper/OcciStmt.cpp | 10 +++++----- rdbms/wrapper/Postgres.hpp | 8 ++++---- rdbms/wrapper/PostgresStmtTest.cpp | 2 +- rdbms/wrapper/SqliteRset.cpp | 8 ++++---- rdbms/wrapper/SqliteStmt.cpp | 18 +++++++++--------- rdbms/wrapper/SqliteStmtTest.cpp | 10 ++++++---- 21 files changed, 105 insertions(+), 104 deletions(-) rename common/exception/DatabaseCheckConstraintError.cpp => rdbms/CheckConstraintError.cpp (80%) rename common/exception/DatabaseCheckConstraintError.hpp => rdbms/CheckConstraintError.hpp (76%) rename common/exception/DatabaseConstraintError.cpp => rdbms/ConstraintError.cpp (81%) rename common/exception/DatabaseConstraintError.hpp => rdbms/ConstraintError.hpp (79%) rename common/exception/DatabaseUniqueError.cpp => rdbms/PrimaryKeyError.cpp (78%) rename common/exception/DatabaseUniqueError.hpp => rdbms/PrimaryKeyError.hpp (77%) rename common/exception/DatabasePrimaryKeyError.cpp => rdbms/UniqueError.cpp (77%) rename common/exception/DatabasePrimaryKeyError.hpp => rdbms/UniqueError.hpp (76%) diff --git a/catalogue/MysqlCatalogue.cpp b/catalogue/MysqlCatalogue.cpp index db7a4ecc1f..edd101bdd7 100644 --- a/catalogue/MysqlCatalogue.cpp +++ b/catalogue/MysqlCatalogue.cpp @@ -19,8 +19,6 @@ #include "catalogue/ArchiveFileRow.hpp" #include "catalogue/MysqlCatalogueSchema.hpp" #include "catalogue/MysqlCatalogue.hpp" -#include "common/exception/DatabaseConstraintError.hpp" -#include "common/exception/DatabasePrimaryKeyError.hpp" #include "common/exception/Exception.hpp" #include "common/exception/UserError.hpp" #include "common/make_unique.hpp" @@ -28,6 +26,8 @@ #include "common/Timer.hpp" #include "common/utils/utils.hpp" #include "rdbms/AutoRollback.hpp" +#include "rdbms/ConstraintError.hpp" +#include "rdbms/PrimaryKeyError.hpp" namespace cta { namespace catalogue { @@ -336,7 +336,7 @@ void MysqlCatalogue::fileWrittenToTape(rdbms::Conn &conn, const TapeFileWritten row.diskFileOwnerUid = event.diskFileOwnerUid; row.diskFileGid = event.diskFileGid; insertArchiveFile(conn, row); - } catch(exception::DatabasePrimaryKeyError &) { + } catch(rdbms::PrimaryKeyError &) { // Ignore this error } diff --git a/catalogue/SqliteCatalogue.cpp b/catalogue/SqliteCatalogue.cpp index 9146b85d11..5432b89552 100644 --- a/catalogue/SqliteCatalogue.cpp +++ b/catalogue/SqliteCatalogue.cpp @@ -19,8 +19,6 @@ #include "catalogue/ArchiveFileRow.hpp" #include "catalogue/SqliteCatalogueSchema.hpp" #include "catalogue/SqliteCatalogue.hpp" -#include "common/exception/DatabaseConstraintError.hpp" -#include "common/exception/DatabasePrimaryKeyError.hpp" #include "common/exception/Exception.hpp" #include "common/exception/UserError.hpp" #include "common/make_unique.hpp" @@ -28,6 +26,8 @@ #include "common/Timer.hpp" #include "common/utils/utils.hpp" #include "rdbms/AutoRollback.hpp" +#include "rdbms/ConstraintError.hpp" +#include "rdbms/PrimaryKeyError.hpp" namespace cta { namespace catalogue { @@ -418,7 +418,7 @@ void SqliteCatalogue::fileWrittenToTape(rdbms::Conn &conn, const TapeFileWritten row.diskFileOwnerUid = event.diskFileOwnerUid; row.diskFileGid = event.diskFileGid; insertArchiveFile(conn, row); - } catch(exception::DatabasePrimaryKeyError &) { + } catch(rdbms::PrimaryKeyError &) { // Ignore this error } catch(...) { throw; diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 5296e06c6f..f1063e5b02 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -81,10 +81,6 @@ set (COMMON_LIB_SRC_FILES exception/Backtrace.cpp exception/BadAlloc.cpp exception/CommandLineNotParsed.cpp - exception/DatabaseCheckConstraintError.cpp - exception/DatabaseConstraintError.cpp - exception/DatabasePrimaryKeyError.cpp - exception/DatabaseUniqueError.cpp exception/DismountFailed.cpp exception/ForceDismountFailed.cpp exception/Errnum.cpp diff --git a/rdbms/CMakeLists.txt b/rdbms/CMakeLists.txt index a3fa9ad9df..ff41876b49 100644 --- a/rdbms/CMakeLists.txt +++ b/rdbms/CMakeLists.txt @@ -21,15 +21,19 @@ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow") set (RDBMS_LIB_SRC_FILES AutoRollback.cpp + CheckConstraintError.cpp Conn.cpp ConnPool.cpp + ConstraintError.cpp Login.cpp LoginFactory.cpp NullDbValue.cpp + PrimaryKeyError.cpp rdbms.cpp Rset.cpp Stmt.cpp - StmtPool.cpp) + StmtPool.cpp + UniqueError.cpp) add_library (ctardbms SHARED ${RDBMS_LIB_SRC_FILES}) diff --git a/common/exception/DatabaseCheckConstraintError.cpp b/rdbms/CheckConstraintError.cpp similarity index 80% rename from common/exception/DatabaseCheckConstraintError.cpp rename to rdbms/CheckConstraintError.cpp index a80ed5daa6..f1f9052d56 100644 --- a/common/exception/DatabaseCheckConstraintError.cpp +++ b/rdbms/CheckConstraintError.cpp @@ -16,25 +16,25 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "common/exception/DatabaseCheckConstraintError.hpp" +#include "rdbms/CheckConstraintError.hpp" namespace cta { -namespace exception { +namespace rdbms { //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ -DatabaseCheckConstraintError::DatabaseCheckConstraintError( +CheckConstraintError::CheckConstraintError( const std::string &context, const bool embedBacktrace): - DatabaseConstraintError(context, embedBacktrace) { + ConstraintError(context, embedBacktrace) { } //------------------------------------------------------------------------------ // destructor //------------------------------------------------------------------------------ -DatabaseCheckConstraintError::~DatabaseCheckConstraintError() noexcept { +CheckConstraintError::~CheckConstraintError() noexcept { } -} // namespace exception +} // namespace rdbms } // namespace cta diff --git a/common/exception/DatabaseCheckConstraintError.hpp b/rdbms/CheckConstraintError.hpp similarity index 76% rename from common/exception/DatabaseCheckConstraintError.hpp rename to rdbms/CheckConstraintError.hpp index 7a81d0503c..b92f6a579c 100644 --- a/common/exception/DatabaseCheckConstraintError.hpp +++ b/rdbms/CheckConstraintError.hpp @@ -18,18 +18,17 @@ #pragma once -#include "common/exception/DatabaseConstraintError.hpp" +#include "rdbms/ConstraintError.hpp" #include <string> - namespace cta { -namespace exception { +namespace rdbms { /** * A database constraint error. */ -class DatabaseCheckConstraintError : public DatabaseConstraintError { +class CheckConstraintError : public ConstraintError { public: /** @@ -40,15 +39,15 @@ public: * @param embedBacktrace whether to embed a backtrace of where the * exception was throw in the message */ - DatabaseCheckConstraintError(const std::string &context = "", const bool embedBacktrace = true); + CheckConstraintError(const std::string &context = "", const bool embedBacktrace = true); /** * Empty Destructor, explicitely non-throwing (needed for std::exception * inheritance) */ - ~DatabaseCheckConstraintError() noexcept override; + ~CheckConstraintError() noexcept override; -}; // class DatabaseCheckConstraintError +}; // class CheckConstraintError -} // namespace exception +} // namespace rdbms } // namespace cta diff --git a/common/exception/DatabaseConstraintError.cpp b/rdbms/ConstraintError.cpp similarity index 81% rename from common/exception/DatabaseConstraintError.cpp rename to rdbms/ConstraintError.cpp index d0b2f1e340..cf39e97d67 100644 --- a/common/exception/DatabaseConstraintError.cpp +++ b/rdbms/ConstraintError.cpp @@ -16,23 +16,23 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "common/exception/DatabaseConstraintError.hpp" +#include "rdbms/ConstraintError.hpp" namespace cta { -namespace exception { +namespace rdbms { //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ -DatabaseConstraintError::DatabaseConstraintError(const std::string &context, const bool embedBacktrace): +ConstraintError::ConstraintError(const std::string &context, const bool embedBacktrace): Exception(context, embedBacktrace) { } //------------------------------------------------------------------------------ // destructor //------------------------------------------------------------------------------ -DatabaseConstraintError::~DatabaseConstraintError() noexcept { +ConstraintError::~ConstraintError() noexcept { } -} // namespace exception +} // namespace rdbms } // namespace cta diff --git a/common/exception/DatabaseConstraintError.hpp b/rdbms/ConstraintError.hpp similarity index 79% rename from common/exception/DatabaseConstraintError.hpp rename to rdbms/ConstraintError.hpp index 60a9248497..6c3557f688 100644 --- a/common/exception/DatabaseConstraintError.hpp +++ b/rdbms/ConstraintError.hpp @@ -23,13 +23,13 @@ #include <string> -namespace cta { -namespace exception { +namespace cta { +namespace rdbms { /** * A database constraint error. */ -class DatabaseConstraintError : public cta::exception::Exception { +class ConstraintError : public cta::exception::Exception { public: /** @@ -40,15 +40,15 @@ public: * @param embedBacktrace whether to embed a backtrace of where the * exception was throw in the message */ - DatabaseConstraintError(const std::string &context = "", const bool embedBacktrace = true); + ConstraintError(const std::string &context = "", const bool embedBacktrace = true); /** * Empty Destructor, explicitely non-throwing (needed for std::exception * inheritance) */ - ~DatabaseConstraintError() noexcept override; + ~ConstraintError() noexcept override; -}; // class DatabaseConstraintError +}; // class ConstraintError -} // namespace exception +} // namespace rdbms } // namespace cta diff --git a/common/exception/DatabaseUniqueError.cpp b/rdbms/PrimaryKeyError.cpp similarity index 78% rename from common/exception/DatabaseUniqueError.cpp rename to rdbms/PrimaryKeyError.cpp index db0e01cbb6..1d69cedb7a 100644 --- a/common/exception/DatabaseUniqueError.cpp +++ b/rdbms/PrimaryKeyError.cpp @@ -16,23 +16,23 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "common/exception/DatabaseUniqueError.hpp" +#include "rdbms/PrimaryKeyError.hpp" namespace cta { -namespace exception { +namespace rdbms { //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ -DatabaseUniqueError::DatabaseUniqueError(const std::string &context, const bool embedBacktrace): - DatabaseConstraintError(context, embedBacktrace) { +PrimaryKeyError::PrimaryKeyError(const std::string &context, const bool embedBacktrace): + ConstraintError(context, embedBacktrace) { } //------------------------------------------------------------------------------ // destructor //------------------------------------------------------------------------------ -DatabaseUniqueError::~DatabaseUniqueError() noexcept { +PrimaryKeyError::~PrimaryKeyError() noexcept { } -} // namespace exception +} // namespace rdbms } // namespace cta diff --git a/common/exception/DatabaseUniqueError.hpp b/rdbms/PrimaryKeyError.hpp similarity index 77% rename from common/exception/DatabaseUniqueError.hpp rename to rdbms/PrimaryKeyError.hpp index caf511c7e9..714c1558ce 100644 --- a/common/exception/DatabaseUniqueError.hpp +++ b/rdbms/PrimaryKeyError.hpp @@ -18,18 +18,18 @@ #pragma once -#include "common/exception/DatabaseConstraintError.hpp" +#include "rdbms/ConstraintError.hpp" #include <string> -namespace cta { -namespace exception { +namespace cta { +namespace rdbms { /** * A database constraint has been violated. */ -class DatabaseUniqueError : public DatabaseConstraintError { +class PrimaryKeyError : public ConstraintError { public: /** @@ -40,15 +40,15 @@ public: * @param embedBacktrace whether to embed a backtrace of where the * exception was throw in the message */ - DatabaseUniqueError(const std::string &context = "", const bool embedBacktrace = true); + PrimaryKeyError(const std::string &context = "", const bool embedBacktrace = true); /** * Empty Destructor, explicitely non-throwing (needed for std::exception * inheritance) */ - ~DatabaseUniqueError() noexcept override; + ~PrimaryKeyError() noexcept override; -}; // class DatabaseUniqueError +}; // class PrimaryKeyError -} // namespace exception +} // namespace rdbms } // namespace cta diff --git a/rdbms/StmtTest.cpp b/rdbms/StmtTest.cpp index a16c49311d..03ea228ec2 100644 --- a/rdbms/StmtTest.cpp +++ b/rdbms/StmtTest.cpp @@ -16,14 +16,14 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "common/exception/DatabaseCheckConstraintError.hpp" -#include "common/exception/DatabasePrimaryKeyError.hpp" -#include "common/exception/DatabaseUniqueError.hpp" #include "common/exception/Exception.hpp" #include "common/make_unique.hpp" #include "common/utils/utils.hpp" +#include "rdbms/CheckConstraintError.hpp" #include "rdbms/ConnPool.hpp" +#include "rdbms/PrimaryKeyError.hpp" #include "rdbms/StmtTest.hpp" +#include "rdbms/UniqueError.hpp" #include <gtest/gtest.h> @@ -420,7 +420,7 @@ TEST_P(cta_rdbms_StmtTest, insert_with_bindString_invalid_bool_value) { auto stmt = m_conn.createStmt(sql); stmt.bindString(":BOOL_COL", insertValue); - ASSERT_THROW(stmt.executeNonQuery(), cta::exception::DatabaseCheckConstraintError); + ASSERT_THROW(stmt.executeNonQuery(), CheckConstraintError); } } @@ -474,10 +474,10 @@ TEST_P(cta_rdbms_StmtTest, insert_same_primary_twice) { case Login::DBTYPE_IN_MEMORY: case Login::DBTYPE_ORACLE: case Login::DBTYPE_POSTGRESQL: - ASSERT_THROW(stmt.executeNonQuery(), cta::exception::DatabaseUniqueError); + ASSERT_THROW(stmt.executeNonQuery(), UniqueError); break; default: - ASSERT_THROW(stmt.executeNonQuery(), cta::exception::DatabasePrimaryKeyError); + ASSERT_THROW(stmt.executeNonQuery(), PrimaryKeyError); } } } diff --git a/common/exception/DatabasePrimaryKeyError.cpp b/rdbms/UniqueError.cpp similarity index 77% rename from common/exception/DatabasePrimaryKeyError.cpp rename to rdbms/UniqueError.cpp index 9e5cea183d..5ed7377aaa 100644 --- a/common/exception/DatabasePrimaryKeyError.cpp +++ b/rdbms/UniqueError.cpp @@ -16,23 +16,23 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "common/exception/DatabasePrimaryKeyError.hpp" +#include "rdbms/UniqueError.hpp" namespace cta { -namespace exception { +namespace rdbms { //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ -DatabasePrimaryKeyError::DatabasePrimaryKeyError(const std::string &context, const bool embedBacktrace): - DatabaseConstraintError(context, embedBacktrace) { +UniqueError::UniqueError(const std::string &context, const bool embedBacktrace): + ConstraintError(context, embedBacktrace) { } //------------------------------------------------------------------------------ // destructor //------------------------------------------------------------------------------ -DatabasePrimaryKeyError::~DatabasePrimaryKeyError() noexcept { +UniqueError::~UniqueError() noexcept { } -} // namespace exception +} // namespace rdbms } // namespace cta diff --git a/common/exception/DatabasePrimaryKeyError.hpp b/rdbms/UniqueError.hpp similarity index 76% rename from common/exception/DatabasePrimaryKeyError.hpp rename to rdbms/UniqueError.hpp index 84b756b88b..a67aa92230 100644 --- a/common/exception/DatabasePrimaryKeyError.hpp +++ b/rdbms/UniqueError.hpp @@ -18,18 +18,18 @@ #pragma once -#include "common/exception/DatabaseConstraintError.hpp" +#include "rdbms/ConstraintError.hpp" #include <string> -namespace cta { -namespace exception { +namespace cta { +namespace rdbms { /** * A database constraint has been violated. */ -class DatabasePrimaryKeyError : public DatabaseConstraintError { +class UniqueError : public ConstraintError { public: /** @@ -40,15 +40,15 @@ public: * @param embedBacktrace whether to embed a backtrace of where the * exception was throw in the message */ - DatabasePrimaryKeyError(const std::string &context = "", const bool embedBacktrace = true); + UniqueError(const std::string &context = "", const bool embedBacktrace = true); /** * Empty Destructor, explicitely non-throwing (needed for std::exception * inheritance) */ - ~DatabasePrimaryKeyError() noexcept override; + ~UniqueError() noexcept override; -}; // class DatabasePrimaryKeyError +}; // class UniqueError -} // namespace exception +} // namespace rdbms } // namespace cta diff --git a/rdbms/wrapper/MysqlRset.cpp b/rdbms/wrapper/MysqlRset.cpp index ee45544fba..d25c8c79f3 100644 --- a/rdbms/wrapper/MysqlRset.cpp +++ b/rdbms/wrapper/MysqlRset.cpp @@ -16,11 +16,11 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "common/exception/DatabaseConstraintError.hpp" -#include "common/exception/DatabasePrimaryKeyError.hpp" #include "common/exception/Exception.hpp" #include "common/exception/Errnum.hpp" +#include "rdbms/ConstraintError.hpp" #include "rdbms/NullDbValue.hpp" +#include "rdbms/PrimaryKeyError.hpp" #include "rdbms/wrapper/Mysql.hpp" #include "rdbms/wrapper/MysqlRset.hpp" #include "rdbms/wrapper/MysqlStmt.hpp" diff --git a/rdbms/wrapper/MysqlStmt.cpp b/rdbms/wrapper/MysqlStmt.cpp index fd3cc16f84..7d9d48eb51 100644 --- a/rdbms/wrapper/MysqlStmt.cpp +++ b/rdbms/wrapper/MysqlStmt.cpp @@ -16,12 +16,12 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "common/exception/DatabaseCheckConstraintError.hpp" -#include "common/exception/DatabasePrimaryKeyError.hpp" #include "common/exception/Exception.hpp" #include "common/make_unique.hpp" #include "common/threading/MutexLocker.hpp" +#include "rdbms/CheckConstraintError.hpp" +#include "rdbms/PrimaryKeyError.hpp" #include "rdbms/wrapper/MysqlConn.hpp" #include "rdbms/wrapper/MysqlRset.hpp" #include "rdbms/wrapper/MysqlStmt.hpp" @@ -380,10 +380,10 @@ void MysqlStmt::executeNonQuery() { switch(rc) { case ER_DUP_ENTRY: - throw exception::DatabasePrimaryKeyError(std::string(__FUNCTION__) + " " + msg); + throw PrimaryKeyError(std::string(__FUNCTION__) + " " + msg); break; case 4025: // Newer MariaDB versions have ER_CONSTRAINT_FAILED = 4025 - throw exception::DatabaseCheckConstraintError(std::string(__FUNCTION__) + " " + msg); + throw CheckConstraintError(std::string(__FUNCTION__) + " " + msg); break; } diff --git a/rdbms/wrapper/OcciStmt.cpp b/rdbms/wrapper/OcciStmt.cpp index 560862d145..a7f65171a4 100644 --- a/rdbms/wrapper/OcciStmt.cpp +++ b/rdbms/wrapper/OcciStmt.cpp @@ -16,13 +16,13 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "common/exception/DatabaseCheckConstraintError.hpp" -#include "common/exception/DatabasePrimaryKeyError.hpp" -#include "common/exception/DatabaseUniqueError.hpp" #include "common/exception/Exception.hpp" #include "common/exception/LostDatabaseConnection.hpp" #include "common/make_unique.hpp" #include "common/threading/MutexLocker.hpp" +#include "rdbms/CheckConstraintError.hpp" +#include "rdbms/PrimaryKeyError.hpp" +#include "rdbms/UniqueError.hpp" #include "rdbms/wrapper/OcciColumn.hpp" #include "rdbms/wrapper/OcciConn.hpp" #include "rdbms/wrapper/OcciRset.hpp" @@ -274,9 +274,9 @@ void OcciStmt::executeNonQuery() { switch(ex.getErrorCode()) { case 1: - throw exception::DatabaseUniqueError(msg.str()); + throw UniqueError(msg.str()); case 2290: - throw exception::DatabaseCheckConstraintError(msg.str()); + throw CheckConstraintError(msg.str()); default: throw exception::Exception(msg.str()); } diff --git a/rdbms/wrapper/Postgres.hpp b/rdbms/wrapper/Postgres.hpp index f7e3ee223f..5c3c902933 100644 --- a/rdbms/wrapper/Postgres.hpp +++ b/rdbms/wrapper/Postgres.hpp @@ -18,10 +18,10 @@ #pragma once -#include "common/exception/DatabaseCheckConstraintError.hpp" -#include "common/exception/DatabaseUniqueError.hpp" #include "common/exception/Exception.hpp" #include "common/exception/LostDatabaseConnection.hpp" +#include "rdbms/CheckConstraintError.hpp" +#include "rdbms/UniqueError.hpp" #include <algorithm> #include <cstring> @@ -95,10 +95,10 @@ public: throw exception::LostDatabaseConnection(dbmsg); } if (uniqueViolation) { - throw exception::DatabaseUniqueError(dbmsg); + throw UniqueError(dbmsg); } if (checkViolation) { - throw exception::DatabaseCheckConstraintError(dbmsg); + throw CheckConstraintError(dbmsg); } throw exception::Exception(dbmsg); } diff --git a/rdbms/wrapper/PostgresStmtTest.cpp b/rdbms/wrapper/PostgresStmtTest.cpp index 8d27cd91fa..812a70201e 100644 --- a/rdbms/wrapper/PostgresStmtTest.cpp +++ b/rdbms/wrapper/PostgresStmtTest.cpp @@ -16,8 +16,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "common/exception/DatabaseConstraintError.hpp" #include "common/make_unique.hpp" +#include "rdbms/ConstraintError.hpp" #include "rdbms/wrapper/PostgresConn.hpp" #include "rdbms/wrapper/PostgresRset.hpp" #include "rdbms/wrapper/PostgresStmt.hpp" diff --git a/rdbms/wrapper/SqliteRset.cpp b/rdbms/wrapper/SqliteRset.cpp index e332320f23..d01cf7d3fe 100644 --- a/rdbms/wrapper/SqliteRset.cpp +++ b/rdbms/wrapper/SqliteRset.cpp @@ -16,11 +16,11 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "common/exception/DatabaseConstraintError.hpp" -#include "common/exception/DatabasePrimaryKeyError.hpp" #include "common/exception/Exception.hpp" #include "common/exception/Errnum.hpp" +#include "rdbms/ConstraintError.hpp" #include "rdbms/NullDbValue.hpp" +#include "rdbms/PrimaryKeyError.hpp" #include "rdbms/wrapper/Sqlite.hpp" #include "rdbms/wrapper/SqliteRset.hpp" #include "rdbms/wrapper/SqliteStmt.hpp" @@ -158,9 +158,9 @@ bool SqliteRset::next() { switch(stepRc) { case SQLITE_CONSTRAINT_PRIMARYKEY: - throw exception::DatabasePrimaryKeyError(msg.str()); + throw PrimaryKeyError(msg.str()); case SQLITE_CONSTRAINT: - throw exception::DatabaseConstraintError(msg.str()); + throw ConstraintError(msg.str()); default: throw exception::Exception(msg.str()); } diff --git a/rdbms/wrapper/SqliteStmt.cpp b/rdbms/wrapper/SqliteStmt.cpp index 0b2c228faf..d063aaf2ba 100644 --- a/rdbms/wrapper/SqliteStmt.cpp +++ b/rdbms/wrapper/SqliteStmt.cpp @@ -16,13 +16,13 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "common/exception/DatabaseCheckConstraintError.hpp" -#include "common/exception/DatabaseConstraintError.hpp" -#include "common/exception/DatabasePrimaryKeyError.hpp" -#include "common/exception/DatabaseUniqueError.hpp" #include "common/exception/Exception.hpp" #include "common/make_unique.hpp" #include "common/threading/MutexLocker.hpp" +#include "rdbms/CheckConstraintError.hpp" +#include "rdbms/ConstraintError.hpp" +#include "rdbms/PrimaryKeyError.hpp" +#include "rdbms/UniqueError.hpp" #include "rdbms/wrapper/Sqlite.hpp" #include "rdbms/wrapper/SqliteConn.hpp" #include "rdbms/wrapper/SqliteRset.hpp" @@ -288,16 +288,16 @@ void SqliteStmt::executeNonQuery() { switch(stepRc) { case SQLITE_CONSTRAINT: - throw exception::DatabaseConstraintError(msg.str()); + throw ConstraintError(msg.str()); case SQLITE_CONSTRAINT_CHECK: - throw exception::DatabaseCheckConstraintError(msg.str()); + throw CheckConstraintError(msg.str()); case SQLITE_CONSTRAINT_PRIMARYKEY: - throw exception::DatabasePrimaryKeyError(msg.str()); + throw PrimaryKeyError(msg.str()); case SQLITE_CONSTRAINT_UNIQUE: - throw exception::DatabaseUniqueError(msg.str()); + throw UniqueError(msg.str()); default: if ((stepRc & 0xFF) == SQLITE_CONSTRAINT) - throw exception::DatabaseConstraintError(msg.str()); + throw ConstraintError(msg.str()); else throw exception::Exception(msg.str()); } diff --git a/rdbms/wrapper/SqliteStmtTest.cpp b/rdbms/wrapper/SqliteStmtTest.cpp index 1ec7e9a2e6..6f286f5302 100644 --- a/rdbms/wrapper/SqliteStmtTest.cpp +++ b/rdbms/wrapper/SqliteStmtTest.cpp @@ -16,8 +16,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "common/exception/DatabaseConstraintError.hpp" -#include "common/exception/DatabasePrimaryKeyError.hpp" +#include "rdbms/ConstraintError.hpp" +#include "rdbms/PrimaryKeyError.hpp" #include "rdbms/wrapper/SqliteConn.hpp" #include "rdbms/wrapper/SqliteRset.hpp" #include "rdbms/wrapper/SqliteStmt.hpp" @@ -362,6 +362,7 @@ TEST_F(cta_rdbms_wrapper_SqliteStmtTest, isolated_transaction) { TEST_F(cta_rdbms_wrapper_SqliteStmtTest, executeNonQuery_insert_violating_primary_key) { using namespace cta; + using namespace cta::rdbms; using namespace cta::rdbms::wrapper; // Create a connection a memory resident database @@ -402,12 +403,13 @@ TEST_F(cta_rdbms_wrapper_SqliteStmtTest, executeNonQuery_insert_violating_primar ":COL1);"; auto stmt = conn.createStmt(sql); stmt->bindUint64(":COL1", 1); - ASSERT_THROW(stmt->executeNonQuery(), exception::DatabasePrimaryKeyError); + ASSERT_THROW(stmt->executeNonQuery(), PrimaryKeyError); } } TEST_F(cta_rdbms_wrapper_SqliteStmtTest, executeQuery_insert_violating_primary_key) { using namespace cta; + using namespace cta::rdbms; using namespace cta::rdbms::wrapper; // Create a connection a memory resident database @@ -449,7 +451,7 @@ TEST_F(cta_rdbms_wrapper_SqliteStmtTest, executeQuery_insert_violating_primary_k auto stmt = conn.createStmt(sql); stmt->bindUint64(":COL1", 1); auto rset = stmt->executeQuery(); - ASSERT_THROW(rset->next(), exception::DatabasePrimaryKeyError); + ASSERT_THROW(rset->next(), PrimaryKeyError); } } -- GitLab