line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
18
|
|
|
18
|
|
843
|
use strict; |
|
18
|
|
|
|
|
29
|
|
|
18
|
|
|
|
|
2913
|
|
2
|
18
|
|
|
18
|
|
97
|
use warnings; |
|
18
|
|
|
|
|
27
|
|
|
18
|
|
|
|
|
791
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package UR::DataSource::RDBMS::FkConstraint; |
5
|
|
|
|
|
|
|
|
6
|
18
|
|
|
18
|
|
67
|
use UR; |
|
18
|
|
|
|
|
23
|
|
|
18
|
|
|
|
|
102
|
|
7
|
|
|
|
|
|
|
our $VERSION = "0.46"; # UR $VERSION; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
UR::Object::Type->define( |
10
|
|
|
|
|
|
|
class_name => 'UR::DataSource::RDBMS::FkConstraint', |
11
|
|
|
|
|
|
|
is => ['UR::DataSource::RDBMS::Entity'], |
12
|
|
|
|
|
|
|
dsmap => 'dd_fk_constraint', |
13
|
|
|
|
|
|
|
er_role => '', |
14
|
|
|
|
|
|
|
id_properties => [qw/data_source table_name r_table_name fk_constraint_name/], |
15
|
|
|
|
|
|
|
properties => [ |
16
|
|
|
|
|
|
|
data_source => { type => 'varchar', len => undef, sql => 'data_source' }, |
17
|
|
|
|
|
|
|
data_source_obj => { type => 'UR::DataSource', id_by => 'data_source'}, |
18
|
|
|
|
|
|
|
namespace => { calculate_from => [ 'data_source'], |
19
|
|
|
|
|
|
|
calculate => q( (split(/::/,$data_source))[0] ) }, |
20
|
|
|
|
|
|
|
fk_constraint_name => { type => 'varchar', len => undef, sql => 'fk_constraint_name' }, |
21
|
|
|
|
|
|
|
owner => { type => 'varchar', len => undef, is_optional => 1, sql => 'owner' }, |
22
|
|
|
|
|
|
|
r_owner => { type => 'varchar', len => undef, is_optional => 1, sql => 'r_owner' }, |
23
|
|
|
|
|
|
|
r_table_name => { type => 'varchar', len => undef, sql => 'r_table_name' }, |
24
|
|
|
|
|
|
|
table_name => { type => 'varchar', len => undef, sql => 'table_name' }, |
25
|
|
|
|
|
|
|
last_object_revision => { type => 'timestamp', len => undef, sql => 'last_object_revision' }, |
26
|
|
|
|
|
|
|
], |
27
|
|
|
|
|
|
|
data_source => 'UR::DataSource::Meta', |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
#UR::Object::Type->bootstrap_object(__PACKAGE__); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _fk_constraint_column_class { |
33
|
0
|
0
|
|
0
|
|
0
|
if (shift->isa('UR::Object::Ghost')) { |
34
|
0
|
|
|
|
|
0
|
return 'UR::DataSource::RDBMS::FkConstraintColumn::Ghost'; |
35
|
|
|
|
|
|
|
} else { |
36
|
0
|
|
|
|
|
0
|
return 'UR::DataSource::RDBMS::FkConstraintColumn'; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _table_classes { |
41
|
0
|
0
|
|
0
|
|
0
|
if (shift->isa('UR::Object::Ghost')) { |
42
|
0
|
|
|
|
|
0
|
return ('UR::DataSource::RDBMS::Table::Ghost', 'UR::DataSource::RDBMS::Table'); |
43
|
|
|
|
|
|
|
} else { |
44
|
0
|
|
|
|
|
0
|
return ('UR::DataSource::RDBMS::Table', 'UR::DataSource::RDBMS::Table::Ghost'); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub get_with_special_params { |
49
|
0
|
|
|
0
|
0
|
0
|
my($class,$rule,%args) = @_; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
#$DB::single = 1; |
52
|
0
|
|
|
|
|
0
|
my $column_name = delete $args{'column_name'}; |
53
|
0
|
|
|
|
|
0
|
my $r_column_name = delete $args{'r_column_name'}; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
0
|
my @fks = $class->get($rule); |
56
|
0
|
0
|
0
|
|
|
0
|
return $class->context_return(@fks) unless ($column_name || $r_column_name); |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
0
|
my @objects; |
59
|
0
|
|
|
|
|
0
|
foreach my $fk ( @fks ) { |
60
|
0
|
|
|
|
|
0
|
my %fkc_args = ( data_source => $fk->data_source, |
61
|
|
|
|
|
|
|
table_name => $fk->table_name, |
62
|
|
|
|
|
|
|
r_table_name => $fk->r_table_name, |
63
|
|
|
|
|
|
|
); |
64
|
0
|
0
|
|
|
|
0
|
$fkc_args{'column_name'} = $column_name if $column_name; |
65
|
0
|
0
|
|
|
|
0
|
$fkc_args{'r_column_name'} = $r_column_name if $r_column_name; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
0
|
my @fkc = UR::DataSource::RDBMS::FkConstraintColumn->get(%fkc_args); |
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
0
|
push @objects,$fk if @fkc; |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
0
|
return $class->context_return(@objects); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub create { |
76
|
0
|
|
|
0
|
1
|
0
|
my $class = shift; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
0
|
my $params = { $class->define_boolexpr(@_)->normalize->params_list }; |
79
|
0
|
|
|
|
|
0
|
my $column_name = delete $params->{'column_name'}; |
80
|
0
|
|
|
|
|
0
|
my $r_column_name = delete $params->{'r_column_name'}; |
81
|
|
|
|
|
|
|
|
82
|
0
|
0
|
0
|
|
|
0
|
if ($column_name || $r_column_name) { |
83
|
0
|
0
|
|
|
|
0
|
$column_name = [ $column_name ] unless (ref $column_name); |
84
|
0
|
0
|
|
|
|
0
|
$r_column_name = [ $r_column_name ] unless (ref $r_column_name); |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
0
|
unless (scalar @$column_name == scalar @$r_column_name) { |
87
|
0
|
|
|
|
|
0
|
Carp::confess('column_name list and r_column_name list must be the same length'); |
88
|
0
|
|
|
|
|
0
|
return undef; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
0
|
my $self = $class->SUPER::create($params); |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
0
|
|
|
0
|
while ($column_name && @$column_name) { |
95
|
0
|
|
|
|
|
0
|
my $col_name = shift @$column_name; |
96
|
0
|
|
|
|
|
0
|
my $r_col_name = shift @$r_column_name; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
0
|
my $col_class = $self->_fk_constraint_column_class; |
99
|
0
|
|
|
|
|
0
|
$col_class->create(data_source => $self->data_source, |
100
|
|
|
|
|
|
|
fk_constraint_name => $self->fk_constraint_name, |
101
|
|
|
|
|
|
|
table_name => $self->table_name, |
102
|
|
|
|
|
|
|
column_name => $col_name, |
103
|
|
|
|
|
|
|
r_table_name => $self->r_table_name, |
104
|
|
|
|
|
|
|
r_column_name => $r_col_name); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
0
|
return $self; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub get_related_column_objects { |
114
|
26
|
|
|
26
|
0
|
44
|
my($self,$prop_name) = @_; |
115
|
|
|
|
|
|
|
|
116
|
26
|
|
|
|
|
107
|
my @fkcs = UR::DataSource::RDBMS::FkConstraintColumn->get( |
117
|
|
|
|
|
|
|
data_source => $self->data_source, |
118
|
|
|
|
|
|
|
table_name => $self->table_name, |
119
|
|
|
|
|
|
|
r_table_name => $self->r_table_name, |
120
|
|
|
|
|
|
|
fk_constraint_name => $self->fk_constraint_name, |
121
|
|
|
|
|
|
|
); |
122
|
26
|
100
|
|
|
|
187
|
return @fkcs unless $prop_name; |
123
|
|
|
|
|
|
|
|
124
|
1
|
|
|
|
|
3
|
return map { $_->$prop_name } @fkcs; |
|
1
|
|
|
|
|
5
|
|
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub column_names { |
128
|
1
|
|
|
1
|
0
|
6
|
return shift->get_related_column_objects('column_name'); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub r_column_names { |
132
|
0
|
|
|
0
|
0
|
|
return shift->get_related_column_objects('r_column_name'); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub column_name_map { |
136
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
my @fkcs = $self->get_related_column_objects(); |
139
|
0
|
|
|
|
|
|
return map { [ $_->column_name, $_->r_column_name ] } @fkcs; |
|
0
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub _get_related_table { |
144
|
0
|
|
|
0
|
|
|
my($self,$table_name) = @_; |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
foreach my $try_class ( $self->_table_classes ) { |
147
|
0
|
|
|
|
|
|
my $table = $try_class->get(data_source => $self->data_source, |
148
|
|
|
|
|
|
|
table_name => $table_name); |
149
|
0
|
0
|
|
|
|
|
return $table if $table; |
150
|
|
|
|
|
|
|
} |
151
|
0
|
|
|
|
|
|
return undef; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub get_table { |
156
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
157
|
0
|
|
|
|
|
|
return $self->_get_related_table($self->table_name); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub get_r_table { |
161
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
162
|
0
|
|
|
|
|
|
return $self->_get_related_table($self->r_table_name); |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
1; |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=pod |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 NAME |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
UR::DataSource::RDBMS::FkConstraint - metadata about a data source's foreign keys |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 DESCRIPTION |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
This class represents instances of foreign keys in a data source. They are |
179
|
|
|
|
|
|
|
maintained by 'ur update classes' and stored in the namespace's MetaDB. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=cut |