NAME

Podius::Persistence::ComponentPropertyMap - maps component properties to table fields


SYNOPSIS

  use Podius;
  use Podius::Persistence::ComponentPropertyMap;
  use Podius::ComponentClasses;
  use Data::NeatDump;
  my $map = new Podius::Persistence::ComponentPropertyMap;
  print_data_dump($map->prepare_pm_retrieve_component_data('Section'));
  print_data_dump($map->get_create_tables_data(@Podius::ComponentClasses::LIST));


DESCRIPTION

Defines standardized component mapping interface for persistence media(s) and provides default mapping.

Supports primary Persistence Media (table mapping) and secondary RawData Persistence Media (file mapping).


STATIC CONSTANTS

  $table_name_prefix - string
  $use_c_table_name_prefix - boolean
  $property_type_map - HASH { (property_type => property_map_entry)* }
  $property_name_map - HASH { ('c_type:p_name' => property_map_entry)* }
  $property_type_aliases - HASH { (property_type1 => property_type2)* }
  $property_name_aliases - HASH { ('c_type:p_name1'=>'c_type:p_name2')* }
  $inheritance_map - [ name, [ <super_type,id,real_type>_field_entry ] ]
  $high_key_map - [ name, [ <super_type,last_value>_field_entry ] ]
  $key_field_entry - <id>_field_entry == [ name, type, search-type ]
  $revision_field_entry - <revision>_f_e == [ name, type, search-type ]


REQUIREMENTS

the Exception manpage, the Debug manpage, the Podius::Component manpage.


CONSTRUCTOR

new

description
Class constructor.

parameters
Class name or instance.

returns
New formed component-property-map reference.


METHODS

prepare_pm_save_component_data

description
Forms data model suitable for PM save (insert, update) methods for given component.

parameters
  * component - instance of Podius::Component subclass
  * flag - 0: save all properties (default), 1: update only modified
returns
Two array of arrays (for primary and secondary PM), as described here:
  [
    # the commented in array included only when flag == 1
  # [ [ unmodified_field* ], [ unmodified_add_table_property* ] ],
    [ [ field, ftype, value ]* ],
    [ add_table,
      [ [ kfield, kvalue ]* ],
      [ [ rfield, rvalue ]* ],
      [ [ lfield, [ lvalue* ] ]* ]
    ]*
  ], [
    [ [ field, value ]* ],
  ]

prepare_pm_retrieve_component_data

description
Forms data model suitable for PM retrieve method for given component type.

parameters
  * concrete component type
  * property names to retrieve
returns
Two array of arrays (for primary and secondary PM), as described here:
  [
    [ [ field, ftype ]* ],
    [ add_table, [ ifield, [ cfield, cvalue ]* ],
      [ rfield* ], [ lfield* ] ]*
  ], [
    [ field* ],
  ]

init_component_from_pm_retrieve

description
Restores component from its representation in persistence media.

parameters
  * component
  * two array of arrays (for primary and secondary PM), as described here:
  [
    [ value* ],
    [ [ rvalue* ], [ [ lvalue* ]* ] ]*
  ], [
    [ value* ],
  ]
  * property names to retrieve
returns
None.

prepare_pm_delete_component_data

description
Forms data model suitable for PM delete method for given component type.

parameters
 * concrete component type
 * component id to delete (not used)
returns
Two array of arrays (for primary and secondary PM), as described here:
 [
        [ add_table, [ ifield, [ cfield, cvalue ]* ] ]*
 ], [
 ]

prepare_pm_find_components_data

description
Forms data model suitable for PM find_keys method for given component type.

parameters
 * component type (may be abstract)
 * query object
returns
Hash, as described here:
 {
   name => type,
 }

where type may be 0 (unknown), 1 (regular field), [ 2, delim ] (joined list).

get_table_name_by_component_type

description
Returns list of component table names for given component types.

returns
Array ref of scalars, as list of component table names, if the argument was array of scalars.

Scalar, as component table name, if the argument was scalar.

get_component_type_by_table_name

description
Returns list of component types for given component table names.

returns
Array ref of scalars, as list of component types, if the argument was array of scalars.

Scalar, as component type, if the argument was scalar.

get_create_tables_data

description
Returns information needed to create all tables for given component classes. This include inheritance table and for for each component class - main table and additional tables (included once). May be used for creating all project tables.

parameters
  * array ref of scalars, representing component classes,
we want to create tables for them
  * flag: 1 - don't include special tables, like inheritance, high_key etc.
returns
Array of arrays, as described here:
  [
    [ table, [ [ field, type, searchable ]* ] ]*
  ]

get_inheritance_table_names

description
Provides a name of inheritance table and names of its fields.

returns
Array of form:
  [
    table-name, [
      supertype-field-name,
      id-field-name,
      realtype-field-name,
    ]
  ]

get_high_key_table_names

description
Provides a name of inheritance table and names of its fields.

returns
Array of form:
  [
    table-name, [
      supertype-field-name,
      value-field-name,
    ]
  ]

get_key_field_name

description
Provides a name of the id field in component tables.

returns
Scalar.

get_revision_field_name

description
Provides a name of the revision field in component tables.

returns
Scalar.