Qore BulkSqlUtil Module Reference  1.3
AbstractBulkOperation.qc.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* AbstractBulkOperation.qc 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 
34 namespace BulkSqlUtil {
36 
86 
87 public:
89  const OptionKeys = (
90  "block_size": sprintf("the row block size used for bulk DML / batch operations; default: %y", OptionDefaults.block_size),
91  "info_log": "a call reference / closure for informational logging",
92  );
93 
95  const OptionDefaults = (
96  "block_size": 1000,
97  );
98 
99 protected:
101  SqlUtil::AbstractTable table;
102 
104  softint block_size;
105 
108 
111 
114 
116  *code info_log;
117 
119  int row_count = 0;
120 
122  string opname;
123 
126 
127 public:
128 
130 
136  constructor(string name, SqlUtil::Table target, *hash opts);
137 
138 
140 
146  constructor(string name, SqlUtil::AbstractTable target, *hash opts);
147 
148 
150 
152  destructor();
153 
154 
156 
190  queueData(hash data);
191 
192 
194 
228  queueData(list l);
229 
230 
232 
236  int size();
237 
238 
240 protected:
241  init(*hash opts);
242 public:
243 
244 
246 protected:
248 public:
249 
250 
252 protected:
253  setupInitialRow(hash row);
254 public:
255 
256 
258 
288  flush();
289 
290 
292 protected:
293  flushIntern();
294 public:
295 
296 
298 
328  discard();
329 
330 
332  nothing commit();
333 
334 
336  nothing rollback();
337 
338 
340  string getTableName();
341 
342 
344  SqlUtil::AbstractTable getTable();
345 
346 
349 
350 
352  int getRowCount();
353 
354 
356 protected:
357  abstract flushImpl();
358 public:
359  };
360 };
hash cval
"constant" row values; must be equal in all calls to queueData
Definition: AbstractBulkOperation.qc.dox.h:110
*code info_log
an optional info logging callback; must accept a sprintf()-style format specifier and optional argume...
Definition: AbstractBulkOperation.qc.dox.h:116
SqlUtil::AbstractTable getTable()
returns the underlying SqlUtil::AbstractTable object
string sprintf(string fmt,...)
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
int row_count
row count
Definition: AbstractBulkOperation.qc.dox.h:119
const OptionKeys
option keys for this object
Definition: AbstractBulkOperation.qc.dox.h:89
Qore AbstractBulkOperation class definition.
Definition: AbstractBulkOperation.qc.dox.h:34
string getTableName()
returns the table name
flushIntern()
flushes queued data to the database
list< auto > list(...)
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: AbstractBulkOperation.qc.dox.h:122
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
hash< auto > hash(object obj)
SqlUtil::AbstractTable table
the target table object
Definition: AbstractBulkOperation.qc.dox.h:101
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: AbstractBulkOperation.qc.dox.h:95
list cval_keys
"constant" row value keys
Definition: AbstractBulkOperation.qc.dox.h:113
flush()
flushes any remaining batched data to the database; this method should always be called before commit...
base class for bulk DML operations
Definition: AbstractBulkOperation.qc.dox.h:85
list ret_args
list of "returning" columns
Definition: AbstractBulkOperation.qc.dox.h:125
int size()
returns the current size of the cache as a number of rows
hash hbuf
buffer for bulk operations
Definition: AbstractBulkOperation.qc.dox.h:107
init(*hash opts)
common constructor initialization
softint block_size
bulk operation block size
Definition: AbstractBulkOperation.qc.dox.h:104