20 #include <UtilTransactions.hpp>
42 const char* tableNames[] = {
51 tableNamesSize =
sizeof(tableNames)/
sizeof(
const char*);
54 int Bank::getNumAccountTypes(){
55 return accountTypesSize;
58 int Bank::createAndLoadBank(
bool ovrWrt,
bool disk,
int num_accounts){
66 if (pSysValTab != NULL){
69 ndbout <<
"Bank already exist and overwrite == false" << endl;
74 if (!m_skip_create && createTables(disk) != NDBT_OK)
77 if (clearTables() != NDBT_OK)
80 if (loadAccountType() != NDBT_OK)
83 if (loadAccount(num_accounts) != NDBT_OK)
86 if (loadSystemValues() != NDBT_OK)
89 if (loadGl() != NDBT_OK)
102 if (dropTables() != NDBT_OK)
109 int Bank::createTables(
bool disk){
110 for (
int i = 0;
i < tableNamesSize;
i++){
111 if (createTable(tableNames[
i], disk) != NDBT_OK)
118 int Bank::dropTables(){
119 for (
int i = 0;
i < tableNamesSize;
i++){
120 if (dropTable(tableNames[
i]) != NDBT_OK)
126 int Bank::clearTables(){
127 for (
int i = 0;
i < tableNamesSize;
i++){
128 if (clearTable(tableNames[
i]) != NDBT_OK)
134 int Bank::clearTable(
const char* tabName){
136 if(util.clearTable(&m_ndb, 64) != 0)
141 int Bank::createTable(
const char* tabName,
bool disk){
142 ndbout <<
"createTable " << tabName << endl;
151 if (org != 0 && (disk || pTab->
equal(* org)))
157 ndbout <<
"Different table with same name exists" << endl;
163 if (NDBT_Tables::create_default_tablespace(&m_ndb))
165 ndbout <<
"Failed to create tablespaces" << endl;
169 copy.setTablespaceName(
"DEFAULT-TS");
170 for (
int i = 0;
i<copy.getNoOfColumns();
i++)
171 copy.getColumn(
i)->setStorageType(NdbDictionary::Column::StorageTypeDisk);
173 ndbout <<
"Failed to create table: " <<
181 ndbout <<
"Failed to create table: " <<
190 int Bank::dropTable(
const char* tabName){
197 ndbout <<
"dropTable " <<tabName<<endl;
219 int Bank::loadSystemValues (){
226 result = writeSystemValue(LastTransactionId, 0);
232 result = writeSystemValue(CurrentTime, 1);
245 g_info <<
"loadGl" << endl;
254 for (
int i = 0;
i < getNumAccountTypes();
i++){
271 check = pOp->
equal(
"TIME", time);
278 check = pOp->
equal(
"ACCOUNT_TYPE",
i);
286 if (getBalanceForAccountType(
i, balance) != NDBT_OK){
290 check = pOp->
setValue(
"BALANCE", balance);
297 Uint32 depositCount = 0;
298 check = pOp->
setValue(
"DEPOSIT_COUNT", depositCount);
305 Uint32 depositSum = 0;
306 check = pOp->
setValue(
"DEPOSIT_SUM", depositSum);
313 Uint32 withdrawalCount = 0;
314 check = pOp->
setValue(
"WITHDRAWAL_COUNT", withdrawalCount);
321 Uint32 withdrawalSum = 0;
322 check = pOp->
setValue(
"WITHDRAWAL_SUM", withdrawalSum);
330 check = pOp->
setValue(
"PURGED", purged);
338 check = pTrans->
execute(Commit);
350 int Bank::getBalanceForAccountType(
const Uint32 accountType,
353 g_info <<
"getBalanceForAccountType: accountType="<<accountType<<endl;
356 if (pScanTrans == NULL) {
375 if( accountTypeRec ==NULL ) {
382 if( balanceRec ==NULL ) {
388 check = pScanTrans->
execute(NoCommit);
404 if (a == accountType){
429 int Bank::loadAccountType(){
430 g_info <<
"loadAccountType" << endl;
439 for (
int i = 0;
i < getNumAccountTypes();
i++){
455 check = pOp->
equal(
"ACCOUNT_TYPE_ID", accountTypes[
i].
id);
469 check = pTrans->
execute(Commit);
486 int Bank::loadAccount (
int numAccounts){
487 g_info <<
"loadAccount" << endl;
496 for (
int i = 0;
i < numAccounts;
i++){
512 check = pOp->
equal(
"ACCOUNT_ID",
i);
524 check = pOp->
setValue(
"OWNER", owner);
544 check = pOp->
setValue(
"BALANCE", balance);
562 accountType = ((
i%accountTypesSize) == 0 ? 1 : (
i%getNumAccountTypes()));
563 check = pOp->
setValue(
"ACCOUNT_TYPE", accountType);
570 check = pTrans->
execute(Commit);
582 int Bank::getNumAccounts(){
585 if (accountTab == NULL){
586 g_err <<
"Table ACCOUNT does not exist" << endl;
590 if(util.selectCount(&m_ndb, 64, &m_maxAccount) != 0)
595 int Bank::getMaxAmount(){