diff Lib/IMPL/ORM/Schema.pm @ 30:dd4d72600c69

ORM in works
author Sergey
date Tue, 03 Nov 2009 16:31:47 +0300
parents 6d33f75c6e1f
children d59526f6310e
line wrap: on
line diff
--- a/Lib/IMPL/ORM/Schema.pm	Wed Oct 21 17:30:20 2009 +0400
+++ b/Lib/IMPL/ORM/Schema.pm	Tue Nov 03 16:31:47 2009 +0300
@@ -4,16 +4,24 @@
 
 use base qw(IMPL::DOM::Document);
 use IMPL::Class::Property;
+require IMPL::ORM::Schema::Entity;
+
+our %CTOR = (
+    'IMPL::DOM::Document' => sub { nodeName => 'Schema' }
+);
 
 BEGIN {
     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_all; 
 }
 
 sub CTOR {
     my ($this ) = @_;
     $this->mapValueTypes({});
     $this->mapReferenceTypes({});
+    $this->mapPending({});
 }
 
 # return an entity for the specified typename
@@ -32,6 +40,22 @@
     }
 }
 
+sub declareReferenceType {
+    my ($this,$typeName) = @_;
+    
+    my $entity = new IMPL::ORM::Schema::Entity($typeName);
+    
+    $this->mapPending->{$typeName} = $entity;
+    
+    return $this->mapReferenceTypes->{$typeName} = $entity;
+}
+
+sub _addReferenceType {
+    my ($this,$className) = @_;
+    
+    $this->mapReferenceTypes->{$className} = $className->ormGetSchema($this,delete $this->mapPending->{$className});
+}
+
 # returns valuetype name
 sub isValueType {
     my ($this,$typeName) = @_;
@@ -48,6 +72,28 @@
     return ($instances{$class} || ($instances{$class} = $class->new));
 }
 
+sub ValueTypes {
+    my ($this,%classes) = @_;
+    
+    $this = ref $this ? $this : $this->instance;
+    
+    $this->mapValueTypes->{$_} = $classes{$_} foreach keys %classes;
+}
+
+sub Classes {
+    my ($this,@classNames) = @_;
+    
+    $this = ref $this ? $this : $this->instance;
+    
+    $this->_addReferenceType($this->prefix . $_) foreach @classNames;
+}
+
+sub usePrefix {
+    my ($this,$prefix) = @_;
+    
+    (ref $this ? $this : $this->instance)->prefix($prefix);
+}
+
 1;
 
 __END__