Qore TableMapper Module Reference  1.3
TableMapper::InboundTableMapperIterator Class Reference

provides a hash iterator based on a InboundTableMapper object and an iterator input source; for each iteration the iterted row is inserted into the Table target More...

Inheritance diagram for TableMapper::InboundTableMapperIterator:

Public Member Methods

nothing commit ()
 commits the transaction
 
int commitLimit ()
 returns the commit_limit value set in the constructor()
 
 constructor (Qore::AbstractIterator i, InboundTableMapper mapper)
 creates the iterator from the mapper passed More...
 
 constructor (Qore::AbstractIterator i, SqlUtil::AbstractTable target, hash< auto > mapv, *hash< auto > opts, int commit_limit=0)
 creates the iterator from the arguments passed More...
 
 constructor (Qore::AbstractIterator i, SqlUtil::Table target, hash< auto > mapv, *hash< auto > opts, int commit_limit=0)
 creates the iterator from the arguments passed More...
 
 constructor (Qore::AbstractIterator i, TableMapper::InboundTableMapper mapv, int commit_limit)
 creates the iterator from the arguments passed More...
 
int getCount ()
 returns the internal record count More...
 
Qore::SQL::AbstractDatasource getDatasource ()
 returns the AbstractDatasource object associated with this object
 
auto getRuntime (string key)
 get current runtime option value for a key More...
 
string getTableName ()
 returns the table name
 
hash< auto > getValue ()
 returns the current row transformed with the mapper
 
bool next ()
 Moves the current position of the input iterator to the next element; returns False if there are no more elements otherwise inserts the row in the target table and returns True. More...
 
 replaceRuntime (*hash< auto > runtime)
 replaces runtime options More...
 
 resetCount ()
 resets the internal record count More...
 
nothing rollback ()
 rolls back the transaction
 
 setRuntime (hash< auto > runtime)
 adds runtime options to the current runtime option hash More...
 
 setRuntime (string key, auto value)
 set the runtime option with "key" to value "value" More...
 

Private Attributes

int cnt = 0
 row count for commit
 
int commit_limit
 row commit limit (<= 0 for no commits)
 
TableMapper::InboundTableMapper mapc
 data mapper
 
hash< auto > val
 a copy of the last hash value mapped
 

Detailed Description

provides a hash iterator based on a InboundTableMapper object and an iterator input source; for each iteration the iterted row is inserted into the Table target

Member Function Documentation

◆ constructor() [1/4]

TableMapper::InboundTableMapperIterator::constructor ( Qore::AbstractIterator  i,
InboundTableMapper  mapper 
)

creates the iterator from the mapper passed

Parameters
iinput iterator; AbstractIterator::getValue() must return a hash
mapperthe mapper object that the iterator will be based on
Since
TableMapper 1.1.1

◆ constructor() [2/4]

TableMapper::InboundTableMapperIterator::constructor ( Qore::AbstractIterator  i,
SqlUtil::AbstractTable  target,
hash< auto >  mapv,
*hash< auto >  opts,
int  commit_limit = 0 
)

creates the iterator from the arguments passed

The target table is also scanned using SqlUtil and column definitions are used to update the target record specification, also if there are any columns with NOT NULL constraints and no default value, mapping, or constant value, then a MAP-ERROR exception is thrown

Example:
const DbMapper = (
"id": ("sequence": "seq_inventory_example"),
"store_code": "StoreCode",
"product_code": "ProductCode",
"product_desc": "ProductDescription",
"ordered": "Ordered",
"available": "Available",
"in_transit": "InTransit",
"status": ("constant": "01"),
"total": int sub (any x, hash rec) { return rec.Available.toInt() + rec.Ordered.toInt() + rec.InTransit.toInt(); },
);
InboundTableMapperIterator i(input, table, DbMapper);
Parameters
iinput iterator; AbstractIterator::getValue() must return a hash
targetthe target table object
mapva hash providing field mappings; each hash key is the name of the output column in lower case in the target table; each value is either True (meaning no translations are done; the data is copied 1:1) or a hash describing the mapping; see Mapper Specification Format for detailed documentation for this option
optsan optional hash of options for the mapper; see Mapper Options for a description of valid mapper options; note that options related to bulk DML are ignored by this object since it works on one row at a time
commit_limitrow count before a commit is made; if <= 0 then no commits are made by this object, otherwise a commit is made for each commit_limit rows processed by this object, commits are made in calls to next()
Note
by default commit_limit is 0 meaning that this object will make no commits; in this case the transaction will have to be commited explicitly externally

◆ constructor() [3/4]

TableMapper::InboundTableMapperIterator::constructor ( Qore::AbstractIterator  i,
SqlUtil::Table  target,
hash< auto >  mapv,
*hash< auto >  opts,
int  commit_limit = 0 
)

