Mercurial > pub > Impl
diff Lib/IMPL/SQL/Schema/Traits.pm @ 168:6148f89bb7bf
IMPL::SQL::Schema::Traits::Diff alfa version
IMPL::lang added hash traits
author | sourcer |
---|---|
date | Mon, 16 May 2011 04:30:38 +0400 |
parents | 1f7a6d762394 |
children | fd92830036c3 |
line wrap: on
line diff
--- a/Lib/IMPL/SQL/Schema/Traits.pm Thu May 12 08:57:19 2011 +0400 +++ b/Lib/IMPL/SQL/Schema/Traits.pm Mon May 16 04:30:38 2011 +0400 @@ -6,9 +6,11 @@ use parent qw(IMPL::Object); use IMPL::Code::Loader(); -BEGIN { - IMPL::Code::Loader->Provide(__PACKAGE__); -} +# required for use with typeof operator +use IMPL::SQL::Schema::Constraint::PrimaryKey(); +use IMPL::SQL::Schema::Constraint::Index(); +use IMPL::SQL::Schema::Constraint::Unique(); +use IMPL::SQL::Schema::Constraint::ForeignKey(); ################################################### @@ -68,7 +70,11 @@ my ($this, $name, $columns) = @_; $this->{name} = $name; - $$this->{columns} = $columns; # list of columnNames + $this->{columns} = $columns; # list of columnNames +} + +sub constraintClass { + die new IMPL::NotImplementedException(); } ################################################## @@ -79,6 +85,8 @@ __PACKAGE__->PassThroughArgs; +use constant { constraintClass => typeof IMPL::SQL::Schema::Constraint::PrimaryKey }; + ################################################## package IMPL::SQL::Schema::Traits::Index; @@ -87,6 +95,8 @@ __PACKAGE__->PassThroughArgs; +use constant { constraintClass => typeof IMPL::SQL::Schema::Constraint::Index }; + ################################################## package IMPL::SQL::Schema::Traits::Unique; @@ -95,6 +105,8 @@ __PACKAGE__->PassThroughArgs; +use constant { constraintClass => typeof IMPL::SQL::Schema::Constraint::Unique }; + ################################################## package IMPL::SQL::Schema::Traits::ForeignKey; @@ -105,6 +117,8 @@ foreignColumns ); +use constant { constraintClass => typeof IMPL::SQL::Schema::Constraint::ForeignKey }; + our %CTOR = ( 'IMPL::SQL::Schema::Traits::Constraint' => sub { @_[0..1] } ); @@ -274,10 +288,10 @@ BEGIN { public property tableName => prop_get | owner_set; public property columnName => prop_get | owner_set; - public property columnType => prop_get | owner_set; - public property defaultValue => prop_get | owner_set; - public property isNullable => prop_get | owner_set; - public property options => prop_get | owner_set; + public property columnType => prop_all; + public property defaultValue => prop_all; + public property isNullable => prop_all; + public property options => prop_all; # hash diff format, (keys have a prefix '+' - add or update value, '-' remove value) } sub CTOR { @@ -297,10 +311,10 @@ return eval { my $column = $schema->GetTable($this->tableName)->GetColumn($this->columnName); - $column->SetType($this->columnType) if $this->columnType; - $column->SetNullable($this->isNullable) if $this->isNullable; - $column->SetDefaultValue($this->defaultValue) if $this->defaultValue; - $column->SetOptions($this->options) if $this->options; + $column->SetType($this->columnType) if defined $this->columnType; + $column->SetNullable($this->isNullable) if defined $this->isNullable; + $column->SetDefaultValue($this->defaultValue) if defined $this->defaultValue; + $column->SetOptions($this->options) if defined $this->options; return 1; } || 0; @@ -335,7 +349,7 @@ local $@; return eval { - $schema->GetTable($this->tableName)->AddConstraint($this->constraint); + $schema->GetTable($this->tableName)->AddConstraint($this->constraint->constraintClass, $this->constraint); return 1; } || 0;