49
|
1 use strict;
|
|
2 package IMPL::SQL::Schema::Column;
|
165
|
3 use parent qw(IMPL::Object IMPL::Object::Autofill);
|
49
|
4
|
168
|
5 use IMPL::lang qw( :DEFAULT :compare :declare :constants :hash );
|
49
|
6 use IMPL::Class::Property::Direct;
|
167
|
7 use IMPL::Exception();
|
49
|
8
|
|
9 BEGIN {
|
167
|
10 public _direct property name => PROP_GET;
|
|
11 public _direct property type => PROP_GET;
|
|
12 public _direct property isNullable => PROP_GET;
|
|
13 public _direct property defaultValue => PROP_GET;
|
|
14 public _direct property tag => PROP_GET;
|
49
|
15 }
|
|
16
|
|
17 __PACKAGE__->PassThroughArgs;
|
|
18
|
|
19 sub CTOR {
|
|
20 my $this = shift;
|
|
21
|
167
|
22 $this->{$name} or
|
|
23 die new IMPL::InvalidArgumentException('A column name is required');
|
49
|
24
|
167
|
25 $this->{$isNullable} = 0 if not exists $this->{$isNullable};
|
|
26
|
|
27 is( $this->{$type}, typeof IMPL::SQL::Schema::Type) or
|
|
28 die new IMPL::InvalidArgumentException('a type is required for the column',$this->{$name});
|
49
|
29 }
|
|
30
|
167
|
31 sub SameValue {
|
49
|
32 my ($this,$other) = @_;
|
|
33
|
167
|
34 return (
|
|
35 $this->{$name} eq $other->{$name}
|
|
36 and $this->{$isNullable} == $other->{$isNullable}
|
|
37 and equals_s($this->{$defaultValue}, $other->{$defaultValue})
|
|
38 and $this->{$type}->SameValue($other->{$type})
|
|
39 );
|
49
|
40 }
|
|
41
|
168
|
42 sub SetType {
|
|
43 my ($this,$newType) = @_;
|
|
44
|
|
45 $this->{$type} = $newType;
|
|
46 }
|
|
47
|
|
48 sub SetDefaultValue {
|
|
49 my ($this,$value) = @_;
|
|
50
|
|
51 $this->{$defaultValue} = $value;
|
|
52 }
|
|
53
|
|
54 sub SetNullable {
|
|
55 my ($this, $value) = @_;
|
|
56
|
|
57 $this->{$isNullable} = $value;
|
|
58 }
|
|
59
|
|
60 sub SetOptions {
|
|
61 my ($this,$diff) = @_;
|
|
62
|
|
63 return unless ref $diff eq 'HASH';
|
|
64
|
|
65 $this->tag({}) unless $this->tag;
|
|
66
|
|
67 hashApply($this->tag,$diff);
|
|
68 }
|
|
69
|
49
|
70 1;
|