Qore BulkSqlUtil Module Reference  1.2
BulkSqlUtil.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* BulkSqlUtil.qm Copyright 2015 - 2017 Qore Technologies, s.r.o.
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23 */
24 
25 // minimum required Qore version
26 
27 // require type definitions everywhere
28 
29 // enable all warnings
30 
31 // assume local scope for variables, do not use "$" signs
32 
33 // use SqlUtil
34 
35 
69 namespace BulkSqlUtil {
72 
122 
123 public:
124  public :
126  const OptionKeys = (
127  "block_size": sprintf("the row block size used for bulk DML / batch operations; default: %y", OptionDefaults.block_size),
128  "info_log": "a call reference / closure for informational logging",
129  );
130 
132  const OptionDefaults = (
133  "block_size": 1000,
134  );
135 
136 public:
137 
138  private :
141 
143  softint block_size;
144 
147 
150 
153 
155  *code info_log;
156 
158  int row_count = 0;
159 
161  string opname;
162 
165 
166 public:
167 
169 
175  constructor(string name, SqlUtil::Table target, *hash opts);
176 
177 
179 
185  constructor(string name, SqlUtil::AbstractTable target, *hash opts);
186 
187 
189 
191  destructor();
192 
193 
195 
229  queueData(hash data);
230 
231 
233 
267  queueData(list l);
268 
269 
271 
275  int size();
276 
277 
279 
280 private:
281  init(*hash opts);
282 public:
283 
284 
286 
287 private:
289 public:
290 
291 
293 
294 private:
295  setupInitialRow(hash row);
296 public:
297 
298 
300 
330  flush();
331 
332 
334 
335 private:
336  flushIntern();
337 public:
338 
339 
341 
371  discard();
372 
373 
375  nothing commit();
376 
377 
379  nothing rollback();
380 
381 
383  string getTableName();
384 
385 
388 
389 
392 
393 
395  int getRowCount();
396 
397 
399 
400 private:
401  abstract flushImpl();
402 public:
403  };
404 
406 
462 
463 public:
464  private :
466  SQLStatement stmt;
467 
469  *code rowcode;
470 
473 
474 public:
475 
477 
485  constructor(SqlUtil::Table target, *hash opts) ;
486 
487 
489 
497  constructor(SqlUtil::AbstractTable target, *hash opts) ;
498 
499 
501 
526  setRowCode(*code rowc);
527 
528 
530 
531 private:
532  init(*hash opts);
533 public:
534 
535 
537 
538 private:
540 public:
541 
542 
544 
545 private:
546  setupInitialRow(hash row);
547 public:
548 
549 
550 
551 private:
552  setupStaticRowValues(reference<hash> row);
553 public:
554 
555 
557 
566 private:
567  flushImpl();
568 public:
569 
570  };
571 
573 
620 
621 public:
622  private :
623  // upsert strategy to use
624  int upsert_strategy;
625  // upsert closure
626  code upsert;
627 
628 public:
629 
631 
637  constructor(SqlUtil::Table target, *hash opts) ;
638 
639 
641 
647  constructor(SqlUtil::AbstractTable target, *hash opts) ;
648 
649 
651 
652 private:
653  init(*hash opts);
654 public:
655 
656 
658 
659 private:
660  flushImpl();
661 public:
662 
663  };
664 };
hash cval
"constant" row values; must be equal in all calls to queueData
Definition: BulkSqlUtil.qm.dox.h:149
*code info_log
an optional info logging callback; must accept a sprintf()-style format specifier and optional argume...
Definition: BulkSqlUtil.qm.dox.h:155
constructor(SqlUtil::Table target, *hash opts)
creates the object from the supplied arguments
SqlUtil::AbstractTable getTable()
returns the underlying SqlUtil::AbstractTable object
string sprintf(string fmt,...)
constructor(SqlUtil::Table target, *hash opts)
creates the object from the supplied arguments
flushImpl()
executes bulk DML upserts in the database with internally queued data
Qore::SQL::AbstractDatasource getDatasource()
returns the AbstractDatasource object associated with this object
abstract flushImpl()
flushes queued data to the database
queueData(hash data)
queues row data in the block buffer; the block buffer is flushed to the DB if the buffer size reaches...
discard()
discards any buffered batched data; this method should be called before destroying the object if an e...
setupInitialRow(hash row)
sets up the block buffer given the initial template row for inserting
setupInitialRow(hash row)
sets up support for "returning" insert options for any possible rowcode member
int row_count
row count
Definition: BulkSqlUtil.qm.dox.h:158
base class for bulk DML upsert operations
Definition: BulkSqlUtil.qm.dox.h:619
setupInitialRowColumns(hash row)
sets up the block buffer given the initial template hash of lists for inserting
const OptionKeys
option keys for this object
Definition: BulkSqlUtil.qm.dox.h:126
the BulkSqlUtil namespace contains all the definitions in the BulkSqlUtil module
Definition: BulkSqlUtil.qm.dox.h:70
string getTableName()
returns the table name
hash static_ret_expr
hash of "returning" arguments
Definition: BulkSqlUtil.qm.dox.h:472
list list(...)
setRowCode(*code rowc)
sets a closure or call reference that will be called when data has been sent to the database and all ...
flushIntern()
flushes queued data to the database
init(*hash opts)
common constructor initialization
SQLStatement stmt
statement for DML
Definition: BulkSqlUtil.qm.dox.h:466
base class for bulk DML insert operations
Definition: BulkSqlUtil.qm.dox.h:461
nothing rollback()
discards any queued data and rolls back the transaction
constructor(string name, SqlUtil::Table target, *hash opts)
creates the object from the supplied arguments
int getRowCount()
returns the affected row count
string opname
operation name
Definition: BulkSqlUtil.qm.dox.h:161
setupInitialRowColumns(hash row)
sets up the block buffer given the initial template hash of lists for inserting
nothing commit()
flushes any queued data and commits the transaction
SqlUtil::AbstractTable table
the target table object
Definition: BulkSqlUtil.qm.dox.h:140
*code rowcode
per-row Closures or Call References for inserts
Definition: BulkSqlUtil.qm.dox.h:469
destructor()
throws an exception if there is data pending in the internal row data cache; make sure to call flush(...
const OptionDefaults
default option values
Definition: BulkSqlUtil.qm.dox.h:132
list cval_keys
"constant" row value keys
Definition: BulkSqlUtil.qm.dox.h:152
flushImpl()
inserts internally-queued queued data in the database with bulk DML operations
flush()
flushes any remaining batched data to the database; this method should always be called before commit...
base class for bulk DML operations
Definition: BulkSqlUtil.qm.dox.h:121
list ret_args
list of "returning" columns
Definition: BulkSqlUtil.qm.dox.h:164
init(*hash opts)
common constructor initialization
int size()
returns the current size of the cache as a number of rows
hash hash(object obj)
hash hbuf
buffer for bulk operations
Definition: BulkSqlUtil.qm.dox.h:146
init(*hash opts)
common constructor initialization
softint block_size
bulk operation block size
Definition: BulkSqlUtil.qm.dox.h:143