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