All Classes Namespaces Functions Variables Groups Pages
TableMapper.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
/* TableMapper.qm Copyright 2014 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.
*/
// this module requires Qore 0.8.9 or better
// require type definitions everywhere
// enable all warnings
// requires the Mapper module
// requires the SqlUtil module
/* Version History
* 2014-01-03 v1.0: David Nichols <david@qore.org>
+ the initial version of the TableMapper module
*/
namespace TableMapper {
class InboundTableMapper : public Mapper::Mapper {
public:
// no public members
public :
public:
private :
SqlUtil::AbstractTable table;
SqlUtil::AbstractDatabase db;
public:
constructor(SqlUtil::Table table, hash map, *hash opts);
constructor(SqlUtil::AbstractTable table, hash map, *hash opts);
private checkMap();
private mapFieldType(string key, hash m, reference v, hash rec);
private bool hasMapping(hash fh);
private checkMapField(string k, reference fh, hash th);
hash validKeys();
hash optionKeys();
hash insertRowNoCommit(hash rec);
hash insertRow(hash rec);
nothing commit();
nothing rollback();
string getTableName();
SqlUtil::AbstractTable getTable();
};
class InboundTableMapperIterator : public Mapper::AbstractMapperIterator {
public:
public :
public:
private :
TableMapper::InboundTableMapper map;
int commit_limit;
int cnt = 0;
hash val;
public:
constructor(Qore::AbstractIterator i, SqlUtil::Table table, hash map, *hash opts, int commit_limit = 0);
constructor(Qore::AbstractIterator i, SqlUtil::AbstractTable table, hash map, *hash opts, int commit_limit = 0);
constructor(Qore::AbstractIterator i, TableMapper::InboundTableMapper map, int commit_limit = 0);
hash getValue();
bool next();
int commitLimit();
nothing commit();
nothing rollback();
string getTableName();
int getCount();
resetCount();
};
};
TableMapper::InboundTableMapperIterator::getTableName
string getTableName()
returns the table name
Mapper::AbstractMapperIterator::i
Qore::AbstractIterator i
TableMapper::InboundTableMapperIterator::commitLimit
int commitLimit()
returns the commit_limit value set in the constructor()
TableMapper::InboundTableMapperIterator::commit
nothing commit()
commits the transaction
TableMapper::InboundTableMapper::getTableName
string getTableName()
returns the table name
SqlUtil::AbstractTable
TableMapper::InboundTableMapperIterator
provides a hash iterator based on a InboundTableMapper object and an iterator input source; for each ...
Definition: TableMapper.qm.dox.h:240
TableMapper::InboundTableMapper::hasMapping
private bool hasMapping(hash fh)
returns True if the field has a mapping, False if not
TableMapper::InboundTableMapperIterator::commit_limit
int commit_limit
row commit limit (&lt;= 0 for no commits)
Definition: TableMapper.qm.dox.h:252
TableMapper::InboundTableMapper::validKeys
hash validKeys()
returns a list of valid field keys for this class (can be overridden in subclasses) ...
TableMapper::InboundTableMapperIterator::next
bool next()
Moves the current position of the input iterator to the next element; returns False if there are no m...
TableMapper::InboundTableMapper::optionKeys
hash optionKeys()
returns a list of valid constructor options for this class (can be overridden in subclasses) ...
TableMapper::InboundTableMapper::insertRowNoCommit
hash insertRowNoCommit(hash rec)
inserts a row into the target table based on a mapped input record; does not commit the transaction ...
TableMapper::InboundTableMapper::checkMap
private checkMap()
verifies the input map in the constructor
TableMapper::InboundTableMapper::rollback
nothing rollback()
rolls back the transaction
TableMapper::InboundTableMapperIterator::val
hash val
a copy of the last hash value mapped
Definition: TableMapper.qm.dox.h:258
Mapper::Mapper
TableMapper::InboundTableMapperIterator::constructor
constructor(Qore::AbstractIterator i, SqlUtil::Table table, hash map, *hash opts, int commit_limit=0)
creates the iterator from the arguments passed
TableMapper::InboundTableMapperIterator::resetCount
resetCount()
resets the internal record count
TableMapper::InboundTableMapper::checkMapField
private checkMapField(string k, reference fh, hash th)
perform per-field pre-processing on the passed map in the constructor
TableMapper::InboundTableMapper::getTable
SqlUtil::AbstractTable getTable()
returns the underlying SqlUtil::AbstractTable object
Mapper::AbstractMapperIterator
TableMapper::InboundTableMapperIterator::rollback
nothing rollback()
rolls back the transaction
TableMapper::InboundTableMapperIterator::getCount
int getCount()
returns the internal record count
TableMapper::InboundTableMapper::commit
nothing commit()
commits the transaction
TableMapper::InboundTableMapperIterator::cnt
int cnt
row count for commit
Definition: TableMapper.qm.dox.h:255
TableMapper::InboundTableMapper::db
SqlUtil::AbstractDatabase db
the target Database object in case sequence value need to be acquired
Definition: TableMapper.qm.dox.h:107
TableMapper::InboundTableMapperIterator::map
TableMapper::InboundTableMapper map
data mapper
Definition: TableMapper.qm.dox.h:249
TableMapper::InboundTableMapperIterator::getValue
hash getValue()
returns the current row transformed with the mapper
Mapper::Mapper::constructor
private constructor()
SqlUtil::Table
Mapper::Mapper::map
hash map
TableMapper::InboundTableMapper
provides an inbound data mapper to a Table target
Definition: TableMapper.qm.dox.h:94
TableMapper::InboundTableMapper::insertRow
hash insertRow(hash rec)
inserts a row into the target table based on a mapped input record; commits the transaction ...
hash
hash hash(object obj)
SqlUtil::AbstractDatabase
TableMapper::InboundTableMapper::table
SqlUtil::AbstractTable table
the target table object
Definition: TableMapper.qm.dox.h:104
Qore::AbstractIterator
TableMapper::InboundTableMapper::mapFieldType
private mapFieldType(string key, hash m, reference v, hash rec)
performs type handling