Mercurial > pub > Impl
diff Lib/IMPL/ORM/Object.pm @ 27:b544a772b654
ORM in progress
author | Sergey |
---|---|
date | Fri, 16 Oct 2009 16:37:53 +0400 |
parents | fafe56cfcd69 |
children | 6d33f75c6e1f |
line wrap: on
line diff
--- a/Lib/IMPL/ORM/Object.pm Thu Oct 15 17:52:09 2009 +0400 +++ b/Lib/IMPL/ORM/Object.pm Fri Oct 16 16:37:53 2009 +0400 @@ -2,7 +2,81 @@ use strict; use warnings; -use base qw(IMPL::Object::Abstract); +use base qw(IMPL::Object); +use IMPL::Class::Property; +use IMPL::Class::Property::Direct; + +require IMPL::ORM::Entity; + +BEGIN { + private _direct property _entities => prop_all; +} + +my %schemaCache; + +sub CTOR { + my ($this) = @_; + + while ( my ($class,$schema) = $this->ormGetSchema ) { + $this->{$_entities}{$class} = new IMPL::ORM::Entity($class,$schema); + } +} + +sub ormStore { + my ($this,$class,$prop,$value) = @_; + + die IMPL::InvalidOperationException("Cannot find entity for the specified class",$class) unless $this->{$_entities}{$class}; + + $this->{$_entities}{$class}->Store($prop,$value); +} +sub ormGet { + my ($this,$class,$prop,$value) = @_; + + return $this->{$_entities}{$class} ? $this->{$_entities}{$class}->Get($prop,$value) : undef; +} + +sub _PropertyImplementor { + 'IMPL::ORM::Property' +} + +sub ormGetSchema { + my ($self) = @_; + + my $class = ref $self || $self; + + return $schemaCache{$class} if $schemaCache{$class}; + + my %schema; + + foreach my $ormProp ( + $self->get_meta( + 'IMPL::Class::PropertyInfo', + sub { + UNIVERSAL::isa($_->Implementor, 'IMPL::ORM::Property' ) + }, + 1 + ) + ){ + push @{$schema{$ormProp->Class}},{ + name => $ormProp->Name, + virtual => $ormProp->Virtual, + type => $ormProp->Type + }; + } + + return ($schemaCache{$class} = \%schema); +} 1; + +__END__ + +=pod + +=head1 DESCRIPTION + +Базовый объект для реляционного отображения, +содержит в себе реляционные записи представляющие данный объект. + +=cut \ No newline at end of file