SQL/Amazon/StorageEngine.pm

filter: Statementstmt 16.4% 15 / 91 Branchbran 0.0% 0 / 46 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 21.0% 4 / 19 Podpod 0.0% 0 / 14 totaltotal 11.1% 19 / 170 CC 29 SCAR 27.2
CC
29
Cov
11%
get_table
30.0
debug
30.0
cache_item
20.0
CRAP 15.1
« SQL/Amazon/Functions.pm ↑ Summary DBD/Amazon.pm »
1 #
2 # Copyright (c) 2005, Presicient Corp., USA
3 #
4 # Permission is granted to use this software according to the terms of the
5 # Artistic License, as specified in the Perl README file,
6 # with the exception that commercial redistribution, either
7 # electronic or via physical media, as either a standalone package,
8 # or incorporated into a third party product, requires prior
9 # written approval of the author.
10 #
11 # This software is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 #
15 # Presicient Corp. reserves the right to provide support for this software
16 # to individual sites under a separate (possibly fee-based)
17 # agreement.
18 #
19 # History:
20 #
21 # 2005-Jan-27 D. Arnold
22 # Coded.
23 #
24 package SQL::Amazon::StorageEngine;
25 1 ▶use SQL::Amazon::Tables::SysSchema;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use constant AMZN_STORE_TABLES => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use constant AMZN_STORE_ERRSTR => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 our %amzn_table_classes = (
30 'ACCESSORIES', 'SQL::Amazon::Tables::Accessories',
31 'APPAREL', 'SQL::Amazon::Tables::Apparel',
32 'BABY', 'SQL::Amazon::Tables::Baby',
33 'BEAUTY', 'SQL::Amazon::Tables::Beauty',
34 'BLENDED', 'SQL::Amazon::Tables::Blended',
35 'BOOKS', 'SQL::Amazon::Tables::Books',
36 'BROWSENODES', 'SQL::Amazon::Tables::BrowseNodes',
37 'CAMERAPHOTO', 'SQL::Amazon::Tables::Photo',
38 'CLASSICALMUSIC', 'SQL::Amazon::Tables::ClassicalMusic',
39 'CUSTOMERREVIEWS', 'SQL::Amazon::Tables::CustomerReviews',
40 'CUSTOMERS', 'SQL::Amazon::Tables::Customers',
41 'DIGITALMUSIC', 'SQL::Amazon::Tables::DigitalMusic',
42 'DVDS', 'SQL::Amazon::Tables::DVDs',
43 'EDITORIALREVIEWS', 'SQL::Amazon::Tables::EditorialReviews',
44 'ELECTRONICS', 'SQL::Amazon::Tables::Electronics',
45 'GOURMETFOOD', 'SQL::Amazon::Tables::GourmetFood',
46 'HARDWARE', 'SQL::Amazon::Tables::Hardware',
47 'HEALTHPERSONALCARE', 'SQL::Amazon::Tables::HealthPersonalCare',
48 'HOMEGARDEN', 'SQL::Amazon::Tables::HomeGarden',
49 'ITEMS', 'SQL::Amazon::Tables::Items',
50 'ITEMATTRIBUTES', 'SQL::Amazon::Tables::ItemAttributes',
51 'ITEMFEATURES', 'SQL::Amazon::Tables::ItemFeatures',
52 'JEWELRY', 'SQL::Amazon::Tables::Jewelry',
53 'KITCHEN', 'SQL::Amazon::Tables::Kitchen',
54 'LISTMANIALISTS', 'SQL::Amazon::Tables::ListManiaLists',
55 'MAGAZINES', 'SQL::Amazon::Tables::Magazines',
56 'MERCHANTS', 'SQL::Amazon::Tables::Merchants',
57 'MISCELLANEOUS', 'SQL::Amazon::Tables::Miscellaneous',
58 'MUSIC', 'SQL::Amazon::Tables::Music',
59 'MUSICALINSTRUMENTS', 'SQL::Amazon::Tables::MusicalInstruments',
60 'MUSICTRACKS', 'SQL::Amazon::Tables::MusicTracks',
61 'OFFERS', 'SQL::Amazon::Tables::Offers',
62 'OFFERLISTINGS', 'SQL::Amazon::Tables::OfferListings',
63 'OFFICEPRODUCTS', 'SQL::Amazon::Tables::OfficeProducts',
64 'OUTDOORLIVING', 'SQL::Amazon::Tables::OutdoorLiving',
65 'PCHARDWARE', 'SQL::Amazon::Tables::PCHardware',
66 'RESTAURANTS', 'SQL::Amazon::Tables::Restaurants',
67 'SAVEDITEMS', 'SQL::Amazon::Tables::SavedItems',
68 'SYSSCHEMA', 'SQL::Amazon::Tables::SysSchema',
69 'SELLERS', 'SQL::Amazon::Tables::Sellers',
70 'SELLERFEEDBACK', 'SQL::Amazon::Tables::SellerFeedback',
71 'SELLERLISTINGS', 'SQL::Amazon::Tables::SellerListings',
72 'SIMILARITEMS', 'SQL::Amazon::Tables::SimilarItems',
73 'SIMILARPRODUCTS', 'SQL::Amazon::Tables::SimilarProducts',
74 'SOFTWARE', 'SQL::Amazon::Tables::Software',
75 'SPORTINGGOODS', 'SQL::Amazon::Tables::SportingGoods',
76 'TRACKS', 'SQL::Amazon::Tables::Tracks',
77 'TRANSACTIONS', 'SQL::Amazon::Tables::Transactions',
78 'TRANSACTIONITEMS', 'SQL::Amazon::Tables::TransactionItems',
79 'TOYS', 'SQL::Amazon::Tables::Toys',
80 'VARIATIONS', 'SQL::Amazon::Tables::Variations',
81 'VHS', 'SQL::Amazon::Tables::VHS',
82 'VIDEO', 'SQL::Amazon::Tables::Video',
83 'VIDEOLANGUAGES', 'SQL::Amazon::Tables::VideoLanguages',
84 'VIDEOGAMES', 'SQL::Amazon::Tables::VideoGames',
85 'WIRELESS', 'SQL::Amazon::Tables::Wireless',
86 'WIRELESSACCESSORIES', 'SQL::Amazon::Tables::WirelessAccessories',
87 );
88 1 our %amzn_table_names = (
89 'ACCESSORIES', [ 'Accessories', 'Item' ],
90 'APPAREL', [ 'Apparel', 'Item' ],
91 'BABY', [ 'Baby', 'Item' ],
92 'BEAUTY', [ 'Beauty', 'Item' ],
93 'BLENDED', [ 'Blended', 'Item' ],
94 'BOOKS', [ 'Books', 'Item' ],
95 'BROWSENODES', [ 'BrowseNodes', 'BrowseNode' ],
96 'CAMERAPHOTO', [ 'Photo', 'Item' ],
97 'CART', [ 'Cart', 'Cart' ],
98 'CLASSICALMUSIC', [ 'ClassicalMusic', 'Item' ],
99 'CUSTOMERREVIEWS', [ 'CustomerReviews', 'CustomerContent' ],
100 'CUSTOMERS', [ 'Customers', 'CustomerContent' ],
101 'DIGITALMUSIC', [ 'DigitalMusic', 'Item' ],
102 'DVDS', [ 'DVDs', 'Item' ],
103 'EDITORIALREVIEWS', [ 'EditorialReviews', undef ],
104 'ELECTRONICS', [ 'Electronics', 'Item' ],
105 'GOURMETFOOD', [ 'GourmetFood', 'Item' ],
106 'HARDWARE', [ 'Hardware', 'Item' ],
107 'HEALTHPERSONALCARE', [ 'HealthPersonalCare', 'Item' ],
108 'HOMEGARDEN', [ 'HomeGarden', 'Item' ],
109 'ITEMS', [ 'Items', 'Item' ],
110 'ITEMATTRIBUTES', [ 'ItemAttributes', undef ],
111 'ITEMFEATURES', [ 'ItemFeatures', undef ],
112 'JEWELRY', [ 'Jewelry', 'Item' ],
113 'KITCHEN', [ 'Kitchen', 'Item' ],
114 'LISTMANIALISTS', [ 'ListManiaLists', 'Lists' ],
115 'MAGAZINES', [ 'Magazines', 'Item' ],
116 'MERCHANTS', [ 'Merchants', 'Merchants', 'Sellers' ],
117 'MISCELLANEOUS', [ 'Miscellaneous', 'Item' ],
118 'MUSIC', [ 'Music', 'Item' ],
119 'MUSICALINSTRUMENTS', [ 'MusicalInstruments', 'Item' ],
120 'MUSICTRACKS', [ 'MusicTracks', 'Item' ],
121 'OFFERS', [ 'Offers', undef ],
122 'OFFERLISTINGS', [ 'OfferListings', undef ],
123 'OFFICEPRODUCTS', [ 'OfficeProducts', 'Item' ],
124 'OUTDOORLIVING', [ 'OutdoorLiving', 'Item' ],
125 'PURCHASES', [ 'Purchases', undef ],
126 'PCHARDWARE', [ 'PCHardware', 'Item' ],
127 'RESTAURANTS', [ 'Restaurants', 'Item' ],
128 'SAVEDITEMS', [ 'SavedItems', 'Cart' ],
129 'SELLERS', [ 'Sellers', 'Sellers' ],
130 'SELLERFEEDBACK', [ 'SellerFeedback', 'Sellers' ],
131 'SELLERLISTINGS', [ 'SellerListings', 'Sellers' ],
132 'SIMILARITEMS', [ 'SimilarItems', 'Similar' ],
133 'SIMILARPRODUCTS', [ 'SimilarProducts', 'Similar' ],
134 'SOFTWARE', [ 'Software', 'Item' ],
135 'SPORTINGGOODS', [ 'SportingGoods', 'Item' ],
136 'TRACKS', [ 'Tracks', 'Item' ],
137 'TRANSACTIONS', [ 'Transactions', 'Transactions' ],
138 'TRANSACTIONITEMS', [ 'TransactionItems', 'Transactions' ],
139 'TOYS', [ 'Toys', 'Item' ],
140 'VARIATIONS', [ 'Variations', 'Item' ],
141 'VHS', [ 'VHS', 'Item' ],
142 'VIDEO', [ 'Video', 'Item' ],
143 'VIDEOLANGUAGES', [ 'VideoLanguages', 'Item' ],
144 'VIDEOGAMES', [ 'VideoGames', 'Item' ],
145 'WIRELESS', [ 'Wireless', 'Item' ],
146 'WIRELESSACCESSORIES', [ 'WirelessAccessories', 'Item' ],
147 );
148  
149 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
150 0 my $class = shift;
151 0 my $obj = [ {} ];
152 $obj->[AMZN_STORE_TABLES]{SYSSCHEMA} =
153 0 SQL::Amazon::Tables::SysSchema->new;
154  
155 0 bless $obj, $class;
156 0 return $obj;
157 }
158 0 ▶sub has_table {
Subroutine has_table: not called CC=3 SCAR=24.8
Pod undocumented
159 0 my $table = shift;
160 0 ▶ $table = $1 if ($table=~/^CACHED(\w+)$/i);
Branch: 1 branch
BranchTrueFalseTotal
if $table =~ /^CACHED(\w+)$/i 0 0 0
161  
162 0 return wantarray ? @{$amzn_table_names{uc $table}} :
163 0 ▶ $amzn_table_names{uc $table}[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
164 }
165  
166 0 ▶sub get_table {
Subroutine get_table: not called CC=5 SCAR=34.0
Pod undocumented
167 0 my ($obj, $table) = @_;
168 0 ▶ $table = $1
Branch: 1 branch
BranchTrueFalseTotal
if $table =~ /^CACHED(\w+)$/i 0 0 0
169 if ($table=~/^CACHED(\w+)$/i);
170  
171 $obj->[AMZN_STORE_ERRSTR] = 'Unknown table $table.',
172 return undef
173 0 ▶ unless $amzn_table_classes{uc $table};
Branch: 1 branch
BranchTrueFalseTotal
unless $SQL::Amazon::StorageEngine::amzn_table_classes{uc $table} 0 0 0
174 0 $table = uc $table;
175 0 $obj->[AMZN_STORE_ERRSTR] = undef;
176 0 ▶ unless ($obj->[AMZN_STORE_TABLES]{$table}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj->[0]{$table}) 0 0 0
177 0 eval "require $amzn_table_classes{$table};";
178 0 ▶ $obj->[AMZN_STORE_ERRSTR] = $@,
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
179 return undef
180 if $@;
181 0 my $class = $amzn_table_classes{$table};
182 0 $obj->[AMZN_STORE_TABLES]{$table} = ${class}->new();
183 }
184 0 return $obj->[AMZN_STORE_TABLES]{$table};
185 }
186 0 ▶sub debug {
Subroutine debug: not called CC=5 SCAR=34.0
Pod undocumented
187 0 my ($obj, $debug, @tables) = @_;
188
189 0 ▶ unless (scalar @tables) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @tables) 0 0 0
190 $_->debug($debug)
191 0 foreach (values %{$obj->[AMZN_STORE_TABLES]});
192 0 return $obj;
193 }
194  
195 0 foreach (@tables) {
196 $obj->[AMZN_STORE_TABLES]{$_}->debug($debug)
197 0 ▶ if $obj->[AMZN_STORE_TABLES]{uc $_};
Branch: 1 branch
BranchTrueFalseTotal
if $obj->[0]{uc $_} 0 0 0
198 }
199 0 return $obj;
200 }
201 0 ▶sub close {
Subroutine close: not called CC=2 SCAR=17.9
Pod undocumented
202 0 my $obj = shift;
203 delete $obj->[AMZN_STORE_TABLES]{$_}
204 0 foreach (keys %{$obj->[AMZN_STORE_TABLES]});
205 0 return $obj;
206 }
207  
208 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
209 0 shift->close;
210 0 1;
211 }
212 0 ▶sub cache_item {
Subroutine cache_item: not called CC=4 SCAR=30.0
Pod undocumented
213 0 my ($obj, $table, $row) = @_;
214  
215 0 ▶ $table = $1
Branch: 1 branch
BranchTrueFalseTotal
if $table =~ /^CACHED(\w+)$/i 0 0 0
216 if ($table=~/^CACHED(\w+)$/i);
217  
218 0 $table = uc $table;
219 0 my $table_obj = $obj->get_table($table);
220 return undef
221 0 ▶ unless $table_obj;
Branch: 1 branch
BranchTrueFalseTotal
unless $table_obj 0 0 0
222  
223 0 ▶ $obj->[AMZN_STORE_ERRSTR] = $table_obj->errstr,
Branch: 1 branch
BranchTrueFalseTotal
unless $table_obj->insert($row) 0 0 0
224 return undef
225 unless $table_obj->insert($row);
226 0 return $obj;
227 }
228 0 ▶sub spoil_cache_item {
Subroutine spoil_cache_item: not called CC=3 SCAR=24.8
Pod undocumented
229 0 my ($obj, $id, $table) = @_;
230
231 0 ▶ $table = $1
Branch: 1 branch
BranchTrueFalseTotal
if $table =~ /^CACHED(\w+)$/i 0 0 0
232 if ($table=~/^CACHED(\w+)$/i);
233  
234 $obj->[AMZN_STORE_TABLES]{$table}->spoil($id)
235 0 ▶ if $obj->[AMZN_STORE_TABLES]{$table};
Branch: 1 branch
BranchTrueFalseTotal
if $obj->[0]{$table} 0 0 0
236
237 0 return $obj;
238 }
239  
240 0 ▶sub spoil_cache_table {
Subroutine spoil_cache_table: not called CC=3 SCAR=24.8
Pod undocumented
241 0 my ($obj, $table) = @_;
242
243 0 ▶ $table = $1
Branch: 1 branch
BranchTrueFalseTotal
if $table =~ /^CACHED(\w+)$/i 0 0 0
244 if ($table=~/^CACHED(\w+)$/i);
245  
246 $obj->[AMZN_STORE_TABLES]{$table}->spoil_all()
247 0 ▶ if $obj->[AMZN_STORE_TABLES]{$table};
Branch: 1 branch
BranchTrueFalseTotal
if $obj->[0]{$table} 0 0 0
248
249 0 return $obj;
250 }
251  
252 0 ▶sub spoil_cache_all {
Subroutine spoil_cache_all: not called CC=2 SCAR=17.9
Pod undocumented
253 0 my $obj = shift;
254
255 $obj->spoil_cache_table($_)
256 0 foreach (keys %{$obj->[AMZN_STORE_TABLES]});
257  
258 0 return $obj;
259 }
260 0 ▶sub send_requests {
Subroutine send_requests: not called CC=4 SCAR=30.0
Pod undocumented
261 0 my ($obj, $requests) = @_;
262  
263 0 my $start = time();
264 0 my %reqids = ();
265 0 my $warnmsg;
266 0 my $reqno = 1;
267 0 foreach (@$requests) {
268 0 $_->{_reqno} = $reqno++;
269 0 ▶ return ($_->errstr, undef, undef)
Branch: 1 branch
BranchTrueFalseTotal
unless $_->send_request($obj, \%reqids) 0 0 0
270 unless $_->send_request($obj, \%reqids);
271 0 ▶ $warnmsg = $_->warnstr unless $warnmsg;
Branch: 1 branch
BranchTrueFalseTotal
unless $warnmsg 0 0 0
272 }
273 0 return ($warnmsg, \%reqids, time() - $start);
274 }
275 0 ▶sub get_result_set {
Subroutine get_result_set: not called CC=3 SCAR=24.8
Pod undocumented
276 0 my ($obj, $table, $reqids) = @_;
277 0 ▶ $reqids = undef,
Branch: 1 branch
BranchTrueFalseTotal
if $table =~ /^CACHED(\w+)$/i 0 0 0
278 $table = $1
279 if ($table=~/^CACHED(\w+)$/i);
280  
281 0 $table = uc $table;
282 return undef
283 0 ▶ unless $obj->[AMZN_STORE_TABLES]{$table};
Branch: 1 branch
BranchTrueFalseTotal
unless $obj->[0]{$table} 0 0 0
284 0 return SQL::Amazon::Spool->new($obj->[AMZN_STORE_TABLES]{$table}, $reqids);
285 }
286 0 ▶sub fetch_row {
Subroutine fetch_row: not called CC=3 SCAR=24.8
Pod undocumented
287 0 my ($obj, $table, $id, $timeout) = @_;
288  
289 0 ▶ $table = $1
Branch: 1 branch
BranchTrueFalseTotal
if $table =~ /^CACHED(\w+)$/i 0 0 0
290 if ($table=~/^CACHED(\w+)$/i);
291  
292 return $obj->[AMZN_STORE_TABLES]{$table} ?
293 0 ▶ $obj->[AMZN_STORE_TABLES]{$table}->fetch($id, $timeout) :
Branch: 1 branch
BranchTrueFalseTotal
$obj->[0]{$table} ? : 0 0 0
294 "Unknown table $table.";
295 }
296  
297 0 ▶sub is_readonly {
Subroutine is_readonly: not called CC=3 SCAR=24.8
Pod undocumented
298 0 my ($obj, $table) = @_;
299  
300 0 ▶ $table = $1
Branch: 1 branch
BranchTrueFalseTotal
if $table =~ /^CACHED(\w+)$/i 0 0 0
301 if ($table=~/^CACHED(\w+)$/i);
302  
303 0 $table = uc $table;
304 return $obj->[AMZN_STORE_TABLES]{$table} ?
305 0 ▶ $obj->[AMZN_STORE_TABLES]{$table}->is_readonly : 1;
Branch: 1 branch
BranchTrueFalseTotal
$obj->[0]{$table} ? : 0 0 0
306 }
307  
308 0 ▶sub errstr { return shift->[AMZN_STORE_ERRSTR]; }
Subroutine errstr: not called CC=1 SCAR=6.9
Pod undocumented
309  
310 1 1;
« SQL/Amazon/Functions.pm ↑ Summary DBD/Amazon.pm »