NAME

Podius::Persistence::Media::RawData - File-based persistence sub-layer for raw data


SYNOPSIS

  # This example is not up to date and will not work
  use Podius::Persistence::Media::RawData;
  $data_root_dir = '/usr/local/project/data';
  $pm = new Podius::Persistence::Media::RawData($data_root_dir);
  $pm->insert(
    'students',
    [1, 2],
    [{ name => 'Tom', age => '22' }, { name => 'Bob', age => '34' }]
  );
  my $first_student_name = $pm->retrieve('students', [1])->[0]->{name};
  $pm->delete('students', [1]);


DESCRIPTION

This package implements File Based Raw Data Persistence Media for Podius Persistence Layer.

Data is stored in files. Unlike FileBased PM, where entire data for the table row is stored in one keyed file, there is an directory for every table raw named ``<table>/<key>'' and every column is stored in separate file named ``field_name.raw''. The directories are in the raw data base directory, which is specified in the constructor.

These virtual methods of the superclass are not implemented (because it is not a primary media): request_high_key, get_all_keys, get_all_tables.


REQUIREMENTS

the Podius::Persistence::Media manpage, the File::Operations manpage, the Exception manpage, the Debug manpage.


CONSTRUCTORS

new

description
Class constructor.

parameters
data_base_dir - raw data base directory, where all table key directories are

returns
New formed Media reference.


METHODS

begin

description
Starts transaction, which can be them submitted by submint method or aborted by rollback method.

parameters
None.

returns
None. Throws exception on failure.

commit

description
Commits transaction, started by begin method. All changes done during transaction to Persistence Media are commited.

parameters
None.

returns
None. Throws exception on failure.

rollback

description
Aborts transaction, started by begin method. All changes done during transaction to Persistence Media are restored.

parameters
None.

returns
None. Throws exception on failure.

insert

description
Inserts (new) given 'rows', referenced by 'keys' into 'table'.

parameters
  * table - name of table to insert data into.
If table is ARRAY ref - the last name in the array is taken as table name
and all rest are taken as supertable names and links in supertables to table
instance are created.
  * keys - array ref of row-keys to insert data into
  * complex_rows - array of elements, each representing data of one row to save.
Some of the row data will be saved in specified additional tables, instead of
the main table. One complex_row is an array of the form:
  [
    [ [ field, value ]* ],
  # [ add_table, [ [ kfield, kvalue ]* ],
  #   [ [ rfield, rvalue ]* ], [ [ lfield, [ lvalue* ] ]* ] ]*
  ]
returns
1 on success, otherwise exception is thrown.

update

description
Updates given 'rows', referenced by 'keys' inside 'table'.

parameters
  * table - name of table to update data in
  * keys - array ref of row-keys to insert data into
  * complex_rows - array of elements, each representing data of one row to save.
Some of the row data will be saved in specified additional tables, instead of
the main table. One complex_row is an array of the form:
  [
  # [ [ unmodified_field* ], [ unmodified_add_table_property* ] ],
    [ [ field, value ]* ],
  # [ add_table, [ [ kfield, kvalue ]* ],
  #   [ [ rfield, rvalue ]* ], [ [ lfield, [ lvalue* ] ]* ] ]*
  ]
returns
1 on success, otherwise exception is thrown.

retrieve

description
Retrieves and returns the 'rows' inside table 'table', referenced by 'keys'.

parameters
  * table - name of real table to retrieve data from
  * table_data - array of the form:
  [
    [ field* ],
  # [ add_table, [ ifield, [ cfield, cvalue ]* ],
  #   [ rfield* ], [ lfield* ] ]*
  ]
  * keys - array ref of row-keys to retrieve data from
  * out_of_tx - optional boolean flag, work outside of the transaction
returns
Array of complex_row. On failure exception is thrown. One complex_row (for one key) is an array of the form (according to table_data):
  [
    [ value* ],
  # [ [ rvalue* ], [ [ lvalue* ]* ] ]*
  ]

If any table key does not exist, Exception::Podius::NoTableKeyError is thrown.

delete

description
Deletes rows, referenced by 'keys' from table 'table'.

parameters
  * table - name of table to delete from.
If table is ARRAY ref - the last name in the array is taken as table name
and all rest are taken as supertable names and links in supertables to table
instance are deleted.
  * table_data - array of the form:
  [
  # [ add_table, [ ifield, [ cfield, cvalue ]* ] ]*
  ]
  * keys - array ref of row-keys to delete
returns
1 on success, otherwise exception is thrown.

trash

description
Restores rows (undo), referenced by 'keys' in table 'table'. This forgets all update changes done to rows pointed by keys.

Calling this method outside a transaction should have no effect.

parameters
The same as for delete method.

returns
1 on success, otherwise exception is thrown.