diff Lib/IMPL/SQL/Schema/Traits.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 dacfe7c0311a
line wrap: on
line diff
--- a/Lib/IMPL/SQL/Schema/Traits.pm	Tue Apr 10 08:13:22 2012 +0400
+++ b/Lib/IMPL/SQL/Schema/Traits.pm	Tue Apr 10 20:08:29 2012 +0400
@@ -4,7 +4,6 @@
 use IMPL::Exception();
 
 use parent qw(IMPL::Object);
-use IMPL::Code::Loader();
 
 # required for use with typeof operator
 use IMPL::SQL::Schema::Constraint::PrimaryKey();
@@ -18,19 +17,19 @@
 use base qw(IMPL::Object::Fields);
 
 use fields qw(
-	name
-	columns
-	constraints
-	options
+    name
+    columns
+    constraints
+    options
 );
 
 sub CTOR {
-	my ($this,$table,$columns,$constraints,$options) = @_;
-	
-	$this->{name} = $table or die new IMPL::InvalidArgumentException(table => "A table name is required");
-	$this->{columns} = $columns if defined $columns;
-	$this->{constraints} = $constraints if defined $constraints;
-	$this->{options} = $options if defined $options;
+    my ($this,$table,$columns,$constraints,$options) = @_;
+    
+    $this->{name} = $table or die new IMPL::InvalidArgumentException(table => "A table name is required");
+    $this->{columns} = $columns if defined $columns;
+    $this->{constraints} = $constraints if defined $constraints;
+    $this->{options} = $options if defined $options;
 }
 
 ###################################################
@@ -39,21 +38,21 @@
 use base qw(IMPL::Object::Fields);
 
 use fields qw(
-	name
-	type
-	isNullable
-	defaultValue
-	tag
+    name
+    type
+    isNullable
+    defaultValue
+    tag
 );
 
 sub CTOR {
-	my ($this, $name, $type, %args) = @_;
-	
-	$this->{name} = $name or die new IMPL::InvalidArgumentException("name");
-	$this->{type} = $type or die new IMPL::InvalidArgumentException("type");
-	$this->{isNullable} = $args{isNullable} if exists $args{isNullable};
-	$this->{defaultValue} = $args{defaultValue} if exists $args{defaultValue};
-	$this->{tag} = $args{tag} if exists $args{tag};
+    my ($this, $name, $type, %args) = @_;
+    
+    $this->{name} = $name or die new IMPL::InvalidArgumentException("name");
+    $this->{type} = $type or die new IMPL::InvalidArgumentException("type");
+    $this->{isNullable} = $args{isNullable} if exists $args{isNullable};
+    $this->{defaultValue} = $args{defaultValue} if exists $args{defaultValue};
+    $this->{tag} = $args{tag} if exists $args{tag};
 }
 
 ##################################################
@@ -62,19 +61,19 @@
 use base qw(IMPL::Object::Fields);
  
 use fields qw(
-	name
-	columns
+    name
+    columns
 );
 
 sub CTOR {
-	my ($this, $name, $columns) = @_;
-	
-	$this->{name} = $name;
-	$this->{columns} = $columns; # list of columnNames
+    my ($this, $name, $columns) = @_;
+    
+    $this->{name} = $name;
+    $this->{columns} = $columns; # list of columnNames
 }
 
 sub constraintClass  {
-	die new IMPL::NotImplementedException();
+    die new IMPL::NotImplementedException();
 }
 
 ##################################################
@@ -113,21 +112,21 @@
 
 use base qw(IMPL::SQL::Schema::Traits::Constraint);
 use fields qw(
-	foreignTable
-	foreignColumns
+    foreignTable
+    foreignColumns
 );
 
 use constant { constraintClass => typeof IMPL::SQL::Schema::Constraint::ForeignKey };
 
 our %CTOR = (
-	'IMPL::SQL::Schema::Traits::Constraint' => sub { @_[0..1] }
+    'IMPL::SQL::Schema::Traits::Constraint' => sub { @_[0..1] }
 );
 
 sub CTOR {
-	my ($this,$foreignTable,$foreignColumns) = @_[0,3,4];
-	
-	$this->{foreignTable} = $foreignTable;
-	$this->{foreignColunms} = $foreignColumns;
+    my ($this,$foreignTable,$foreignColumns) = @_[0,3,4];
+    
+    $this->{foreignTable} = $foreignTable;
+    $this->{foreignColunms} = $foreignColumns;
 }
  
 
