MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Bank.hpp
1 /*
2  Copyright (C) 2003-2007 MySQL AB, 2008 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef BANK_HPP
20 #define BANK_HPP
21 
22 #include <NdbOut.hpp>
23 #include <NdbApi.hpp>
24 #include <NDBT.hpp>
25 #include <NdbTick.h>
26 #include <random.h>
27 
28 
29 class Bank {
30 public:
31 
32  Bank(Ndb_cluster_connection&, bool init = true, const char *dbase="BANK");
33 
34  void setSkipCreate(bool skip) { m_skip_create = skip; }
35  int createAndLoadBank(bool overWrite, bool disk= false, int num_accounts=10);
36  int dropBank();
37 
38  int performTransactions(int maxSleepBetweenTrans = 20, int yield=0);
39  int performMakeGLs(int yield=0);
41  int performSumAccounts(int maxSleepBetweenSums = 2000, int yield=0);
42  int performIncreaseTime(int maxSleepBetweenDays = 30, int yield=0);
43 private:
44 
45  int init();
46 
47  enum TransactionTypes{
48  WithDrawal = 2000,
49  Deposit = 3000
50  };
51 
52  static const int NOT_ENOUGH_FUNDS = 1000;
53  static const int VERIFICATION_FAILED = 1001;
54 
55  int performTransaction();
56  int performTransaction(int fromAccountId,
57  int toAccountId,
58  int amount );
59  int performTransactionImpl1(int fromAccountId,
60  int toAccountId,
61  int amount );
62 
63  int performValidateGLs(Uint64 age = 20);
64  int performValidateGL(Uint64 GLTime);
65  int performValidatePurged();
66 
67  int performMakeGL(Uint64 time);
68  int performMakeGLForAccountType(NdbConnection* pTrans,
69  Uint64 time,
70  Uint32 accountTypeId);
71  int sumTransactionsForGL(const Uint64 time,
72  const Uint32 accountType,
73  Uint32& balance,
74  Uint32& withdrawalCount,
75  Uint32& withdrawalSum,
76  Uint32& depositSum,
77  Uint32& depositCount,
78  Uint32& transactionsCount,
79  NdbConnection* pTrans);
80  int getBalanceForAccountType(const Uint32 accountType,
81  Uint32& balance);
82  int getBalanceForGL(const Uint64 glTime,
83  const Uint32 accountType,
84  Uint32 &balance);
85 
86  int checkNoTransactionsOlderThan(const Uint32 accountType,
87  const Uint64 oldest);
88  int getOldestPurgedGL(const Uint32 accountType,
89  Uint64 &oldest);
90  int getOldestNotPurgedGL(Uint64 &oldest,
91  Uint32 &accountTypeId,
92  bool &found);
93  int findLastGL(Uint64 &lastTime);
94  int purgeOldGLTransactions(Uint64 currTime, Uint32 age);
95 
96  int purgeTransactions(const Uint64 glTime,
97  const Uint32 accountTypeId);
98  int findTransactionsToPurge(const Uint64 glTime,
99  const Uint32 accountType,
100  NdbConnection* pTrans);
101 
102 
103  int getSumAccounts(Uint32 &sumAccounts,
104  Uint32 &numAccounts);
105  int getNumAccounts();
106  int getNumAccountTypes();
107  int getMaxAmount();
108 
109 
110  enum SystemValueId {
111  LastTransactionId = 0,
112  CurrentTime = 1
113  };
114 
115 
116  int readSystemValue(SystemValueId sysValId, Uint64 & value);
117  int increaseSystemValue(SystemValueId sysValId, Uint64 &value);
118  int increaseSystemValue2(SystemValueId sysValId, Uint64 &value);
119  int writeSystemValue(SystemValueId sysValId, Uint64 value);
120  int getNextTransactionId(Uint64 &value);
121  int incCurrTime(Uint64 &value);
122  int getCurrTime(Uint64 &time);
123 
124  int prepareReadSystemValueOp(NdbConnection*, SystemValueId sysValId, Uint64 &time);
125  int prepareGetCurrTimeOp(NdbConnection*, Uint64 &time);
126 
127  int createTables(bool disk);
128  int createTable(const char* tabName, bool disk);
129 
130  int dropTables();
131  int dropTable(const char* tabName);
132 
133  int clearTables();
134  int clearTable(const char* tabName);
135 
136  int loadGl();
137  int loadAccountType();
138  int loadAccount (int numAccounts);
139  int loadSystemValues();
140 
141 private:
142 
143  Ndb m_ndb;
144  int m_maxAccount;
145  bool m_initialized;
146  bool m_skip_create;
147 };
148 
149 #endif