comparison Lib/IMPL/SQL/Schema.pm @ 194:4d0e1962161c

Replaced tabs with spaces IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author cin
date Tue, 10 Apr 2012 20:08:29 +0400
parents d1676be8afcc
children 5c82eec23bb6
comparison
equal deleted inserted replaced
193:8e8401c0aea4 194:4d0e1962161c
4 use IMPL::_core::version; 4 use IMPL::_core::version;
5 5
6 use IMPL::lang qw(is :declare :constants); 6 use IMPL::lang qw(is :declare :constants);
7 7
8 use parent qw( 8 use parent qw(
9 IMPL::Object 9 IMPL::Object
10 IMPL::Object::Disposable 10 IMPL::Object::Disposable
11 IMPL::Object::Autofill 11 IMPL::Object::Autofill
12 IMPL::Object::Clonable 12 IMPL::Object::Clonable
13 ); 13 );
14 14
15 use IMPL::Class::Property::Direct; 15 use IMPL::Class::Property::Direct;
16 16
17 require IMPL::SQL::Schema::Table; 17 require IMPL::SQL::Schema::Table;
31 31
32 $table->Schema == $this or die new IMPL::InvalidOperationException('The specified table must belong to the database'); 32 $table->Schema == $this or die new IMPL::InvalidOperationException('The specified table must belong to the database');
33 not exists $this->{$tables}->{$table->name} or die new IMPL::InvalidOperationException('a table with the same name already exists in the database'); 33 not exists $this->{$tables}->{$table->name} or die new IMPL::InvalidOperationException('a table with the same name already exists in the database');
34 34
35 } elsif (UNIVERSAL::isa($table,'HASH')) { 35 } elsif (UNIVERSAL::isa($table,'HASH')) {
36 36
37 not exists $this->{$tables}->{$table->{'name'}} or die new IMPL::InvalidOperationException('a table with the same name already exists in the database'); 37 not exists $this->{$tables}->{$table->{'name'}} or die new IMPL::InvalidOperationException('a table with the same name already exists in the database');
38 $table = { %$table }; 38 $table = { %$table };
39 $table->{'schema'} = $this; 39 $table->{'schema'} = $this;
40 $table = new IMPL::SQL::Schema::Table(%{$table}); 40 $table = new IMPL::SQL::Schema::Table(%{$table});
41 } else { 41 } else {
42 die new IMPL::InvalidArgumentException('Either a table object or a hash with table parameters is required'); 42 die new IMPL::InvalidArgumentException('Either a table object or a hash with table parameters is required');
43 } 43 }
60 60
61 return 1; 61 return 1;
62 } 62 }
63 63
64 sub ResolveTable { 64 sub ResolveTable {
65 my ($this,$table) = @_; 65 my ($this,$table) = @_;
66 66
67 UNIVERSAL::isa($table,'IMPL::SQL::Schema::Table') ? $table : $this->{$tables}{$table}; 67 UNIVERSAL::isa($table,'IMPL::SQL::Schema::Table') ? $table : $this->{$tables}{$table};
68 } 68 }
69 69
70 sub GetTable { 70 sub GetTable {
71 my ($this,$tableName) = @_; 71 my ($this,$tableName) = @_;
72 return $this->{$tables}{$tableName}; 72 return $this->{$tables}{$tableName};
73 } 73 }
74 74
75 sub GetTables { 75 sub GetTables {
76 my ($this) = @_; 76 my ($this) = @_;
77 77
78 return wantarray ? values %{$this->{$tables}} : [values %{$this->{$tables}}]; 78 return wantarray ? values %{$this->{$tables}} : [values %{$this->{$tables}}];
79 } 79 }
80 80
81 sub RenameTable { 81 sub RenameTable {
82 my ($this,$oldName,$newName) = @_; 82 my ($this,$oldName,$newName) = @_;
83 83
84 die new IMPL::InvalidOperationException("A source table doesn't exists", $oldName) unless exists $this->{$tables}{$oldName}; 84 die new IMPL::InvalidOperationException("A source table doesn't exists", $oldName) unless exists $this->{$tables}{$oldName};
85 die new IMPL::InvalidOperationException("A target table already exists", $newName) if exists $this->{$tables}{$newName}; 85 die new IMPL::InvalidOperationException("A target table already exists", $newName) if exists $this->{$tables}{$newName};
86 86
87 my $table = delete $this->{$tables}{$oldName}; 87 my $table = delete $this->{$tables}{$oldName};
88 $table->_setName($newName); 88 $table->_setName($newName);
89 $this->{$tables}{$newName} = $table; 89 $this->{$tables}{$newName} = $table;
90 } 90 }
91 91
92 sub Dispose { 92 sub Dispose {
93 my ($this) = @_; 93 my ($this) = @_;
94 94