comparison 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
comparison
equal deleted inserted replaced
37:c2e7f7c96bcd 38:d660fb38b7cc
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 => 'ORMSchema' }
11 ); 12 );
12 13
13 BEGIN { 14 BEGIN {
14 public property mapValueTypes => prop_get | owner_set; 15 private property mapValueTypes => prop_all;
15 public property mapReferenceTypes => prop_get | owner_set; 16 private property mapReferenceTypes => prop_all;
16 public property mapPending => prop_get | owner_set; 17 private property mapPending => prop_all;
17 public property prefix => prop_get | owner_set; 18 public property prefix => prop_get | owner_set;
18 } 19 }
19 20
20 sub CTOR { 21 sub CTOR {
21 my ($this ) = @_; 22 my ($this ) = @_;
43 sub declareReferenceType { 44 sub declareReferenceType {
44 my ($this,$typeName) = @_; 45 my ($this,$typeName) = @_;
45 46
46 my $entity = new IMPL::ORM::Schema::Entity($typeName); 47 my $entity = new IMPL::ORM::Schema::Entity($typeName);
47 48
49 $this->appendChild($entity);
50
48 $this->mapPending->{$typeName} = $entity; 51 $this->mapPending->{$typeName} = $entity;
49 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 $this->mapReferenceTypes->{$className} = $className->ormGetSchema($this,delete $this->mapPending->{$className} || $this->appendChild(new IMPL::ORM::Schema::Entity($className)));
57 } 60 }
58 61
59 # returns valuetype name 62 # returns valuetype name
60 sub isValueType { 63 sub isValueType {
61 my ($this,$typeName) = @_; 64 my ($this,$typeName) = @_;
62 65
63 $this = ref $this ? $this : $this->instance; 66 $this = ref $this ? $this : $this->instance;
64 67
65 return $this->mapValueTypes->{$typeName}; 68 return $this->mapValueTypes->{$typeName};
69 }
70
71 sub ReferenceTypes {
72 my ($this) = @_;
73
74 values %{$this->mapReferenceTypes};
66 } 75 }
67 76
68 my %instances; 77 my %instances;
69 sub instance { 78 sub instance {
70 my ($class) = @_; 79 my ($class) = @_;
75 sub ValueTypes { 84 sub ValueTypes {
76 my ($this,%classes) = @_; 85 my ($this,%classes) = @_;
77 86
78 $this = ref $this ? $this : $this->instance; 87 $this = ref $this ? $this : $this->instance;
79 88
80 $this->mapValueTypes->{$_} = $classes{$_} foreach keys %classes; 89 $this->mapValueTypes->{$_} = $this->appendChild(
90 IMPL::ORM::Schema::ValueType->new(
91 name => $_,
92 mapper => $classes{$_}
93 )
94 ) foreach keys %classes;
81 } 95 }
82 96
83 sub Classes { 97 sub Classes {
84 my ($this,@classNames) = @_; 98 my ($this,@classNames) = @_;
85 99