Reduced includes
This commit is contained in:
@@ -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/TrackList.hpp"
|
||||
#include "database/TrackLyrics.hpp"
|
||||
#include "database/TransactionChecker.hpp"
|
||||
#include "database/UIState.hpp"
|
||||
#include "database/User.hpp"
|
||||
|
||||
#include "Db.hpp"
|
||||
#include "Migration.hpp"
|
||||
#include "TransactionChecker.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "traits/EnumSetTraits.hpp"
|
||||
#include "traits/ImageHashTypeTraits.hpp"
|
||||
@@ -62,40 +62,6 @@
|
||||
|
||||
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)
|
||||
: _db{ db }
|
||||
{
|
||||
@@ -148,6 +114,19 @@ namespace lms::db
|
||||
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)
|
||||
{
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#include "database/TransactionChecker.hpp"
|
||||
#include "TransactionChecker.hpp"
|
||||
|
||||
static_assert(LMS_CHECK_TRANSACTION_ACCESSES, "File should be excluded from build");
|
||||
|
||||
@@ -32,39 +32,39 @@ namespace lms::db
|
||||
struct StackEntry
|
||||
{
|
||||
TransactionChecker::TransactionType type;
|
||||
Wt::Dbo::Session* session{};
|
||||
const Wt::Dbo::Session* session{};
|
||||
};
|
||||
|
||||
static thread_local std::vector<StackEntry> transactionStack;
|
||||
} // namespace
|
||||
|
||||
void TransactionChecker::pushWriteTransaction(Wt::Dbo::Session& session)
|
||||
void TransactionChecker::pushWriteTransaction(const Wt::Dbo::Session& session)
|
||||
{
|
||||
pushTransaction(TransactionType::Write, session);
|
||||
}
|
||||
|
||||
void TransactionChecker::pushReadTransaction(Wt::Dbo::Session& session)
|
||||
void TransactionChecker::pushReadTransaction(const Wt::Dbo::Session& session)
|
||||
{
|
||||
pushTransaction(TransactionType::Read, session);
|
||||
}
|
||||
|
||||
void TransactionChecker::popWriteTransaction(Wt::Dbo::Session& session)
|
||||
void TransactionChecker::popWriteTransaction(const Wt::Dbo::Session& session)
|
||||
{
|
||||
popTransaction(TransactionType::Write, session);
|
||||
}
|
||||
|
||||
void TransactionChecker::popReadTransaction(Wt::Dbo::Session& session)
|
||||
void TransactionChecker::popReadTransaction(const Wt::Dbo::Session& 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);
|
||||
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.back().type == type);
|
||||
@@ -72,25 +72,25 @@ namespace lms::db
|
||||
transactionStack.pop_back();
|
||||
}
|
||||
|
||||
void TransactionChecker::checkWriteTransaction(Wt::Dbo::Session& session)
|
||||
void TransactionChecker::checkWriteTransaction(const Wt::Dbo::Session& session)
|
||||
{
|
||||
assert(!transactionStack.empty());
|
||||
assert(transactionStack.back().type == TransactionType::Write);
|
||||
assert(transactionStack.back().session == &session);
|
||||
}
|
||||
|
||||
void TransactionChecker::checkWriteTransaction(Session& session)
|
||||
void TransactionChecker::checkWriteTransaction(const Session& session)
|
||||
{
|
||||
checkWriteTransaction(*session.getDboSession());
|
||||
}
|
||||
|
||||
void TransactionChecker::checkReadTransaction(Wt::Dbo::Session& session)
|
||||
void TransactionChecker::checkReadTransaction(const Wt::Dbo::Session& session)
|
||||
{
|
||||
assert(!transactionStack.empty());
|
||||
assert(transactionStack.back().session == &session);
|
||||
}
|
||||
|
||||
void TransactionChecker::checkReadTransaction(Session& session)
|
||||
void TransactionChecker::checkReadTransaction(const Session& session)
|
||||
{
|
||||
checkReadTransaction(*session.getDboSession());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
#define LMS_CHECK_TRANSACTION_ACCESSES 1
|
||||
#else
|
||||
#define LMS_CHECK_TRANSACTION_ACCESSES 0
|
||||
#endif
|
||||
|
||||
#if LMS_CHECK_TRANSACTION_ACCESSES
|
||||
|
||||
namespace Wt::Dbo
|
||||
{
|
||||
class Session;
|
||||
}
|
||||
|
||||
namespace lms::db
|
||||
{
|
||||
class Session;
|
||||
|
||||
class TransactionChecker
|
||||
{
|
||||
public:
|
||||
enum class TransactionType
|
||||
{
|
||||
Read,
|
||||
Write,
|
||||
};
|
||||
|
||||
static void pushWriteTransaction(const Wt::Dbo::Session& session);
|
||||
static void pushReadTransaction(const Wt::Dbo::Session& session);
|
||||
|
||||
static void popWriteTransaction(const Wt::Dbo::Session& session);
|
||||
static void popReadTransaction(const Wt::Dbo::Session& session);
|
||||
|
||||
static void checkWriteTransaction(const Wt::Dbo::Session& session);
|
||||
static void checkWriteTransaction(const Session& session);
|
||||
static void checkReadTransaction(const Wt::Dbo::Session& session);
|
||||
static void checkReadTransaction(const Session& session);
|
||||
|
||||
private:
|
||||
static void pushTransaction(TransactionType type, const Wt::Dbo::Session& session);
|
||||
static void popTransaction(TransactionType type, const Wt::Dbo::Session& session);
|
||||
};
|
||||
} // namespace lms::db
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user