| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Alzabo::Create::Index; |
|
2
|
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
54
|
use strict; |
|
|
9
|
|
|
|
|
18
|
|
|
|
9
|
|
|
|
|
634
|
|
|
4
|
9
|
|
|
9
|
|
53
|
use vars qw($VERSION); |
|
|
9
|
|
|
|
|
18
|
|
|
|
9
|
|
|
|
|
397
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
9
|
|
|
9
|
|
49
|
use Alzabo::Create; |
|
|
9
|
|
|
|
|
17
|
|
|
|
9
|
|
|
|
|
300
|
|
|
7
|
9
|
|
|
9
|
|
57
|
use Alzabo::Exceptions ( abbr => 'params_exception' ); |
|
|
9
|
|
|
|
|
18
|
|
|
|
9
|
|
|
|
|
61
|
|
|
8
|
9
|
|
|
9
|
|
54
|
use Alzabo::Utils; |
|
|
9
|
|
|
|
|
16
|
|
|
|
9
|
|
|
|
|
215
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
9
|
|
|
9
|
|
45
|
use Params::Validate qw( :all ); |
|
|
9
|
|
|
|
|
19
|
|
|
|
9
|
|
|
|
|
2259
|
|
|
11
|
|
|
|
|
|
|
Params::Validate::validation_options |
|
12
|
|
|
|
|
|
|
( on_fail => sub { params_exception join '', @_ } ); |
|
13
|
|
|
|
|
|
|
|
|
14
|
9
|
|
|
9
|
|
55
|
use base qw(Alzabo::Index); |
|
|
9
|
|
|
|
|
18
|
|
|
|
9
|
|
|
|
|
11775
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$VERSION = 2.0; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
1; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new |
|
21
|
|
|
|
|
|
|
{ |
|
22
|
0
|
|
|
0
|
1
|
|
my $proto = shift; |
|
23
|
0
|
|
0
|
|
|
|
my $class = ref $proto || $proto; |
|
24
|
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
validate( @_, { table => { isa => 'Alzabo::Create::Table' }, |
|
26
|
|
|
|
|
|
|
columns => { type => ARRAYREF }, |
|
27
|
|
|
|
|
|
|
unique => { type => BOOLEAN, default => 0 }, |
|
28
|
|
|
|
|
|
|
fulltext => { type => BOOLEAN, default => 0 }, |
|
29
|
|
|
|
|
|
|
function => { type => UNDEF | SCALAR, default => undef }, |
|
30
|
|
|
|
|
|
|
} ); |
|
31
|
0
|
|
|
|
|
|
my %p = @_; |
|
32
|
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
$self->{table} = $p{table}; |
|
36
|
0
|
|
0
|
|
|
|
$self->{unique} = $p{unique} || 0; |
|
37
|
0
|
|
0
|
|
|
|
$self->{fulltext} = $p{fulltext} || 0; |
|
38
|
0
|
|
|
|
|
|
$self->{function} = $p{function}; |
|
39
|
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
$self->{columns} = Tie::IxHash->new; |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
foreach my $c (@{ $p{columns} }) |
|
|
0
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
{ |
|
44
|
0
|
0
|
|
|
|
|
my %p = Alzabo::Utils::safe_isa( $c, 'Alzabo::Column' ) ? ( column => $c ) : %$c; |
|
45
|
0
|
|
|
|
|
|
$self->add_column(%p); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
$self->table->schema->rules->validate_index($self); |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
return $self; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub add_column |
|
54
|
|
|
|
|
|
|
{ |
|
55
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
validate( @_, { column => { isa => 'Alzabo::Create::Column' }, |
|
58
|
|
|
|
|
|
|
prefix => { type => SCALAR, |
|
59
|
|
|
|
|
|
|
optional => 1 } } ); |
|
60
|
0
|
|
|
|
|
|
my %p = @_; |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $new_name = $p{column}->name; |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
params_exception "Column $new_name already exists in index." |
|
65
|
|
|
|
|
|
|
if $self->{columns}->EXISTS($new_name); |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$self->{columns}->STORE( $new_name, \%p ); |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
eval { $self->table->schema->rules->validate_index($self); }; |
|
|
0
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
if ($@) |
|
72
|
|
|
|
|
|
|
{ |
|
73
|
0
|
|
|
|
|
|
$self->{columns}->DELETE($new_name); |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
rethrow_exception($@); |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub delete_column |
|
80
|
|
|
|
|
|
|
{ |
|
81
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
validate_pos( @_, { isa => 'Alzabo::Create::Column' } ); |
|
84
|
0
|
|
|
|
|
|
my $c = shift; |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
params_exception "Column " . $c->name . " is not part of index." |
|
87
|
|
|
|
|
|
|
unless $self->{columns}->EXISTS( $c->name ); |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
$self->{columns}->DELETE( $c->name ); |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub set_prefix |
|
93
|
|
|
|
|
|
|
{ |
|
94
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
validate( @_, { column => { isa => 'Alzabo::Create::Column' }, |
|
97
|
|
|
|
|
|
|
prefix => { type => SCALAR } } ); |
|
98
|
0
|
|
|
|
|
|
my %p = @_; |
|
99
|
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
|
params_exception "Column " . $p{column}->name . " is not part of index." |
|
101
|
|
|
|
|
|
|
unless $self->{columns}->EXISTS( $p{column}->name ); |
|
102
|
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my $col = $self->{columns}->FETCH( $p{column}->name ); |
|
104
|
0
|
|
|
|
|
|
my $old_val = delete $col->{prefix}; |
|
105
|
0
|
|
|
|
|
|
$col->{prefix} = $p{prefix}; |
|
106
|
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
eval { $self->table->schema->rules->validate_index($self); }; |
|
|
0
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
if ($@) |
|
110
|
|
|
|
|
|
|
{ |
|
111
|
0
|
0
|
|
|
|
|
if ($old_val) |
|
112
|
|
|
|
|
|
|
{ |
|
113
|
0
|
|
|
|
|
|
$col->{prefix} = $old_val; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
else |
|
116
|
|
|
|
|
|
|
{ |
|
117
|
0
|
|
|
|
|
|
delete $col->{prefix}; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
rethrow_exception($@); |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub set_unique |
|
125
|
|
|
|
|
|
|
{ |
|
126
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
127
|
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
validate_pos( @_, 1 ); |
|
129
|
0
|
|
|
|
|
|
$self->{unique} = shift; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub set_fulltext |
|
133
|
|
|
|
|
|
|
{ |
|
134
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
135
|
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
validate_pos( @_, 1 ); |
|
137
|
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
my $old_val = $self->{fulltext}; |
|
139
|
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
$self->{fulltext} = shift; |
|
141
|
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
eval { $self->table->schema->rules->validate_index($self); }; |
|
|
0
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
|
144
|
0
|
0
|
|
|
|
|
if ($@) |
|
145
|
|
|
|
|
|
|
{ |
|
146
|
0
|
|
|
|
|
|
$self->{fulltext} = $old_val; |
|
147
|
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
rethrow_exception($@); |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub register_column_name_change |
|
153
|
|
|
|
|
|
|
{ |
|
154
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
155
|
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
validate( @_, { column => { isa => 'Alzabo::Create::Column' }, |
|
157
|
|
|
|
|
|
|
old_name => { type => SCALAR } } ); |
|
158
|
0
|
|
|
|
|
|
my %p = @_; |
|
159
|
|
|
|
|
|
|
|
|
160
|
0
|
0
|
|
|
|
|
return unless $self->{columns}->EXISTS( $p{old_name} ); |
|
161
|
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
my $new_name = $p{column}->name; |
|
163
|
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
my $index = $self->{columns}->Indices( $p{old_name} ); |
|
165
|
0
|
|
|
|
|
|
my $val = $self->{columns}->Values($index); |
|
166
|
0
|
|
|
|
|
|
$val->{column} = $p{column}; |
|
167
|
0
|
|
|
|
|
|
$self->{columns}->Replace( $index, $val, $new_name ); |
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
__END__ |