Mercurial > pub > Impl
annotate Lib/IMPL/SQL/Schema/Constraint.pm @ 377:a0d342ac9a36
sync
author | cin |
---|---|
date | Tue, 14 Jan 2014 20:06:36 +0400 |
parents | 77df11605d3a |
children |
rev | line source |
---|---|
167 | 1 package IMPL::SQL::Schema::Constraint; |
49 | 2 use strict; |
167 | 3 use warnings; |
4 | |
280 | 5 use IMPL::lang; |
278 | 6 use IMPL::Const qw(:prop); |
7 use IMPL::declare { | |
8 base => [ | |
9 'IMPL::Object' => undef, | |
10 'IMPL::Object::Disposable' => undef | |
11 ], | |
12 props => [ | |
13 name => PROP_RO | PROP_DIRECT, | |
14 table => PROP_RO | PROP_DIRECT, | |
15 columns => PROP_RO | PROP_LIST | |
16 ] | |
17 }; | |
167 | 18 |
168 | 19 my %aliases; |
20 | |
49 | 21 sub CTOR { |
22 my ($this,%args) = @_; | |
167 | 23 is( $args{table}, typeof IMPL::SQL::Schema::Table ) or |
194 | 24 die new IMPL::InvalidArgumentException("table argument must be a table object"); |
165 | 25 $this->{$name} = $args{'name'}; |
26 $this->{$table} = $args{'table'}; | |
167 | 27 $this->columns( [map { ResolveColumn($this->table,$_) } @{$args{'columns'}}] ); |
49 | 28 } |
29 | |
30 sub ResolveColumn { | |
31 my ($Table,$Column) = @_; | |
32 | |
271
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
232
diff
changeset
|
33 my $cn = is($Column,'IMPL::SQL::Schema::Column') ? $Column->name : $Column; |
49 | 34 |
168 | 35 my $resolved = $Table->GetColumn($cn); |
165 | 36 die new IMPL::InvalidOperationException("The column is not found in the table", $cn, $Table->name) if not $resolved; |
49 | 37 return $resolved; |
38 } | |
39 | |
40 sub HasColumn { | |
41 my ($this,@Columns) = @_; | |
42 | |
43 my %Columns = map { $_, 1} @Columns; | |
44 | |
168 | 45 return scalar(grep { $Columns{$_->name} } $this->columns ) == scalar(@Columns); |
49 | 46 } |
47 | |
165 | 48 sub uniqName { |
49 | 49 my ($this) = @_; |
165 | 50 return $this->{$table}->name.'_'.$this->{$name}; |
49 | 51 } |
52 | |
53 sub Dispose { | |
54 my ($this) = @_; | |
55 | |
167 | 56 $this->columns([]); |
57 | |
58 delete $$this{$table}; | |
59 | |
49 | 60 $this->SUPER::Dispose; |
61 } | |
167 | 62 |
63 sub SameValue { | |
194 | 64 my ($this,$other) = @_; |
65 | |
66 return 0 unless $this->columns->Count == $other->columns->Count; | |
67 | |
68 for ( my $i=0; $i < $this->columns->Count; $i++ ) { | |
69 return 0 unless $this->columns->[$i]->name eq $other->columns->[$i]->name; | |
70 } | |
71 | |
72 return 1; | |
167 | 73 } |
168 | 74 |
75 sub ResolveAlias { | |
194 | 76 my ($self,$alias) = @_; |
77 | |
271
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
232
diff
changeset
|
78 return isclass($alias, typeof IMPL::SQL::Schema::Constraint) ? $alias : $aliases{$alias}; |
168 | 79 } |
80 | |
81 sub RegisterAlias { | |
194 | 82 my ($self,$alias) = @_; |
83 | |
315 | 84 $aliases{$alias} = typeof($self); |
168 | 85 } |
86 | |
49 | 87 1; |