Adrian Witas > Persistence-Entity > Persistence::Meta::XML

Download:
Persistence-Entity-0.07.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.04   Source  

NAME ^

Persistence::Meta::XML - Persistence meta object xml injection

SYNOPSIS ^

   use Persistence::Meta::XML;
   my $meta = Persistence::Meta::XML->new(persistence_dir => 'meta/');
   my $entity_manager = $meta->inject('my_persistence.xml');
   #or
   # $meta->inject('my_persistence.xml');
   # my $entity_manager = Persistence::Entity::Manager->manager('manager_name');

DESCRIPTION ^

Loads xml files that containt meta persistence definition.

    persistence.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence name="test"  connection_name="test" >
        <entities>
            <entity_file  file="emp.xml"  />
            <entity_file  file="dept.xml" />
        </entities>
        <mapping_rules>
            <orm_file file="Employee.xml" />
            <orm_file file="Department.xml" />
        </mapping_rules>
    </persistence>

    emp.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <entity name="emp" alias="e">
        <primary_key>empno</primary_key>
        <columns>
            <column name="empno" />
            <column name="ename" unique="1" />
            <column name="sal" />
            <column name="job" />
            <column name="deptno" />
        </columns>
        <subquery_columns>
            <subquery_column name="dname" entity="dept" />
        </subquery_columns>
    </entity>

    dept.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <entity name="dept" alias="d">
        <primary_key>deptno</primary_key>
        <columns>
            <column name="deptno" />
            <column name="dname"  unique="1" />
            <column name="loc" />
        </columns>
        <to_many_relationships>
            <relationship target_entity="emp" order_by="deptno, empno">
                <join_column>deptno</join_column>
            </relationship>
        </to_many_relationships>
    </entity>

    Employee.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <orm entity="emp"  class="Employee" >
        <column name="empno"  attribute="id" />
        <column name="ename"  attribute="name" />
        <column name="job"    attribute="job" />
        <column name="dname"  attribute="dept_name" />
        <to_one_relationship  name="dept" attribute="dept" fetch_method="EAGER" cascade="ALL"/>
    </orm>

    Department.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <orm entity="dept"  class="Department" >
        <column name="deptno" attribute="id" />
        <column name="dname" attribute="name" />
        <column name="loc" attribute="location" />
        <one_to_many_relationship  name="emp" attribute="employees" fetch_method="EAGER" cascade="ALL"/>
    </orm>


    package Employee;
    use Abstract::Meta::Class ':all';

    has '$.id';
    has '$.name';
    has '$.job';
    has '$.dept_name';
    has '$.dept' => (associated_class => 'Department');

    package Department;
    use Abstract::Meta::Class ':all';

    has '$.id';
    has '$.name';
    has '$.location';
    has '@.employees' => (associated_class => 'Employee');

    my $meta = Persistence::Meta::XML->new(persistence_dir => $dir);
    my $entity_manager = $meta->inject('persistence.xml');

    my ($dept) = $entity_manager->find(dept => 'Department', name => 'dept3');

    my $enp = Employee->new(id => 88, name => 'emp88');
    $enp->set_dept(Department->new(id => 99, name => 'd99'));
    $entity_manager->insert($enp);

EXPORT ^

None

ATTRIBUTES

cache_dir

Containts cache directory.

use_cache

Flag that indicates if cache is used.

persistence_dir

Directory for xml meta persistence definition.

persistence_dir

Contains directory of xml files that contain persistence object definition.

injection

METHODS

initialise
inject

Injects persistence xml definition. Takes xml file definition

    my $meta = Persistence::Meta::XML->new(persistence_dir => $dir);
    my $entity_manager = $meta->inject('persistence.xml');
persistence_xml_handler

Retunds xml handlers that will transform the persistence xml into objects. Persistence node is mapped to the Persistence::Entity::Manager;

    <!ELEMENT persistence (entities+,mapping_rules*, value_generators*)>
    <!ATTLIST persistence name #REQUIRED>
    <!ATTLIST persistence connection_name #REQUIRED>
    <!ELEMENT entities (entity_file+)>
    <!ELEMENT entity_file (filter_condition_value+ .dml_filter_value) >
    <!ATTLIST entity_file file id order_index>
    <!ELEMENT mapping_rules (orm_file+)>
    <!ATTLIST mapping_rules file>
    <!ELEMENT value_generators (sequence_generator*, table_generator*)>
    <!ELEMENT sequence_generator>
    <!ATTLIST sequence_generator name sequence_name allocation_size>
    <!ELEMENT table_generator>
    <!ATTLIST table_generator name table primary_key_column_name primary_key_column_value value_column allocation_size>

    <?xml version='1.0' encoding='UTF-8'?>
    <persistence name="test"  connection_name="test" >
        <entities>
            <entity_file file="emp.xml"  />
            <entity_file file="dept.xml"  />
        </entities>
        <mapping_rules>
            <orm_file file="Employee" />
        </mapping_rules>
        <value_generators>
            <sequence_generator name="pk_generator" sequence_name="cust_seq" allocation_size="1" />
            <table_generator name="pk_generator" table="primary_key_generator" primary_key_column_name="pk_column" primary_key_column_value="empno" value_column="alue_column" allocation_size="20" />
        </value_generators>
    </persistence>
add_xml_persistence_handlers

Adds persistence xml handlers/ Takes Simple::SAX::Serializer object as parameter.

orm_xml_handler
    <!ELEMENT orm (column+, lob+, to_one_relationship*, one_to_many_relationship*, many_to_many_relationship*)
    <!ATTRLIST orm class entity mop_attribute_adapter>
    <!ELEMENT column>
    <!ATTRLIST column name attribute>
    <!ELEMENT lob name attribute fetch_method>
    <!ELEMENT to_one_relationship>
    <!ATTRLIST to_one_relationship name attribute #REQUIRED>
    <!ATTRLIST to_one_relationship fetch_method (LAZY|EAGER) "LAZY">
    <!ATTRLIST to_one_relationship cascade (NONE|ALL|ON_INSERT|ON_UPDATE|ON_DELETE) "NONE">

    <orm entity="emp"  class="Employee" >
        <column name="empno" attribute="id" />
        <column name="ename" attribute="name" />
        <column name="job" attribute="job" />
        <to_one_relationship name="dept" attribute="depts" fetch_method="LAZY" cascade="ALL">
    </orm>

    many_to_many 'project' => (
        attribute        => has('%.projects' => (associated_class => 'Project'), index_by => 'name'),
        join_entity_name => 'emp_project',
        fetch_method     => LAZY,
        cascade          => ALL,
    );
orm_xml_handler

Retunds xml handlers that will transform the orm xml into Persistence::ORM object

add_orm_xml_handlers

Adds orm xml handler to Simple::SAX::Serializer object.

entity_xml_handler

Retunds xml handlers that will transform the enity xml into Persistence::Entity

    <!ELEMENT entity (primary_key*, indexes?, columns?, lobs?, subquery_columns?,
    filter_condition_value+ .dml_filter_value+, to_one_relationships? to_many_relationships?, value_generators*)>
    <!ATTLIST entity id name alias unique_expression query_from schema order_index>
    <!ELEMENT primary_key (#PCDATA)>
    <!ELEMENT indexes (index+)>
    <!ELEMENT index (index_columns+)>
    <!ATTLIST index name hint>
    <!ELEMENT index_columns (#PCDATA)>
    <!ELEMENT columns (column+) >
    <!ELEMENT lobs (lob+) >
    <!ELEMENT subquery_columns (subquery_column+)>
    <!ELEMENT subquery_column>
    <!ATTLIST subquery_column entity name>
    <!ELEMENT column>
    <!ATTLIST column id name unique expression case_sensitive queryable insertable updatable>
    <!ELEMENT lob>
    <!ATTLIST lob id name siz_column>
    <!ELEMENT filter_condition_values (#PCDATA)>
    <!ATTLIST filter_condition_values name #REQUIRED>
    <!ELEMENT dml_filter_values (#PCDATA)>
    <!ATTLIST dml_filter_values name #REQUIRED>
    <!ELEMENT to_one_relationships (relationship+)>
    <!ELEMENT to_many_relationships (relationship+)>
    <!ELEMENT relationship (join_columns*, condition?)>
    <!ATTLIST relationship  name target_entity order_by>
    <!ELEMENT join_columns (#PCDATA)>
    <!ELEMENT condition (condition+) >
    <!ATTLIST condition operand1  operator operand2 relation>
    <!ELEMENT value_generators (#PCDATA)>

    For instnace.
    <?xml version="1.0" encoding="UTF-8"?>
    <entity name="emp" alias="e">
        <primary_key>empno</primary_key>
        <indexes>
            <index name="emp_idx_empno" hint="INDEX_ASC(e emp_idx_empno)">
                <index_column>ename</index_column>
            </index>
            <index name="emp_idx_ename">
                <index_column>empno</index_column>
            </index>
        </indexes>
        <columns>
            <column name="empno" />
            <column name="ename" />
        </columns>
        <lobs>
            <lob name="blob_content" size_column="doc_size" />
         </lobs>
        <subquery_columns>
            <subquery_column name="dname" entity_id="dept" />
        </subquery_columns>
        <to_one_relationships>
            <relationship target_entity="dept">
                <join_column>deptno</join_column>
            </relationship>
        </to_one_relationships>
    </entity>
add_entity_xml_handlers

Adds entity xml handler to the Simple::SAX::Serializer object.

cache_file_name

Returns fulle path to cache file, takes persistence file name.

TOO DO ^

Add caching of xml.

SEE ALSO ^

Simple::SAX::Handler

COPYRIGHT AND LICENSE ^

The Persistence::Meta::Xml module is free software. You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.

AUTHOR ^

Adrian Witas,adrian@webapp.strefa.pl

syntax highlighting: