25 #include "helpers.hpp"
26 #include "string_helpers.hpp"
28 #include "NdbApiDriver.hpp"
29 #include "CrundNdbApiOperations.hpp"
35 using std::ostringstream;
39 using utils::toString;
51 const char* delAByPK_s =
"delAByPK";
52 const char* delB0ByPK_s =
"delB0ByPK";
53 const char* setAByPK_s =
"setAByPK";
54 const char* setB0ByPK_s =
"setB0ByPK";
55 const char* getAByPK_bb_s =
"getAByPK_bb";
56 const char* getB0ByPK_bb_s =
"getB0ByPK_bb";
57 const char* getAByPK_ar_s =
"getAByPK_ar";
58 const char* getB0ByPK_ar_s =
"getB0ByPK_ar";
60 const char* setVarbinary_s =
"setVarbinary";
61 const char* getVarbinary_s =
"getVarbinary";
62 const char* clearVarbinary_s =
"clearVarbinary";
63 const char* setVarchar_s =
"setVarchar";
64 const char* getVarchar_s =
"getVarchar";
65 const char* clearVarchar_s =
"clearVarchar";
67 const char* setB0ToA_s =
"setB0->A";
68 const char* navB0ToA_s =
"navB0->A";
69 const char* navB0ToAalt_s =
"navB0->A_alt";
70 const char* navAToB0_s =
"navA->B0";
71 const char* navAToB0alt_s =
"navA->B0_alt";
72 const char* nullB0ToA_s =
"nullB0->A";
77 NdbApiDriver::init() {
82 assert(!mgmdConnect.empty());
83 ops->init(mgmdConnect.c_str());
87 NdbApiDriver::close() {
98 NdbApiDriver::initProperties() {
99 CrundDriver::initProperties();
101 cout <<
"setting ndb properties ..." << flush;
105 mgmdConnect = toString(props[L
"ndb.mgmdConnect"]);
106 if (mgmdConnect.empty()) {
107 mgmdConnect = string(
"localhost");
110 catalog = toString(props[L
"ndb.catalog"]);
111 if (catalog.empty()) {
112 catalog = string(
"crunddb");
115 schema = toString(props[L
"ndb.schema"]);
116 if (schema.empty()) {
117 schema = string(
"def");
121 if (msg.str().empty()) {
122 cout <<
" [ok]" << endl;
124 cout << endl << msg.str() << endl;
127 descr =
"ndbapi(" + mgmdConnect +
")";
131 NdbApiDriver::printProperties() {
132 CrundDriver::printProperties();
134 const ios_base::fmtflags f = cout.flags();
137 cout.flags(ios_base::boolalpha);
139 cout << endl <<
"ndb settings ..." << endl;
140 cout <<
"ndb.mgmdConnect: \"" << mgmdConnect <<
"\"" << endl;
141 cout <<
"ndb.catalog: \"" << catalog <<
"\"" << endl;
142 cout <<
"ndb.schema: \"" << schema <<
"\"" << endl;
150 NdbApiDriver::initOperations() {
151 cout <<
"initializing operations ..." << flush;
153 const bool feat =
true;
154 initOperationsFeat< !feat >();
155 initOperationsFeat< feat >();
157 cout <<
" [Op: " << operations.size() <<
"]" << endl;
166 + (OB ?
"_batch" :
"")) {
169 virtual void run(
int nOps)
const {
171 ops->delByScan(ops->model->table_A, count, OB);
172 assert(count == nOps);
179 + (OB ?
"_batch" :
"")) {
182 virtual void run(
int nOps)
const {
184 ops->delByScan(ops->model->table_B0, count, OB);
185 assert(count == nOps);
189 template<
bool OSA,
bool OB >
192 + (OSA ?
"_attr" :
"")
193 + (OB ?
"_batch" :
"")) {
196 virtual void run(
int nOps)
const {
197 ops->ins(ops->model->table_A, 1, nOps, OSA, OB);
201 template<
bool OSA,
bool OB >
204 + (OSA ?
"_attr" :
"")
205 + (OB ?
"_batch" :
"")) {
208 virtual void run(
int nOps)
const {
209 ops->ins(ops->model->table_B0, 1, nOps, OSA, OB);
213 template<
const char** ON,
218 + (OB ?
"_batch" :
"")) {
221 virtual void run(
int nOps)
const {
222 (ops->*OF)(ops->model->table_A, 1, nOps, OB);
226 template<
const char** ON,
231 + (OB ?
"_batch" :
"")) {
234 virtual void run(
int nOps)
const {
235 (ops->*OF)(ops->model->table_B0, 1, nOps, OB);
239 template<
const char** ON,
247 + (OB ?
"_batch" :
"")),
251 virtual void run(
int nOps)
const {
252 (ops->*OF)(ops->model->table_B0, 1, nOps, OB, length);
256 template<
const char** ON,
263 virtual void run(
int nOps)
const {
264 (ops->*OF)(ops->model->table_B0, 1, nOps, OB, 0);
268 template<
const char** ON,
273 + (OFS ?
"_forceSend" :
"")) {
276 virtual void run(
int nOps)
const {
277 (ops->*OF)(nOps, OFS);
281 template<
bool feat >
void
282 NdbApiDriver::initOperationsFeat() {
284 const bool setAttr =
true;
285 operations.push_back(
288 operations.push_back(
291 operations.push_back(
294 operations.push_back(
297 operations.push_back(
300 operations.push_back(
303 operations.push_back(
306 operations.push_back(
309 for (
int i = 1;
i <= maxVarbinaryBytes;
i *= 10) {
310 const int length =
i;
312 operations.push_back(
315 operations.push_back(
318 operations.push_back(
322 for (
int i = 1;
i <= maxVarcharChars;
i *= 10) {
323 const int length =
i;
325 operations.push_back(
326 new LengthOp< &setVarchar_s, &CrundNdbApiOperations::setVarchar, feat >(length));
328 operations.push_back(
329 new LengthOp< &getVarchar_s, &CrundNdbApiOperations::getVarchar, feat >(length));
331 operations.push_back(
332 new ZeroLengthOp< &clearVarchar_s, &CrundNdbApiOperations::setVarchar, feat >(length));
335 operations.push_back(
336 new RelOp< &setB0ToA_s, &CrundNdbApiOperations::setB0ToA, feat >());
338 operations.push_back(
339 new RelOp< &navB0ToA_s, &CrundNdbApiOperations::navB0ToA, feat >());
341 operations.push_back(
342 new RelOp< &navB0ToAalt_s, &CrundNdbApiOperations::navB0ToAalt, feat >());
344 operations.push_back(
345 new RelOp< &navAToB0_s, &CrundNdbApiOperations::navAToB0, feat >());
347 operations.push_back(
348 new RelOp< &navAToB0alt_s, &CrundNdbApiOperations::navAToB0alt, feat >());
350 operations.push_back(
351 new RelOp< &nullB0ToA_s, &CrundNdbApiOperations::nullB0ToA, feat >());
353 operations.push_back(
354 new B0ByPKOp< &setAByPK_s, &CrundNdbApiOperations::delByPK, feat >());
356 operations.push_back(
357 new AByPKOp< &setB0ByPK_s, &CrundNdbApiOperations::delByPK, feat >());
359 operations.push_back(
360 new AInsOp< setAttr, feat >());
362 operations.push_back(
363 new B0InsOp< setAttr, feat >());
365 operations.push_back(
366 new ADelAllOp< feat >());
368 operations.push_back(
369 new B0DelAllOp< feat >());
373 NdbApiDriver::closeOperations() {
374 cout <<
"closing operations ..." << flush;
375 for (Operations::const_iterator
i = operations.begin();
376 i != operations.end(); ++
i) {
380 cout <<
" [ok]" << endl;
386 NdbApiDriver::initConnection() {
403 ops->initConnection(catalog.c_str(), schema.c_str(), ndbOpLockMode);
407 NdbApiDriver::closeConnection() {
408 ops->closeConnection();
412 NdbApiDriver::clearPersistenceContext() {
417 NdbApiDriver::clearData()
425 main(
int argc,
const char* argv[])