1 /*
2    Copyright (C) 2003, 2005, 2006 MySQL AB
3     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 NDBT_DATA_SET_TRANSACTION_HPP
27 #define NDBT_DATA_SET_TRANSACTION_HPP
28 
29 #include "NDBT_Table.hpp"
30 #include <NdbApi.hpp>
31 
32 class NDBT_DataSet;
33 
34 /**
35  * This class contains a bunch a methods
36  * that operates on NDB together with a NDBT_DataSet
37  * using <b>one</b> transaction
38  */
39 class NDBT_DataSetTransaction {
40 public:
41   /**
42    * Store the data into ndb
43    */
44   static void insert(Ndb * theNdbObject,
45 		     const NDBT_DataSet *,
46 		     bool rollback = false);
47 
48   /**
49    * Read data (using pk) from ndb
50    */
51   static void readByPk(Ndb * theNdbObject,
52 		       NDBT_DataSet *,
53 		       bool rollback = false);
54 
55   /**
56    * Update data using pk
57    *
58    */
59   static void updateByPk(Ndb * theNdbObject,
60 			 const NDBT_DataSet *,
61 			 bool rollback = false);
62 
63   /**
64    * Delete
65    */
66   static void deleteByPk(Ndb * theNdbObject,
67 			 const NDBT_DataSet *,
68 			 bool rollback = false);
69 };
70 
71 class NDBT_DataSetAsyncTransaction {
72 public:
73   enum OperationType {
74     OT_Insert,
75     OT_ReadByPk,
76     OT_UpdateByPk,
77     OT_DeleteByPk
78   };
79 
80   /**
81    * A callback for the NDBT_DataSetAsyncTransaction
82    * interface.
83    *
84    * The callback method returns:
85    * - the operation performed
86    * - the data set
87    * - if the transaction was commited or aborted
88    */
89   typedef (* NDBT_DataSetAsyncTransactionCallback)(OperationType,
90 						   const NDBT_DataSet *,
91 						   bool commit,
92 						   void * anyObject);
93   /**
94    * Store the data into ndb
95    */
96   static void insert(Ndb * theNdbObject,
97 		     const NDBT_DataSet *,
98 		     bool rollback = false,
99 		     NDBT_DataSetAsyncTransactionCallback fun,
100 		     void * anyObject);
101 
102   /**
103    * Read data (using pk) from ndb
104    */
105   static void readByPk(Ndb * theNdbObject,
106 		       NDBT_DataSet *,
107 		       bool rollback = false,
108 		       NDBT_DataSetAsyncTransactionCallback fun,
109 		       void * anyObject);
110 
111 
112   /**
113    * Update data using pk
114    *
115    */
116   static void updateByPk(Ndb * theNdbObject,
117 			 const NDBT_DataSet *,
118 			 bool rollback = false,
119 			 NDBT_DataSetAsyncTransactionCallback fun,
120 			 void * anyObject);
121 
122 
123   /**
124    * Delete
125    */
126   static void deleteByPk(Ndb * theNdbObject,
127 			 const NDBT_DataSet *,
128 			 bool rollback = false,
129 			 NDBT_DataSetAsyncTransactionCallback fun,
130 			 void * anyObject);
131 
132 };
133 
134 class NDBT_DataSetBulkOperation {
135 public:
136   /**
137    * Store the data into ndb
138    */
139   static void insert(Ndb * theNdbObject,
140 		     const NDBT_DataSet *,
141 		     int parallellTransactions = 1,
142 		     int operationsPerTransaction = 10);
143 
144   /**
145    * Read data (using pk) from ndb
146    */
147   static void readByPk(Ndb * theNdbObject,
148 		       NDBT_DataSet *,
149 		       int parallellTransactions = 1,
150 		       int operationsPerTransaction = 10);
151 
152   /**
153    * Update data using pk
154    *
155    */
156   static void updateByPk(Ndb * theNdbObject,
157 			 const NDBT_DataSet *,
158 			 int parallellTransactions = 1,
159 			 int operationsPerTransaction = 10);
160 
161   /**
162    * Delete
163    */
164   static void deleteByPk(Ndb * theNdbObject,
165 			 const NDBT_DataSet *,
166 			 int parallellTransactions = 1,
167 			 int operationsPerTransaction = 10);
168 };
169 
170 
171 #endif
172