diff Lib/IMPL/ORM/Schema.pm @ 38:d660fb38b7cc

small fixes ORM shema to SQL schema transformation
author Sergey
date Mon, 23 Nov 2009 17:57:07 +0300
parents d59526f6310e
children 009aa9ca2e48
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	Mon Nov 23 17:57:07 2009 +0300
@@ -5,15 +5,16 @@
 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' }
+    'IMPL::DOM::Document' => sub { nodeName => 'ORMSchema' }
 );
 
 BEGIN {
-    public property mapValueTypes => prop_get | owner_set;
-    public property mapReferenceTypes => prop_get | owner_set;
-    public property mapPending => prop_get | owner_set;
+    private property mapValueTypes => prop_all;
+    private property mapReferenceTypes => prop_all;
+    private property mapPending => prop_all;
     public property prefix => prop_get | owner_set; 
 }
 
@@ -45,6 +46,8 @@
     
     my $entity = new IMPL::ORM::Schema::Entity($typeName);
     
+    $this->appendChild($entity);
+    
     $this->mapPending->{$typeName} = $entity;
     
     return $this->mapReferenceTypes->{$typeName} = $entity;
@@ -53,7 +56,7 @@
 sub _addReferenceType {
     my ($this,$className) = @_;
     
-    $this->mapReferenceTypes->{$className} = $className->ormGetSchema($this,delete $this->mapPending->{$className});
+    $this->mapReferenceTypes->{$className} = $className->ormGetSchema($this,delete $this->mapPending->{$className} || $this->appendChild(new IMPL::ORM::Schema::Entity($className)));
 }
 
 # returns valuetype name
@@ -65,6 +68,12 @@
     return $this->mapValueTypes->{$typeName};
 }
 
+sub ReferenceTypes {
+    my ($this) = @_;
+    
+    values %{$this->mapReferenceTypes};
+}
+
 my %instances;
 sub instance {
     my ($class) = @_;
@@ -77,7 +86,12 @@
     
     $this = ref $this ? $this : $this->instance;
     
-    $this->mapValueTypes->{$_} = $classes{$_} foreach keys %classes;
+    $this->mapValueTypes->{$_} = $this->appendChild(
+        IMPL::ORM::Schema::ValueType->new(
+            name => $_,
+            mapper => $classes{$_}
+        )
+    ) foreach keys %classes;
 }
 
 sub Classes {