annotate lib/IMPL/SQL/Schema/Column.pm @ 413:af8d359ee4cc ref20150831

working on di container
author cin
date Thu, 24 Sep 2015 12:19:30 +0300
parents c6e90e02dd17
children 3ed0c58e9da3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
1 use strict;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
2 package IMPL::SQL::Schema::Column;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
3
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
4 use IMPL::lang qw( :DEFAULT :compare :hash );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
5 use IMPL::Exception();
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
6 use IMPL::Const qw(:prop);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
7 use IMPL::declare {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
8 require => {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
9 SchemaType => '-IMPL::SQL::Schema::Type'
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
10 },
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
11 base => [
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
12 'IMPL::Object' => undef,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
13 'IMPL::Object::Autofill' => '@_'
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
14 ],
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
15 props => [
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
16 name => PROP_RO | PROP_DIRECT,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
17 type => PROP_RO | PROP_DIRECT,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
18 isNullable => PROP_RO | PROP_DIRECT,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
19 defaultValue => PROP_RO | PROP_DIRECT,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
20 tag => PROP_RO | PROP_DIRECT
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
21 ]
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
22 };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
23
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
24 sub CTOR {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
25 my $this = shift;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
26
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
27 $this->{$name} or
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
28 die new IMPL::InvalidArgumentException('A column name is required');
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
29
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
30 $this->{$isNullable} ||= 0; # if not exists $this->{$isNullable};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
31
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
32 is( $this->{$type}, SchemaType) or
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
33 die new IMPL::InvalidArgumentException('a type is required for the column',$this->{$name});
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
34 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
35
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
36 sub SameValue {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
37 my ($this,$other) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
38
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
39 return (
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
40 $this->{$name} eq $other->{$name}
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
41 and $this->{$isNullable} == $other->{$isNullable}
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
42 and equals_s($this->{$defaultValue}, $other->{$defaultValue})
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
43 and $this->{$type}->SameValue($other->{$type})
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
44 );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
45 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
46
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
47 sub SetType {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
48 my ($this,$newType) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
49
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
50 $this->{$type} = $newType;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
51 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
52
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
53 sub SetDefaultValue {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
54 my ($this,$value) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
55
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
56 $this->{$defaultValue} = $value;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
57 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
58
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
59 sub SetNullable {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
60 my ($this, $value) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
61
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
62 $this->{$isNullable} = $value;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
63 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
64
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
65 sub SetOptions {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
66 my ($this,$diff) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
67
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
68 return unless ref $diff eq 'HASH';
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
69
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
70 $this->tag({}) unless $this->tag;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
71
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
72 hashApply($this->tag,$diff);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
73 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
74
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
75 1;