TrinityCore
Loading...
Searching...
No Matches
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
28
template
<
class
T>
29
class
DatabaseWorkerPool
;
30
31
// A helper class to initiate all database worker pools,
32
// handles updating, delays preparing of statements and cleans up on failure.
33
class
TC_DATABASE_API
DatabaseLoader
34
{
35
public
:
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
45
enum
DatabaseTypeFlags
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
56
private
:
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
;
71
uint32
const
_updateFlags
;
72
73
std::queue<Predicate>
_open
, _populate, _update, _prepare;
74
std::stack<Closer>
_close
;
75
};
76
77
#endif
// DatabaseLoader_h__
Define.h
TC_DATABASE_API
#define TC_DATABASE_API
Definition
Define.h:102
uint32
uint32_t uint32
Definition
Define.h:133
DatabaseLoader
Definition
DatabaseLoader.h:34
DatabaseLoader::_logger
std::string const _logger
Definition
DatabaseLoader.h:69
DatabaseLoader::_autoSetup
bool const _autoSetup
Definition
DatabaseLoader.h:70
DatabaseLoader::DatabaseTypeFlags
DatabaseTypeFlags
Definition
DatabaseLoader.h:46
DatabaseLoader::Closer
std::function< void()> Closer
Definition
DatabaseLoader.h:63
DatabaseLoader::_updateFlags
uint32 const _updateFlags
Definition
DatabaseLoader.h:71
DatabaseLoader::Predicate
std::function< bool()> Predicate
Definition
DatabaseLoader.h:62
DatabaseLoader::_open
std::queue< Predicate > _open
Definition
DatabaseLoader.h:73
DatabaseLoader::_close
std::stack< Closer > _close
Definition
DatabaseLoader.h:74
DatabaseWorkerPool
Definition
DatabaseWorkerPool.h:36
server
database
Database
DatabaseLoader.h
Generated on Sun May 10 2026 02:30:13 for TrinityCore by
1.9.8