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