Commit a6416d00 authored by Steven Murray's avatar Steven Murray
Browse files

Moved rdbms exceptions into the rdbms directory and namespace

parent f4c6cf58
......@@ -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
}
......
......@@ -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;
......
......@@ -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
......
......@@ -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})
......
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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);
}
}
}
......
......@@ -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
......@@ -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
......@@ -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"
......
......@@ -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;
}
......
......@@ -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());
}
......
......@@ -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);
}
......
......@@ -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"
......
......@@ -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());
}
......
......@@ -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());
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment