Qore TableMapper Module Reference 1.0

- Main Page
- Related Pages
- Namespaces
- Classes

All Classes Namespaces Functions Variables Groups Pages
TableMapper.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3
4 /* TableMapper.qm Copyright 2014 Qore Technologies, sro
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 // this module requires Qore 0.8.10 or better
26
27 // require type definitions everywhere
28
29 // enable all warnings
30
31 // requires the Mapper module
32 // requires the SqlUtil module
33
34
35 /* Version History
36 * 2014-01-03 v1.0: David Nichols <david@qore.org>
37 + the initial version of the TableMapper module
38 */
39
91 namespace TableMapper {
94 class InboundTableMapper : public Mapper::Mapper {
95
96 public:
97 // no public members
98 public :
99
100 public:
101
102 private :
104 SqlUtil::AbstractTable table;
105
107 SqlUtil::AbstractDatabase db;
108
109 public:
110
112
136 constructor(SqlUtil::Table table, hash map, *hash opts);
137
138
140
164 constructor(SqlUtil::AbstractTable table, hash map, *hash opts);
165
166
168 private checkMap();
169
170
172 private mapFieldType(string key, hash m, reference v, hash rec);
173
174
176 private bool hasMapping(hash fh);
177
178
180
183 private checkMapField(string k, reference fh, hash th);
184
185
187
189 hash validKeys();
190
191
193
195 hash optionKeys();
196
197
199
207 hash insertRowNoCommit(hash rec);
208
209
211
219 hash insertRow(hash rec);
220
221
223 nothing commit();
224
225
227 nothing rollback();
228
229
231 string getTableName();
232
233
235 SqlUtil::AbstractTable getTable();
236
237 };
238
240 class InboundTableMapperIterator : public Mapper::AbstractMapperIterator {
241
242 public:
243 public :
244
245 public:
246
247 private :
249 TableMapper::InboundTableMapper map;
250
252 int commit_limit;
253
255 int cnt = 0;
256
258 hash val;
259
260 public:
261
263
290 constructor(Qore::AbstractIterator i, SqlUtil::Table table, hash map, *hash opts, int commit_limit = 0);
291
292
294
321 constructor(Qore::AbstractIterator i, SqlUtil::AbstractTable table, hash map, *hash opts, int commit_limit = 0);
322
323
325
348 constructor(Qore::AbstractIterator i, TableMapper::InboundTableMapper map, int commit_limit = 0);
349
350
352 hash getValue();
353
354
356
360 bool next();
361
362
364 int commitLimit();
365
366
368 nothing commit();
369
370
372 nothing rollback();
373
374
376 string getTableName();
377
378
380
382 int getCount();
383
384
386
388 resetCount();
389
390 };
391 };
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