changeset 42:4ff27cd051e3

updated ORM schema model
author Sergey
date Thu, 07 Jan 2010 15:34:42 +0300
parents c2e7f7c96bcd
children 009aa9ca2e48
files Lib/IMPL/ORM/Schema.pm Lib/IMPL/ORM/Schema/ValueType.pm
diffstat 2 files changed, 59 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/ORM/Schema.pm	Mon Nov 23 00:59:06 2009 +0300
+++ b/Lib/IMPL/ORM/Schema.pm	Thu Jan 07 15:34:42 2010 +0300
@@ -5,6 +5,7 @@
 use base qw(IMPL::DOM::Document);
 use IMPL::Class::Property;
 require IMPL::ORM::Schema::Entity;
+require IMPL::ORM::Schema::ValueType;
 
 our %CTOR = (
     'IMPL::DOM::Document' => sub { nodeName => 'Schema' }
@@ -47,13 +48,20 @@
     
     $this->mapPending->{$typeName} = $entity;
     
+    $this->appendChild($entity);
+    
     return $this->mapReferenceTypes->{$typeName} = $entity;
 }
 
 sub _addReferenceType {
     my ($this,$className) = @_;
     
-    $this->mapReferenceTypes->{$className} = $className->ormGetSchema($this,delete $this->mapPending->{$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
@@ -77,7 +85,10 @@
     
     $this = ref $this ? $this : $this->instance;
     
-    $this->mapValueTypes->{$_} = $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 {
@@ -101,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;
@@ -118,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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/IMPL/ORM/Schema/ValueType.pm	Thu Jan 07 15:34:42 2010 +0300
@@ -0,0 +1,31 @@
+package IMPL::ORM::Schema::ValueType;
+
+use strict;
+
+use base qw(IMPL::DOM::Node);
+
+our %CTOR = (
+    'IMPL::DOM::Node' => sub { nodeName => 'ValueType' }
+);
+
+use IMPL::Class::Property;
+
+BEGIN {
+    public property typeName => prop_all;
+    public property typeReflected => prop_all;
+}
+
+sub CTOR {
+    my ($this,$typeName,$typeReflected) = @_;
+    
+    $this->typeName($typeName);
+    $this->typeReflected($typeReflected);
+}
+
+1;
+
+__END__
+
+=pod
+
+=cut
\ No newline at end of file