# HG changeset patch
# User Sergey
# Date 1257255107 -10800
# Node ID dd4d72600c69c4c3e9284388e41075356c6c56ae
# Parent 37160f7c8edb61e5de349ade6482dcf2bb6ea8e7
ORM in works
diff -r 37160f7c8edb -r dd4d72600c69 Lib/IMPL/DOM/Node.pm
--- a/Lib/IMPL/DOM/Node.pm Wed Oct 21 17:30:20 2009 +0400
+++ b/Lib/IMPL/DOM/Node.pm Tue Nov 03 16:31:47 2009 +0300
@@ -42,7 +42,7 @@
return $node;
}
-sub appendNode {
+sub appendChild {
my ($this,$node) = @_;
die new IMPL::InvalidOperationException("You can't insert the node to itselft") if $this == $node;
@@ -57,6 +57,10 @@
return $node;
}
+sub appendNode {
+ goto &appendChild;
+}
+
sub appendRange {
my ($this,@range) = @_;
diff -r 37160f7c8edb -r dd4d72600c69 Lib/IMPL/ORM/Object.pm
--- a/Lib/IMPL/ORM/Object.pm Wed Oct 21 17:30:20 2009 +0400
+++ b/Lib/IMPL/ORM/Object.pm Tue Nov 03 16:31:47 2009 +0300
@@ -42,9 +42,9 @@
return $this->{$_entities}{$class} ? $this->{$_entities}{$class}->Get($prop,$value) : undef;
}
-#sub _PropertyImplementor {
-# 'IMPL::ORM::Property'
-#}
+sub _PropertyImplementor {
+ 'IMPL::ORM::PropertyImplementor'
+}
sub entityName {
(my $self = ref $_[0] || $_[0]) =~ s/::/_/g;
@@ -52,16 +52,16 @@
}
sub ormGetSchema {
- my ($self,$dataSchema) = @_;
+ my ($self,$dataSchema,$surrogate) = @_;
- my $schema = IMPL::ORM::Schema::Entity->new($self->entityName);
+ my $schema = $surrogate || IMPL::ORM::Schema::Entity->new($self->entityName);
# для текущего класса, проходим по всем свойствам
foreach my $ormProp (
$self->get_meta(
'IMPL::Class::PropertyInfo',
sub {
- UNIVERSAL::isa($_->Implementor, 'IMPL::ORM::Property' )
+ UNIVERSAL::isa($_->Implementor, 'IMPL::ORM::PropertyImplementor' )
},
0
)
@@ -92,7 +92,7 @@
# по всем классам
foreach my $super (grep $_->isa(__PACKAGE__), @{"${class}::ISA"}) {
my $type = $dataSchema->resolveType($super) or die new IMPL::InvalidOperationException("Failed to resolve a super class due building schema for a class", $class, $super);
- $schema->appentChild(new IMPL::ORM::Schema::Relation::Subclass($type));
+ $schema->appendChild(new IMPL::ORM::Schema::Relation::Subclass($type));
}
}
diff -r 37160f7c8edb -r dd4d72600c69 Lib/IMPL/ORM/PropertyImplementor.pm
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/IMPL/ORM/PropertyImplementor.pm Tue Nov 03 16:31:47 2009 +0300
@@ -0,0 +1,8 @@
+package IMPL::ORM::PropertyImplementor;
+use strict;
+use warnings;
+
+use base qw(IMPL::Class::Property::Direct);
+
+
+1;
diff -r 37160f7c8edb -r dd4d72600c69 Lib/IMPL/ORM/Schema.pm
--- 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__
diff -r 37160f7c8edb -r dd4d72600c69 Lib/IMPL/ORM/Schema/Relation/Subclass.pm
--- a/Lib/IMPL/ORM/Schema/Relation/Subclass.pm Wed Oct 21 17:30:20 2009 +0400
+++ b/Lib/IMPL/ORM/Schema/Relation/Subclass.pm Tue Nov 03 16:31:47 2009 +0300
@@ -10,7 +10,7 @@
}
our %CTOR = (
- 'IMPL::DOM::Node' => sub { 'Subclass' }
+ 'IMPL::ORM::Schema::Relation' => sub { 'Subclass' }
);
sub CTOR {
diff -r 37160f7c8edb -r dd4d72600c69 _test/ORM.t
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/_test/ORM.t Tue Nov 03 16:31:47 2009 +0300
@@ -0,0 +1,17 @@
+#!/usr/bin/perl -w
+use strict;
+use lib '../Lib';
+use lib '.';
+
+use IMPL::Test::Plan;
+use IMPL::Test::TAPListener;
+
+my $plan = new IMPL::Test::Plan qw(
+ Test::ORM::Schema
+);
+
+$plan->AddListener(new IMPL::Test::TAPListener);
+$plan->Prepare();
+$plan->Run();
+
+1;
\ No newline at end of file
diff -r 37160f7c8edb -r dd4d72600c69 _test/Test/ORM/Schema.pm
--- a/_test/Test/ORM/Schema.pm Wed Oct 21 17:30:20 2009 +0400
+++ b/_test/Test/ORM/Schema.pm Tue Nov 03 16:31:47 2009 +0300
@@ -1,10 +1,29 @@
package Test::ORM::Schema;
use strict;
use warnings;
+use base qw(IMPL::Test::Unit);
-require Exporter;
-our @ISA = qw(Exporter);
-our @EXPORT_OK = qw();
+__PACKAGE__->PassThroughArgs;
+
+use IMPL::Test qw(test failed);
+
+test ExtractClassSchema => sub {
+ my ($this) = @_;
+
+ my $schema = Test::ORM::Schema::Data::User->ormGetSchema('Test::ORM::Schema::Data');
+ failed "Wrong number of the elements","expected: 4","got: ".$schema->childNodes->Count unless $schema->childNodes->Count == 4;
+
+ return 1;
+};
+
+test StaticSchema => sub {
+ my ($this) = @_;
+
+ my $schema = Test::ORM::Schema::Data->instance;
+
+ return 1;
+};
+
package Test::ORM::Schema::Data::User;
use base qw(IMPL::ORM::Object);
@@ -39,13 +58,6 @@
package Test::ORM::Schema::Data;
use base qw(IMPL::ORM::Schema);
-__PACKAGE__->usePrefix(__PACKAGE__);
-__PACKAGE__->Classes qw(
- User
- Role
- Session
-);
-
__PACKAGE__->ValueTypes (
'String' => 'IMPL::ORM::Value::String',
'DateTime' => 'IMPL::ORM::Value::DateTime',
@@ -54,4 +66,11 @@
'Decimal' => 'IMPL::ORM::Value::Decimal'
);
+__PACKAGE__->usePrefix(__PACKAGE__);
+__PACKAGE__->Classes qw(
+ User
+ Role
+ Session
+);
+
1;
diff -r 37160f7c8edb -r dd4d72600c69 impl.kpf
--- a/impl.kpf Wed Oct 21 17:30:20 2009 +0400
+++ b/impl.kpf Tue Nov 03 16:31:47 2009 +0300
@@ -378,6 +378,32 @@
default
+
+
+
+
+
+ 9011
+
+
+ _test/ORM.t
+
+ Perl
+
+
+
+ application/x-www-form-urlencoded
+ GET
+ 1
+ 0
+ 0
+
+
+ enabled
+
+
+ default
+