MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CrundNdbApiOperations.hpp
1 /* -*- mode: java; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=4:tabstop=4:smarttab:
3  *
4  * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #ifndef CrundNdbApiOperations_hpp
21 #define CrundNdbApiOperations_hpp
22 
23 #include <NdbApi.hpp>
24 #include <NdbError.hpp>
25 
29 struct CrundModel
30 {
31  const NdbDictionary::Table* table_A;
32  const NdbDictionary::Table* table_B0;
33  const NdbDictionary::Column* column_A_id;
34  const NdbDictionary::Column* column_A_cint;
35  const NdbDictionary::Column* column_A_clong;
36  const NdbDictionary::Column* column_A_cfloat;
37  const NdbDictionary::Column* column_A_cdouble;
38  const NdbDictionary::Column* column_B0_id;
39  const NdbDictionary::Column* column_B0_cint;
40  const NdbDictionary::Column* column_B0_clong;
41  const NdbDictionary::Column* column_B0_cfloat;
42  const NdbDictionary::Column* column_B0_cdouble;
43  const NdbDictionary::Column* column_B0_a_id;
44  const NdbDictionary::Column* column_B0_cvarbinary_def;
45  const NdbDictionary::Column* column_B0_cvarchar_def;
46  const NdbDictionary::Index* idx_B0_a_id;
47 
48  int attr_id;
49  int attr_cint;
50  int attr_clong;
51  int attr_cfloat;
52  int attr_cdouble;
53  int attr_B0_a_id;
54  int attr_B0_cvarbinary_def;
55  int attr_B0_cvarchar_def;
56  int attr_idx_B0_a_id;
57 
58  // initialize this instance from the dictionary
59  void init(Ndb* ndb);
60 };
61 
66 {
67 // For a better locality of information, consider refactorizing this
68 // class into separate classes: Cluster, Db, Tx, and Operations by
69 // use of delegation (private inheritance doesn't match cardinalities).
70 // Another advantage: can use *const members/references then and
71 // initialize them in the constructor's initializer lists.
72 // But for now, having all in one class is good enough.
73 
74 public:
75 
77  : model(NULL), mgmd(NULL), ndb(NULL), tx(NULL) {
78  }
79 
81  assert(model == NULL);
82  assert(mgmd == NULL); assert(ndb == NULL); assert(tx == NULL);
83  }
84 
85  // NDB Api metadata resources
86  const CrundModel* model;
87 
88 protected:
89 
90  // NDB API resources
92  Ndb* ndb;
93  NdbTransaction* tx;
94  NdbOperation::LockMode ndbOpLockMode;
95 
96  // NDB Api data resources
97  // XXX not used yet, see TwsDriver
98  //char* bb;
99  //char* bb_pos;
100  //NdbRecAttr** ra;
101  //NdbRecAttr** ra_pos;
102 
103 private:
104 
106  CrundNdbApiOperations& operator=(const CrundNdbApiOperations&);
107 
108 public:
109 
110  void init(const char* mgmd_conn_str);
111 
112  void close();
113 
114  void initConnection(const char* catalog, const char* schema,
115  NdbOperation::LockMode defaultLockMode);
116 
117  void closeConnection();
118 
119  void clearData();
120 
121  void delByScan(const NdbDictionary::Table* table, int& count,
122  bool batch);
123 
124  void ins(const NdbDictionary::Table* table, int from, int to,
125  bool setAttrs, bool batch);
126 
127  void delByPK(const NdbDictionary::Table* table, int from, int to,
128  bool batch);
129 
130  void setByPK(const NdbDictionary::Table* table, int from, int to,
131  bool batch);
132 
133  void getByPK_bb(const NdbDictionary::Table* table, int from, int to,
134  bool batch);
135 
136  void getByPK_ar(const NdbDictionary::Table* table, int from, int to,
137  bool batch);
138 
139  void setVarbinary(const NdbDictionary::Table* table,
140  int from, int to, bool batch, int length);
141 
142  void getVarbinary(const NdbDictionary::Table* table,
143  int from, int to, bool batch, int length);
144 
145  void setVarchar(const NdbDictionary::Table* table,
146  int from, int to, bool batch, int length);
147 
148  void getVarchar(const NdbDictionary::Table* table,
149  int from, int to, bool batch, int length);
150 
151  void setB0ToA(int nOps, bool batch);
152 
153  void navB0ToA(int nOps, bool batch);
154 
155  void navB0ToAalt(int nOps, bool batch);
156 
157  void navAToB0(int nOps, bool forceSend);
158 
159  void navAToB0alt(int nOps, bool forceSend);
160 
161  void nullB0ToA(int nOps, bool batch);
162 
163 protected:
164 
165  // XXX not used yet, see TwsDriver
166  //void ndbapiBeginTransaction();
167  //void ndbapiExecuteTransaction();
168  //void ndbapiCommitTransaction();
169  //void ndbapiCloseTransaction();
170  void beginTransaction();
171  void executeOperations();
172  void commitTransaction();
173  void closeTransaction();
174 
175  void setVar(const NdbDictionary::Table* table, int attr_cvar,
176  int from, int to, bool batch, const char* str);
177 
178  void getVar(const NdbDictionary::Table* table, int attr_cvar,
179  int from, int to, bool batch, const char* str);
180 
181  // XXX not used yet, see TwsDriver
182  //static void ndbapiToBuffer1blp(void* to, const char* from, size_t width);
183  //static void ndbapiToString1blp(char* to, const void* from, size_t width);
184 };
185 
186 #endif // CrundNdbApiOperations_hpp