Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
DatabaseWorkerPool< T > Class Template Reference

#include <DatabaseWorkerPool.h>

Collaboration diagram for DatabaseWorkerPool< T >:

Public Member Functions

QueryResultFuture AsyncPQuery (const char *sql,...)
QueryResultFuture AsyncQuery (const char *sql)
PreparedQueryResultFuture AsyncQuery (PreparedStatement *stmt)
SQLTransaction BeginTransaction ()
 Begins an automanaged transaction pointer that will automatically rollback if not commited. (Autocommit=0).
void Close ()
void CommitTransaction (SQLTransaction transaction)
 DatabaseWorkerPool ()
QueryResultHolderFuture DelayQueryHolder (SQLQueryHolder *holder)
void DirectCommitTransaction (SQLTransaction &transaction)
void DirectExecute (const char *sql)
void DirectExecute (PreparedStatement *stmt)
void DirectPExecute (const char *sql,...)
void EscapeString (std::string &str)
 Apply escape string'ing for current collation. (utf8).
void Execute (const char *sql)
void Execute (PreparedStatement *stmt)
void ExecuteOrAppend (SQLTransaction &trans, const char *sql)
void ExecuteOrAppend (SQLTransaction &trans, PreparedStatement *stmt)
PreparedStatementGetPreparedStatement (uint32 index)
void KeepAlive ()
 Keeps all our MySQL connections alive, prevent the server from disconnecting us.
bool Open (const char *host, const char *port, const char *user, const char *password, const char *database, uint8 async_threads, uint8 synch_threads)
bool Open (const std::string &infoString, uint8 async_threads, uint8 synch_threads)
void PExecute (const char *sql,...)
QueryResult PQuery (const char *sql, T *conn,...)
QueryResult PQuery (const char *sql,...)
QueryResult Query (const char *sql, T *conn=NULL)
PreparedQueryResult Query (PreparedStatement *stmt)
void Wait ()
 Blocks until all currently queued asynchronous operations have finished.
 ~DatabaseWorkerPool ()

Private Types

enum  _internalIndex { IDX_ASYNC , IDX_SYNCH , IDX_SIZE }

Private Member Functions

void Enqueue (SQLOperation *op)
unsigned long EscapeString (char *to, const char *from, unsigned long length)
char const * GetDatabaseName () const
T * GetFreeConnection ()

Private Attributes

uint32 _connectionCount [2]
MySQLConnectionInfo * _connectionInfo
 Counter of MySQL connections;.
std::vector< std::vector< T * > > _connections
 Queue shared by async worker threads.
Skyfire::DatabaseQueue_queue

Detailed Description

template<class T>
class DatabaseWorkerPool< T >

Definition at line 35 of file DatabaseWorkerPool.h.

Member Enumeration Documentation

◆ _internalIndex

template<class T>
enum DatabaseWorkerPool::_internalIndex
private
Enumerator
IDX_ASYNC 
IDX_SYNCH 
IDX_SIZE 

Definition at line 546 of file DatabaseWorkerPool.h.

Constructor & Destructor Documentation

◆ DatabaseWorkerPool()

template<class T>
DatabaseWorkerPool< T >::DatabaseWorkerPool ( )
inline

Definition at line 39 of file DatabaseWorkerPool.h.

◆ ~DatabaseWorkerPool()

template<class T>
DatabaseWorkerPool< T >::~DatabaseWorkerPool ( )
inline

Definition at line 48 of file DatabaseWorkerPool.h.

Member Function Documentation

◆ AsyncPQuery()

template<class T>
QueryResultFuture DatabaseWorkerPool< T >::AsyncPQuery ( const char * sql,
... )
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.

Definition at line 339 of file DatabaseWorkerPool.h.

◆ AsyncQuery() [1/2]

template<class T>
QueryResultFuture DatabaseWorkerPool< T >::AsyncQuery ( const char * sql)
inline

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.

Actual return value has no use yet

Definition at line 329 of file DatabaseWorkerPool.h.

Referenced by DatabaseWorkerPool< CharacterDatabaseConnection >::AsyncPQuery().

◆ AsyncQuery() [2/2]

template<class T>
PreparedQueryResultFuture DatabaseWorkerPool< T >::AsyncQuery ( PreparedStatement * stmt)
inline

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.

