Reduced includes
This commit is contained in:
@@ -11,6 +11,7 @@ add_library(lmsdatabase STATIC
|
|||||||
impl/Listen.cpp
|
impl/Listen.cpp
|
||||||
impl/MediaLibrary.cpp
|
impl/MediaLibrary.cpp
|
||||||
impl/Migration.cpp
|
impl/Migration.cpp
|
||||||
|
impl/Object.cpp
|
||||||
impl/PlayListFile.cpp
|
impl/PlayListFile.cpp
|
||||||
impl/PlayQueue.cpp
|
impl/PlayQueue.cpp
|
||||||
impl/TrackArtistLink.cpp
|
impl/TrackArtistLink.cpp
|
||||||
@@ -31,6 +32,7 @@ add_library(lmsdatabase STATIC
|
|||||||
impl/TrackEmbeddedImage.cpp
|
impl/TrackEmbeddedImage.cpp
|
||||||
impl/TrackEmbeddedImageLink.cpp
|
impl/TrackEmbeddedImageLink.cpp
|
||||||
impl/TrackLyrics.cpp
|
impl/TrackLyrics.cpp
|
||||||
|
impl/Transaction.cpp
|
||||||
impl/Types.cpp
|
impl/Types.cpp
|
||||||
impl/UIState.cpp
|
impl/UIState.cpp
|
||||||
impl/User.cpp
|
impl/User.cpp
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2025 Emeric Poupon
|
||||||
|
*
|
||||||
|
* This file is part of LMS.
|
||||||
|
*
|
||||||
|
* LMS is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* LMS is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "database/Object.hpp"
|
||||||
|
|
||||||
|
#include "TransactionChecker.hpp"
|
||||||
|
|
||||||
|
namespace lms::db
|
||||||
|
{
|
||||||
|
void ObjectPtrBase::checkWriteTransaction(Wt::Dbo::Session& session)
|
||||||
|
{
|
||||||
|
#if LMS_CHECK_TRANSACTION_ACCESSES
|
||||||
|
TransactionChecker::checkWriteTransaction(session);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
} // namespace lms::db
|
||||||
@@ -48,12 +48,12 @@
|
|||||||
#include "database/TrackFeatures.hpp"
|
#include "database/TrackFeatures.hpp"
|
||||||
#include "database/TrackList.hpp"
|
#include "database/TrackList.hpp"
|
||||||
#include "database/TrackLyrics.hpp"
|
#include "database/TrackLyrics.hpp"
|
||||||
#include "database/TransactionChecker.hpp"
|
|
||||||
#include "database/UIState.hpp"
|
#include "database/UIState.hpp"
|
||||||
#include "database/User.hpp"
|
#include "database/User.hpp"
|
||||||
|
|
||||||
#include "Db.hpp"
|
#include "Db.hpp"
|
||||||
#include "Migration.hpp"
|
#include "Migration.hpp"
|
||||||
|
#include "TransactionChecker.hpp"
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
#include "traits/EnumSetTraits.hpp"
|
#include "traits/EnumSetTraits.hpp"
|
||||||
#include "traits/ImageHashTypeTraits.hpp"
|
#include "traits/ImageHashTypeTraits.hpp"
|
||||||
@@ -62,40 +62,6 @@
|
|||||||
|
|
||||||
namespace lms::db
|
namespace lms::db
|
||||||
{
|
{
|
||||||
WriteTransaction::WriteTransaction(core::RecursiveSharedMutex& mutex, Wt::Dbo::Session& session)
|
|
||||||
: _lock{ mutex }
|
|
||||||
, _transaction{ session }
|
|
||||||
{
|
|
||||||
#if LMS_CHECK_TRANSACTION_ACCESSES
|
|
||||||
TransactionChecker::pushWriteTransaction(_transaction.session());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
WriteTransaction::~WriteTransaction()
|
|
||||||
{
|
|
||||||
#if LMS_CHECK_TRANSACTION_ACCESSES
|
|
||||||
TransactionChecker::popWriteTransaction(_transaction.session());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
core::tracing::ScopedTrace _trace{ "Database", core::tracing::Level::Detailed, "Commit" };
|
|
||||||
_transaction.commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
ReadTransaction::ReadTransaction(Wt::Dbo::Session& session)
|
|
||||||
: _transaction{ session }
|
|
||||||
{
|
|
||||||
#if LMS_CHECK_TRANSACTION_ACCESSES
|
|
||||||
TransactionChecker::pushReadTransaction(_transaction.session());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
ReadTransaction::~ReadTransaction()
|
|
||||||
{
|
|
||||||
#if LMS_CHECK_TRANSACTION_ACCESSES
|
|
||||||
TransactionChecker::popReadTransaction(_transaction.session());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
Session::Session(IDb& db)
|
Session::Session(IDb& db)
|
||||||
: _db{ db }
|
: _db{ db }
|
||||||
{
|
{
|
||||||
@@ -148,6 +114,19 @@ namespace lms::db
|
|||||||
return ReadTransaction{ _session };
|
return ReadTransaction{ _session };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Session::checkWriteTransaction() const
|
||||||
|
{
|
||||||
|
#if LMS_CHECK_TRANSACTION_ACCESSES
|
||||||
|
TransactionChecker::checkWriteTransaction(_session);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
void Session::checkReadTransaction() const
|
||||||
|
{
|
||||||
|
#if LMS_CHECK_TRANSACTION_ACCESSES
|
||||||
|
TransactionChecker::checkReadTransaction(_session);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void Session::execute(std::string_view statement)
|
void Session::execute(std::string_view statement)
|
||||||
{
|
{
|
||||||
utils::executeCommand(_session, std::string{ statement });
|
utils::executeCommand(_session, std::string{ statement });
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2025 Emeric Poupon
|
||||||
|
*
|
||||||
|
* This file is part of LMS.
|
||||||
|
*
|
||||||
|
* LMS is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* LMS is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "database/Transaction.hpp"
|
||||||
|
|
||||||
|
#include "core/RecursiveSharedMutex.hpp"
|
||||||
|
|
||||||
|
#include "TransactionChecker.hpp"
|
||||||
|
|
||||||
|
namespace lms::db
|
||||||
|
{
|
||||||
|
WriteTransaction::WriteTransaction(core::RecursiveSharedMutex& mutex, Wt::Dbo::Session& session)
|
||||||
|
: _lock{ mutex }
|
||||||
|
, _trace{ "Database", core::tracing::Level::Detailed, "WriteTransaction" }
|
||||||
|
, _transaction{ session }
|
||||||
|
{
|
||||||
|
#if LMS_CHECK_TRANSACTION_ACCESSES
|
||||||
|
TransactionChecker::pushWriteTransaction(_transaction.session());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
WriteTransaction::~WriteTransaction()
|
||||||
|
{
|
||||||
|
#if LMS_CHECK_TRANSACTION_ACCESSES
|
||||||
|
TransactionChecker::popWriteTransaction(_transaction.session());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
core::tracing::ScopedTrace _trace{ "Database", core::tracing::Level::Detailed, "Commit" };
|
||||||
|
_transaction.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
ReadTransaction::ReadTransaction(Wt::Dbo::Session& session)
|
||||||
|
: _trace{ "Database", core::tracing::Level::Detailed, "ReadTransaction" }
|
||||||
|
, _transaction{ session }
|
||||||
|
{
|
||||||
|
#if LMS_CHECK_TRANSACTION_ACCESSES
|
||||||
|
TransactionChecker::pushReadTransaction(_transaction.session());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
ReadTransaction::~ReadTransaction()
|
||||||
|
{
|
||||||
|
#if LMS_CHECK_TRANSACTION_ACCESSES
|
||||||
|
TransactionChecker::popReadTransaction(_transaction.session());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
} // namespace lms::db
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "database/TransactionChecker.hpp"
|
#include "TransactionChecker.hpp"
|
||||||
|
|
||||||
static_assert(LMS_CHECK_TRANSACTION_ACCESSES, "File should be excluded from build");
|
static_assert(LMS_CHECK_TRANSACTION_ACCESSES, "File should be excluded from build");
|
||||||
|
|
||||||
@@ -32,39 +32,39 @@ namespace lms::db
|
|||||||
struct StackEntry
|
struct StackEntry
|
||||||
{
|
{
|
||||||
TransactionChecker::TransactionType type;
|
TransactionChecker::TransactionType type;
|
||||||
Wt::Dbo::Session* session{};
|
const Wt::Dbo::Session* session{};
|
||||||
};
|
};
|
||||||
|
|
||||||
static thread_local std::vector<StackEntry> transactionStack;
|
static thread_local std::vector<StackEntry> transactionStack;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void TransactionChecker::pushWriteTransaction(Wt::Dbo::Session& session)
|
void TransactionChecker::pushWriteTransaction(const Wt::Dbo::Session& session)
|
||||||
{
|
{
|
||||||
pushTransaction(TransactionType::Write, session);
|
pushTransaction(TransactionType::Write, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransactionChecker::pushReadTransaction(Wt::Dbo::Session& session)
|
void TransactionChecker::pushReadTransaction(const Wt::Dbo::Session& session)
|
||||||
{
|
{
|
||||||
pushTransaction(TransactionType::Read, session);
|
pushTransaction(TransactionType::Read, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransactionChecker::popWriteTransaction(Wt::Dbo::Session& session)
|
void TransactionChecker::popWriteTransaction(const Wt::Dbo::Session& session)
|
||||||
{
|
{
|
||||||
popTransaction(TransactionType::Write, session);
|
popTransaction(TransactionType::Write, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransactionChecker::popReadTransaction(Wt::Dbo::Session& session)
|
void TransactionChecker::popReadTransaction(const Wt::Dbo::Session& session)
|
||||||
{
|
{
|
||||||
popTransaction(TransactionType::Read, session);
|
popTransaction(TransactionType::Read, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransactionChecker::pushTransaction(TransactionType type, Wt::Dbo::Session& session)
|
void TransactionChecker::pushTransaction(TransactionType type, const Wt::Dbo::Session& session)
|
||||||
{
|
{
|
||||||
assert(transactionStack.empty() || transactionStack.back().session == &session);
|
assert(transactionStack.empty() || transactionStack.back().session == &session);
|
||||||
transactionStack.push_back(StackEntry{ type, &session });
|
transactionStack.push_back(StackEntry{ type, &session });
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransactionChecker::popTransaction(TransactionType type, Wt::Dbo::Session& session)
|
void TransactionChecker::popTransaction(TransactionType type, const Wt::Dbo::Session& session)
|
||||||
{
|
{
|
||||||
assert(!transactionStack.empty());
|
assert(!transactionStack.empty());
|
||||||
assert(transactionStack.back().type == type);
|
assert(transactionStack.back().type == type);
|
||||||
@@ -72,25 +72,25 @@ namespace lms::db
|
|||||||
transactionStack.pop_back();
|
transactionStack.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransactionChecker::checkWriteTransaction(Wt::Dbo::Session& session)
|
void TransactionChecker::checkWriteTransaction(const Wt::Dbo::Session& session)
|
||||||
{
|
{
|
||||||
assert(!transactionStack.empty());
|
assert(!transactionStack.empty());
|
||||||
assert(transactionStack.back().type == TransactionType::Write);
|
assert(transactionStack.back().type == TransactionType::Write);
|
||||||
assert(transactionStack.back().session == &session);
|
assert(transactionStack.back().session == &session);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransactionChecker::checkWriteTransaction(Session& session)
|
void TransactionChecker::checkWriteTransaction(const Session& session)
|
||||||
{
|
{
|
||||||
checkWriteTransaction(*session.getDboSession());
|
checkWriteTransaction(*session.getDboSession());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransactionChecker::checkReadTransaction(Wt::Dbo::Session& session)
|
void TransactionChecker::checkReadTransaction(const Wt::Dbo::Session& session)
|
||||||
{
|
{
|
||||||
assert(!transactionStack.empty());
|
assert(!transactionStack.empty());
|
||||||
assert(transactionStack.back().session == &session);
|
assert(transactionStack.back().session == &session);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransactionChecker::checkReadTransaction(Session& session)
|
void TransactionChecker::checkReadTransaction(const Session& session)
|
||||||
{
|
{
|
||||||
checkReadTransaction(*session.getDboSession());
|
checkReadTransaction(*session.getDboSession());
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-12
@@ -26,8 +26,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LMS_CHECK_TRANSACTION_ACCESSES
|
#if LMS_CHECK_TRANSACTION_ACCESSES
|
||||||
#include <Wt/Dbo/Session.h>
|
|
||||||
#include <vector>
|
namespace Wt::Dbo
|
||||||
|
{
|
||||||
|
class Session;
|
||||||
|
}
|
||||||
|
|
||||||
namespace lms::db
|
namespace lms::db
|
||||||
{
|
{
|
||||||
@@ -42,20 +45,20 @@ namespace lms::db
|
|||||||
Write,
|
Write,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void pushWriteTransaction(Wt::Dbo::Session& session);
|
static void pushWriteTransaction(const Wt::Dbo::Session& session);
|
||||||
static void pushReadTransaction(Wt::Dbo::Session& session);
|
static void pushReadTransaction(const Wt::Dbo::Session& session);
|
||||||
|
|
||||||
static void popWriteTransaction(Wt::Dbo::Session& session);
|
static void popWriteTransaction(const Wt::Dbo::Session& session);
|
||||||
static void popReadTransaction(Wt::Dbo::Session& session);
|
static void popReadTransaction(const Wt::Dbo::Session& session);
|
||||||
|
|
||||||
static void checkWriteTransaction(Wt::Dbo::Session& session);
|
static void checkWriteTransaction(const Wt::Dbo::Session& session);
|
||||||
static void checkWriteTransaction(Session& session);
|
static void checkWriteTransaction(const Session& session);
|
||||||
static void checkReadTransaction(Wt::Dbo::Session& session);
|
static void checkReadTransaction(const Wt::Dbo::Session& session);
|
||||||
static void checkReadTransaction(Session& session);
|
static void checkReadTransaction(const Session& session);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void pushTransaction(TransactionType type, Wt::Dbo::Session& session);
|
static void pushTransaction(TransactionType type, const Wt::Dbo::Session& session);
|
||||||
static void popTransaction(TransactionType type, Wt::Dbo::Session& session);
|
static void popTransaction(TransactionType type, const Wt::Dbo::Session& session);
|
||||||
};
|
};
|
||||||
} // namespace lms::db
|
} // namespace lms::db
|
||||||
|
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
|
|||||||
@@ -20,15 +20,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Wt/Dbo/ptr.h>
|
#include <Wt/Dbo/ptr.h>
|
||||||
#include <Wt/WSignal.h>
|
|
||||||
|
|
||||||
#include "database/IdType.hpp"
|
#include "database/IdType.hpp"
|
||||||
#include "database/TransactionChecker.hpp"
|
|
||||||
|
|
||||||
namespace lms::db
|
namespace lms::db
|
||||||
{
|
{
|
||||||
|
class ObjectPtrBase
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
static void checkWriteTransaction(Wt::Dbo::Session& session);
|
||||||
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class ObjectPtr
|
class ObjectPtr : public ObjectPtrBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ObjectPtr() = default;
|
ObjectPtr() = default;
|
||||||
@@ -45,18 +49,13 @@ namespace lms::db
|
|||||||
|
|
||||||
auto modify()
|
auto modify()
|
||||||
{
|
{
|
||||||
#if LMS_CHECK_TRANSACTION_ACCESSES
|
checkWriteTransaction(*_obj.session());
|
||||||
TransactionChecker::checkWriteTransaction(*_obj.session());
|
|
||||||
#endif
|
|
||||||
return _obj.modify();
|
return _obj.modify();
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove()
|
void remove()
|
||||||
{
|
{
|
||||||
#if LMS_CHECK_TRANSACTION_ACCESSES
|
checkWriteTransaction(*_obj.session());
|
||||||
TransactionChecker::checkWriteTransaction(*_obj.session());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
_obj.remove();
|
_obj.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,52 +19,17 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Wt/Dbo/Dbo.h>
|
#include <Wt/Dbo/Session.h>
|
||||||
#include <Wt/Dbo/SqlConnectionPool.h>
|
|
||||||
|
|
||||||
#include <span>
|
#include <span>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "core/ITraceLogger.hpp"
|
#include "database/Transaction.hpp"
|
||||||
#include "core/RecursiveSharedMutex.hpp"
|
|
||||||
#include "database/TransactionChecker.hpp"
|
|
||||||
|
|
||||||
namespace lms::db
|
namespace lms::db
|
||||||
{
|
{
|
||||||
class WriteTransaction
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
~WriteTransaction();
|
|
||||||
|
|
||||||
private:
|
|
||||||
friend class Session;
|
|
||||||
WriteTransaction(core::RecursiveSharedMutex& mutex, Wt::Dbo::Session& session);
|
|
||||||
|
|
||||||
WriteTransaction(const WriteTransaction&) = delete;
|
|
||||||
WriteTransaction& operator=(const WriteTransaction&) = delete;
|
|
||||||
|
|
||||||
const std::unique_lock<core::RecursiveSharedMutex> _lock;
|
|
||||||
const core::tracing::ScopedTrace _trace{ "Database", core::tracing::Level::Detailed, "WriteTransaction" }; // before actual transaction
|
|
||||||
Wt::Dbo::Transaction _transaction;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ReadTransaction
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
~ReadTransaction();
|
|
||||||
|
|
||||||
private:
|
|
||||||
friend class Session;
|
|
||||||
ReadTransaction(Wt::Dbo::Session& session);
|
|
||||||
|
|
||||||
ReadTransaction(const ReadTransaction&) = delete;
|
|
||||||
ReadTransaction& operator=(const ReadTransaction&) = delete;
|
|
||||||
|
|
||||||
const core::tracing::ScopedTrace _trace{ "Database", core::tracing::Level::Detailed, "ReadTransaction" }; // before actual transaction
|
|
||||||
Wt::Dbo::Transaction _transaction;
|
|
||||||
};
|
|
||||||
|
|
||||||
class IDb;
|
class IDb;
|
||||||
class Session
|
class Session
|
||||||
{
|
{
|
||||||
@@ -77,18 +42,8 @@ namespace lms::db
|
|||||||
[[nodiscard]] WriteTransaction createWriteTransaction();
|
[[nodiscard]] WriteTransaction createWriteTransaction();
|
||||||
[[nodiscard]] ReadTransaction createReadTransaction();
|
[[nodiscard]] ReadTransaction createReadTransaction();
|
||||||
|
|
||||||
void checkWriteTransaction()
|
void checkWriteTransaction() const;
|
||||||
{
|
void checkReadTransaction() const;
|
||||||
#if LMS_CHECK_TRANSACTION_ACCESSES
|
|
||||||
TransactionChecker::checkWriteTransaction(_session);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
void checkReadTransaction()
|
|
||||||
{
|
|
||||||
#if LMS_CHECK_TRANSACTION_ACCESSES
|
|
||||||
TransactionChecker::checkReadTransaction(_session);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void execute(std::string_view statement);
|
void execute(std::string_view statement);
|
||||||
|
|
||||||
@@ -107,14 +62,10 @@ namespace lms::db
|
|||||||
void refreshTracingLoggerStats();
|
void refreshTracingLoggerStats();
|
||||||
|
|
||||||
// returning a ptr here to ease further wrapping using operator->
|
// returning a ptr here to ease further wrapping using operator->
|
||||||
Wt::Dbo::Session* getDboSession()
|
Wt::Dbo::Session* getDboSession() { return &_session; }
|
||||||
{
|
const Wt::Dbo::Session* getDboSession() const { return &_session; }
|
||||||
return &_session;
|
|
||||||
}
|
IDb& getDb() { return _db; }
|
||||||
IDb& getDb()
|
|
||||||
{
|
|
||||||
return _db;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Object, typename... Args>
|
template<typename Object, typename... Args>
|
||||||
typename Object::pointer create(Args&&... args)
|
typename Object::pointer create(Args&&... args)
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2025 Emeric Poupon
|
||||||
|
*
|
||||||
|
* This file is part of LMS.
|
||||||
|
*
|
||||||
|
* LMS is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* LMS is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
#include <Wt/Dbo/Transaction.h>
|
||||||
|
|
||||||
|
#include "core/ITraceLogger.hpp"
|
||||||
|
|
||||||
|
namespace lms::core
|
||||||
|
{
|
||||||
|
class RecursiveSharedMutex;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace lms::db
|
||||||
|
{
|
||||||
|
class WriteTransaction
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
~WriteTransaction();
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class Session;
|
||||||
|
WriteTransaction(core::RecursiveSharedMutex& mutex, Wt::Dbo::Session& session);
|
||||||
|
|
||||||
|
WriteTransaction(const WriteTransaction&) = delete;
|
||||||
|
WriteTransaction& operator=(const WriteTransaction&) = delete;
|
||||||
|
|
||||||
|
const std::unique_lock<core::RecursiveSharedMutex> _lock;
|
||||||
|
const core::tracing::ScopedTrace _trace; // before actual transaction
|
||||||
|
Wt::Dbo::Transaction _transaction;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ReadTransaction
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
~ReadTransaction();
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class Session;
|
||||||
|
ReadTransaction(Wt::Dbo::Session& session);
|
||||||
|
|
||||||
|
ReadTransaction(const ReadTransaction&) = delete;
|
||||||
|
ReadTransaction& operator=(const ReadTransaction&) = delete;
|
||||||
|
|
||||||
|
const core::tracing::ScopedTrace _trace; // before actual transaction
|
||||||
|
Wt::Dbo::Transaction _transaction;
|
||||||
|
};
|
||||||
|
} // namespace lms::db
|
||||||
Reference in New Issue
Block a user