comparison Lib/IMPL/SQL/Schema/Constraint.pm @ 167:1f7a6d762394

SQL schema in progress
author sourcer
date Thu, 12 May 2011 08:57:19 +0400
parents 76515373dac0
children 6148f89bb7bf
comparison
equal deleted inserted replaced
166:4267a2ac3d46 167:1f7a6d762394
1 package IMPL::SQL::Schema::Constraint;
1 use strict; 2 use strict;
2 package IMPL::SQL::Schema::Constraint; 3 use warnings;
4
5 use IMPL::lang qw(:declare :constants is);
6
3 use parent qw(IMPL::Object IMPL::Object::Disposable); 7 use parent qw(IMPL::Object IMPL::Object::Disposable);
4 8
5 use IMPL::Class::Property;
6 use IMPL::Class::Property::Direct; 9 use IMPL::Class::Property::Direct;
7 10
8 BEGIN { 11 BEGIN {
9 public _direct property name => prop_get; 12 public _direct property name => PROP_GET;
10 public _direct property table => prop_get; 13 public _direct property table => PROP_GET;
11 public _direct property columns => prop_get;
12 } 14 }
15
16 public property columns => PROP_GET | PROP_LIST | PROP_OWNERSET;
13 17
14 sub CTOR { 18 sub CTOR {
15 my ($this,%args) = @_; 19 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'); 20 is( $args{table}, typeof IMPL::SQL::Schema::Table ) or
21 die new IMPL::InvalidArgumentException("table argument must be a table object");
17 $this->{$name} = $args{'name'}; 22 $this->{$name} = $args{'name'};
18 $this->{$table} = $args{'table'}; 23 $this->{$table} = $args{'table'};
19 $this->{$columns} = [map { ResolveColumn($this->table,$_) } @{$args{'columns'}}]; 24 $this->columns( [map { ResolveColumn($this->table,$_) } @{$args{'columns'}}] );
20 } 25 }
21 26
22 sub ResolveColumn { 27 sub ResolveColumn {
23 my ($Table,$Column) = @_; 28 my ($Table,$Column) = @_;
24 29
43 } 48 }
44 49
45 sub Dispose { 50 sub Dispose {
46 my ($this) = @_; 51 my ($this) = @_;
47 52
48 delete @$this{$table,$columns}; 53 $this->columns([]);
54
55 delete $$this{$table};
56
49 $this->SUPER::Dispose; 57 $this->SUPER::Dispose;
50 } 58 }
59
60 sub SameValue {
61 my ($this,$other) = @_;
62
63 return 0 unless $this->columns->Count == $other->columns->Count;
64
65 for ( my $i=0; $i < $this->columns->Count; $i++ ) {
66 return 0 unless $this->columns->[$i]->name eq $other->columns->[$i]->name;
67 }
68
69 return 1;
70 }
51 1; 71 1;