2015-03-21 00:25:21 +01:00
|
|
|
/*
|
2020-01-02 06:44:10 +01:00
|
|
|
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
|
2015-03-21 00:25:21 +01:00
|
|
|
*
|
|
|
|
|
* This program 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 2 of the License, or (at your
|
|
|
|
|
* option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef DatabaseLoader_h__
|
|
|
|
|
#define DatabaseLoader_h__
|
|
|
|
|
|
2017-05-12 18:49:51 +02:00
|
|
|
#include "Define.h"
|
2015-03-21 00:25:21 +01:00
|
|
|
|
|
|
|
|
#include <functional>
|
2016-03-03 01:27:02 +01:00
|
|
|
#include <queue>
|
2017-05-12 18:49:51 +02:00
|
|
|
#include <stack>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2020-09-04 13:38:24 +02:00
|
|
|
template <class T>
|
2017-05-12 18:49:51 +02:00
|
|
|
class DatabaseWorkerPool;
|
2015-03-21 00:25:21 +01:00
|
|
|
|
|
|
|
|
// A helper class to initiate all database worker pools,
|
|
|
|
|
// handles updating, delays preparing of statements and cleans up on failure.
|
2016-03-11 15:57:26 +01:00
|
|
|
class TC_DATABASE_API DatabaseLoader
|
2015-03-21 00:25:21 +01:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
DatabaseLoader(std::string const& logger, uint32 const defaultUpdateMask);
|
|
|
|
|
|
|
|
|
|
// Register a database to the loader (lazy implemented)
|
|
|
|
|
template <class T>
|
|
|
|
|
DatabaseLoader& AddDatabase(DatabaseWorkerPool<T>& pool, std::string const& name);
|
|
|
|
|
|
|
|
|
|
// Load all databases
|
|
|
|
|
bool Load();
|
|
|
|
|
|
|
|
|
|
enum DatabaseTypeFlags
|
|
|
|
|
{
|
|
|
|
|
DATABASE_NONE = 0,
|
|
|
|
|
|
|
|
|
|
DATABASE_LOGIN = 1,
|
|
|
|
|
DATABASE_CHARACTER = 2,
|
|
|
|
|
DATABASE_WORLD = 4,
|
|
|
|
|
DATABASE_HOTFIX = 8,
|
|
|
|
|
|
|
|
|
|
DATABASE_MASK_ALL = DATABASE_LOGIN | DATABASE_CHARACTER | DATABASE_WORLD | DATABASE_HOTFIX
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool OpenDatabases();
|
|
|
|
|
bool PopulateDatabases();
|
|
|
|
|
bool UpdateDatabases();
|
|
|
|
|
bool PrepareStatements();
|
|
|
|
|
|
|
|
|
|
using Predicate = std::function<bool()>;
|
2016-03-03 01:27:02 +01:00
|
|
|
using Closer = std::function<void()>;
|
2015-03-21 00:25:21 +01:00
|
|
|
|
2016-03-03 01:27:02 +01:00
|
|
|
// Invokes all functions in the given queue and closes the databases on errors.
|
|
|
|
|
// Returns false when there was an error.
|
|
|
|
|
bool Process(std::queue<Predicate>& queue);
|
2015-03-21 00:25:21 +01:00
|
|
|
|
2015-03-21 17:09:25 +00:00
|
|
|
std::string const _logger;
|
2015-03-21 00:25:21 +01:00
|
|
|
bool const _autoSetup;
|
|
|
|
|
uint32 const _updateFlags;
|
|
|
|
|
|
2016-03-03 01:27:02 +01:00
|
|
|
std::queue<Predicate> _open, _populate, _update, _prepare;
|
|
|
|
|
std::stack<Closer> _close;
|
2015-03-21 00:25:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // DatabaseLoader_h__
|