line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Rose::DB::Object::Metadata::PrimaryKey; |
2
|
|
|
|
|
|
|
|
3
|
61
|
|
|
61
|
|
474
|
use strict; |
|
61
|
|
|
|
|
153
|
|
|
61
|
|
|
|
|
2079
|
|
4
|
|
|
|
|
|
|
|
5
|
61
|
|
|
61
|
|
26995
|
use Rose::DB::Object::Metadata::UniqueKey; |
|
61
|
|
|
|
|
232
|
|
|
61
|
|
|
|
|
3763
|
|
6
|
|
|
|
|
|
|
our @ISA = qw(Rose::DB::Object::Metadata::UniqueKey); |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.58'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Rose::Object::MakeMethods::Generic |
11
|
|
|
|
|
|
|
( |
12
|
61
|
|
|
|
|
362
|
scalar => |
13
|
|
|
|
|
|
|
[ |
14
|
|
|
|
|
|
|
'generator', |
15
|
|
|
|
|
|
|
], |
16
|
61
|
|
|
61
|
|
481
|
); |
|
61
|
|
|
|
|
164
|
|
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
0
|
0
|
0
|
sub init_name { 'primary_key' } |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub sequence_names |
21
|
|
|
|
|
|
|
{ |
22
|
0
|
|
|
0
|
1
|
0
|
my($self) = shift; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
0
|
my $db; |
25
|
0
|
0
|
|
|
|
0
|
$db = shift if(UNIVERSAL::isa($_[0], 'Rose::DB')); |
26
|
0
|
|
0
|
|
|
0
|
$db ||= $self->parent->init_db; |
27
|
0
|
|
|
|
|
0
|
my $db_id = $db->id; |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
0
|
if(@_) |
30
|
|
|
|
|
|
|
{ |
31
|
|
|
|
|
|
|
my $seqs = $self->{'sequence_names'}{$db->driver} = |
32
|
0
|
0
|
0
|
|
|
0
|
$self->{'sequence_names'}{$db_id} = |
33
|
|
|
|
|
|
|
(@_ == 1 && ref $_[0]) ? $_[0] : [ @_ ]; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
0
|
my $i = 0; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
0
|
foreach my $column ($self->SUPER::columns) |
38
|
|
|
|
|
|
|
{ |
39
|
0
|
0
|
|
|
|
0
|
next unless(ref $column); # may just be a column name |
40
|
|
|
|
|
|
|
# Push down into column metadata object too |
41
|
0
|
|
|
|
|
0
|
$column->default_value_sequence_name($db, $seqs->[$i++]); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $ret = $self->{'sequence_names'}{$db_id} || |
46
|
0
|
|
0
|
|
|
0
|
$self->{'sequence_names'}{$db->driver}; |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
0
|
unless(ref $ret) |
49
|
|
|
|
|
|
|
{ |
50
|
0
|
|
|
|
|
0
|
$self->sync_sequence_names; |
51
|
|
|
|
|
|
|
$ret = $self->{'sequence_names'}{$db_id} || |
52
|
0
|
|
0
|
|
|
0
|
$self->{'sequence_names'}{$db->driver}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
0
|
return unless(ref $ret); |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
0
|
return wantarray ? @$ret : $ret; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub auto_init_columns |
61
|
|
|
|
|
|
|
{ |
62
|
77
|
|
|
77
|
0
|
200
|
my($self) = shift; |
63
|
77
|
|
50
|
|
|
195
|
my $meta = $self->parent || return []; |
64
|
77
|
|
50
|
|
|
233
|
return $meta->convention_manager->auto_primary_key_column_names || []; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub add_columns |
68
|
|
|
|
|
|
|
{ |
69
|
3
|
|
|
3
|
1
|
28
|
my($self) = shift; |
70
|
|
|
|
|
|
|
|
71
|
3
|
|
|
|
|
44
|
$self->SUPER::add_columns(@_); |
72
|
3
|
|
|
|
|
15
|
$self->sync_sequence_names; |
73
|
3
|
|
|
|
|
16
|
$self->parent->init_primary_key_column_info; |
74
|
3
|
|
|
|
|
8
|
return; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
*add_column = \&add_columns; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub columns |
80
|
|
|
|
|
|
|
{ |
81
|
153
|
|
|
153
|
1
|
725
|
my($self) = shift; |
82
|
|
|
|
|
|
|
|
83
|
153
|
|
|
|
|
294
|
my(@ret, $ret); |
84
|
|
|
|
|
|
|
|
85
|
153
|
|
|
|
|
288
|
my $wantarray = wantarray; |
86
|
153
|
100
|
|
|
|
321
|
if(defined $wantarray) |
87
|
|
|
|
|
|
|
{ |
88
|
152
|
100
|
|
|
|
287
|
if($wantarray) |
89
|
|
|
|
|
|
|
{ |
90
|
75
|
|
|
|
|
278
|
@ret = $self->SUPER::columns(@_); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
else |
93
|
|
|
|
|
|
|
{ |
94
|
77
|
|
|
|
|
231
|
$ret = $self->SUPER::columns(@_); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else |
98
|
|
|
|
|
|
|
{ |
99
|
1
|
|
|
|
|
11
|
$self->SUPER::columns(@_); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
153
|
100
|
|
|
|
411
|
$self->parent->init_primary_key_column_info if(@_); |
103
|
153
|
|
|
|
|
460
|
$self->sync_sequence_names; |
104
|
|
|
|
|
|
|
|
105
|
153
|
100
|
|
|
|
608
|
return $wantarray ? @ret : $ret; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub sync_sequence_names |
109
|
|
|
|
|
|
|
{ |
110
|
156
|
|
|
156
|
0
|
293
|
my($self) = shift; |
111
|
|
|
|
|
|
|
|
112
|
156
|
|
|
|
|
295
|
my @sequences; |
113
|
|
|
|
|
|
|
|
114
|
156
|
|
|
|
|
376
|
foreach my $column ($self->SUPER::columns) |
115
|
|
|
|
|
|
|
{ |
116
|
160
|
100
|
|
|
|
465
|
next unless(ref $column); # may just be a column name |
117
|
157
|
|
|
|
|
500
|
push(@sequences, $column->default_value_sequence_name); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
156
|
50
|
|
|
|
423
|
return unless(grep { defined } @sequences); |
|
157
|
|
|
|
|
673
|
|
121
|
|
|
|
|
|
|
|
122
|
0
|
0
|
|
|
|
|
$self->sequence_names(\@sequences) if(@sequences); |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
return; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 NAME |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Rose::DB::Object::Metadata::PrimaryKey - Primary key metadata. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 SYNOPSIS |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
use Rose::DB::Object::Metadata::PrimaryKey; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
$pk = Rose::DB::Object::Metadata::PrimaryKey->new( |
140
|
|
|
|
|
|
|
columns => [ 'id', 'type' ]); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
MyClass->meta->primary_key($pk); |
143
|
|
|
|
|
|
|
... |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 DESCRIPTION |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Objects of this class store and manipulate metadata for primary keys in a database table. Each primary key is made up of one or more columns. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 OBJECT METHODS |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=over 4 |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item B<add_column [COLUMNS]> |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
This method is an alias for the L<add_columns|/add_columns> method. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item B<add_columns [COLUMNS]> |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Add COLUMNS to the list of columns that make up the primary key. COLUMNS must be a list or reference to an array of column names or L<Rose::DB::Object::Metadata::Column>-derived objects. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item B<columns [COLUMNS]> |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Get or set the list of columns that make up the primary key. COLUMNS must a list or reference to an array of column names or L<Rose::DB::Object::Metadata::Column>-derived objects. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
This method returns all of the columns that make up the primary key. Each column is a L<Rose::DB::Object::Metadata::Column>-derived column object if the primary key's L<parent|/parent> has a column object with the same name, or just the column name otherwise. In scalar context, a reference to an array of columns is returned. In list context, a list is returned. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=item B<column_names> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Returns a list (in list context) or reference to an array (in scalar context) of the names of the columns that make up the primary key. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item B<delete_columns> |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Delete the entire list of columns that make up the primary key. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=item B<name [NAME]> |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Get or set the name of the primary key. Traditionally, this is the name of the index that the database uses to maintain the primary key, but databases vary. If left undefined, the default value is "primary_key". |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item B<parent [META]> |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Get or set the L<Rose::DB::Object::Metadata>-derived object that this primary key belongs to. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item B<sequence_names [NAMES]> |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Get or set the list of database sequence names (if any) used to generate values for the primary key columns. The sequence names must be in the same order as the L<columns|/columns>. NAMES may be a list or reference to an array of sequence names. Returns a list (in list context) or reference to the array (in scalar context) of sequence names. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=back |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 AUTHOR |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
John C. Siracusa (siracusa@gmail.com) |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 LICENSE |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Copyright (c) 2010 by John C. Siracusa. All rights reserved. This program is |
196
|
|
|
|
|
|
|
free software; you can redistribute it and/or modify it under the same terms |
197
|
|
|
|
|
|
|
as Perl itself. |