diff Lib/IMPL/SQL/Schema/Table.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 6148f89bb7bf
children 5c82eec23bb6
line wrap: on
line diff
--- a/Lib/IMPL/SQL/Schema/Table.pm	Tue Apr 10 08:13:22 2012 +0400
+++ b/Lib/IMPL/SQL/Schema/Table.pm	Tue Apr 10 20:08:29 2012 +0400
@@ -4,8 +4,8 @@
 use IMPL::lang qw(:declare :constants is);
 
 use parent qw(
-	IMPL::Object
-	IMPL::Object::Disposable
+    IMPL::Object
+    IMPL::Object::Disposable
 );
 
 require IMPL::SQL::Schema::Column;
@@ -32,15 +32,15 @@
     $this->{$schema} = $args{'schema'} or die new IMPL::InvalidArgumentException('a parent schema is required');
     
     if ($args{columns}) {
-    	die new IMPL::InvalidOperationException('A columns property should be a reference to an array') unless ref $args{columns} eq 'ARRAY';
-   		
-    	$this->InsertColumn($_) foreach @{$args{columns}};
+        die new IMPL::InvalidOperationException('A columns property should be a reference to an array') unless ref $args{columns} eq 'ARRAY';
+           
+        $this->InsertColumn($_) foreach @{$args{columns}};
     }
     
     if ($args{constraints}) {
-    	die new IMPL::InvalidOperationException('A constraints property should be a reference to an array') unless ref $args{constraints} eq 'ARRAY';
-   		
-    	$this->AddConstraint($_) foreach @{$args{constraints}};
+        die new IMPL::InvalidOperationException('A constraints property should be a reference to an array') unless ref $args{constraints} eq 'ARRAY';
+           
+        $this->AddConstraint($_) foreach @{$args{constraints}};
     }
 }
 
@@ -110,47 +110,47 @@
     my ($this,$index) = @_;
     
     die new IMPL::InvalidArgumentException("The index is out of range")
-    	if $index < 0 || $index >= ($this->{$columns} ? scalar(@{$this->{$columns}}) : 0);
+        if $index < 0 || $index >= ($this->{$columns} ? scalar(@{$this->{$columns}}) : 0);
     
     return $this->{$columns}[$index];
 }
 
 sub ColumnsCount {
-	my ($this) = @_;
-	
-	return scalar(@{$this->{$columns}});
+    my ($this) = @_;
+    
+    return scalar(@{$this->{$columns}});
 }
 
 sub AddConstraint {
-	my $this = shift;
+    my $this = shift;
     if (@_ == 1) {
-    	my ($Constraint) = @_;
-    	
-	    die new IMPL::InvalidArgumentException('The invalid parameter') if not is($Constraint,typeof IMPL::SQL::Schema::Constraint);
-	    
-	    $Constraint->table == $this or die new IMPL::InvalidOperationException('The constaint must belong to the target table');
-	    
-	    if (exists $this->{$constraints}->{$Constraint->name}) {
-	        die new IMPL::InvalidOperationException('The table already has the specified constraint',$Constraint->name);
-	    } else {
-	        if (UNIVERSAL::isa($Constraint,'IMPL::SQL::Schema::Constraint::PrimaryKey')) {
-	            not $this->{$primaryKey} or die new IMPL::InvalidOperationException('The table already has a primary key');
-	            $this->{$primaryKey} = $Constraint;
-	        }
-	        
-	        $this->{$constraints}->{$Constraint->name} = $Constraint;
-	    }
+        my ($Constraint) = @_;
+        
+        die new IMPL::InvalidArgumentException('The invalid parameter') if not is($Constraint,typeof IMPL::SQL::Schema::Constraint);
+        
+        $Constraint->table == $this or die new IMPL::InvalidOperationException('The constaint must belong to the target table');
+        
+        if (exists $this->{$constraints}->{$Constraint->name}) {
+            die new IMPL::InvalidOperationException('The table already has the specified constraint',$Constraint->name);
+        } else {
+            if (UNIVERSAL::isa($Constraint,'IMPL::SQL::Schema::Constraint::PrimaryKey')) {
+                not $this->{$primaryKey} or die new IMPL::InvalidOperationException('The table already has a primary key');
+                $this->{$primaryKey} = $Constraint;
+            }
+            
+            $this->{$constraints}->{$Constraint->name} = $Constraint;
+        }
     } elsif( @_ == 2) {
-    	my ($type,$params) = @_;
-    	
-    	$type = IMPL::SQL::Schema::Constraint->ResolveAlias($type) or
-    		die new IMPL::Exception("Can't resolve a constraint alias",$_[0]);
-    		
-    	$params->{table} = $this;
-    	
-    	$this->AddConstraint($type->new(%$params));
+        my ($type,$params) = @_;
+        
+        $type = IMPL::SQL::Schema::Constraint->ResolveAlias($type) or
+            die new IMPL::Exception("Can't resolve a constraint alias",$_[0]);
+            
+        $params->{table} = $this;
+        
+        $this->AddConstraint($type->new(%$params));
     } else {
-    	die new IMPL::Exception("Wrong arguments number",scalar(@_));
+        die new IMPL::Exception("Wrong arguments number",scalar(@_));
     }
 }
 
@@ -171,15 +171,15 @@
 }
 
 sub GetConstraint {
-	my ($this,$name) = @_;
-	
-	return $this->{$constraints}{$name};
+    my ($this,$name) = @_;
+    
+    return $this->{$constraints}{$name};
 }
 
 sub GetConstraints {
-	my ($this) = @_;
-	
-	return wantarray ? values %{$this->{$constraints}} : [values %{$this->{$constraints}}];
+    my ($this) = @_;
+    
+    return wantarray ? values %{$this->{$constraints}} : [values %{$this->{$constraints}}];
 }
 
 sub GetColumnConstraints {
@@ -214,28 +214,28 @@
 }
 
 sub SameValue {
-	my ($this,$other) = @_;
-	
-	return 0 unless is $other, typeof $this;
-	
-	return 0 unless $this->name eq $other->name;
-	return 0 unless $this->ColumnsCount eq $other->ColumnsCount;
-	
-	for (my $i = 0; $i < $this->ColumsCount; $i ++) {
-		return 0 unless $this->($i)->SameValue($other->GetColumnAt($i));
-	}
-	
-	my %thisConstraints = map { $_->name, $_ } $this->GetConstraints();
-	my %otherConstraints = map { $_->name, $_ } $other->GetConstraints();
-	
-	foreach my $name ( keys %thisConstraints ) {
-		return 0 unless $otherConstraints{$name};
-		return 0 unless $thisConstraints{$name}->SameValue(delete $otherConstraints{$name});
-	}
-	
-	return 0 if %otherConstraints;
-	
-	return 1;
+    my ($this,$other) = @_;
+    
+    return 0 unless is $other, typeof $this;
+    
+    return 0 unless $this->name eq $other->name;
+    return 0 unless $this->ColumnsCount eq $other->ColumnsCount;
+    
+    for (my $i = 0; $i < $this->ColumsCount; $i ++) {
+        return 0 unless $this->($i)->SameValue($other->GetColumnAt($i));
+    }
+    
+    my %thisConstraints = map { $_->name, $_ } $this->GetConstraints();
+    my %otherConstraints = map { $_->name, $_ } $other->GetConstraints();
+    
+    foreach my $name ( keys %thisConstraints ) {
+        return 0 unless $otherConstraints{$name};
+        return 0 unless $thisConstraints{$name}->SameValue(delete $otherConstraints{$name});
+    }
+    
+    return 0 if %otherConstraints;
+    
+    return 1;
 }
 
 1;