line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Replicate.pm 22870 2008-11-06 16:06:55Z kazuho $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package DBIx::Replicate; |
4
|
1
|
|
|
1
|
|
25744
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
6
|
1
|
|
|
1
|
|
2331
|
use Carp::Clan; |
|
1
|
|
|
|
|
14807
|
|
|
1
|
|
|
|
|
10
|
|
7
|
1
|
|
|
1
|
|
38052
|
use DBI; |
|
1
|
|
|
|
|
37892
|
|
|
1
|
|
|
|
|
67
|
|
8
|
1
|
|
|
1
|
|
665
|
use DBIx::Replicate::Node; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
12
|
|
9
|
1
|
|
|
1
|
|
53
|
use UNIVERSAL::require; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
10
|
1
|
|
|
1
|
|
34
|
use Exporter 'import'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
52
|
|
11
|
1
|
|
|
1
|
|
8
|
use base qw(Class::Accessor::Fast); |
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
1562
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
14
|
|
|
|
|
|
|
'all' => [ qw/dbix_replicate/ ], |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
our @EXPORT_OK = map { @{$EXPORT_TAGS{$_}} } qw/all/; |
17
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors($_) for qw(src dest columns block extra_cond limit_cond strategy); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new |
22
|
|
|
|
|
|
|
{ |
23
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
24
|
0
|
|
0
|
|
|
|
my $args = shift || {}; |
25
|
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
|
if (! $args->{strategy}) { |
27
|
0
|
|
0
|
|
|
|
$args->{strategy_class} ||= 'DBIx::Replicate::Strategy::PK'; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
if ( my $strategy_class = $args->{strategy_class}) { |
31
|
0
|
|
0
|
|
|
|
my $strategy_args = $args->{strategy_args} || {}; |
32
|
0
|
0
|
|
|
|
|
$strategy_class->require or die; |
33
|
0
|
|
|
|
|
|
$args->{strategy} = $strategy_class->new($strategy_args); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
foreach my $p (qw/src dest columns strategy/) { |
37
|
0
|
0
|
|
|
|
|
croak "required parameter $p is missing\n" |
38
|
|
|
|
|
|
|
unless $args->{$p}; |
39
|
|
|
|
|
|
|
} |
40
|
0
|
|
0
|
|
|
|
$args->{block} ||= 1000; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new({ |
43
|
|
|
|
|
|
|
strategy => $args->{strategy}, |
44
|
|
|
|
|
|
|
columns => $args->{columns}, |
45
|
|
|
|
|
|
|
block => $args->{block}, |
46
|
|
|
|
|
|
|
src => $args->{src}, |
47
|
|
|
|
|
|
|
dest => $args->{dest}, |
48
|
|
|
|
|
|
|
extra_cond => $args->{extra_cond}, |
49
|
|
|
|
|
|
|
limit_cond => $args->{limit_cond}, |
50
|
|
|
|
|
|
|
}); |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
return $self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub dbix_replicate { |
56
|
0
|
|
|
0
|
0
|
|
my $args = shift; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
$args = { %$args }; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
foreach my $p (qw/src_table src_conn dest_table dest_conn columns/) { |
61
|
0
|
0
|
|
|
|
|
croak "required parameter $p is missing\n" |
62
|
|
|
|
|
|
|
unless $args->{$p}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $src = DBIx::Replicate::Node->new( { |
66
|
|
|
|
|
|
|
table => delete $args->{src_table}, |
67
|
|
|
|
|
|
|
conn => delete $args->{src_conn}, |
68
|
|
|
|
|
|
|
} ); |
69
|
0
|
|
|
|
|
|
my $dest = DBIx::Replicate::Node->new( { |
70
|
|
|
|
|
|
|
table => delete $args->{dest_table}, |
71
|
|
|
|
|
|
|
conn => delete $args->{dest_conn} |
72
|
|
|
|
|
|
|
}); |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
0
|
|
|
|
if (! $args->{strategy} && ! $args->{strategy_class}) { |
75
|
0
|
0
|
|
|
|
|
if ($args->{copy_by}) { |
76
|
0
|
|
0
|
|
|
|
$args->{strategy_class} ||= 'DBIx::Replicate::Strategy::CopyBy'; |
77
|
|
|
|
|
|
|
} else { |
78
|
0
|
|
0
|
|
|
|
$args->{strategy_class} ||= 'DBIx::Replicate::Strategy::PK'; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my %args = ( |
83
|
|
|
|
|
|
|
src => $src, |
84
|
|
|
|
|
|
|
dest => $dest, |
85
|
|
|
|
|
|
|
columns => delete $args->{columns}, |
86
|
|
|
|
|
|
|
block => delete $args->{block}, |
87
|
|
|
|
|
|
|
extra_cond => delete $args->{extra_cond}, |
88
|
|
|
|
|
|
|
limit_cond => delete $args->{limit_cond}, |
89
|
|
|
|
|
|
|
strategy => delete $args->{strategy}, |
90
|
|
|
|
|
|
|
strategy_class => delete $args->{strategy_class}, |
91
|
|
|
|
|
|
|
strategy_args => delete $args->{strategy_args}, |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my $dr = DBIx::Replicate->new( \%args ); |
95
|
0
|
|
|
|
|
|
$dr->replicate($args); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub replicate |
99
|
|
|
|
|
|
|
{ |
100
|
0
|
|
|
0
|
0
|
|
my ($self, $args) = @_; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
$self->strategy->replicate( $self, $args ); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
__END__ |