BulkSqlUtil.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
/* BulkSqlUtil.qm Copyright 2015 Qore Technologies, sro
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
// minimum required Qore version
// require type definitions everywhere
// enable all warnings
// assume local scope for variables, do not use "$" signs
// use SqlUtil
/* Version History
* 2015-08-02 v1.0: David Nichols <david@qore.org>
+ the initial version of the BulkSqlUtil module
*/
namespace BulkSqlUtil {
class AbstractBulkOperation {
public:
public :
const OptionKeys = (
"block_size": sprintf("the row block size used for bulk DML / batch operations; default: %y", OptionDefaults.block_size),
"info_log": "a call reference / closure for informational logging",
);
const OptionDefaults = (
"block_size": 1000,
);
public:
private :
SqlUtil::AbstractTable table;
softint block_size;
hash hbuf;
hash cval;
*code info_log;
int row_count = 0;
string opname;
list ret_args = ();
public:
constructor(string name, SqlUtil::Table target, *hash opts);
constructor(string name, SqlUtil::AbstractTable target, *hash opts);
destructor();
private init(*hash opts);
queueData(hash data);
queueData(list l);
private setupInitialRowColumns(hash row);
private setupInitialRow(hash row);
flush();
private flushIntern();
discard();
nothing commit();
nothing rollback();
string getTableName();
SqlUtil::AbstractTable getTable();
Qore::SQL::AbstractDatasource getDatasource();
int getRowCount();
abstract private flushImpl();
};
class BulkInsertOperation : public BulkSqlUtil::AbstractBulkOperation {
public:
private :
SQLStatement stmt;
*code rowcode;
hash static_ret_expr;
public:
constructor(SqlUtil::Table target, *hash opts) ;
constructor(SqlUtil::AbstractTable target, *hash opts) ;
setRowCode(*code rowc);
private init(*hash opts);
private setupInitialRowColumns(hash row);
private setupInitialRow(hash row);
private setupStaticRowValues(reference row);
private flushImpl();
};
class BulkUpsertOperation : public BulkSqlUtil::AbstractBulkOperation {
public:
private :
// upsert strategy to use
int upsert_strategy;
// upsert closure
code upsert;
public:
constructor(SqlUtil::Table target, *hash opts) ;
constructor(SqlUtil::AbstractTable target, *hash opts) ;
private init(*hash opts);
private flushImpl();
};
};
BulkSqlUtil::AbstractBulkOperation::cval
hash cval
"constant" row values; must be equal in all calls to queueData
Definition: BulkSqlUtil.qm.dox.h:146
BulkSqlUtil::AbstractBulkOperation::info_log
*code info_log
an optional info logging callback; must accept a sprintf()-style format specifier and optional argume...
Definition: BulkSqlUtil.qm.dox.h:149
BulkSqlUtil::BulkInsertOperation::constructor
constructor(SqlUtil::Table target, *hash opts)
creates the object from the supplied arguments
BulkSqlUtil::AbstractBulkOperation::setupInitialRowColumns
private setupInitialRowColumns(hash row)
sets up the block buffer given the initial template hash of lists for inserting
BulkSqlUtil::AbstractBulkOperation::getTable
SqlUtil::AbstractTable getTable()
returns the underlying SqlUtil::AbstractTable object
sprintf
string sprintf(string fmt,...)
BulkSqlUtil::AbstractBulkOperation::flushIntern
private flushIntern()
flushes queued data to the database
SqlUtil::AbstractTable
BulkSqlUtil::BulkUpsertOperation::constructor
constructor(SqlUtil::Table target, *hash opts)
creates the object from the supplied arguments
BulkSqlUtil::AbstractBulkOperation::getDatasource
Qore::SQL::AbstractDatasource getDatasource()
returns the AbstractDatasource object associated with this object
BulkSqlUtil::AbstractBulkOperation::queueData
queueData(hash data)
queues row data in the block buffer; the block buffer is flushed to the DB if the buffer size reaches...
BulkSqlUtil::AbstractBulkOperation::discard
discard()
discards any buffered batched data; this method should be called before destroying the object if an e...
BulkSqlUtil::AbstractBulkOperation::row_count
int row_count
row count
Definition: BulkSqlUtil.qm.dox.h:152
BulkSqlUtil::BulkUpsertOperation
base class for bulk DML upsert operations
Definition: BulkSqlUtil.qm.dox.h:575
BulkSqlUtil::BulkInsertOperation::flushImpl
private flushImpl()
inserts internally-queued queued data in the database wuith bulk DML operations
BulkSqlUtil::AbstractBulkOperation::OptionKeys
const OptionKeys
option keys for this object
Definition: BulkSqlUtil.qm.dox.h:123
BulkSqlUtil
the BulkSqlUtil namespace contains all the definitions in the BulkSqlUtil module
Definition: BulkSqlUtil.qm.dox.h:67
Qore::SQL::AbstractDatasource
BulkSqlUtil::AbstractBulkOperation::setupInitialRow
private setupInitialRow(hash row)
sets up the block buffer given the initial template row for inserting
BulkSqlUtil::AbstractBulkOperation::getTableName
string getTableName()
returns the table name
BulkSqlUtil::BulkInsertOperation::static_ret_expr
hash static_ret_expr
hash of "returning" arguments
Definition: BulkSqlUtil.qm.dox.h:443
list
list list(...)
BulkSqlUtil::BulkInsertOperation::setRowCode
setRowCode(*code rowc)
sets a closure or call reference that will be called when data has been sent to the database and all ...
BulkSqlUtil::BulkInsertOperation::setupInitialRow
private setupInitialRow(hash row)
sets up support for "returning" insert options for any possible rowcode member
BulkSqlUtil::BulkInsertOperation::stmt
SQLStatement stmt
statement for DML
Definition: BulkSqlUtil.qm.dox.h:437
BulkSqlUtil::BulkInsertOperation
base class for bulk DML insert operations
Definition: BulkSqlUtil.qm.dox.h:432
BulkSqlUtil::AbstractBulkOperation::rollback
nothing rollback()
discards any queued data and rolls back the transaction
BulkSqlUtil::AbstractBulkOperation::constructor
constructor(string name, SqlUtil::Table target, *hash opts)
creates the object from the supplied arguments
BulkSqlUtil::AbstractBulkOperation::getRowCount
int getRowCount()
returns the affected row count
BulkSqlUtil::AbstractBulkOperation::opname
string opname
operation name
Definition: BulkSqlUtil.qm.dox.h:155
BulkSqlUtil::AbstractBulkOperation::init
private init(*hash opts)
common constructor initialization
BulkSqlUtil::AbstractBulkOperation::commit
nothing commit()
flushes any queued data and commits the transaction
BulkSqlUtil::BulkUpsertOperation::init
private init(*hash opts)
common constructor initialization
BulkSqlUtil::BulkUpsertOperation::flushImpl
private flushImpl()
executes bulk DML upserts in the database with internally queued data
BulkSqlUtil::AbstractBulkOperation::table
SqlUtil::AbstractTable table
the target table object
Definition: BulkSqlUtil.qm.dox.h:137
BulkSqlUtil::BulkInsertOperation::rowcode
*code rowcode
per-row Closures or Call References for inserts
Definition: BulkSqlUtil.qm.dox.h:440
BulkSqlUtil::BulkInsertOperation::setupInitialRowColumns
private setupInitialRowColumns(hash row)
sets up the block buffer given the initial template hash of lists for inserting
BulkSqlUtil::AbstractBulkOperation::destructor
destructor()
throws an exception if there is data pending in the internal row data cache; make sure to call flush(...
BulkSqlUtil::AbstractBulkOperation::OptionDefaults
const OptionDefaults
default option values
Definition: BulkSqlUtil.qm.dox.h:129
BulkSqlUtil::AbstractBulkOperation::flushImpl
abstract private flushImpl()
flushes queued data to the database
BulkSqlUtil::AbstractBulkOperation::flush
flush()
flushes any remaining batched data to the database; this method should always be called before commit...
SqlUtil::Table
BulkSqlUtil::AbstractBulkOperation
base class for bulk DML operations
Definition: BulkSqlUtil.qm.dox.h:118
BulkSqlUtil::BulkInsertOperation::init
private init(*hash opts)
common constructor initialization
BulkSqlUtil::AbstractBulkOperation::ret_args
list ret_args
list of "returning" columns
Definition: BulkSqlUtil.qm.dox.h:158
hash
hash hash(object obj)
BulkSqlUtil::AbstractBulkOperation::hbuf
hash hbuf
buffer for bulk operations
Definition: BulkSqlUtil.qm.dox.h:143
BulkSqlUtil::AbstractBulkOperation::block_size
softint block_size
bulk operation block size
Definition: BulkSqlUtil.qm.dox.h:140