annotate Lib/IMPL/SQL/Schema/Constraint.pm @ 327:6cb0d4d325d7

sync
author sergey
date Thu, 30 May 2013 20:31:37 +0400
parents 77df11605d3a
children
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
280
c6d0f889ef87 +IMPL::declare now supports meta attributes
cin
parents: 278
diff changeset
5 use IMPL::lang;
278
4ddb27ff4a0b core refactoring
cin
parents: 271
diff changeset
6 use IMPL::Const qw(:prop);
4ddb27ff4a0b core refactoring
cin
parents: 271
diff changeset
7 use IMPL::declare {
4ddb27ff4a0b core refactoring
cin
parents: 271
diff changeset
8 base => [
4ddb27ff4a0b core refactoring
cin
parents: 271
diff changeset
9 'IMPL::Object' => undef,
4ddb27ff4a0b core refactoring
cin
parents: 271
diff changeset
10 'IMPL::Object::Disposable' => undef
4ddb27ff4a0b core refactoring
cin
parents: 271
diff changeset
11 ],
4ddb27ff4a0b core refactoring
cin
parents: 271
diff changeset
12 props => [
4ddb27ff4a0b core refactoring
cin
parents: 271
diff changeset
13 name => PROP_RO | PROP_DIRECT,
4ddb27ff4a0b core refactoring
cin
parents: 271
diff changeset
14 table => PROP_RO | PROP_DIRECT,
4ddb27ff4a0b core refactoring
cin
parents: 271
diff changeset
15 columns => PROP_RO | PROP_LIST
4ddb27ff4a0b core refactoring
cin
parents: 271
diff changeset
16 ]
4ddb27ff4a0b core refactoring
cin
parents: 271
diff changeset
17 };
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
18
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
19 my %aliases;
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
20
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
21 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
22 my ($this,%args) = @_;
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
23 is( $args{table}, typeof IMPL::SQL::Schema::Table ) or
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
24 die new IMPL::InvalidArgumentException("table argument must be a table object");
165
76515373dac0 Added Class::Template,
wizard
parents: 163
diff changeset
25 $this->{$name} = $args{'name'};
76515373dac0 Added Class::Template,
wizard
parents: 163
diff changeset
26 $this->{$table} = $args{'table'};
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
27 $this->columns( [map { ResolveColumn($this->table,$_) } @{$args{'columns'}}] );
49
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
30 sub ResolveColumn {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
31 my ($Table,$Column) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
32
271
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents: 232
diff changeset
33 my $cn = is($Column,'IMPL::SQL::Schema::Column') ? $Column->name : $Column;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
34
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
35 my $resolved = $Table->GetColumn($cn);
165
76515373dac0 Added Class::Template,
wizard
parents: 163
diff changeset
36 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
37 return $resolved;
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
40 sub HasColumn {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
41 my ($this,@Columns) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
42
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
43 my %Columns = map { $_, 1} @Columns;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
44
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
45 return scalar(grep { $Columns{$_->name} } $this->columns ) == scalar(@Columns);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
46 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
47
165
76515373dac0 Added Class::Template,
wizard
parents: 163
diff changeset
48 sub uniqName {
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
49 my ($this) = @_;
165
76515373dac0 Added Class::Template,
wizard
parents: 163
diff changeset
50 return $this->{$table}->name.'_'.$this->{$name};
49
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
53 sub Dispose {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
54 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
55
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
56 $this->columns([]);
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
57
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
58 delete $$this{$table};
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
59
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
60 $this->SUPER::Dispose;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
61 }
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
62
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
63 sub SameValue {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
64 my ($this,$other) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
65
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
66 return 0 unless $this->columns->Count == $other->columns->Count;
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
67
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
68 for ( my $i=0; $i < $this->columns->Count; $i++ ) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
69 return 0 unless $this->columns->[$i]->name eq $other->columns->[$i]->name;
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
70 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
71
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
72 return 1;
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
73 }
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
74
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
75 sub ResolveAlias {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
76 my ($self,$alias) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
77
271
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents: 232
diff changeset
78 return isclass($alias, typeof IMPL::SQL::Schema::Constraint) ? $alias : $aliases{$alias};
168
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
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
81 sub RegisterAlias {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
82 my ($self,$alias) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 168
diff changeset
83
315
77df11605d3a code cleanup
cin
parents: 280
diff changeset
84 $aliases{$alias} = typeof($self);
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
85 }
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
86
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
87 1;