MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NdbApiTwsDriver.hpp
1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=4:tabstop=4:smarttab:
3  *
4  * Copyright (c) 2010, 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 NdbApiTwsDriver_hpp
21 #define NdbApiTwsDriver_hpp
22 
23 #include "TwsDriver.hpp"
24 
25 #include <NdbApi.hpp>
26 #include <NdbError.hpp>
27 
28 using std::string;
29 
31  const NdbDictionary::Table* table_t0;
32  const NdbDictionary::Column* column_c0;
33  const NdbDictionary::Column* column_c1;
34  const NdbDictionary::Column* column_c2;
35  const NdbDictionary::Column* column_c3;
36  const NdbDictionary::Column* column_c4;
37  const NdbDictionary::Column* column_c5;
38  const NdbDictionary::Column* column_c6;
39  const NdbDictionary::Column* column_c7;
40  const NdbDictionary::Column* column_c8;
41  const NdbDictionary::Column* column_c9;
42  const NdbDictionary::Column* column_c10;
43  const NdbDictionary::Column* column_c11;
44  const NdbDictionary::Column* column_c12;
45  const NdbDictionary::Column* column_c13;
46  const NdbDictionary::Column* column_c14;
47 
48  int attr_c0;
49  int attr_c1;
50  int attr_c2;
51  int attr_c3;
52  int attr_c4;
53  int attr_c5;
54  int attr_c6;
55  int attr_c7;
56  int attr_c8;
57  int attr_c9;
58  int attr_c10;
59  int attr_c11;
60  int attr_c12;
61  int attr_c13;
62  int attr_c14;
63 
64  int width_c0;
65  int width_c1;
66  int width_c2;
67  int width_c3;
68  int width_c4;
69  int width_c5;
70  int width_c6;
71  int width_c7;
72  int width_c8;
73  int width_c9;
74  int width_c10;
75  int width_c11;
76  int width_c12;
77  int width_c13;
78  int width_c14;
79  int width_row; // sum of {width_c0 .. width_c14}
80  static const int nCols = 15;
81 
82  NdbApiTwsModel(Ndb* ndb);
83 
84  ~NdbApiTwsModel() {}
85 
86  static int columnWidth(const NdbDictionary::Column* c) {
87  int s = c->getSize(); // size of type or of base type
88  int al = c->getLength(); // length or max length, 1 for scalars
89  int at = c->getArrayType(); // size of length prefix, practically
90  return (s * al) + at;
91  }
92 
93 private:
94 
96  NdbApiTwsModel& operator=(const NdbApiTwsModel&);
97 };
98 
99 class NdbApiTwsDriver : public TwsDriver {
100 public:
101 
103  : mgmd(NULL), ndb(NULL), tx(NULL), model(NULL), bb(NULL), ra(NULL) {
104  }
105 
106  virtual ~NdbApiTwsDriver() {
107  assert(mgmd == NULL); assert(ndb == NULL); assert(tx == NULL);
108  assert(model == NULL); assert(bb == NULL); assert(ra == NULL);
109  }
110 
111 private:
112 
114  NdbApiTwsDriver& operator=(const NdbApiTwsDriver&);
115 
116 protected:
117 
118  // NDB API settings
119  string mgmdConnect;
120  string catalog;
121  string schema;
122 
123  // NDB API resources
125  Ndb* ndb;
126  NdbTransaction* tx;
127  NdbOperation::LockMode ndbOpLockMode;
128 
129  // NDB Api metadata resources
130  NdbApiTwsModel* model;
131 
132  // NDB Api data resources
133  char* bb;
134  char* bb_pos;
135  NdbRecAttr** ra;
136  NdbRecAttr** ra_pos;
137 
138  // NDB API intializers/finalizers
139  virtual void init();
140  virtual void close();
141  virtual void initProperties();
142  virtual void printProperties();
143  void initNdbapiBuffers();
144  void closeNdbapiBuffers();
145 
146  // NDB API operations
147  virtual void runLoadOperations();
148  void runNdbapiInsert(XMode mode);
149  void ndbapiInsert(int c0);
150  void runNdbapiLookup(XMode mode);
151  void ndbapiLookup(int c0);
152  void ndbapiRead(int c0);
153  void runNdbapiUpdate(XMode mode);
154  void ndbapiUpdate(int c0);
155  void runNdbapiDelete(XMode mode);
156  void ndbapiDelete(int c0);
157  void ndbapiBeginTransaction();
158  void ndbapiExecuteTransaction();
159  void ndbapiCommitTransaction();
160  void ndbapiCloseTransaction();
161  static void ndbapiToBuffer1blp(void* to, const char* from, size_t width);
162  static void ndbapiToString1blp(char* to, const void* from, size_t width);
163 
164  // NDB API datastore operations
165  virtual void initConnection();
166  virtual void closeConnection();
167  //virtual void clearPersistenceContext(); // not used
168  //virtual void clearData(); // not used
169 };
170 
171 #endif // NdbApiTwsDriver_hpp