diff Lib/IMPL/SQL/Schema/Constraint.pm @ 167:1f7a6d762394

SQL schema in progress
author sourcer
date Thu, 12 May 2011 08:57:19 +0400
parents 76515373dac0
children 6148f89bb7bf
line wrap: on
line diff
--- a/Lib/IMPL/SQL/Schema/Constraint.pm	Sat Apr 23 23:12:06 2011 +0400
+++ b/Lib/IMPL/SQL/Schema/Constraint.pm	Thu May 12 08:57:19 2011 +0400
@@ -1,22 +1,27 @@
+package IMPL::SQL::Schema::Constraint;
 use strict;
-package IMPL::SQL::Schema::Constraint;
+use warnings;
+
+use IMPL::lang qw(:declare :constants is);
+
 use parent qw(IMPL::Object IMPL::Object::Disposable);
 
-use IMPL::Class::Property;
 use IMPL::Class::Property::Direct;
 
 BEGIN {
-    public _direct property name => prop_get;
-    public _direct property table => prop_get;
-    public _direct property columns => prop_get;
+    public _direct property name => PROP_GET;
+    public _direct property table => PROP_GET;
 }
 
+public property columns => PROP_GET | PROP_LIST | PROP_OWNERSET;
+
 sub CTOR {
     my ($this,%args) = @_;
-    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');
+    is( $args{table}, typeof IMPL::SQL::Schema::Table ) or
+    	die new IMPL::InvalidArgumentException("table argument must be a table object");
     $this->{$name} = $args{'name'};
     $this->{$table} = $args{'table'};
-    $this->{$columns} = [map { ResolveColumn($this->table,$_) } @{$args{'columns'}}];
+    $this->columns( [map { ResolveColumn($this->table,$_) } @{$args{'columns'}}] );
 }
 
 sub ResolveColumn {
@@ -45,7 +50,22 @@
 sub Dispose {
     my ($this) = @_;
     
-    delete @$this{$table,$columns};
+    $this->columns([]);
+    
+    delete $$this{$table};
+    
     $this->SUPER::Dispose;
 }
+
+sub SameValue {
+	my ($this,$other) = @_;
+			
+	return 0 unless $this->columns->Count == $other->columns->Count;
+	
+	for ( my $i=0; $i < $this->columns->Count; $i++ ) {
+		return 0 unless $this->columns->[$i]->name eq $other->columns->[$i]->name;
+	}
+	
+	return 1;
+}
 1;