Mercurial > pub > Impl
comparison Lib/Schema/DB/Constraint.pm @ 0:03e58a454b20
Создан репозитарий
author | Sergey |
---|---|
date | Tue, 14 Jul 2009 12:54:37 +0400 |
parents | |
children | 16ada169ca75 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:03e58a454b20 |
---|---|
1 package Schema::DB::Constraint; | |
2 use Common; | |
3 our @ISA = qw(Object); | |
4 | |
5 BEGIN { | |
6 DeclareProperty Name => ACCESS_READ; | |
7 DeclareProperty Table => ACCESS_READ; | |
8 DeclareProperty Columns => ACCESS_READ; | |
9 } | |
10 | |
11 sub CTOR { | |
12 my ($this,%args) = @_; | |
13 die new Exception("The table argument must be an instance of a table object") if not UNIVERSAL::isa($args{'Table'},'Schema::DB::Table'); | |
14 $this->{$Name} = $args{'Name'}; | |
15 $this->{$Table} = $args{'Table'}; | |
16 $this->{$Columns} = [map { ResolveColumn($this->Table,$_) } @{$args{'Columns'}}]; | |
17 } | |
18 | |
19 sub ResolveColumn { | |
20 my ($Table,$Column) = @_; | |
21 | |
22 my $cn = UNIVERSAL::isa($Column,'Schema::DB::Column') ? $Column->Name : $Column; | |
23 | |
24 my $resolved = $Table->Column($cn); | |
25 die new Exception("The column is not found in the table", $cn, $Table->Name) if not $resolved; | |
26 return $resolved; | |
27 } | |
28 | |
29 sub HasColumn { | |
30 my ($this,@Columns) = @_; | |
31 | |
32 my %Columns = map { $_, 1} @Columns; | |
33 | |
34 return scalar(grep { $Columns{$_->Name} } $this->Columns) == scalar(@Columns); | |
35 } | |
36 | |
37 sub UniqName { | |
38 my ($this) = @_; | |
39 return $this->{$Table}->Name.'_'.$this->{$Name}; | |
40 } | |
41 | |
42 sub Dispose { | |
43 my ($this) = @_; | |
44 | |
45 delete @$this{$Table,$Columns}; | |
46 $this->SUPER::Dispose; | |
47 } | |
48 1; |