diff Lib/IMPL/ORM.pm @ 0:03e58a454b20

Создан репозитарий
author Sergey
date Tue, 14 Jul 2009 12:54:37 +0400
parents
children 16ada169ca75
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/IMPL/ORM.pm	Tue Jul 14 12:54:37 2009 +0400
@@ -0,0 +1,123 @@
+package IMPL::ORM;
+use strict;
+use warnings;
+
+use base qw(IMPL::Object);
+use IMPL::Class::Property;
+use Scalar::Util qw(weaken refaddr);
+
+use IMPL::Exception;
+
+our $Depth = 1; # çàãðóæàòü îáúåêò + 1 óðîâåíü äåòåé
+our $UseProxy = 1;
+
+BEGIN {
+    private property _ObjectCache => prop_all;
+    private property _MapInstances => prop_all;
+    private property _WorkUnit => prop_all;
+    public property Schema => prop_all;
+}
+
+sub ObjectInfoById {
+    my ($this,$oid) = @_;
+    
+    return $this->_ObjectCache->{$oid};
+}
+
+sub ObjectInfo {
+    my ($this,$inst) = @_;
+    
+    die new IMPL::InvalidOperationException("This method can be used only for a reference") unless ref $inst;
+    
+    return $this->_MapInstances->{refaddr $inst};
+}
+
+
+1;
+__END__
+=pod
+=head1 SYNOPSIS
+
+use IMPL::ORM::Sql;
+
+my $DB = new IMPL::ORM::Sql("connection string");
+
+local $IMPL::ORM::Depth = 1; # load childs only, no more
+
+my $artist = $DB->Lookup( Artist => { name => 'Beatles' } );
+
+my $order = new Order();
+$order->AddItem($_) foreach $artist->Albums->List;
+
+$DB->Save($order);
+
+my $label = $artist->Albums->Index(0)->Label;
+
+$DB->Populate($label); #load $label
+
+=head1 DESCRIPTION
+=head2 MEMBERS
+=level 4
+=back
+=head2 Variables
+=head2 INTERNALS
+=head3 Object Representation
+
+Êàæäûé êëàññ îòîáðàæàåìûé â èñòî÷íèê äàííûõ ïðåäñòàâëÿåòñÿ â âèäå íàáîðà
+ñóùíîñòåé, êàæäàÿ èç êîòîðûõ ïðåäñòàâëÿåò ñîñòîÿíèå áàçîâîãî êëàññà.
+
+Foo         entityFoo
+    Bar         entityBar
+    Baz         entityBaz
+
+Ïðè ñîõðàíåíèè âèðòóàëüíûõ ñâîéñòâ êëàññîâ â ñîîòâåòñòâóþùèõ ñóùíîñòÿõ çàâîäèòñÿ
+äâà ïîëÿ - îäíî ïîä ñîõðàíåíèå ñîáñòâåííîãî çíà÷åíèÿ ñâîéñòâà, äðóãîå - äëÿ
+õðåíåèÿ âèðòóàëüíîãî çíà÷åíèÿ.
+
+Foo
+    public virtual property Name => prop_all, {Type => String};
+    
+entityFoo
+    string m_Name - ñîáñòâåííîå çíà÷åíèå
+    string v_Name - âðòóàëüíîå çíà÷åíèå
+    
+Êàæäûé ñîõðàíåííûé îáúåêò â áàçå èìååò ñîáñòâåííûé èäåíòèôèêàòîð.
+Íîâûå îáúåêòû èäåíòèôèêàòîðà íå èìåþò, äî òåõ ïîð ïîêà îíè íå áóäóò ñîõðàíåíû.
+
+=head3 Object Cache
+
+Äëÿ ó÷åòà îáúåêòîâ, êîòîðûå ïðèñóòñòâóþò â èñòî÷íèêå äàííûõ èñïîëüçóåòñÿ êåø
+îáúåêòîâ. Ñþäà ïîïàäàþò ïîëó÷åííûå èç áàçû îáúåêòû, à òàêæå âíîâü äîáàâëåííûå
+îáúåêòû.
+
+ObjectInfo => {
+    instance => weak ref
+    _id => data source dependent id
+    state => {persistent|null|new|deleted}
+    work_unit => ref to the work unit where object is acting
+}
+
+äàííàÿ ñòðóêòóðà äîñòóïíà ÷åðåç äâå ôóíêöèè ObjectInfoById è ObjectInfo
+
+=head3 Type mapping
+
+Èñòî÷íèê äàííûõ èìååò â ñåáå ñõåìó äàííûõ, êîòîðàÿ îïðåäåëÿåò íàáîð òèïîâ,
+õðàíèìûõ â äàííîì èñòî÷íèêå. Åñòü íåñêîëüêî âèäîâ îòîáðàæåíèÿ òèïîâ:
+
+=level 4
+
+=item 1
+
+Îòîáðàæåíèå êëàññîâ, êîãäà êëàññ ðàññìàðèâàåòñÿ â èäå íàáîðà ñâîéñòâ
+
+=item
+
+Îòîáðàæåíèå êëàññîâ â îäíî çíà÷åíèå (íàïðìåð ñòðîêó, äàííûå è ò.ï.)
+
+=item
+
+Êëàññû, êîòîðûå íà ïðÿìóþ ðàáîòàþò ñ èñòî÷íèêîì äàííûõ, òàêèå êàê êîëëåêöèè.
+
+=back
+
+=cut
\ No newline at end of file