changeset 27:b544a772b654

ORM in progress
author Sergey
date Fri, 16 Oct 2009 16:37:53 +0400
parents c529d386d80e
children 6d33f75c6e1f
files Lib/IMPL/Class/PropertyInfo.pm Lib/IMPL/ORM/Entity.pm Lib/IMPL/ORM/MapInfo.pm Lib/IMPL/ORM/Object.pm Lib/IMPL/ORM/Sql.pm Lib/IMPL/ORM/WorkUnit.pm impl.kpf
diffstat 7 files changed, 166 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/Class/PropertyInfo.pm	Thu Oct 15 17:52:09 2009 +0400
+++ b/Lib/IMPL/Class/PropertyInfo.pm	Fri Oct 16 16:37:53 2009 +0400
@@ -11,6 +11,10 @@
 sub CTOR {
     my $this = shift;
     
+    if ( my $type = $this->Attributes ? delete $this->Attributes->{type} : undef ) {
+        $this->Type($type);
+    }
+    
     $this->Mutators(0) unless defined $this->Mutators;
 }
 
--- a/Lib/IMPL/ORM/Entity.pm	Thu Oct 15 17:52:09 2009 +0400
+++ b/Lib/IMPL/ORM/Entity.pm	Fri Oct 16 16:37:53 2009 +0400
@@ -2,12 +2,43 @@
 use strict;
 use warnings;
 
-use base qw(IMPL::DOM::Node);
+use base qw(IMPL::Object);
 use IMPL::Class::Property;
+use IMPL::Class::Property::Direct;
+
+BEGIN {
+    public _direct property Name => prop_get;
+    public _direct property Class => prop_get;
+    public _direct property Values => prop_get;
+    public _direct property Schema => prop_get;
+}
+
+sub CTOR {
+    my ($this,$class,$schema) = @_;
+    
+    
+}
 
-# Name
-# Fields
-# Relations
+sub Store;
+*Store = \&dbgStore;
 
+sub dbgStore {
+    my ($this,$prop,$value) = @_;
+    
+    if ( my $container = $this->{$Values}{$prop} ) {
+        if ($container->{type} eq 'SCALAR') {
+            
+        } else {
+            
+        }
+        
+    } else {
+        die new IMPL::InvalidOperationException("Property not found",$this->Name,$prop);
+    }
+}
+
+sub Get {
+    
+}
 
 1;
--- a/Lib/IMPL/ORM/MapInfo.pm	Thu Oct 15 17:52:09 2009 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-use strict;
-use warnings;
-
-package IMPL::ORM::MapInfo;
-use base qw(IMPL::Object);
-use IMPL::Class::Property;
-
-BEGIN {
-    public property Entities => prop_all;
-    public property Cumulative => prop_all;
-}
-
-package IMPL::ORM::MapEntityInfo;
-use base qw(IMPL::Object IMPL::Object::Autofill);
-use IMPL::Class::Property;
-
-BEGIN {
-    public property Name => prop_all;
-    public property Fields => prop_all;
-}
-
-1;
--- 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
--- a/Lib/IMPL/ORM/Sql.pm	Thu Oct 15 17:52:09 2009 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-package IMPL::ORM::Sql;
-use strict;
-use warnings;
-
-require Exporter;
-our @ISA = qw(Exporter);
-our @EXPORT_OK = qw();
-
-
-
-1;
--- a/Lib/IMPL/ORM/WorkUnit.pm	Thu Oct 15 17:52:09 2009 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
-package IMPL::ORM::WorkUnit;
-use strict;
-use warnings;
-
-use base qw(IMPL::Object);
-
-
-1;
--- a/impl.kpf	Thu Oct 15 17:52:09 2009 +0400
+++ b/impl.kpf	Fri Oct 16 16:37:53 2009 +0400
@@ -274,6 +274,58 @@
 </preference-set>
   <string id="lastInvocation">default</string>
 </preference-set>
+<preference-set idref="66c7d414-175f-45b6-92fe-dbda51c64843/Lib/IMPL/ORM/Entity.pm">
+<preference-set id="Invocations">
+<preference-set id="default">
+  <string id="cookieparams"></string>
+  <string id="cwd"></string>
+  <long id="debugger.io-port">9011</long>
+  <string id="documentRoot"></string>
+  <string id="executable-params"></string>
+  <string relative="path" id="filename">Lib/IMPL/ORM/Entity.pm</string>
+  <string id="getparams"></string>
+  <string id="language">Perl</string>
+  <string id="mpostparams"></string>
+  <string id="params"></string>
+  <string id="postparams"></string>
+  <string id="posttype">application/x-www-form-urlencoded</string>
+  <string id="request-method">GET</string>
+  <boolean id="show-dialog">1</boolean>
+  <boolean id="sim-cgi">0</boolean>
+  <boolean id="use-console">0</boolean>
+  <string id="userCGIEnvironment"></string>
+  <string id="userEnvironment"></string>
+  <string id="warnings">enabled</string>
+</preference-set>
+</preference-set>
+  <string id="lastInvocation">default</string>
+</preference-set>
+<preference-set idref="66c7d414-175f-45b6-92fe-dbda51c64843/Lib/IMPL/ORM/Object.pm">
+<preference-set id="Invocations">
+<preference-set id="default">
+  <string id="cookieparams"></string>
+  <string id="cwd"></string>
+  <long id="debugger.io-port">9011</long>
+  <string id="documentRoot"></string>
+  <string id="executable-params"></string>
+  <string relative="path" id="filename">Lib/IMPL/ORM/Object.pm</string>
+  <string id="getparams"></string>
+  <string id="language">Perl</string>
+  <string id="mpostparams"></string>
+  <string id="params"></string>
+  <string id="postparams"></string>
+  <string id="posttype">application/x-www-form-urlencoded</string>
+  <string id="request-method">GET</string>
+  <boolean id="show-dialog">1</boolean>
+  <boolean id="sim-cgi">0</boolean>
+  <boolean id="use-console">0</boolean>
+  <string id="userCGIEnvironment"></string>
+  <string id="userEnvironment"></string>
+  <string id="warnings">enabled</string>
+</preference-set>
+</preference-set>
+  <string id="lastInvocation">default</string>
+</preference-set>
 <preference-set idref="66c7d414-175f-45b6-92fe-dbda51c64843/Lib/IMPL/Object.pm">
 <preference-set id="Invocations">
 <preference-set id="default">