407
|
1 use strict;
|
417
|
2
|
407
|
3 package IMPL::SQL::Schema::Column;
|
|
4
|
417
|
5 use IMPL::lang qw( :base :compare :hash );
|
407
|
6 use IMPL::Exception();
|
|
7 use IMPL::Const qw(:prop);
|
|
8 use IMPL::declare {
|
417
|
9 require => {
|
|
10 SchemaType => '-IMPL::SQL::Schema::Type'
|
|
11 },
|
|
12 base => [
|
|
13 'IMPL::Object' => undef,
|
|
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 ]
|
407
|
22 };
|
|
23
|
|
24 sub CTOR {
|
417
|
25 my ( $this, %args ) = @_;
|
|
26
|
|
27 $this->$_( $args{$_} )
|
|
28 foreach grep exists $args{$_}, qw( name type isNullable defaultValue tag);
|
|
29
|
|
30 $this->{$name} or
|
|
31 die new IMPL::InvalidArgumentException('A column name is required');
|
|
32
|
|
33 $this->{$isNullable} ||= 0; # if not exists $this->{$isNullable};
|
|
34
|
|
35 is( $this->{$type}, SchemaType )
|
|
36 or die new IMPL::InvalidArgumentException(
|
|
37 'a type is required for the column',
|
|
38 $this->{$name} );
|
407
|
39 }
|
|
40
|
|
41 sub SameValue {
|
417
|
42 my ( $this, $other ) = @_;
|
|
43
|
|
44 return ( $this->{$name} eq $other->{$name}
|
|
45 and $this->{$isNullable} == $other->{$isNullable}
|
|
46 and equals_s( $this->{$defaultValue}, $other->{$defaultValue} )
|
|
47 and $this->{$type}->SameValue( $other->{$type} ) );
|
407
|
48 }
|
|
49
|
|
50 sub SetType {
|
417
|
51 my ( $this, $newType ) = @_;
|
|
52
|
|
53 $this->{$type} = $newType;
|
407
|
54 }
|
|
55
|
|
56 sub SetDefaultValue {
|
417
|
57 my ( $this, $value ) = @_;
|
|
58
|
|
59 $this->{$defaultValue} = $value;
|
407
|
60 }
|
|
61
|
|
62 sub SetNullable {
|
417
|
63 my ( $this, $value ) = @_;
|
|
64
|
|
65 $this->{$isNullable} = $value;
|
407
|
66 }
|
|
67
|
|
68 sub SetOptions {
|
417
|
69 my ( $this, $diff ) = @_;
|
|
70
|
|
71 return unless ref $diff eq 'HASH';
|
|
72
|
|
73 $this->tag( {} ) unless $this->tag;
|
|
74
|
|
75 hashApply( $this->tag, $diff );
|
407
|
76 }
|
|
77
|
417
|
78 1;
|