line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id$ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Data::ObjectDriver; |
4
|
1
|
|
|
1
|
|
737
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
6
|
1
|
|
|
1
|
|
22
|
use 5.006_001; |
|
1
|
|
|
|
|
3
|
|
7
|
1
|
|
|
1
|
|
466
|
use Class::Accessor::Fast; |
|
1
|
|
|
|
|
2554
|
|
|
1
|
|
|
|
|
9
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
35
|
use base qw( Class::Accessor::Fast ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
74
|
|
10
|
1
|
|
|
1
|
|
383
|
use Data::ObjectDriver::Iterator; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
942
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw( pk_generator txn_active )); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.22'; |
15
|
|
|
|
|
|
|
our $DEBUG = $ENV{DOD_DEBUG} || 0; |
16
|
|
|
|
|
|
|
our $PROFILE = $ENV{DOD_PROFILE} || 0; |
17
|
|
|
|
|
|
|
our $PROFILER; |
18
|
|
|
|
|
|
|
our $LOGGER; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
22
|
0
|
|
|
|
|
|
my $driver = bless {}, $class; |
23
|
0
|
|
|
|
|
|
$driver->init(@_); |
24
|
0
|
|
|
|
|
|
$driver; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub logger { |
28
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
29
|
0
|
0
|
|
|
|
|
if ( @_ ) { |
30
|
0
|
|
|
|
|
|
return $LOGGER = shift; |
31
|
|
|
|
|
|
|
} else { |
32
|
|
|
|
|
|
|
return $LOGGER ||= sub { |
33
|
0
|
|
|
0
|
|
|
print STDERR @_; |
34
|
0
|
|
0
|
|
|
|
}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub init { |
39
|
0
|
|
|
0
|
0
|
|
my $driver = shift; |
40
|
0
|
|
|
|
|
|
my %param = @_; |
41
|
0
|
|
|
|
|
|
$driver->pk_generator($param{pk_generator}); |
42
|
0
|
|
|
|
|
|
$driver->txn_active(0); |
43
|
0
|
|
|
|
|
|
$driver; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Alias record_query to start_query |
47
|
|
|
|
|
|
|
*record_query = \*start_query; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub start_query { |
50
|
0
|
|
|
0
|
0
|
|
my $driver = shift; |
51
|
0
|
|
|
|
|
|
my($sql, $bind) = @_; |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
$driver->debug($sql, $bind) if $DEBUG; |
54
|
0
|
0
|
|
|
|
|
$driver->profiler($sql) if $PROFILE; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
return; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
0
|
0
|
|
sub end_query { } |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub begin_work { |
62
|
0
|
|
|
0
|
1
|
|
my $driver = shift; |
63
|
0
|
|
|
|
|
|
$driver->txn_active(1); |
64
|
0
|
|
|
|
|
|
$driver->debug(sprintf("%14s", "BEGIN_WORK") . ": driver=$driver"); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub commit { |
68
|
0
|
|
|
0
|
1
|
|
my $driver = shift; |
69
|
0
|
|
|
|
|
|
_end_txn($driver, 'commit'); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub rollback { |
73
|
0
|
|
|
0
|
1
|
|
my $driver = shift; |
74
|
0
|
|
|
|
|
|
_end_txn($driver, 'rollback'); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _end_txn { |
78
|
0
|
|
|
0
|
|
|
my $driver = shift; |
79
|
0
|
|
|
|
|
|
my $method = shift; |
80
|
0
|
|
|
|
|
|
$driver->txn_active(0); |
81
|
0
|
|
|
|
|
|
$driver->debug(sprintf("%14s", uc($method)) . ": driver=$driver"); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub debug { |
85
|
0
|
|
|
0
|
0
|
|
my $driver = shift; |
86
|
0
|
0
|
|
|
|
|
return unless $DEBUG; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
0
|
|
|
|
my $class = ref $driver || $driver; |
89
|
0
|
|
|
|
|
|
my @caller; |
90
|
0
|
|
|
|
|
|
my $i = 0; |
91
|
0
|
|
|
|
|
|
while (1) { |
92
|
0
|
|
|
|
|
|
@caller = caller($i++); |
93
|
0
|
0
|
|
|
|
|
last if $caller[0] !~ /^(Data::ObjectDriver|$class)/; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my $where = " in file $caller[1] line $caller[2]\n"; |
97
|
|
|
|
|
|
|
|
98
|
0
|
0
|
0
|
|
|
|
if (@_ == 1 && !ref($_[0])) { |
99
|
0
|
|
|
|
|
|
$driver->logger->( @_, $where ); |
100
|
|
|
|
|
|
|
} else { |
101
|
0
|
|
|
|
|
|
require Data::Dumper; |
102
|
0
|
|
|
|
|
|
local $Data::Dumper::Indent = 1; |
103
|
0
|
|
|
|
|
|
$driver->logger->( Data::Dumper::Dumper(@_), $where ); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub profiler { |
108
|
0
|
|
|
0
|
0
|
|
my $driver = shift; |
109
|
0
|
|
|
|
|
|
my ($sql) = @_; |
110
|
0
|
|
|
|
|
|
local $@; |
111
|
0
|
|
0
|
|
|
|
$PROFILER ||= eval { |
112
|
0
|
|
|
|
|
|
require Data::ObjectDriver::Profiler; |
113
|
0
|
|
|
|
|
|
Data::ObjectDriver::Profiler->new; |
114
|
|
|
|
|
|
|
}; |
115
|
0
|
0
|
0
|
|
|
|
return $PROFILE = 0 if $@ || !$PROFILER; |
116
|
0
|
0
|
|
|
|
|
return $PROFILER unless @_; |
117
|
0
|
|
|
|
|
|
$PROFILER->record_query($driver, $sql); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub list_or_iterator { |
121
|
0
|
|
|
0
|
0
|
|
my $driver = shift; |
122
|
0
|
|
|
|
|
|
my($objs) = @_; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
## Emulate the standard search behavior of returning an |
125
|
|
|
|
|
|
|
## iterator in scalar context, and the full list in list context. |
126
|
0
|
0
|
|
|
|
|
if (wantarray) { |
127
|
0
|
|
|
|
|
|
return @{$objs}; |
|
0
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
} else { |
129
|
0
|
|
|
0
|
|
|
my $iter = sub { shift @{$objs} }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
return Data::ObjectDriver::Iterator->new($iter); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
0
|
0
|
|
sub cache_object { } |
135
|
|
|
|
0
|
0
|
|
sub uncache_object { } |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |
138
|
|
|
|
|
|
|
__END__ |