annotate Lib/IMPL/SQL/Schema/Constraint.pm @ 170:b88b7fe60aa3

refactoring
author sourcer
date Tue, 24 May 2011 01:11:16 +0400
parents 6148f89bb7bf
children 4d0e1962161c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
1 package IMPL::SQL::Schema::Constraint;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
2 use strict;
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
3 use warnings;
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
4
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
5 use IMPL::lang qw(:declare :constants is);
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
6
165
76515373dac0 Added Class::Template,
wizard
parents: 163
diff changeset
7 use parent qw(IMPL::Object IMPL::Object::Disposable);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
8
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
9 use IMPL::Class::Property::Direct;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
10
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
11 BEGIN {
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
12 public _direct property name => PROP_GET;
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
13 public _direct property table => PROP_GET;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
14 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
15
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
16 public property columns => PROP_GET | PROP_LIST | PROP_OWNERSET;
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
17
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
18 my %aliases;
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
19
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
20 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
21 my ($this,%args) = @_;
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
22 is( $args{table}, typeof IMPL::SQL::Schema::Table ) or
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
23 die new IMPL::InvalidArgumentException("table argument must be a table object");
165
76515373dac0 Added Class::Template,
wizard
parents: 163
diff changeset
24 $this->{$name} = $args{'name'};
76515373dac0 Added Class::Template,
wizard
parents: 163
diff changeset
25 $this->{$table} = $args{'table'};
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
26 $this->columns( [map { ResolveColumn($this->table,$_) } @{$args{'columns'}}] );
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
27 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
28
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
29 sub ResolveColumn {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
30 my ($Table,$Column) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
31
165
76515373dac0 Added Class::Template,
wizard
parents: 163
diff changeset
32 my $cn = UNIVERSAL::isa($Column,'IMPL::SQL::Schema::Column') ? $Column->name : $Column;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
33
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
34 my $resolved = $Table->GetColumn($cn);
165
76515373dac0 Added Class::Template,
wizard
parents: 163
diff changeset
35 die new IMPL::InvalidOperationException("The column is not found in the table", $cn, $Table->name) if not $resolved;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
36 return $resolved;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
37 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
38
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
39 sub HasColumn {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
40 my ($this,@Columns) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
41
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
42 my %Columns = map { $_, 1} @Columns;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
43
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
44 return scalar(grep { $Columns{$_->name} } $this->columns ) == scalar(@Columns);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
45 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
46
165
76515373dac0 Added Class::Template,
wizard
parents: 163
diff changeset
47 sub uniqName {
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
48 my ($this) = @_;
165
76515373dac0 Added Class::Template,
wizard
parents: 163
diff changeset
49 return $this->{$table}->name.'_'.$this->{$name};
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
50 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
51
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
52 sub Dispose {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
53 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
54
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
55 $this->columns([]);
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
56
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
57 delete $$this{$table};
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
58
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
59 $this->SUPER::Dispose;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
60 }
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
61
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
62 sub SameValue {
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
63 my ($this,$other) = @_;
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
64
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
65 return 0 unless $this->columns->Count == $other->columns->Count;
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
66
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
67 for ( my $i=0; $i < $this->columns->Count; $i++ ) {
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
68 return 0 unless $this->columns->[$i]->name eq $other->columns->[$i]->name;
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
69 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
70
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
71 return 1;
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
72 }
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
73
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
74 sub ResolveAlias {
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
75 my ($self,$alias) = @_;
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
76
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
77 return is($alias, typeof IMPL::SQL::Schema::Constraint) ? $alias : $aliases{$alias};
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
78 }
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
79
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
80 sub RegisterAlias {
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
81 my ($self,$alias) = @_;
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
82
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
83 $aliases{$alias} = $self->typeof;
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
84 }
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
85
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
86 1;