Skip to content
Snippets Groups Projects
Commit 124e7fbd authored by Steven Murray's avatar Steven Murray
Browse files

Added setAutcommitMode() and getAutcommitMode() to rdbms connection classes

Please note that neither setAutcommitMode() and getAutcommitMode()
should be called for now.  This commit is preparing the future
interface of the code.
parent 9f71acea
Branches
Tags
No related merge requests found
......@@ -80,6 +80,28 @@ Conn &Conn::operator=(Conn &&rhs) {
return *this;
}
//------------------------------------------------------------------------------
// setAutocommitMode
//------------------------------------------------------------------------------
void Conn::setAutocommitMode(const AutocommitMode autocommitMode) {
if(nullptr != m_connAndStmts && nullptr != m_connAndStmts->conn) {
m_connAndStmts->conn->setAutocommitMode(autocommitMode);
} else {
throw exception::Exception(std::string(__FUNCTION__) + " failed: Conn does not contain a connection");
}
}
//------------------------------------------------------------------------------
// getAutocommitMode
//------------------------------------------------------------------------------
AutocommitMode Conn::getAutocommitMode() const noexcept {
if(nullptr != m_connAndStmts && nullptr != m_connAndStmts->conn) {
return m_connAndStmts->conn->getAutocommitMode();
} else {
throw exception::Exception(std::string(__FUNCTION__) + " failed: Conn does not contain a connection");
}
}
//------------------------------------------------------------------------------
// createStmt
//------------------------------------------------------------------------------
......
......@@ -18,6 +18,8 @@
#pragma once
#include "common/exception/Exception.hpp"
#include "rdbms/AutocommitMode.hpp"
#include "rdbms/ConnAndStmts.hpp"
#include "rdbms/Stmt.hpp"
......@@ -83,6 +85,30 @@ public:
*/
Conn &operator=(Conn &&rhs);
/**
* Thrown when a requested autocommit mode is not supported.
*/
struct AutocommitModeNotSupported: public exception::Exception {
AutocommitModeNotSupported(const std::string &context = "", const bool embedBacktrace = true):
Exception(context, embedBacktrace) {}
};
/**
* Sets the autocommit mode of the connection.
*
* @param autocommitMode The autocommit mode of the connection.
* @throw AutocommitModeNotSupported If the specified autocommit mode is not
* supported.
*/
void setAutocommitMode(const AutocommitMode autocommitMode);
/**
* Returns the autocommit mode of the connection.
*
* @return The autocommit mode of the connection.
*/
AutocommitMode getAutocommitMode() const noexcept;
/**
* Creates a prepared statement.
*
......
......@@ -18,6 +18,7 @@
#pragma once
#include "rdbms/AutocommitMode.hpp"
#include "rdbms/wrapper/Stmt.hpp"
#include <atomic>
......@@ -45,6 +46,22 @@ public:
*/
virtual void close() = 0;
/**
* Sets the autocommit mode of the connection.
*
* @param autocommitMode The autocommit mode of the connection.
* @throw AutocommitModeNotSupported If the specified autocommit mode is not
* supported.
*/
virtual void setAutocommitMode(const AutocommitMode autocommitMode) = 0;
/**
* Returns the autocommit mode of the connection.
*
* @return The autocommit mode of the connection.
*/
virtual AutocommitMode getAutocommitMode() const noexcept = 0;
/**
* Executes the statement.
*
......
......@@ -19,8 +19,7 @@
#include "common/exception/Exception.hpp"
#include "common/make_unique.hpp"
#include "common/threading/MutexLocker.hpp"
// Mysql related
#include "rdbms/Conn.hpp"
#include "rdbms/wrapper/Mysql.hpp"
#include "rdbms/wrapper/MysqlConn.hpp"
#include "rdbms/wrapper/MysqlStmt.hpp"
......@@ -98,6 +97,23 @@ void MysqlConn::close() {
}
}
//------------------------------------------------------------------------------
// setAutocommitMode
//------------------------------------------------------------------------------
void MysqlConn::setAutocommitMode(const AutocommitMode autocommitMode) {
if(AutocommitMode::AUTOCOMMIT_OFF == autocommitMode) {
throw rdbms::Conn::AutocommitModeNotSupported("Failed to set autocommit mode to AUTOCOMMIT_OFF: MysqlConn only"
" supports AUTOCOMMIT_ON");
}
}
//------------------------------------------------------------------------------
// getAutocommitMode
//------------------------------------------------------------------------------
AutocommitMode MysqlConn::getAutocommitMode() const noexcept{
return AutocommitMode::AUTOCOMMIT_ON;
}
//------------------------------------------------------------------------------
// executeNonQuery
//------------------------------------------------------------------------------
......
......@@ -66,6 +66,22 @@ public:
*/
void close() override;
/**
* Sets the autocommit mode of the connection.
*
* @param autocommitMode The autocommit mode of the connection.
* @throw AutocommitModeNotSupported If the specified autocommit mode is not
* supported.
*/
void setAutocommitMode(const AutocommitMode autocommitMode) override;
/**
* Returns the autocommit mode of the connection.
*
* @return The autocommit mode of the connection.
*/
AutocommitMode getAutocommitMode() const noexcept override;
/**
* Executes the statement.
*
......
......@@ -17,9 +17,13 @@
*/
#include "common/exception/Exception.hpp"
#include "common/exception/Errnum.hpp"
#include "common/exception/LostDatabaseConnection.hpp"
#include "common/make_unique.hpp"
#include "common/threading/MutexLocker.hpp"
#include "common/threading/RWLockRdLocker.hpp"
#include "common/threading/RWLockWrLocker.hpp"
#include "common/utils/utils.hpp"
#include "rdbms/wrapper/OcciConn.hpp"
#include "rdbms/wrapper/OcciEnv.hpp"
#include "rdbms/wrapper/OcciStmt.hpp"
......@@ -36,7 +40,8 @@ namespace wrapper {
//------------------------------------------------------------------------------
OcciConn::OcciConn(oracle::occi::Environment *const env, oracle::occi::Connection *const conn):
m_env(env),
m_occiConn(conn) {
m_occiConn(conn),
m_autocommitMode(AutocommitMode::AUTOCOMMIT_ON) {
if(nullptr == conn) {
throw exception::Exception(std::string(__FUNCTION__) + " failed"
": The OCCI connection is a nullptr pointer");
......@@ -66,6 +71,22 @@ void OcciConn::close() {
}
}
//------------------------------------------------------------------------------
// setAutocommitMode
//------------------------------------------------------------------------------
void OcciConn::setAutocommitMode(const AutocommitMode autocommitMode) {
threading::RWLockWrLocker wrLocker(m_autocommitModeRWLock);
m_autocommitMode = autocommitMode;
}
//------------------------------------------------------------------------------
// getAutocommitMode
//------------------------------------------------------------------------------
AutocommitMode OcciConn::getAutocommitMode() const noexcept{
threading::RWLockRdLocker rdLocker(m_autocommitModeRWLock);
return m_autocommitMode;
}
//------------------------------------------------------------------------------
// executeNonQuery
//------------------------------------------------------------------------------
......
......@@ -19,6 +19,7 @@
#pragma once
#include "common/threading/MutexLocker.hpp"
#include "common/threading/RWLock.hpp"
#include "rdbms/wrapper/Conn.hpp"
#include <occi.h>
......@@ -60,6 +61,22 @@ public:
*/
void close() override;
/**
* Sets the autocommit mode of the connection.
*
* @param autocommitMode The autocommit mode of the connection.
* @throw AutocommitModeNotSupported If the specified autocommit mode is not
* supported.
*/
void setAutocommitMode(const AutocommitMode autocommitMode) override;
/**
* Returns the autocommit mode of the connection.
*
* @return The autocommit mode of the connection.
*/
AutocommitMode getAutocommitMode() const noexcept override;
/**
* Executes the statement.
*
......@@ -131,6 +148,16 @@ private:
*/
oracle::occi::Connection *m_occiConn;
/**
* Read-write lock to protect m_autocommitMode.
*/
mutable threading::RWLock m_autocommitModeRWLock;
/**
* The autocommit mode of the connection.
*/
AutocommitMode m_autocommitMode;
/**
* Closes the specified OCCI statement.
*
......
......@@ -19,6 +19,7 @@
#include "common/exception/Exception.hpp"
#include "common/make_unique.hpp"
#include "common/threading/MutexLocker.hpp"
#include "rdbms/Conn.hpp"
#include "rdbms/wrapper/Sqlite.hpp"
#include "rdbms/wrapper/SqliteConn.hpp"
#include "rdbms/wrapper/SqliteStmt.hpp"
......@@ -96,6 +97,23 @@ void SqliteConn::close() {
}
}
//------------------------------------------------------------------------------
// setAutocommitMode
//------------------------------------------------------------------------------
void SqliteConn::setAutocommitMode(const AutocommitMode autocommitMode) {
if(AutocommitMode::AUTOCOMMIT_OFF == autocommitMode) {
throw rdbms::Conn::AutocommitModeNotSupported("Failed to set autocommit mode to AUTOCOMMIT_OFF: SqliteConn only"
" supports AUTOCOMMIT_ON");
}
}
//------------------------------------------------------------------------------
// getAutocommitMode
//------------------------------------------------------------------------------
AutocommitMode SqliteConn::getAutocommitMode() const noexcept{
return AutocommitMode::AUTOCOMMIT_ON;
}
//------------------------------------------------------------------------------
// executeNonQuery
//------------------------------------------------------------------------------
......
......@@ -62,6 +62,22 @@ public:
*/
void close() override;
/**
* Sets the autocommit mode of the connection.
*
* @param autocommitMode The autocommit mode of the connection.
* @throw AutocommitModeNotSupported If the specified autocommit mode is not
* supported.
*/
void setAutocommitMode(const AutocommitMode autocommitMode) override;
/**
* Returns the autocommit mode of the connection.
*
* @return The autocommit mode of the connection.
*/
AutocommitMode getAutocommitMode() const noexcept override;
/**
* Executes the statement.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment