All Classes Namespaces Functions Variables Groups Pages
TableMapper::InboundTableMapper Class Reference

provides an inbound data mapper to a Table target More...

Inheritance diagram for TableMapper::InboundTableMapper:
[legend]

## Public Member Functions

private | checkMap ()
| verifies the input map in the constructor
private | checkMapField (string k, reference fh, hash th)
| perform per-field pre-processing on the passed map in the constructor More...
nothing | commit ()
| commits the transaction
| constructor (SqlUtil::Table table, hash map, *hash opts)
| builds the object based on a hash providing field mappings, data constraints, and optionally custom mapping logic More...
| constructor (SqlUtil::AbstractTable table, hash map, *hash opts)
| builds the object based on a hash providing field mappings, data constraints, and optionally custom mapping logic More...
SqlUtil::AbstractTable | getTable ()
| returns the underlying SqlUtil::AbstractTable object
string | getTableName ()
| returns the table name
private bool | hasMapping (hash fh)
| returns True if the field has a mapping, False if not
hash | insertRow (hash rec)
| inserts a row into the target table based on a mapped input record; commits the transaction More...
hash | insertRowNoCommit (hash rec)
| inserts a row into the target table based on a mapped input record; does not commit the transaction More...
private | mapFieldType (string key, hash m, reference v, hash rec)
| performs type handling
hash | optionKeys ()
| returns a list of valid constructor options for this class (can be overridden in subclasses) More...
nothing | rollback ()
| rolls back the transaction
hash | validKeys ()
| returns a list of valid field keys for this class (can be overridden in subclasses) More...

## Private Attributes

SqlUtil::AbstractDatabase | db
| the target Database object in case sequence value need to be acquired
SqlUtil::AbstractTable | table
| the target table object

## Detailed Description

provides an inbound data mapper to a Table target

## Member Function Documentation

private TableMapper::InboundTableMapper::checkMapField | ( | string | k,
|  | reference | fh,
|  | hash | th
| ) |  |

perform per-field pre-processing on the passed map in the constructor

Parameters

  k | the field name
  fh | a reference to the field's value in the map

TableMapper::InboundTableMapper::constructor | ( | SqlUtil::Table | table,
|  | hash | map,
|  | *hash | opts
| ) |  |

builds the object based on a hash providing field mappings, data constraints, and optionally custom mapping logic

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(); },
  );
  my InboundTableMapper $map($table, DbMapper);

Parameters

  table | the target table object
  map | a hash providing field mappings; each hash key is the name of the output field; 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 documnentation for this option
  opts | an optional hash of options for the mapper; see Mapper Options for a description of valid mapper options

Exceptions

  MAP-ERROR | the map hash has a logical error (ex: `"trunc"` key given without `"maxlen"`, invalid map key)

TableMapper::InboundTableMapper::constructor | ( | SqlUtil::AbstractTable | table,
|  | hash | map,
|  | *hash | opts
| ) |  |

builds the object based on a hash providing field mappings, data constraints, and optionally custom mapping logic

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(); },
  );
  my InboundTableMapper $map($table, DbMapper);

Parameters

  table | the target table object
  map | a hash providing field mappings; each hash key is the name of the output field; 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 documnentation for this option
  opts | an optional hash of options for the mapper; see Mapper Options for a description of valid mapper options

Exceptions

  MAP-ERROR | the map hash has a logical error (ex: `"trunc"` key given without `"maxlen"`, invalid map key)

hash TableMapper::InboundTableMapper::insertRow | ( | hash | rec | ) |

inserts a row into the target table based on a mapped input record; commits the transaction

Parameters

  $rec | the input record

Returns
  a hash of the row values inserted (column: value), not including the extra values

Exceptions

  MISSING-INPUT | a field marked mandatory is missing
  STRING-TOO-LONG | a field value exceeds the maximum value and the 'trunc' key is not set
  INVALID-NUMBER | the field is marked as numeric but the input value contains non-numeric data

hash TableMapper::InboundTableMapper::insertRowNoCommit | ( | hash | rec | ) |

inserts a row into the target table based on a mapped input record; does not commit the transaction

Parameters

  $rec | the input record

Returns
  a hash of the row values inserted (row name: value)

Exceptions

  MISSING-INPUT | a field marked mandatory is missing
  STRING-TOO-LONG | a field value exceeds the maximum value and the 'trunc' key is not set
  INVALID-NUMBER | the field is marked as numeric but the input value contains non-numeric data

hash TableMapper::InboundTableMapper::optionKeys | ( |  | ) |

returns a list of valid constructor options for this class (can be overridden in subclasses)

Returns
  a list of valid constructor options for this class (can be overridden in subclasses)

hash TableMapper::InboundTableMapper::validKeys | ( |  | ) |

returns a list of valid field keys for this class (can be overridden in subclasses)

Returns
  a list of valid field keys for this class (can be overridden in subclasses)