annotate Lib/IMPL/SQL/Schema/Column.pm @ 38:d660fb38b7cc

small fixes ORM shema to SQL schema transformation
author Sergey
date Mon, 23 Nov 2009 17:57:07 +0300
parents 56cef8e3cda6
children 16ada169ca75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
Sergey
parents:
diff changeset
1 use strict;
Sergey
parents:
diff changeset
2 package IMPL::SQL::Schema::Column;
Sergey
parents:
diff changeset
3 use base qw(IMPL::Object IMPL::Object::Autofill);
Sergey
parents:
diff changeset
4
Sergey
parents:
diff changeset
5 use IMPL::Class::Property;
Sergey
parents:
diff changeset
6 use IMPL::Class::Property::Direct;
Sergey
parents:
diff changeset
7
Sergey
parents:
diff changeset
8 BEGIN {
Sergey
parents:
diff changeset
9 public _direct property Name => prop_get;
Sergey
parents:
diff changeset
10 public _direct property Type => prop_get;
Sergey
parents:
diff changeset
11 public _direct property CanBeNull => prop_get;
Sergey
parents:
diff changeset
12 public _direct property DefaultValue => prop_get;
Sergey
parents:
diff changeset
13 public _direct property Tag => prop_get;
Sergey
parents:
diff changeset
14 }
Sergey
parents:
diff changeset
15
Sergey
parents:
diff changeset
16 __PACKAGE__->PassThroughArgs;
Sergey
parents:
diff changeset
17
Sergey
parents:
diff changeset
18 sub CTOR {
Sergey
parents:
diff changeset
19 my $this = shift;
Sergey
parents:
diff changeset
20
Sergey
parents:
diff changeset
21 $this->{$Name} or die new IMPL::InvalidArgumentException('a column name is required');
Sergey
parents:
diff changeset
22 $this->{$CanBeNull} = 0 if not exists $this->{$CanBeNull};
Sergey
parents:
diff changeset
23 UNIVERSAL::isa($this->{$Type},'IMPL::SQL::Schema::Type') or die new IMPL::InvalidArgumentException('a type is required for the column',$this->{$Name});
Sergey
parents:
diff changeset
24 }
Sergey
parents:
diff changeset
25
Sergey
parents:
diff changeset
26 sub isEqualsStr {
Sergey
parents:
diff changeset
27 my ($a,$b) = @_;
Sergey
parents:
diff changeset
28
Sergey
parents:
diff changeset
29 if (defined $a and defined $b) {
Sergey
parents:
diff changeset
30 return $a eq $b;
Sergey
parents:
diff changeset
31 } else {
Sergey
parents:
diff changeset
32 if (defined $a or defined $b) {
Sergey
parents:
diff changeset
33 return 0;
Sergey
parents:
diff changeset
34 } else {
Sergey
parents:
diff changeset
35 return 1;
Sergey
parents:
diff changeset
36 }
Sergey
parents:
diff changeset
37 }
Sergey
parents:
diff changeset
38 }
Sergey
parents:
diff changeset
39
Sergey
parents:
diff changeset
40 sub isEquals {
Sergey
parents:
diff changeset
41 my ($a,$b) = @_;
Sergey
parents:
diff changeset
42
Sergey
parents:
diff changeset
43 if (defined $a and defined $b) {
Sergey
parents:
diff changeset
44 return $a == $b;
Sergey
parents:
diff changeset
45 } else {
Sergey
parents:
diff changeset
46 if (defined $a or defined $b) {
Sergey
parents:
diff changeset
47 return 0;
Sergey
parents:
diff changeset
48 } else {
Sergey
parents:
diff changeset
49 return 1;
Sergey
parents:
diff changeset
50 }
Sergey
parents:
diff changeset
51 }
Sergey
parents:
diff changeset
52 }
Sergey
parents:
diff changeset
53
Sergey
parents:
diff changeset
54 sub isSame {
Sergey
parents:
diff changeset
55 my ($this,$other) = @_;
Sergey
parents:
diff changeset
56
Sergey
parents:
diff changeset
57 return ($this->{$Name} eq $other->{$Name} and $this->{$CanBeNull} == $other->{$CanBeNull} and isEqualsStr($this->{$DefaultValue}, $other->{$DefaultValue}) and $this->{$Type}->isSame($other->{$Type}));
Sergey
parents:
diff changeset
58 }
Sergey
parents:
diff changeset
59
Sergey
parents:
diff changeset
60 1;