Mercurial > pub > Impl
comparison Lib/IMPL/SQL/Schema/Constraint.pm @ 165:76515373dac0
Added Class::Template,
Rewritten SQL::Schema
'use parent' directive instead of 'use base'
author | wizard |
---|---|
date | Sat, 23 Apr 2011 23:06:48 +0400 |
parents | 6ce1f052b90a |
children | 1f7a6d762394 |
comparison
equal
deleted
inserted
replaced
164:eb3e9861a761 | 165:76515373dac0 |
---|---|
1 use strict; | 1 use strict; |
2 package IMPL::SQL::Schema::Constraint; | 2 package IMPL::SQL::Schema::Constraint; |
3 use base qw(IMPL::Object IMPL::Object::Disposable IMPL::Object::Clonable); | 3 use parent qw(IMPL::Object IMPL::Object::Disposable); |
4 | 4 |
5 use IMPL::Class::Property; | 5 use IMPL::Class::Property; |
6 use IMPL::Class::Property::Direct; | 6 use IMPL::Class::Property::Direct; |
7 | 7 |
8 BEGIN { | 8 BEGIN { |
9 public _direct property Name => prop_get; | 9 public _direct property name => prop_get; |
10 public _direct property Table => prop_get; | 10 public _direct property table => prop_get; |
11 public _direct property Columns => prop_get; | 11 public _direct property columns => prop_get; |
12 } | 12 } |
13 | 13 |
14 sub CTOR { | 14 sub CTOR { |
15 my ($this,%args) = @_; | 15 my ($this,%args) = @_; |
16 die new IMPL::InvalidArgumentException("The table argument must be an instance of a table object") if not UNIVERSAL::isa($args{'Table'},'IMPL::SQL::Schema::Table'); | 16 die new IMPL::InvalidArgumentException("The table argument must be an instance of a table object") if not UNIVERSAL::isa($args{'table'},'IMPL::SQL::Schema::Table'); |
17 $this->{$Name} = $args{'Name'}; | 17 $this->{$name} = $args{'name'}; |
18 $this->{$Table} = $args{'Table'}; | 18 $this->{$table} = $args{'table'}; |
19 $this->{$Columns} = [map { ResolveColumn($this->Table,$_) } @{$args{'Columns'}}]; | 19 $this->{$columns} = [map { ResolveColumn($this->table,$_) } @{$args{'columns'}}]; |
20 } | 20 } |
21 | 21 |
22 sub ResolveColumn { | 22 sub ResolveColumn { |
23 my ($Table,$Column) = @_; | 23 my ($Table,$Column) = @_; |
24 | 24 |
25 my $cn = UNIVERSAL::isa($Column,'IMPL::SQL::Schema::Column') ? $Column->Name : $Column; | 25 my $cn = UNIVERSAL::isa($Column,'IMPL::SQL::Schema::Column') ? $Column->name : $Column; |
26 | 26 |
27 my $resolved = $Table->Column($cn); | 27 my $resolved = $Table->Column($cn); |
28 die new IMPL::InvalidOperationException("The column is not found in the table", $cn, $Table->Name) if not $resolved; | 28 die new IMPL::InvalidOperationException("The column is not found in the table", $cn, $Table->name) if not $resolved; |
29 return $resolved; | 29 return $resolved; |
30 } | 30 } |
31 | 31 |
32 sub HasColumn { | 32 sub HasColumn { |
33 my ($this,@Columns) = @_; | 33 my ($this,@Columns) = @_; |
34 | 34 |
35 my %Columns = map { $_, 1} @Columns; | 35 my %Columns = map { $_, 1} @Columns; |
36 | 36 |
37 return scalar(grep { $Columns{$_->Name} } @{$this->Columns}) == scalar(@Columns); | 37 return scalar(grep { $Columns{$_->name} } @{$this->columns}) == scalar(@Columns); |
38 } | 38 } |
39 | 39 |
40 sub UniqName { | 40 sub uniqName { |
41 my ($this) = @_; | 41 my ($this) = @_; |
42 return $this->{$Table}->Name.'_'.$this->{$Name}; | 42 return $this->{$table}->name.'_'.$this->{$name}; |
43 } | 43 } |
44 | 44 |
45 sub Dispose { | 45 sub Dispose { |
46 my ($this) = @_; | 46 my ($this) = @_; |
47 | 47 |
48 delete @$this{$Table,$Columns}; | 48 delete @$this{$table,$columns}; |
49 $this->SUPER::Dispose; | 49 $this->SUPER::Dispose; |
50 } | 50 } |
51 1; | 51 1; |