49
|
1 use strict;
|
|
2 package IMPL::SQL::Schema::Constraint;
|
165
|
3 use parent qw(IMPL::Object IMPL::Object::Disposable);
|
49
|
4
|
|
5 use IMPL::Class::Property;
|
|
6 use IMPL::Class::Property::Direct;
|
|
7
|
|
8 BEGIN {
|
165
|
9 public _direct property name => prop_get;
|
|
10 public _direct property table => prop_get;
|
|
11 public _direct property columns => prop_get;
|
49
|
12 }
|
|
13
|
|
14 sub CTOR {
|
|
15 my ($this,%args) = @_;
|
165
|
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'};
|
|
18 $this->{$table} = $args{'table'};
|
|
19 $this->{$columns} = [map { ResolveColumn($this->table,$_) } @{$args{'columns'}}];
|
49
|
20 }
|
|
21
|
|
22 sub ResolveColumn {
|
|
23 my ($Table,$Column) = @_;
|
|
24
|
165
|
25 my $cn = UNIVERSAL::isa($Column,'IMPL::SQL::Schema::Column') ? $Column->name : $Column;
|
49
|
26
|
|
27 my $resolved = $Table->Column($cn);
|
165
|
28 die new IMPL::InvalidOperationException("The column is not found in the table", $cn, $Table->name) if not $resolved;
|
49
|
29 return $resolved;
|
|
30 }
|
|
31
|
|
32 sub HasColumn {
|
|
33 my ($this,@Columns) = @_;
|
|
34
|
|
35 my %Columns = map { $_, 1} @Columns;
|
|
36
|
165
|
37 return scalar(grep { $Columns{$_->name} } @{$this->columns}) == scalar(@Columns);
|
49
|
38 }
|
|
39
|
165
|
40 sub uniqName {
|
49
|
41 my ($this) = @_;
|
165
|
42 return $this->{$table}->name.'_'.$this->{$name};
|
49
|
43 }
|
|
44
|
|
45 sub Dispose {
|
|
46 my ($this) = @_;
|
|
47
|
165
|
48 delete @$this{$table,$columns};
|
49
|
49 $this->SUPER::Dispose;
|
|
50 }
|
|
51 1;
|