TrinityCore
|
#include <DatabaseWorkerPool.h>
Public Types | |
typedef T::Statements | PreparedStatementIndex |
Public Member Functions | |
DatabaseWorkerPool () | |
~DatabaseWorkerPool () | |
void | SetConnectionInfo (std::string const &infoString, uint8 const asyncThreads, uint8 const synchThreads) |
uint32 | Open () |
void | Close () |
bool | PrepareStatements () |
Prepares all prepared statements. More... | |
MySQLConnectionInfo const * | GetConnectionInfo () const |
void | Execute (const char *sql) |
template<typename Format , typename... Args> | |
void | PExecute (Format &&sql, Args &&...args) |
void | Execute (PreparedStatement *stmt) |
void | DirectExecute (const char *sql) |
template<typename Format , typename... Args> | |
void | DirectPExecute (Format &&sql, Args &&...args) |
void | DirectExecute (PreparedStatement *stmt) |
QueryResult | Query (const char *sql, T *connection=nullptr) |
template<typename Format , typename... Args> | |
QueryResult | PQuery (Format &&sql, T *conn, Args &&...args) |
template<typename Format , typename... Args> | |
QueryResult | PQuery (Format &&sql, Args &&...args) |
PreparedQueryResult | Query (PreparedStatement *stmt) |
QueryResultFuture | AsyncQuery (const char *sql) |
template<typename Format , typename... Args> | |
QueryResultFuture | AsyncPQuery (Format &&sql, Args &&...args) |
PreparedQueryResultFuture | AsyncQuery (PreparedStatement *stmt) |
QueryResultHolderFuture | DelayQueryHolder (SQLQueryHolder *holder) |
SQLTransaction | BeginTransaction () |
Begins an automanaged transaction pointer that will automatically rollback if not commited. (Autocommit=0) More... | |
void | CommitTransaction (SQLTransaction transaction) |
void | DirectCommitTransaction (SQLTransaction &transaction) |
void | ExecuteOrAppend (SQLTransaction &trans, PreparedStatement *stmt) |
void | ExecuteOrAppend (SQLTransaction &trans, const char *sql) |
PreparedStatement * | GetPreparedStatement (PreparedStatementIndex index) |
void | EscapeString (std::string &str) |
Apply escape string'ing for current collation. (utf8) More... | |
void | KeepAlive () |
Keeps all our MySQL connections alive, prevent the server from disconnecting us. More... | |
Private Types | |
enum | InternalIndex { IDX_ASYNC, IDX_SYNCH, IDX_SIZE } |
Private Member Functions | |
uint32 | OpenConnections (InternalIndex type, uint8 numConnections) |
unsigned long | EscapeString (char *to, const char *from, unsigned long length) |
void | Enqueue (SQLOperation *op) |
T * | GetFreeConnection () |
char const * | GetDatabaseName () const |
Private Attributes | |
std::unique_ptr < ProducerConsumerQueue < SQLOperation * > > | _queue |
Queue shared by async worker threads. More... | |
std::array< std::vector < std::unique_ptr< T > >, IDX_SIZE > | _connections |
std::unique_ptr < MySQLConnectionInfo > | _connectionInfo |
uint8 | _async_threads |
uint8 | _synch_threads |
typedef T::Statements DatabaseWorkerPool< T >::PreparedStatementIndex |
Other
|
private |
DatabaseWorkerPool< T >::DatabaseWorkerPool | ( | ) |
|
inline |
|
inline |
Enqueues a query in string format -with variable args- that will set the value of the QueryResultFuture return object as soon as the query is executed. The return value is then processed in ProcessQueryCallback methods.
QueryResultFuture DatabaseWorkerPool< T >::AsyncQuery | ( | const char * | sql | ) |
Asynchronous query (with resultset) methods.Enqueues a query in string format that will set the value of the QueryResultFuture return object as soon as the query is executed. The return value is then processed in ProcessQueryCallback methods.
PreparedQueryResultFuture DatabaseWorkerPool< T >::AsyncQuery | ( | PreparedStatement * | stmt | ) |
Enqueues a query in prepared format that will set the value of the PreparedQueryResultFuture return object as soon as the query is executed. The return value is then processed in ProcessQueryCallback methods. Statement must be prepared with CONNECTION_ASYNC flag.
|
inline |
Begins an automanaged transaction pointer that will automatically rollback if not commited. (Autocommit=0)
Transaction context methods.
void DatabaseWorkerPool< T >::Close | ( | ) |
Closes the actualy MySQL connection.
Shut down the synchronous connections There's no need for locking the connection, because DatabaseWorkerPool<>::Close should only be called after any other thread tasks in the core have exited, meaning there can be no concurrent access at this point.
void DatabaseWorkerPool< T >::CommitTransaction | ( | SQLTransaction | transaction | ) |
Enqueues a collection of one-way SQL operations (can be both adhoc and prepared). The order in which these operations were appended to the transaction will be respected during execution.
QueryResultHolderFuture DatabaseWorkerPool< T >::DelayQueryHolder | ( | SQLQueryHolder * | holder | ) |
Enqueues a vector of SQL operations (can be both adhoc and prepared) that will set the value of the QueryResultHolderFuture return object as soon as the query is executed. The return value is then processed in ProcessQueryCallback methods. Any prepared statements added to this holder need to be prepared with the CONNECTION_ASYNC flag.
void DatabaseWorkerPool< T >::DirectCommitTransaction | ( | SQLTransaction & | transaction | ) |
Directly executes a collection of one-way SQL operations (can be both adhoc and prepared). The order in which these operations were appended to the transaction will be respected during execution.
Handle MySQL Errno 1213 without extending deadlock to the core itself
Clean up now.
|
inline |
Direct synchronous one-way statement methods.Directly executes a one-way SQL operation in string format, that will block the calling thread until finished. This method should only be used for queries that are only executed once, e.g during startup.
|
inline |
Directly executes a one-way SQL operation in prepared statement format, that will block the calling thread until finished. Statement must be prepared with the CONNECTION_SYNCH flag.
Delete proxy-class. Not needed anymore
|
inline |
Directly executes a one-way SQL operation in string format -with variable args-, that will block the calling thread until finished. This method should only be used for queries that are only executed once, e.g during startup.
|
inlineprivate |
void DatabaseWorkerPool< T >::EscapeString | ( | std::string & | str | ) |
Apply escape string'ing for current collation. (utf8)
|
inlineprivate |
|
inline |
Delayed one-way statement methods.Enqueues a one-way SQL operation in string format that will be executed asynchronously. This method should only be used for queries that are only executed once, e.g during startup.
|
inline |
Enqueues a one-way SQL operation in prepared statement format that will be executed asynchronously. Statement must be prepared with CONNECTION_ASYNC flag.
|
inline |
Method used to execute prepared statements in a diverse context. Will be wrapped in a transaction if valid object is present, otherwise executed standalone.
|
inline |
Method used to execute ad-hoc statements in a diverse context. Will be wrapped in a transaction if valid object is present, otherwise executed standalone.
|
inline |
|
inlineprivate |
|
private |
Gets a free connection in the synchronous connection pool. Caller MUST call t->Unlock() after touching the MySQL context to prevent deadlocks.
Block forever until a connection is free
Must be matched with t->Unlock() or you will get deadlocks
|
inline |
Automanaged (internally) pointer to a prepared statement object for usage in upper level code. Pointer is deleted in this->DirectExecute(PreparedStatement*), this->Query(PreparedStatement*) or PreparedStatementTask::~PreparedStatementTask. This object is not tied to the prepared statement on the MySQL context yet until execution.
void DatabaseWorkerPool< T >::KeepAlive | ( | ) |
Keeps all our MySQL connections alive, prevent the server from disconnecting us.
Ping synchronous connections
Assuming all worker threads are free, every worker thread will receive 1 ping operation request If one or more worker threads are busy, the ping operations will not be split evenly, but this doesn't matter as the sole purpose is to prevent connections from idling.
uint32 DatabaseWorkerPool< T >::Open | ( | ) |
|
private |
|
inline |
Enqueues a one-way SQL operation in string format -with variable args- that will be executed asynchronously. This method should only be used for queries that are only executed once, e.g during startup.
|
inline |
Directly executes an SQL query in string format -with variable args- that will block the calling thread until finished. Returns reference counted auto pointer, no need for manual memory management in upper level code.
|
inline |
Directly executes an SQL query in string format -with variable args- that will block the calling thread until finished. Returns reference counted auto pointer, no need for manual memory management in upper level code.
bool DatabaseWorkerPool< T >::PrepareStatements | ( | ) |
Prepares all prepared statements.
QueryResult DatabaseWorkerPool< T >::Query | ( | const char * | sql, |
T * | connection = nullptr |
||
) |
Synchronous query (with resultset) methods.Directly executes an SQL query in string format that will block the calling thread until finished. Returns reference counted auto pointer, no need for manual memory management in upper level code.
PreparedQueryResult DatabaseWorkerPool< T >::Query | ( | PreparedStatement * | stmt | ) |
Directly executes an SQL query in prepared format that will block the calling thread until finished. Returns reference counted auto pointer, no need for manual memory management in upper level code. Statement must be prepared with CONNECTION_SYNCH flag.
Delete proxy-class. Not needed anymore
void DatabaseWorkerPool< T >::SetConnectionInfo | ( | std::string const & | infoString, |
uint8 const | asyncThreads, | ||
uint8 const | synchThreads | ||
) |
|
private |
|
private |
|
private |
|
private |
Queue shared by async worker threads.
|
private |