Definition at line 353 of file DatabaseWorkerPool.h.

◆ BeginTransaction()

template<class T>
SQLTransaction DatabaseWorkerPool< T >::BeginTransaction ( )
inline

Begins an automanaged transaction pointer that will automatically rollback if not commited. (Autocommit=0).

Transaction context methods.

Definition at line 378 of file DatabaseWorkerPool.h.

◆ Close()

template<class T>
void DatabaseWorkerPool< T >::Close ( )
inline

Shuts down delaythreads for this connection pool. The next dequeue attempt in worker thread tasks will end the worker thread task.

Block until no more threads are running this task.

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.

Definition at line 130 of file DatabaseWorkerPool.h.

Referenced by DatabaseWorkerPool< CharacterDatabaseConnection >::Close().

◆ CommitTransaction()

template<class T>
void DatabaseWorkerPool< T >::CommitTransaction ( SQLTransaction transaction)
inline

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.

Definition at line 385 of file DatabaseWorkerPool.h.

◆ DelayQueryHolder()

template<class T>
QueryResultHolderFuture DatabaseWorkerPool< T >::DelayQueryHolder ( SQLQueryHolder * holder)
inline

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.

Fool compiler, has no use yet

Definition at line 365 of file DatabaseWorkerPool.h.

◆ DirectCommitTransaction()

template<class T>
void DatabaseWorkerPool< T >::DirectCommitTransaction ( SQLTransaction & transaction)
inline

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

Todo
More elegant way

Clean up now.

Definition at line 415 of file DatabaseWorkerPool.h.

◆ DirectExecute() [1/2]

template<class T>
void DatabaseWorkerPool< T >::DirectExecute ( const char * sql)
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.

Definition at line 209 of file DatabaseWorkerPool.h.

Referenced by DatabaseWorkerPool< CharacterDatabaseConnection >::DirectPExecute().

◆ DirectExecute() [2/2]

template<class T>
void DatabaseWorkerPool< T >::DirectExecute ( PreparedStatement * stmt)
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

Definition at line 237 of file DatabaseWorkerPool.h.

◆ DirectPExecute()

template<class T>
void DatabaseWorkerPool< T >::DirectPExecute ( const char * sql,
... )
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.

Definition at line 221 of file DatabaseWorkerPool.h.

◆ Enqueue()

◆ EscapeString() [1/2]

template<class T>
unsigned long DatabaseWorkerPool< T >::EscapeString ( char * to,
const char * from,
unsigned long length )
inlineprivate

Definition at line 508 of file DatabaseWorkerPool.h.

◆ EscapeString() [2/2]

template<class T>
void DatabaseWorkerPool< T >::EscapeString ( std::string & str)
inline

Apply escape string'ing for current collation. (utf8).

Definition at line 475 of file DatabaseWorkerPool.h.

Referenced by DatabaseWorkerPool< CharacterDatabaseConnection >::EscapeString().

◆ Execute() [1/2]

template<class T>
void DatabaseWorkerPool< T >::Execute ( const char * sql)
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.

Definition at line 170 of file DatabaseWorkerPool.h.

Referenced by DatabaseWorkerPool< CharacterDatabaseConnection >::ExecuteOrAppend(), DatabaseWorkerPool< CharacterDatabaseConnection >::ExecuteOrAppend(), and DatabaseWorkerPool< CharacterDatabaseConnection >::PExecute().

◆ Execute() [2/2]

template<class T>
void DatabaseWorkerPool< T >::Execute ( PreparedStatement * stmt)
inline

Enqueues a one-way SQL operation in prepared statement format that will be executed asynchronously. Statement must be prepared with CONNECTION_ASYNC flag.

Definition at line 197 of file DatabaseWorkerPool.h.

◆ ExecuteOrAppend() [1/2]

template<class T>
void DatabaseWorkerPool< T >::ExecuteOrAppend ( SQLTransaction & trans,
const char * sql )
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.

Definition at line 454 of file DatabaseWorkerPool.h.

◆ ExecuteOrAppend() [2/2]

template<class T>
void DatabaseWorkerPool< T >::ExecuteOrAppend ( SQLTransaction & trans,
PreparedStatement * stmt )
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.

Definition at line 444 of file DatabaseWorkerPool.h.

◆ GetDatabaseName()

◆ GetFreeConnection()

template<class T>
T * DatabaseWorkerPool< T >::GetFreeConnection ( )
inlineprivate

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

Definition at line 523 of file DatabaseWorkerPool.h.

Referenced by DatabaseWorkerPool< CharacterDatabaseConnection >::DirectCommitTransaction(), DatabaseWorkerPool< CharacterDatabaseConnection >::DirectExecute(), DatabaseWorkerPool< CharacterDatabaseConnection >::DirectExecute(), DatabaseWorkerPool< CharacterDatabaseConnection >::Query(), and DatabaseWorkerPool< CharacterDatabaseConnection >::Query().

◆ GetPreparedStatement()

template<class T>
PreparedStatement * DatabaseWorkerPool< T >::GetPreparedStatement ( uint32 index)
inline

Other

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.

Definition at line 469 of file DatabaseWorkerPool.h.

◆ KeepAlive()

template<class T>
void DatabaseWorkerPool< T >::KeepAlive ( )
inline

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.

Definition at line 487 of file DatabaseWorkerPool.h.

◆ Open() [1/2]

template<class T>
bool DatabaseWorkerPool< T >::Open ( const char * host,
const char * port,
const char * user,
const char * password,
const char * database,
uint8 async_threads,
uint8 synch_threads )
inline

Open asynchronous connections (delayed operations)

Open synchronous connections (direct, blocking operations)

Definition at line 52 of file DatabaseWorkerPool.h.

◆ Open() [2/2]

template<class T>
bool DatabaseWorkerPool< T >::Open ( const std::string & infoString,
uint8 async_threads,
uint8 synch_threads )
inline

Open asynchronous connections (delayed operations)

Open synchronous connections (direct, blocking operations)

Definition at line 91 of file DatabaseWorkerPool.h.

◆ PExecute()

template<class T>
void DatabaseWorkerPool< T >::PExecute ( const char * sql,
... )
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.

Definition at line 181 of file DatabaseWorkerPool.h.

◆ PQuery() [1/2]

template<class T>
QueryResult DatabaseWorkerPool< T >::PQuery ( const char * sql,
T * conn,
... )
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.

Definition at line 272 of file DatabaseWorkerPool.h.

◆ PQuery() [2/2]

template<class T>
QueryResult DatabaseWorkerPool< T >::PQuery ( const char * sql,
... )
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.

Definition at line 288 of file DatabaseWorkerPool.h.

◆ Query() [1/2]

template<class T>
QueryResult DatabaseWorkerPool< T >::Query ( const char * sql,
T * conn = NULL )
inline

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.

Definition at line 253 of file DatabaseWorkerPool.h.

Referenced by DatabaseWorkerPool< CharacterDatabaseConnection >::PQuery(), and DatabaseWorkerPool< CharacterDatabaseConnection >::PQuery().

◆ Query() [2/2]

template<class T>
PreparedQueryResult DatabaseWorkerPool< T >::Query ( PreparedStatement * stmt)
inline

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

Definition at line 305 of file DatabaseWorkerPool.h.

◆ Wait()

template<class T>
void DatabaseWorkerPool< T >::Wait ( )
inline

Blocks until all currently queued asynchronous operations have finished.

Definition at line 408 of file DatabaseWorkerPool.h.

Member Data Documentation

◆ _connectionCount

template<class T>
uint32 DatabaseWorkerPool< T >::_connectionCount[2]
private

Definition at line 555 of file DatabaseWorkerPool.h.

◆ _connectionInfo

template<class T>
MySQLConnectionInfo* DatabaseWorkerPool< T >::_connectionInfo
private

Counter of MySQL connections;.

Definition at line 556 of file DatabaseWorkerPool.h.

◆ _connections

template<class T>
std::vector< std::vector<T*> > DatabaseWorkerPool< T >::_connections
private

Queue shared by async worker threads.

Definition at line 554 of file DatabaseWorkerPool.h.

◆ _queue

template<class T>
Skyfire::DatabaseQueue* DatabaseWorkerPool< T >::_queue
private

Definition at line 553 of file DatabaseWorkerPool.h.


The documentation for this class was generated from the following file: