TrinityCore
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DatabaseLoader.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef DatabaseLoader_h__
19#define DatabaseLoader_h__
20
21#include "Define.h"
22
23#include <functional>
24#include <queue>
25#include <stack>
26#include <string>
27
28template <class T>
30
31// A helper class to initiate all database worker pools,
32// handles updating, delays preparing of statements and cleans up on failure.
34{
35public:
36 DatabaseLoader(std::string const& logger, uint32 const defaultUpdateMask);
37
38 // Register a database to the loader (lazy implemented)
39 template <class T>
40 DatabaseLoader& AddDatabase(DatabaseWorkerPool<T>& pool, std::string const& name);
41
42 // Load all databases
43 bool Load();
44
46 {
47 DATABASE_NONE = 0,
48
49 DATABASE_LOGIN = 1,
50 DATABASE_CHARACTER = 2,
51 DATABASE_WORLD = 4,
52
53 DATABASE_MASK_ALL = DATABASE_LOGIN | DATABASE_CHARACTER | DATABASE_WORLD
54 };
55
56private:
57 bool OpenDatabases();
58 bool PopulateDatabases();
59 bool UpdateDatabases();
60 bool PrepareStatements();
61
62 using Predicate = std::function<bool()>;
63 using Closer = std::function<void()>;
64
65 // Invokes all functions in the given queue and closes the databases on errors.
66 // Returns false when there was an error.
67 bool Process(std::queue<Predicate>& queue);
68
69 std::string const _logger;
70 bool const _autoSetup;
72
73 std::queue<Predicate> _open, _populate, _update, _prepare;
74 std::stack<Closer> _close;
75};
76
77#endif // DatabaseLoader_h__
#define TC_DATABASE_API
Definition: Define.h:102
uint32_t uint32
Definition: Define.h:133
std::string const _logger
bool const _autoSetup
std::function< void()> Closer
uint32 const _updateFlags
std::function< bool()> Predicate
std::queue< Predicate > _open
std::stack< Closer > _close