Mercurial > pub > Impl
comparison Lib/IMPL/ORM.pm @ 0:03e58a454b20
Создан репозитарий
author | Sergey |
---|---|
date | Tue, 14 Jul 2009 12:54:37 +0400 |
parents | |
children | 16ada169ca75 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:03e58a454b20 |
---|---|
1 package IMPL::ORM; | |
2 use strict; | |
3 use warnings; | |
4 | |
5 use base qw(IMPL::Object); | |
6 use IMPL::Class::Property; | |
7 use Scalar::Util qw(weaken refaddr); | |
8 | |
9 use IMPL::Exception; | |
10 | |
11 our $Depth = 1; # çàãðóæàòü îáúåêò + 1 óðîâåíü äåòåé | |
12 our $UseProxy = 1; | |
13 | |
14 BEGIN { | |
15 private property _ObjectCache => prop_all; | |
16 private property _MapInstances => prop_all; | |
17 private property _WorkUnit => prop_all; | |
18 public property Schema => prop_all; | |
19 } | |
20 | |
21 sub ObjectInfoById { | |
22 my ($this,$oid) = @_; | |
23 | |
24 return $this->_ObjectCache->{$oid}; | |
25 } | |
26 | |
27 sub ObjectInfo { | |
28 my ($this,$inst) = @_; | |
29 | |
30 die new IMPL::InvalidOperationException("This method can be used only for a reference") unless ref $inst; | |
31 | |
32 return $this->_MapInstances->{refaddr $inst}; | |
33 } | |
34 | |
35 | |
36 1; | |
37 __END__ | |
38 =pod | |
39 =head1 SYNOPSIS | |
40 | |
41 use IMPL::ORM::Sql; | |
42 | |
43 my $DB = new IMPL::ORM::Sql("connection string"); | |
44 | |
45 local $IMPL::ORM::Depth = 1; # load childs only, no more | |
46 | |
47 my $artist = $DB->Lookup( Artist => { name => 'Beatles' } ); | |
48 | |
49 my $order = new Order(); | |
50 $order->AddItem($_) foreach $artist->Albums->List; | |
51 | |
52 $DB->Save($order); | |
53 | |
54 my $label = $artist->Albums->Index(0)->Label; | |
55 | |
56 $DB->Populate($label); #load $label | |
57 | |
58 =head1 DESCRIPTION | |
59 =head2 MEMBERS | |
60 =level 4 | |
61 =back | |
62 =head2 Variables | |
63 =head2 INTERNALS | |
64 =head3 Object Representation | |
65 | |
66 Êàæäûé êëàññ îòîáðàæàåìûé â èñòî÷íèê äàííûõ ïðåäñòàâëÿåòñÿ â âèäå íàáîðà | |
67 ñóùíîñòåé, êàæäàÿ èç êîòîðûõ ïðåäñòàâëÿåò ñîñòîÿíèå áàçîâîãî êëàññà. | |
68 | |
69 Foo entityFoo | |
70 Bar entityBar | |
71 Baz entityBaz | |
72 | |
73 Ïðè ñîõðàíåíèè âèðòóàëüíûõ ñâîéñòâ êëàññîâ â ñîîòâåòñòâóþùèõ ñóùíîñòÿõ çàâîäèòñÿ | |
74 äâà ïîëÿ - îäíî ïîä ñîõðàíåíèå ñîáñòâåííîãî çíà÷åíèÿ ñâîéñòâà, äðóãîå - äëÿ | |
75 õðåíåèÿ âèðòóàëüíîãî çíà÷åíèÿ. | |
76 | |
77 Foo | |
78 public virtual property Name => prop_all, {Type => String}; | |
79 | |
80 entityFoo | |
81 string m_Name - ñîáñòâåííîå çíà÷åíèå | |
82 string v_Name - âðòóàëüíîå çíà÷åíèå | |
83 | |
84 Êàæäûé ñîõðàíåííûé îáúåêò â áàçå èìååò ñîáñòâåííûé èäåíòèôèêàòîð. | |
85 Íîâûå îáúåêòû èäåíòèôèêàòîðà íå èìåþò, äî òåõ ïîð ïîêà îíè íå áóäóò ñîõðàíåíû. | |
86 | |
87 =head3 Object Cache | |
88 | |
89 Äëÿ ó÷åòà îáúåêòîâ, êîòîðûå ïðèñóòñòâóþò â èñòî÷íèêå äàííûõ èñïîëüçóåòñÿ êåø | |
90 îáúåêòîâ. Ñþäà ïîïàäàþò ïîëó÷åííûå èç áàçû îáúåêòû, à òàêæå âíîâü äîáàâëåííûå | |
91 îáúåêòû. | |
92 | |
93 ObjectInfo => { | |
94 instance => weak ref | |
95 _id => data source dependent id | |
96 state => {persistent|null|new|deleted} | |
97 work_unit => ref to the work unit where object is acting | |
98 } | |
99 | |
100 äàííàÿ ñòðóêòóðà äîñòóïíà ÷åðåç äâå ôóíêöèè ObjectInfoById è ObjectInfo | |
101 | |
102 =head3 Type mapping | |
103 | |
104 Èñòî÷íèê äàííûõ èìååò â ñåáå ñõåìó äàííûõ, êîòîðàÿ îïðåäåëÿåò íàáîð òèïîâ, | |
105 õðàíèìûõ â äàííîì èñòî÷íèêå. Åñòü íåñêîëüêî âèäîâ îòîáðàæåíèÿ òèïîâ: | |
106 | |
107 =level 4 | |
108 | |
109 =item 1 | |
110 | |
111 Îòîáðàæåíèå êëàññîâ, êîãäà êëàññ ðàññìàðèâàåòñÿ â èäå íàáîðà ñâîéñòâ | |
112 | |
113 =item | |
114 | |
115 Îòîáðàæåíèå êëàññîâ â îäíî çíà÷åíèå (íàïðìåð ñòðîêó, äàííûå è ò.ï.) | |
116 | |
117 =item | |
118 | |
119 Êëàññû, êîòîðûå íà ïðÿìóþ ðàáîòàþò ñ èñòî÷íèêîì äàííûõ, òàêèå êàê êîëëåêöèè. | |
120 | |
121 =back | |
122 | |
123 =cut |