fix(Data::Session): Set autoCommit to false in Session #4167 #4143

This commit is contained in:
Alex Fabijanic
2023-10-25 22:40:41 +02:00
parent e47b92d641
commit bd06526ee0
11 changed files with 126 additions and 120 deletions

View File

@@ -25,9 +25,9 @@ namespace Data {
Session::Session(Poco::AutoPtr<SessionImpl> pImpl):
_pImpl(pImpl),
_statementCreator(pImpl)
_statementCreator(pImpl),
_wasAutoCommit(false)
{
poco_check_ptr (pImpl.get());
}
@@ -40,8 +40,7 @@ Session::Session(const std::string& connector,
}
Session::Session(const std::string& connection,
std::size_t timeout)
Session::Session(const std::string& connection, std::size_t timeout)
{
Session newSession(SessionFactory::instance().create(connection, timeout));
swap(newSession);
@@ -50,14 +49,16 @@ Session::Session(const std::string& connection,
Session::Session(const Session& other):
_pImpl(other._pImpl),
_statementCreator(other._statementCreator)
_statementCreator(other._statementCreator),
_wasAutoCommit(other._wasAutoCommit)
{
}
Session::Session(Session&& other) noexcept:
_pImpl(std::move(other._pImpl)),
_statementCreator(std::move(other._statementCreator))
_statementCreator(std::move(other._statementCreator)),
_wasAutoCommit(other._wasAutoCommit)
{
}
@@ -78,6 +79,7 @@ Session& Session::operator = (Session&& other) noexcept
{
_pImpl = std::move(other._pImpl);
_statementCreator = std::move(other._statementCreator);
_wasAutoCommit = other._wasAutoCommit;
return *this;
}
@@ -87,6 +89,40 @@ void Session::swap(Session& other)
using std::swap;
swap(_statementCreator, other._statementCreator);
swap(_pImpl, other._pImpl);
swap(_wasAutoCommit, other._wasAutoCommit);
}
void Session::begin()
{
if (isAutocommit())
{
setFeature("autoCommit", false);
_wasAutoCommit = true;
}
return _pImpl->begin();
}
void Session::commit()
{
_pImpl->commit();
if (_wasAutoCommit)
{
setFeature("autoCommit", true);
_wasAutoCommit = false;
}
}
void Session::rollback()
{
_pImpl->rollback();
if (_wasAutoCommit)
{
setFeature("autoCommit", true);
_wasAutoCommit = false;
}
}