comparison Lib/IMPL/SQL/Schema/Constraint.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 4d0e1962161c
comparison
equal deleted inserted replaced
167:1f7a6d762394 168:6148f89bb7bf
13 public _direct property table => PROP_GET; 13 public _direct property table => PROP_GET;
14 } 14 }
15 15
16 public property columns => PROP_GET | PROP_LIST | PROP_OWNERSET; 16 public property columns => PROP_GET | PROP_LIST | PROP_OWNERSET;
17 17
18 my %aliases;
19
18 sub CTOR { 20 sub CTOR {
19 my ($this,%args) = @_; 21 my ($this,%args) = @_;
20 is( $args{table}, typeof IMPL::SQL::Schema::Table ) or 22 is( $args{table}, typeof IMPL::SQL::Schema::Table ) or
21 die new IMPL::InvalidArgumentException("table argument must be a table object"); 23 die new IMPL::InvalidArgumentException("table argument must be a table object");
22 $this->{$name} = $args{'name'}; 24 $this->{$name} = $args{'name'};
27 sub ResolveColumn { 29 sub ResolveColumn {
28 my ($Table,$Column) = @_; 30 my ($Table,$Column) = @_;
29 31
30 my $cn = UNIVERSAL::isa($Column,'IMPL::SQL::Schema::Column') ? $Column->name : $Column; 32 my $cn = UNIVERSAL::isa($Column,'IMPL::SQL::Schema::Column') ? $Column->name : $Column;
31 33
32 my $resolved = $Table->Column($cn); 34 my $resolved = $Table->GetColumn($cn);
33 die new IMPL::InvalidOperationException("The column is not found in the table", $cn, $Table->name) if not $resolved; 35 die new IMPL::InvalidOperationException("The column is not found in the table", $cn, $Table->name) if not $resolved;
34 return $resolved; 36 return $resolved;
35 } 37 }
36 38
37 sub HasColumn { 39 sub HasColumn {
38 my ($this,@Columns) = @_; 40 my ($this,@Columns) = @_;
39 41
40 my %Columns = map { $_, 1} @Columns; 42 my %Columns = map { $_, 1} @Columns;
41 43
42 return scalar(grep { $Columns{$_->name} } @{$this->columns}) == scalar(@Columns); 44 return scalar(grep { $Columns{$_->name} } $this->columns ) == scalar(@Columns);
43 } 45 }
44 46
45 sub uniqName { 47 sub uniqName {
46 my ($this) = @_; 48 my ($this) = @_;
47 return $this->{$table}->name.'_'.$this->{$name}; 49 return $this->{$table}->name.'_'.$this->{$name};
66 return 0 unless $this->columns->[$i]->name eq $other->columns->[$i]->name; 68 return 0 unless $this->columns->[$i]->name eq $other->columns->[$i]->name;
67 } 69 }
68 70
69 return 1; 71 return 1;
70 } 72 }
73
74 sub ResolveAlias {
75 my ($self,$alias) = @_;
76
77 return is($alias, typeof IMPL::SQL::Schema::Constraint) ? $alias : $aliases{$alias};
78 }
79
80 sub RegisterAlias {
81 my ($self,$alias) = @_;
82
83 $aliases{$alias} = $self->typeof;
84 }
85
71 1; 86 1;