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

Removed get() and operator->() from rdbms::OcciConn

parent 04b5bf09
Branches
Tags
No related merge requests found
......@@ -64,32 +64,28 @@ OcciConn::~OcciConn() throw() {
void OcciConn::close() {
std::lock_guard<std::mutex> lock(m_mutex);
if(m_occiConn != nullptr) {
if(nullptr != m_occiConn) {
m_env->terminateConnection(m_occiConn);
m_occiConn = nullptr;
}
}
//------------------------------------------------------------------------------
// get
//------------------------------------------------------------------------------
oracle::occi::Connection *OcciConn::get() const {
return m_occiConn;
}
//------------------------------------------------------------------------------
// operator->()
//------------------------------------------------------------------------------
oracle::occi::Connection *OcciConn::operator->() const {
return get();
}
//------------------------------------------------------------------------------
// createStmt
//------------------------------------------------------------------------------
std::unique_ptr<Stmt> OcciConn::createStmt(const std::string &sql, Stmt::AutocommitMode autocommitMode) {
try {
return cta::make_unique<OcciStmt>(autocommitMode, sql, *this);
std::lock_guard<std::mutex> lock(m_mutex);
if(nullptr == m_occiConn) {
throw exception::Exception("Connection is closed");
}
oracle::occi::Statement *const stmt = m_occiConn->createStatement(sql);
if (nullptr == stmt) {
throw exception::Exception("oracle::occi::createStatement() returned a nullptr pointer");
}
return cta::make_unique<OcciStmt>(autocommitMode, sql, *this, stmt);
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " + sql + ": " +
ex.getMessage().str());
......@@ -103,7 +99,15 @@ std::unique_ptr<Stmt> OcciConn::createStmt(const std::string &sql, Stmt::Autocom
//------------------------------------------------------------------------------
void OcciConn::commit() {
try {
std::lock_guard<std::mutex> lock(m_mutex);
if(nullptr == m_occiConn) {
throw exception::Exception("Connection is closed");
}
m_occiConn->commit();
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
} catch(std::exception &se) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + se.what());
}
......@@ -114,7 +118,15 @@ void OcciConn::commit() {
//------------------------------------------------------------------------------
void OcciConn::rollback() {
try {
std::lock_guard<std::mutex> lock(m_mutex);
if(nullptr == m_occiConn) {
throw exception::Exception("Connection is closed");
}
m_occiConn->rollback();
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
} catch(std::exception &se) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + se.what());
}
......@@ -152,5 +164,28 @@ bool OcciConn::isOpen() const {
return nullptr != m_occiConn;
}
//------------------------------------------------------------------------------
// closeStmt
//------------------------------------------------------------------------------
void OcciConn::closeStmt(oracle::occi::Statement *const stmt) {
try {
std::lock_guard<std::mutex> lock(m_mutex);
if(nullptr == m_occiConn) {
throw exception::Exception("Connection is closed");
}
if(nullptr == stmt) {
throw exception::Exception("stmt is a nullptr");
}
m_occiConn->terminateStatement(stmt);
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
} catch(std::exception &se) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + se.what());
}
}
} // namespace rdbms
} // namespace cta
......@@ -59,22 +59,6 @@ public:
*/
virtual void close() override;
/**
* Returns the underlying OCCI connection.
*
* This method will always return a valid pointer.
*
* @return The underlying OCCI connection.
*/
oracle::occi::Connection *get() const;
/**
* An alias for the get() method.
*
* @return The underlying OCCI connection.
*/
oracle::occi::Connection *operator->() const;
/**
* Creates a prepared statement.
*
......@@ -127,6 +111,13 @@ private:
*/
oracle::occi::Connection *m_occiConn;
/**
* Closes the specified OCCI statement.
*
* @param stmt The OCCI statement to be closed.
*/
void closeStmt(oracle::occi::Statement *const stmt);
}; // class OcciConn
} // namespace rdbms
......
......@@ -36,15 +36,13 @@ namespace rdbms {
OcciStmt::OcciStmt(
const AutocommitMode autocommitMode,
const std::string &sql,
OcciConn &conn) :
OcciConn &conn,
oracle::occi::Statement *const stmt) :
Stmt(autocommitMode),
m_sql(sql),
m_paramNameToIdx(sql),
m_conn(conn) {
m_stmt = m_conn->createStatement(sql);
if (nullptr == m_stmt) {
throw exception::Exception("oracle::occi::createStatement() returned a nullptr pointer");
}
m_conn(conn),
m_stmt(stmt) {
// m_occiConn and m_stmt have been set and m_stmt is not nullptr so it is safe to
// call close() from now on
......@@ -88,7 +86,7 @@ void OcciStmt::close() {
std::lock_guard<std::mutex> lock(m_mutex);
if (nullptr != m_stmt) {
m_conn->terminateStatement(m_stmt);
m_conn.closeStmt(m_stmt);
m_stmt = nullptr;
}
} catch(exception::Exception &ex) {
......
......@@ -53,8 +53,13 @@ public:
* @param autocommitMode The autocommit mode of the statement.
* @param sql The SQL statement.
* @param conn The database connection.
* @param stmt The OCCI statement.
*/
OcciStmt(const AutocommitMode autocommitMode, const std::string &sql, OcciConn &conn);
OcciStmt(
const AutocommitMode autocommitMode,
const std::string &sql,
OcciConn &conn,
oracle::occi::Statement *const stmt);
/**
* Destructor.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment