1 /*
2    Copyright (c) 2003, 2021, Oracle and/or its affiliates.
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, version 2.0,
7    as published by the Free Software Foundation.
8 
9    This program is also distributed with certain software (including
10    but not limited to OpenSSL) that is licensed under separate terms,
11    as designated in a particular file or component or in included license
12    documentation.  The authors of MySQL hereby grant you an additional
13    permission to link the program and your derivative works with the
14    separately licensed software that they have included with MySQL.
15 
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19    GNU General Public License, version 2.0, for more details.
20 
21    You should have received a copy of the GNU General Public License
22    along with this program; if not, write to the Free Software
23    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
24 */
25 
26 #ifndef UTIL_TRANSACTIONS_HPP
27 #define UTIL_TRANSACTIONS_HPP
28 
29 #include <NDBT.hpp>
30 
31 typedef int (ReadCallBackFn)(NDBT_ResultRow*);
32 
33 class UtilTransactions {
34 public:
35   UtilTransactions(const NdbDictionary::Table&,
36 		   const NdbDictionary::Index* idx = 0);
37   UtilTransactions(Ndb* ndb,
38 		   const char * tableName, const char * indexName = 0);
39 
40   int closeTransaction(Ndb*);
41 
42   int clearTable(Ndb*,
43                  NdbScanOperation::ScanFlag,
44 		 int records = 0,
45 		 int parallelism = 0);
46 
47   int clearTable(Ndb*,
48 		 int records = 0,
49 		 int parallelism = 0);
50 
51   // Delete all records from the table using a scan
52   int clearTable1(Ndb*,
53 		  int records = 0,
54 		  int parallelism = 0);
55   // Delete all records from the table using a scan
56   // Using batching
57   int clearTable2(Ndb*,
58 		  int records = 0,
59 		  int parallelism = 0);
60 
61   int clearTable3(Ndb*,
62 		  int records = 0,
63 		  int parallelism = 0);
64 
65   int selectCount(Ndb*,
66 		  int parallelism = 0,
67 		  int* count_rows = NULL,
68 		  NdbOperation::LockMode lm = NdbOperation::LM_CommittedRead);
69 
70   int scanReadRecords(Ndb*,
71 		      int parallelism,
72 		      NdbOperation::LockMode lm,
73 		      int records,
74 		      int noAttribs,
75 		      int* attrib_list,
76 		      ReadCallBackFn* fn = NULL);
77   int verifyIndex(Ndb*,
78 		  const char* indexName,
79 		  int parallelism = 0,
80 		  bool transactional = false);
81 
82   int copyTableData(Ndb*,
83 		const char* destName);
84 
85   /**
86    * Compare this table with other_table
87    *
88    * return 0 - on equality
89    *       -1 - on error
90    *      >0 - otherwise
91    */
92   int compare(Ndb*, const char * other_table, int flags);
93 
94 private:
95   static int takeOverAndDeleteRecord(Ndb*,
96 				     NdbOperation*);
97 
98   int addRowToDelete(Ndb* pNdb,
99 		     NdbConnection* pDelTrans,
100 		     NdbOperation* pOrgOp);
101 
102 
103   int addRowToInsert(Ndb* pNdb,
104 		     NdbConnection* pInsTrans,
105 		     NDBT_ResultRow & row,
106 		     const char* insertTabName);
107 
108 
109   int verifyUniqueIndex(Ndb*,
110 			const NdbDictionary::Index *,
111 			int parallelism = 0,
112 			bool transactional = false);
113 
114   int scanAndCompareUniqueIndex(Ndb* pNdb,
115 				const NdbDictionary::Index *,
116 				int parallelism,
117 				bool transactional);
118 
119   int readRowFromTableAndIndex(Ndb* pNdb,
120 			       NdbConnection* pTrans,
121 			       const NdbDictionary::Index *,
122 			       NDBT_ResultRow& row );
123 
124   int verifyOrderedIndex(Ndb*,
125 			 const NdbDictionary::Index *,
126 			 int parallelism = 0,
127 			 bool transactional = false);
128 
129 
130   int get_values(NdbOperation* op, NDBT_ResultRow& dst);
131   int equal(const NdbDictionary::Table*, NdbOperation*, const NDBT_ResultRow&);
132   int equal(const NdbDictionary::Index*, NdbOperation*, const NDBT_ResultRow&);
133 
134 protected:
135   int m_defaultClearMethod;
136   const NdbDictionary::Table& tab;
137   const NdbDictionary::Index* idx;
138   NdbConnection* pTrans;
139 
140   NdbOperation* getOperation(NdbConnection*,
141 			     NdbOperation::OperationType);
142   NdbScanOperation* getScanOperation(NdbConnection*);
143 };
144 
145 #endif
146