line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wiki::Toolkit::Store::Pg; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1474
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
69
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
10
|
use vars qw( @ISA $VERSION ); |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
93
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
684
|
use Wiki::Toolkit::Store::Database; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
62
|
|
8
|
2
|
|
|
2
|
|
12
|
use Carp qw/carp croak/; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
942
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
@ISA = qw( Wiki::Toolkit::Store::Database ); |
11
|
|
|
|
|
|
|
$VERSION = 0.07; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Wiki::Toolkit::Store::Pg - Postgres storage backend for Wiki::Toolkit |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 REQUIRES |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Subclasses Wiki::Toolkit::Store::Database. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
See Wiki::Toolkit::Store::Database |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Internal method to return the data source string required by DBI. |
28
|
|
|
|
|
|
|
sub _dsn { |
29
|
0
|
|
|
0
|
|
|
my ($self, $dbname, $dbhost, $dbport) = @_; |
30
|
0
|
|
|
|
|
|
my $dsn = "dbi:Pg:dbname=$dbname"; |
31
|
0
|
0
|
|
|
|
|
$dsn .= ";host=$dbhost" if $dbhost; |
32
|
0
|
0
|
|
|
|
|
$dsn .= ";port=$dbport" if $dbport; |
33
|
0
|
|
|
|
|
|
return $dsn; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 METHODS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=over 4 |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item B |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$store->check_and_write_node( node => $node, |
43
|
|
|
|
|
|
|
checksum => $checksum, |
44
|
|
|
|
|
|
|
%other_args ); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Locks the node, verifies the checksum, calls |
47
|
|
|
|
|
|
|
C with all supplied arguments, unlocks the |
48
|
|
|
|
|
|
|
node. Returns the version of the updated node on successful writing, 0 if |
49
|
|
|
|
|
|
|
checksum doesn't match, -1 if the change was not applied, croaks on error. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=back |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub check_and_write_node { |
56
|
0
|
|
|
0
|
1
|
|
my ($self, %args) = @_; |
57
|
0
|
|
|
|
|
|
my ($node, $checksum) = @args{qw( node checksum )}; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $dbh = $self->{_dbh}; |
60
|
0
|
|
|
|
|
|
$dbh->{AutoCommit} = 0; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $ok = eval { |
63
|
0
|
|
|
|
|
|
$dbh->do("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE"); |
64
|
0
|
0
|
|
|
|
|
$self->verify_checksum($node, $checksum) or return 0; |
65
|
0
|
|
|
|
|
|
$self->write_node_post_locking( %args ); |
66
|
|
|
|
|
|
|
}; |
67
|
0
|
0
|
|
|
|
|
if ($@) { |
68
|
0
|
|
|
|
|
|
my $error = $@; |
69
|
0
|
|
|
|
|
|
$dbh->rollback; |
70
|
0
|
|
|
|
|
|
$dbh->{AutoCommit} = 1; |
71
|
0
|
0
|
0
|
|
|
|
if ( $error =~ /can't serialize access due to concurrent update/i |
72
|
|
|
|
|
|
|
or $error =~ /could not serialize access due to concurrent update/i |
73
|
|
|
|
|
|
|
) { |
74
|
0
|
|
|
|
|
|
return 0; |
75
|
|
|
|
|
|
|
} else { |
76
|
0
|
|
|
|
|
|
croak $error; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} else { |
79
|
0
|
|
|
|
|
|
$dbh->commit; |
80
|
0
|
|
|
|
|
|
$dbh->{AutoCommit} = 1; |
81
|
0
|
|
|
|
|
|
return $ok; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _get_comparison_sql { |
86
|
0
|
|
|
0
|
|
|
my ($self, %args) = @_; |
87
|
0
|
0
|
|
|
|
|
if ( $args{ignore_case} ) { |
88
|
0
|
|
|
|
|
|
return "lower($args{thing1}) = lower($args{thing2})"; |
89
|
|
|
|
|
|
|
} else { |
90
|
0
|
|
|
|
|
|
return "$args{thing1} = $args{thing2}"; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub _get_node_exists_ignore_case_sql { |
95
|
0
|
|
|
0
|
|
|
return "SELECT name FROM node WHERE lower(name) = lower(?) "; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |