TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Transaction.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
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 _TRANSACTION_H
19 #define _TRANSACTION_H
20 
21 #include "SQLOperation.h"
22 #include "StringFormat.h"
23 
24 //- Forward declare (don't include header to prevent circular includes)
25 class PreparedStatement;
26 
29 {
30  friend class TransactionTask;
31  friend class MySQLConnection;
32 
33  template <typename T>
34  friend class DatabaseWorkerPool;
35 
36  public:
37  Transaction() : _cleanedUp(false) { }
38  ~Transaction() { Cleanup(); }
39 
40  void Append(PreparedStatement* statement);
41  void Append(const char* sql);
42  template<typename Format, typename... Args>
43  void PAppend(Format&& sql, Args&&... args)
44  {
45  Append(Trinity::StringFormat(std::forward<Format>(sql), std::forward<Args>(args)...).c_str());
46  }
47 
48  size_t GetSize() const { return m_queries.size(); }
49 
50  protected:
51  void Cleanup();
52  std::list<SQLElementData> m_queries;
53 
54  private:
55  bool _cleanedUp;
56 
57 };
58 typedef std::shared_ptr<Transaction> SQLTransaction;
59 
62 {
63  template <class T> friend class DatabaseWorkerPool;
64  friend class DatabaseWorker;
65 
66  public:
67  TransactionTask(SQLTransaction trans) : m_trans(trans) { }
69 
70  protected:
71  bool Execute() override;
72 
74  static std::mutex _deadlockLock;
75 };
76 
77 #endif
Transaction()
Definition: Transaction.h:37
#define TC_DATABASE_API
Definition: Define.h:122
~Transaction()
Definition: Transaction.h:38
#define false
Definition: CascPort.h:18
virtual bool Execute()=0
Definition: PreparedStatement.h:74
bool _cleanedUp
Definition: Transaction.h:55
void PAppend(Format &&sql, Args &&...args)
Definition: Transaction.h:43
~TransactionTask()
Definition: Transaction.h:68
Definition: Transaction.h:28
std::list< SQLElementData > m_queries
Definition: Transaction.h:52
Definition: DatabaseWorker.h:27
std::string StringFormat(Format &&fmt, Args &&...args)
Default TC string format function.
Definition: StringFormat.h:28
SQLTransaction m_trans
Definition: Transaction.h:73
Definition: SQLOperation.h:56
size_t GetSize() const
Definition: Transaction.h:48
Definition: Transaction.h:61
static std::mutex _deadlockLock
Definition: Transaction.h:74
Definition: DatabaseWorkerPool.h:48
TransactionTask(SQLTransaction trans)
Definition: Transaction.h:67
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58