@@ -140,25 +139,25 @@
 use IMPL::lang;
 
 BEGIN {
-	public property table => prop_get | owner_set;
+    public property table => prop_get | owner_set;
 }
 
 sub CTOR {
-	my ($this,$table) = @_;
-	
-	die new IMPL::InvalidArgumentException("table", "An object of IMPL::SQL::Schema::Traits::Table type is required")
-		unless is $table, typeof IMPL::SQL::Schema::Traits::Table;
-	
-	$this->table($table);
+    my ($this,$table) = @_;
+    
+    die new IMPL::InvalidArgumentException("table", "An object of IMPL::SQL::Schema::Traits::Table type is required")
+        unless is $table, typeof IMPL::SQL::Schema::Traits::Table;
+    
+    $this->table($table);
 }
 
 sub apply {
-	my ($this,$schema) = @_;
-	
-	return 0 if ( $schema->GetTable( $this->table->{name} ) );
-	
-	$schema->AddTable($this->table);
-	return 1;
+    my ($this,$schema) = @_;
+    
+    return 0 if ( $schema->GetTable( $this->table->{name} ) );
+    
+    $schema->AddTable($this->table);
+    return 1;
 }
 
 ##################################################
@@ -168,23 +167,23 @@
 use IMPL::Class::Property;
 
 BEGIN {
-	public property tableName => prop_get | owner_set;
+    public property tableName => prop_get | owner_set;
 }
 
 sub CTOR {
-	my ($this,$tableName) = @_;
-	
-	$this->tableName($tableName) or die new IMPL::InvalidArgumentException("tableName is required");
+    my ($this,$tableName) = @_;
+    
+    $this->tableName($tableName) or die new IMPL::InvalidArgumentException("tableName is required");
 }
 
 sub apply {
-	my ($this,$schema) = @_;
-	
-	return 0 if $schema->GetTable( $this->tableName );
-	
-	$schema->RemoveTable($this->tableName);
-	
-	return 1;
+    my ($this,$schema) = @_;
+    
+    return 0 if $schema->GetTable( $this->tableName );
+    
+    $schema->RemoveTable($this->tableName);
+    
+    return 1;
 }
 
 ##################################################
@@ -194,25 +193,25 @@
 use IMPL::Class::Property;
 
 BEGIN {
-	public property tableName => prop_get | owner_set;
-	public property tableNewName => prop_get | owner_set;
+    public property tableName => prop_get | owner_set;
+    public property tableNewName => prop_get | owner_set;
 }
 
 sub CTOR {
-	my ($this, $oldName, $newName) = @_;
-	
-	$this->tableName($oldName) or die new IMPL::InvalidArgumentException("A table name is required");
-	$this->tableNewName($newName) or die new  IMPL::InvalidArgumentException("A new table name is required");
+    my ($this, $oldName, $newName) = @_;
+    
+    $this->tableName($oldName) or die new IMPL::InvalidArgumentException("A table name is required");
+    $this->tableNewName($newName) or die new  IMPL::InvalidArgumentException("A new table name is required");
 }
 
 sub apply {
-	my ($this,$schema) = @_;
-	
-	return 0 if not $schema->GetTable($this->tableName) or $schema->GetTable($this->tableNewName);
-	
-	$this->RenameTable($this->tableName, $this->tableNewName);
-	
-	return 1;
+    my ($this,$schema) = @_;
+    
+    return 0 if not $schema->GetTable($this->tableName) or $schema->GetTable($this->tableNewName);
+    
+    $this->RenameTable($this->tableName, $this->tableNewName);
+    
+    return 1;
 }
 
 #################################################