creates the iterator from the arguments passed

The target table is also scanned using SqlUtil and column definitions are used to update the target record specification, also if there are any columns with NOT NULL constraints and no default value, mapping, or constant value, then a MAP-ERROR exception is thrown

Example:
const DbMapper = (
"id": ("sequence": "seq_inventory_example"),
"store_code": "StoreCode",
"product_code": "ProductCode",
"product_desc": "ProductDescription",
"ordered": "Ordered",
"available": "Available",
"in_transit": "InTransit",
"status": ("constant": "01"),
"total": int sub (any x, hash rec) { return rec.Available.toInt() + rec.Ordered.toInt() + rec.InTransit.toInt(); },
);
InboundTableMapperIterator i(input, table, DbMapper);
Parameters
iinput iterator; AbstractIterator::getValue() must return a hash
targetthe target table object
mapva hash providing field mappings; each hash key is the name of the output column in lower case in the target table; each value is either True (meaning no translations are done; the data is copied 1:1) or a hash describing the mapping; see Mapper Specification Format for detailed documentation for this option
optsan optional hash of options for the mapper; see Mapper Options for a description of valid mapper options; note that options related to bulk DML are ignored by this object since it works on one row at a time
commit_limitrow count before a commit is made; if <= 0 then no commits are made by this object, otherwise a commit is made for each commit_limit rows processed by this object, commits are made in calls to next()
Note
by default commit_limit is 0 meaning that this object will make no commits; in this case the transaction will have to be commited explicitly externally

◆ constructor() [4/4]

TableMapper::InboundTableMapperIterator::constructor ( Qore::AbstractIterator  i,
TableMapper::InboundTableMapper  mapv,
int  commit_limit 
)

creates the iterator from the arguments passed

The target table is also scanned using SqlUtil and column definitions are used to update the target record specification, also if there are any columns with NOT NULL constraints and no default value, mapping, or constant value, then a MAP-ERROR exception is thrown

Example:
const DbMapper = (
"id": ("sequence": "seq_inventory_example"),
"store_code": "StoreCode",
"product_code": "ProductCode",
"product_desc": "ProductDescription",
"ordered": "Ordered",
"available": "Available",
"in_transit": "InTransit",
"total": int sub (any x, hash rec) { return rec.Available.toInt() + rec.Ordered.toInt() + rec.InTransit.toInt(); },
);
InboundTableMapper mapper(table, DbMapper);
InboundTableMapperIterator i(input, mapper);
Parameters
iinput iterator; AbstractIterator::getValue() must return a hash
mapvthe mapper to transform the data
commit_limitrow count before a commit is made; if <= 0 then no commits are made by this object, otherwise a commit is made for each commit_limit rows processed by this object, commits are made in calls to next()

◆ getCount()

int TableMapper::InboundTableMapperIterator::getCount ( )

returns the internal record count

See also
resetCount()

◆ getRuntime()

auto TableMapper::InboundTableMapperIterator::getRuntime ( string  key)

get current runtime option value for a key

Parameters
keythe runtime option key
Returns
a runtime value if the key exists in the current runtime option hash and is set
See also
Since
TableMapper 1.1.1

◆ next()

bool TableMapper::InboundTableMapperIterator::next ( )
virtual

Moves the current position of the input iterator to the next element; returns False if there are no more elements otherwise inserts the row in the target table and returns True.

if commit_limit is > 0 then TableMapper::InboundTableMapper::commit() is called for every commit_limit rows according to the internal row count

Returns
False if there are no more elements, in this case if there is an uncommitted transaction according to the internal row count, then TableMapper::InboundTableMapper::commit() is called as well

Reimplemented from Mapper::AbstractMapperIterator.

◆ replaceRuntime()

TableMapper::InboundTableMapperIterator::replaceRuntime ( *hash< auto >  runtime)

replaces runtime options

Parameters
runtimea hash of runtime options to use to replace the current runtime option hash
See also
Since
TableMapper 1.1.1

◆ resetCount()

TableMapper::InboundTableMapperIterator::resetCount ( )

resets the internal record count

See also
getCount()

◆ setRuntime() [1/2]

TableMapper::InboundTableMapperIterator::setRuntime ( hash< auto >  runtime)

adds runtime options to the current runtime option hash

Parameters
runtimea hash of runtime options to add to the current runtime option hash
See also
Since
TableMapper 1.1.1

◆ setRuntime() [2/2]

TableMapper::InboundTableMapperIterator::setRuntime ( string  key,
auto  value 
)

set the runtime option with "key" to value "value"

Parameters
keya string with valid runtime key
valueanything passed to the current runtime key
See also
Since
TableMapper 1.1.1