annotate Lib/IMPL/SQL/Schema/Constraint.pm @ 35:f25d021780b3

DOM::Navigator::Builder working version
author Sergey
date Tue, 17 Nov 2009 17:46:24 +0300
parents 0004faa276dc
children 16ada169ca75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
Sergey
parents:
diff changeset
1 use strict;
Sergey
parents:
diff changeset
2 package IMPL::SQL::Schema::Constraint;
Sergey
parents:
diff changeset
3 use base qw(IMPL::Object IMPL::Object::Disposable);
Sergey
parents:
diff changeset
4
Sergey
parents:
diff changeset
5 use IMPL::Class::Property;
Sergey
parents:
diff changeset
6 use IMPL::Class::Property::Direct;
Sergey
parents:
diff changeset
7
Sergey
parents:
diff changeset
8 BEGIN {
Sergey
parents:
diff changeset
9 public _direct property Name => prop_get;
Sergey
parents:
diff changeset
10 public _direct property Table => prop_get;
Sergey
parents:
diff changeset
11 public _direct property Columns => prop_get;
Sergey
parents:
diff changeset
12 }
Sergey
parents:
diff changeset
13
Sergey
parents:
diff changeset
14 sub CTOR {
Sergey
parents:
diff changeset
15 my ($this,%args) = @_;
Sergey
parents:
diff changeset
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');
Sergey
parents:
diff changeset
17 $this->{$Name} = $args{'Name'};
Sergey
parents:
diff changeset
18 $this->{$Table} = $args{'Table'};
Sergey
parents:
diff changeset
19 $this->{$Columns} = [map { ResolveColumn($this->Table,$_) } @{$args{'Columns'}}];
Sergey
parents:
diff changeset
20 }
Sergey
parents:
diff changeset
21
Sergey
parents:
diff changeset
22 sub ResolveColumn {
Sergey
parents:
diff changeset
23 my ($Table,$Column) = @_;
Sergey
parents:
diff changeset
24
Sergey
parents:
diff changeset
25 my $cn = UNIVERSAL::isa($Column,'IMPL::SQL::Schema::Column') ? $Column->Name : $Column;
Sergey
parents:
diff changeset
26
Sergey
parents:
diff changeset
27 my $resolved = $Table->Column($cn);
Sergey
parents:
diff changeset
28 die new IMPL::InvalidOperationException("The column is not found in the table", $cn, $Table->Name) if not $resolved;
Sergey
parents:
diff changeset
29 return $resolved;
Sergey
parents:
diff changeset
30 }
Sergey
parents:
diff changeset
31
Sergey
parents:
diff changeset
32 sub HasColumn {
Sergey
parents:
diff changeset
33 my ($this,@Columns) = @_;
Sergey
parents:
diff changeset
34
Sergey
parents:
diff changeset
35 my %Columns = map { $_, 1} @Columns;
Sergey
parents:
diff changeset
36
33
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
37 return scalar(grep { $Columns{$_->Name} } @{$this->Columns}) == scalar(@Columns);
32
Sergey
parents:
diff changeset
38 }
Sergey
parents:
diff changeset
39
Sergey
parents:
diff changeset
40 sub UniqName {
Sergey
parents:
diff changeset
41 my ($this) = @_;
Sergey
parents:
diff changeset
42 return $this->{$Table}->Name.'_'.$this->{$Name};
Sergey
parents:
diff changeset
43 }
Sergey
parents:
diff changeset
44
Sergey
parents:
diff changeset
45 sub Dispose {
Sergey
parents:
diff changeset
46 my ($this) = @_;
Sergey
parents:
diff changeset
47
Sergey
parents:
diff changeset
48 delete @$this{$Table,$Columns};
Sergey
parents:
diff changeset
49 $this->SUPER::Dispose;
Sergey
parents:
diff changeset
50 }
Sergey
parents:
diff changeset
51 1;