@@ -223,31 +222,31 @@
 use IMPL::lang;
 
 BEGIN {
-	public property tableName => prop_get | owner_set;
-	public property column => prop_get | owner_set;
+    public property tableName => prop_get | owner_set;
+    public property column => prop_get | owner_set;
 }
 
 sub CTOR {
-	my ($this,$tableName,$column) = @_;
-	
-	$this->tableName($tableName) or die new IMPL::InvalidArgumentException("A table name is required");
-	
-	die new IMPL::InvalidArgumentException("A column should be a IMPL::SQL::Schema::Traits::Column object")
-		unless is $column, typeof IMPL::SQL::Schema::Traits::Column;
-		
-	$this->column($column);
+    my ($this,$tableName,$column) = @_;
+    
+    $this->tableName($tableName) or die new IMPL::InvalidArgumentException("A table name is required");
+    
+    die new IMPL::InvalidArgumentException("A column should be a IMPL::SQL::Schema::Traits::Column object")
+        unless is $column, typeof IMPL::SQL::Schema::Traits::Column;
+        
+    $this->column($column);
 }
 
 sub apply {
-	my ($this,$schema) = @_;
-	
-	my $table = $schema->GetTable($this->tableName) or return 0;
-	
-	return 0 if $table->GetColumn( $this->column->{name} );
-	
-	$table->AddColumn($this->column);
-	
-	return 1;
+    my ($this,$schema) = @_;
+    
+    my $table = $schema->GetTable($this->tableName) or return 0;
+    
+    return 0 if $table->GetColumn( $this->column->{name} );
+    
+    $table->AddColumn($this->column);
+    
+    return 1;
 }
 
 #################################################
@@ -257,26 +256,26 @@
 use IMPL::Class::Property;
 
 BEGIN {
-	public property tableName => prop_get | owner_set;
-	public property columnName => prop_get | owner_set;
+    public property tableName => prop_get | owner_set;
+    public property columnName => prop_get | owner_set;
 }
 
 sub CTOR { 
-	my ($this,$table,$column) = @_;
-	
-	$this->tableName($table) or die new IMPL::InvalidArgumentException(tableName => "A table name should be specified");
-	$this->columnName($column) or die new IMPL::InvalidArgumentException(columnName => "A column name should be specified");
+    my ($this,$table,$column) = @_;
+    
+    $this->tableName($table) or die new IMPL::InvalidArgumentException(tableName => "A table name should be specified");
+    $this->columnName($column) or die new IMPL::InvalidArgumentException(columnName => "A column name should be specified");
 }
 
 sub apply {
-	my ($this,$schema) = @_;
-	
-	local $@;
-	
-	return eval {
-		$schema->GetTable($this->tableName)->RemoveColumn($this->columnName);
-		return 1;
-	} || 0;
+    my ($this,$schema) = @_;
+    
+    local $@;
+    
+    return eval {
+        $schema->GetTable($this->tableName)->RemoveColumn($this->columnName);
+        return 1;
+    } || 0;
 }
 
 #################################################
@@ -286,38 +285,38 @@
 use IMPL::Class::Property;
 
 BEGIN {
-	public property tableName => prop_get | owner_set;
-	public property columnName => prop_get | owner_set;
-	public property columnType => prop_all;
-	public property defaultValue => prop_all;
-	public property isNullable => prop_all;
-	public property options => prop_all; # hash diff format, (keys have a prefix '+' - add or update value, '-' remove value)
+    public property tableName => prop_get | owner_set;
+    public property columnName => prop_get | owner_set;
+    public property columnType => prop_all;
+    public property defaultValue => prop_all;
+    public property isNullable => prop_all;
+    public property options => prop_all; # hash diff format, (keys have a prefix '+' - add or update value, '-' remove value)
 }
 
 sub CTOR {
-	my ($this, $table,$column,%args) = @_;
-	
-	$this->tableName($table) or die new IMPL::InvalidArgumentException(tableName => "A table name is required");
-	$this->columnName($column) or die new IMPL::InvalidArgumentException(columnName => "A column name is required");
-	
-	$this->$_($args{$_})
-		for (grep exists $args{$_}, qw(columnType defaultValue isNullable options));
+    my ($this, $table,$column,%args) = @_;
+    
+    $this->tableName($table) or die new IMPL::InvalidArgumentException(tableName => "A table name is required");
+    $this->columnName($column) or die new IMPL::InvalidArgumentException(columnName => "A column name is required");
+    
+    $this->$_($args{$_})
+        for (grep exists $args{$_}, qw(columnType defaultValue isNullable options));
 }
 
 sub apply {
-	my ($this,$schema) = @_;
-	
-	local $@;
-	
-	return eval {
-		my $column = $schema->GetTable($this->tableName)->GetColumn($this->columnName);
-		$column->SetType($this->columnType) if defined $this->columnType;
-		$column->SetNullable($this->isNullable) if defined $this->isNullable;
-		$column->SetDefaultValue($this->defaultValue) if defined $this->defaultValue;
-		$column->SetOptions($this->options) if defined $this->options;
-		
-		return 1;
-	} || 0;
+    my ($this,$schema) = @_;
+    
+    local $@;
+    
+    return eval {
+        my $column = $schema->GetTable($this->tableName)->GetColumn($this->columnName);
+        $column->SetType($this->columnType) if defined $this->columnType;
+        $column->SetNullable($this->isNullable) if defined $this->isNullable;
+        $column->SetDefaultValue($this->defaultValue) if defined $this->defaultValue;
+        $column->SetOptions($this->options) if defined $this->options;
+        
+        return 1;
+    } || 0;
 }
 
 #################################################
@@ -328,31 +327,31 @@
 use IMPL::lang;
 
 BEGIN {
-	public property tableName => prop_get | owner_set;
-	public property constraint => prop_get | owner_set;
+    public property tableName => prop_get | owner_set;
+    public property constraint => prop_get | owner_set;
 }
 
 sub CTOR {
-	my ($this,$table,$constraint) = @_;
-	
-	$this->tableName($table) or die new IMPL::InvalidArgumentException( tableName => "A table name is required");
-	
-	die new IMPL::InvalidArgumentException(constaraint => "A valid IMPL::SQL::Schema::Traits::Constarint is required")
-		unless is $constraint, typeof IMPL::SQL::Schema::Traits::Constraint;
-		
-	$this->constraint($constraint);
+    my ($this,$table,$constraint) = @_;
+    
+    $this->tableName($table) or die new IMPL::InvalidArgumentException( tableName => "A table name is required");
+    
+    die new IMPL::InvalidArgumentException(constaraint => "A valid IMPL::SQL::Schema::Traits::Constarint is required")
+        unless is $constraint, typeof IMPL::SQL::Schema::Traits::Constraint;
+        
+    $this->constraint($constraint);
 }
 
 sub apply {
-	my ($this,$schema) = @_;
-	
-	local $@;
-	
-	return eval {
-		$schema->GetTable($this->tableName)->AddConstraint($this->constraint->constraintClass, $this->constraint);
-		return 1;
-	} || 0;
-	
+    my ($this,$schema) = @_;
+    
+    local $@;
+    
+    return eval {
+        $schema->GetTable($this->tableName)->AddConstraint($this->constraint->constraintClass, $this->constraint);
+        return 1;
+    } || 0;
+    
 }
 
 #################################################
@@ -362,29 +361,29 @@
 use IMPL::Class::Property;
 
 BEGIN {
-	public property tableName => prop_get | owner_set;
-	public property constraintName => prop_get | owner_set;
+    public property tableName => prop_get | owner_set;
+    public property constraintName => prop_get | owner_set;
 }
 
 sub CTOR {
-	my ($this,$table,$constraint) = @_;
-	
-	die new IMPL::InvalidArgumentException( tableName => "A table name is required" ) unless $table;
-	die new IMPL::InvalidArgumentException( constraintName => "A constraint name is required" ) unless $constraint;
-	
-	$this->tableName($table);
-	$this->constraintName($constraint);
+    my ($this,$table,$constraint) = @_;
+    
+    die new IMPL::InvalidArgumentException( tableName => "A table name is required" ) unless $table;
+    die new IMPL::InvalidArgumentException( constraintName => "A constraint name is required" ) unless $constraint;
+    
+    $this->tableName($table);
+    $this->constraintName($constraint);
 }
 
 sub apply {
-	my ($this,$schema) = @_;
-	
-	my $table = $schema->GetTable($this->tableName) or return 0;
-	
-	return 0 unless $table->GetConstraint($this->constraintName);
-	
-	$table->RemoveConstraint($this->constraintName);
-	return 1;
+    my ($this,$schema) = @_;
+    
+    my $table = $schema->GetTable($this->tableName) or return 0;
+    
+    return 0 unless $table->GetConstraint($this->constraintName);
+    
+    $table->RemoveConstraint($this->constraintName);
+    return 1;
 }