annotate Lib/IMPL/ORM.pm @ 31:d59526f6310e

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