Mercurial > pub > Impl
changeset 43:009aa9ca2e48
merge
author | Sergey |
---|---|
date | Thu, 07 Jan 2010 15:41:49 +0300 |
parents | 4ff27cd051e3 (diff) c442eb67fa22 (current diff) |
children | 32d2350fccf9 |
files | Lib/IMPL/ORM/Schema.pm Lib/IMPL/ORM/Schema/ValueType.pm |
diffstat | 2 files changed, 51 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/Lib/IMPL/ORM/Schema.pm Mon Dec 21 17:40:09 2009 +0300 +++ b/Lib/IMPL/ORM/Schema.pm Thu Jan 07 15:41:49 2010 +0300 @@ -8,13 +8,13 @@ require IMPL::ORM::Schema::ValueType; our %CTOR = ( - 'IMPL::DOM::Document' => sub { nodeName => 'ORMSchema' } + 'IMPL::DOM::Document' => sub { nodeName => 'Schema' } ); BEGIN { - private property mapValueTypes => prop_all; - private property mapReferenceTypes => prop_all; - private property mapPending => prop_all; + public property mapValueTypes => prop_get | owner_set; + public property mapReferenceTypes => prop_get | owner_set; + public property mapPending => prop_get | owner_set; public property prefix => prop_get | owner_set; } @@ -46,9 +46,9 @@ my $entity = new IMPL::ORM::Schema::Entity($typeName); - $this->appendChild($entity); + $this->mapPending->{$typeName} = $entity; - $this->mapPending->{$typeName} = $entity; + $this->appendChild($entity); return $this->mapReferenceTypes->{$typeName} = $entity; } @@ -56,7 +56,12 @@ sub _addReferenceType { my ($this,$className) = @_; - $this->mapReferenceTypes->{$className} = $className->ormGetSchema($this,delete $this->mapPending->{$className} || $this->appendChild(new IMPL::ORM::Schema::Entity($className))); + if ( my $entity = delete $this->mapPending->{$className} ) { + $className->ormGetSchema($this,$entity); + } else { + return $this->appendChild( $this->mapReferenceTypes->{$className} = $className->ormGetSchema($this) ); + } + } # returns valuetype name @@ -68,12 +73,6 @@ return $this->mapValueTypes->{$typeName}; } -sub ReferenceTypes { - my ($this) = @_; - - values %{$this->mapReferenceTypes}; -} - my %instances; sub instance { my ($class) = @_; @@ -86,12 +85,10 @@ $this = ref $this ? $this : $this->instance; - $this->mapValueTypes->{$_} = $this->appendChild( - IMPL::ORM::Schema::ValueType->new( - name => $_, - mapper => $classes{$_} - ) - ) foreach keys %classes; + while ( my ($typeName,$typeReflected) = each %classes ) { + $this->mapValueTypes->{$typeName} = $typeReflected; + $this->appendChild(IMPL::ORM::Schema::ValueType->new($typeName,$typeReflected)); + } } sub Classes { @@ -115,8 +112,7 @@ $this = ref $this ? $this : $this->instance; - $this->mapReferenceTypes->{$_} = $_->ormGetSchema($this,delete $this->mapPending->{$_}) - foreach (keys %{$this->mapPending}); + $_->ormGetSchema($this,delete $this->mapPending->{$_}) foreach (keys %{$this->mapPending}); } 1; @@ -132,4 +128,18 @@ Каждый узел - это описание сущности. +<Schema> + <Entity entityName="My_Data_Foo"> + <Field fieldName="Doo" fieldType="String"/> + <HasMany name="Boxes" target="My_Data_Box"/> + </Entity> + <Entity entityName="My_Data_Bar"> + <Subclass base="My_Data_Foo"/> + <Field fieldName="Timestamp" fieldType="Integer"/> + </Entity> + <Entity entityName="My_Data_Box"> + <Field fieldName="Capacity" fieldType="Integer"/> + </Entity> +</Schema> + =cut \ No newline at end of file
--- a/Lib/IMPL/ORM/Schema/ValueType.pm Mon Dec 21 17:40:09 2009 +0300 +++ b/Lib/IMPL/ORM/Schema/ValueType.pm Thu Jan 07 15:41:49 2010 +0300 @@ -1,22 +1,31 @@ package IMPL::ORM::Schema::ValueType; + use strict; -use warnings; use base qw(IMPL::DOM::Node); + +our %CTOR = ( + 'IMPL::DOM::Node' => sub { nodeName => 'ValueType' } +); + use IMPL::Class::Property; -use IMPL::DOM::Property qw(_dom); BEGIN { - public _dom property name => prop_all; - public _dom property mapper => prop_all; + public property typeName => prop_all; + public property typeReflected => prop_all; } -our %CTOR = ( - 'IMPL::DOM::Node' => sub { - my %args = @_; - $args{nodeName} = 'ValueType'; - %args; - } -); +sub CTOR { + my ($this,$typeName,$typeReflected) = @_; + + $this->typeName($typeName); + $this->typeReflected($typeReflected); +} 1; + +__END__ + +=pod + +=cut \ No newline at end of file