Mercurial > pub > Impl
comparison Lib/IMPL/ORM/Schema.pm @ 42:4ff27cd051e3
updated ORM schema model
author | Sergey |
---|---|
date | Thu, 07 Jan 2010 15:34:42 +0300 |
parents | d59526f6310e |
children | 009aa9ca2e48 |
comparison
equal
deleted
inserted
replaced
37:c2e7f7c96bcd | 42:4ff27cd051e3 |
---|---|
3 use warnings; | 3 use warnings; |
4 | 4 |
5 use base qw(IMPL::DOM::Document); | 5 use base qw(IMPL::DOM::Document); |
6 use IMPL::Class::Property; | 6 use IMPL::Class::Property; |
7 require IMPL::ORM::Schema::Entity; | 7 require IMPL::ORM::Schema::Entity; |
8 require IMPL::ORM::Schema::ValueType; | |
8 | 9 |
9 our %CTOR = ( | 10 our %CTOR = ( |
10 'IMPL::DOM::Document' => sub { nodeName => 'Schema' } | 11 'IMPL::DOM::Document' => sub { nodeName => 'Schema' } |
11 ); | 12 ); |
12 | 13 |
45 | 46 |
46 my $entity = new IMPL::ORM::Schema::Entity($typeName); | 47 my $entity = new IMPL::ORM::Schema::Entity($typeName); |
47 | 48 |
48 $this->mapPending->{$typeName} = $entity; | 49 $this->mapPending->{$typeName} = $entity; |
49 | 50 |
51 $this->appendChild($entity); | |
52 | |
50 return $this->mapReferenceTypes->{$typeName} = $entity; | 53 return $this->mapReferenceTypes->{$typeName} = $entity; |
51 } | 54 } |
52 | 55 |
53 sub _addReferenceType { | 56 sub _addReferenceType { |
54 my ($this,$className) = @_; | 57 my ($this,$className) = @_; |
55 | 58 |
56 $this->mapReferenceTypes->{$className} = $className->ormGetSchema($this,delete $this->mapPending->{$className}); | 59 if ( my $entity = delete $this->mapPending->{$className} ) { |
60 $className->ormGetSchema($this,$entity); | |
61 } else { | |
62 return $this->appendChild( $this->mapReferenceTypes->{$className} = $className->ormGetSchema($this) ); | |
63 } | |
64 | |
57 } | 65 } |
58 | 66 |
59 # returns valuetype name | 67 # returns valuetype name |
60 sub isValueType { | 68 sub isValueType { |
61 my ($this,$typeName) = @_; | 69 my ($this,$typeName) = @_; |
75 sub ValueTypes { | 83 sub ValueTypes { |
76 my ($this,%classes) = @_; | 84 my ($this,%classes) = @_; |
77 | 85 |
78 $this = ref $this ? $this : $this->instance; | 86 $this = ref $this ? $this : $this->instance; |
79 | 87 |
80 $this->mapValueTypes->{$_} = $classes{$_} foreach keys %classes; | 88 while ( my ($typeName,$typeReflected) = each %classes ) { |
89 $this->mapValueTypes->{$typeName} = $typeReflected; | |
90 $this->appendChild(IMPL::ORM::Schema::ValueType->new($typeName,$typeReflected)); | |
91 } | |
81 } | 92 } |
82 | 93 |
83 sub Classes { | 94 sub Classes { |
84 my ($this,@classNames) = @_; | 95 my ($this,@classNames) = @_; |
85 | 96 |
99 sub CompleteSchema { | 110 sub CompleteSchema { |
100 my ($this) = @_; | 111 my ($this) = @_; |
101 | 112 |
102 $this = ref $this ? $this : $this->instance; | 113 $this = ref $this ? $this : $this->instance; |
103 | 114 |
104 $this->mapReferenceTypes->{$_} = $_->ormGetSchema($this,delete $this->mapPending->{$_}) | 115 $_->ormGetSchema($this,delete $this->mapPending->{$_}) foreach (keys %{$this->mapPending}); |
105 foreach (keys %{$this->mapPending}); | |
106 } | 116 } |
107 | 117 |
108 1; | 118 1; |
109 | 119 |
110 __END__ | 120 __END__ |
116 Схема данных, представляет собой DOM документ, элементами которой | 126 Схема данных, представляет собой DOM документ, элементами которой |
117 являются сущности. | 127 являются сущности. |
118 | 128 |
119 Каждый узел - это описание сущности. | 129 Каждый узел - это описание сущности. |
120 | 130 |
131 <Schema> | |
132 <Entity entityName="My_Data_Foo"> | |
133 <Field fieldName="Doo" fieldType="String"/> | |
134 <HasMany name="Boxes" target="My_Data_Box"/> | |
135 </Entity> | |
136 <Entity entityName="My_Data_Bar"> | |
137 <Subclass base="My_Data_Foo"/> | |
138 <Field fieldName="Timestamp" fieldType="Integer"/> | |
139 </Entity> | |
140 <Entity entityName="My_Data_Box"> | |
141 <Field fieldName="Capacity" fieldType="Integer"/> | |
142 </Entity> | |
143 </Schema> | |
144 | |
121 =cut | 145 =cut |