From: miker Date: Mon, 21 Feb 2005 22:18:13 +0000 (+0000) Subject: added nondestructive "peek" methods to stack, queue and object APIs; added "size... X-Git-Tag: osrf_rel_2_0_1~1779 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=6b58214bb1259838578794589db39fac20611ef7;p=OpenSRF.git added nondestructive "peek" methods to stack, queue and object APIs; added "size" to object API; added "depth" to stack API; added "length to queue API git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@93 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/perlmods/OpenSRF/Application/Persist.pm b/src/perlmods/OpenSRF/Application/Persist.pm index a0d1278..be72d96 100644 --- a/src/perlmods/OpenSRF/Application/Persist.pm +++ b/src/perlmods/OpenSRF/Application/Persist.pm @@ -183,19 +183,77 @@ sub pop_queue { my $name_id = _get_name_id($name); my $value = $dbh->selectrow_arrayref('SELECT id, value FROM storage WHERE name_id = ? ORDER BY id ASC LIMIT 1;', {}, $name_id); - $dbh->do('DELETE FROM storage WHERE id = ?;',{}, $value->[0]); + $dbh->do('DELETE FROM storage WHERE id = ?;',{}, $value->[0]) unless ($self->api_name =~ /peek$/); _flush_by_name($name); return JSON->JSON2perl( $value->[1] ); } __PACKAGE__->register_method( + api_name => 'opensrf.persist.queue.peek', + method => 'pop_queue', + argc => 1, +); +__PACKAGE__->register_method( api_name => 'opensrf.persist.queue.pop', method => 'pop_queue', argc => 1, ); +sub store_size { + my $self = shift; + my $client = shift; + + my $name = shift or do { + throw OpenSRF::EX::WARN ("No queue name specified!"); + }; + my $name_id = _get_name_id($name); + + my $value = $dbh->selectrow_arrayref('SELECT SUM(LENGTH(value)) FROM storage WHERE name_id = ?;', {}, $name_id); + + return JSON->JSON2perl( $value->[0] ); +} +__PACKAGE__->register_method( + api_name => 'opensrf.persist.queue.size', + method => 'shift_stack', + argc => 1, +); +__PACKAGE__->register_method( + api_name => 'opensrf.persist.stack.size', + method => 'shift_stack', + argc => 1, +); +__PACKAGE__->register_method( + api_name => 'opensrf.persist.object.size', + method => 'shift_stack', + argc => 1, +); + +sub store_depth { + my $self = shift; + my $client = shift; + + my $name = shift or do { + throw OpenSRF::EX::WARN ("No queue name specified!"); + }; + my $name_id = _get_name_id($name); + + my $value = $dbh->selectrow_arrayref('SELECT COUNT(*) FROM storage WHERE name_id = ?;', {}, $name_id); + + return JSON->JSON2perl( $value->[0] ); +} +__PACKAGE__->register_method( + api_name => 'opensrf.persist.queue.length', + method => 'shift_stack', + argc => 1, +); +__PACKAGE__->register_method( + api_name => 'opensrf.persist.stack.depth', + method => 'shift_stack', + argc => 1, +); + sub shift_stack { my $self = shift; my $client = shift; @@ -206,13 +264,18 @@ sub shift_stack { my $name_id = _get_name_id($name); my $value = $dbh->selectrow_arrayref('SELECT id, value FROM storage WHERE name_id = ? ORDER BY id DESC LIMIT 1;', {}, $name_id); - $dbh->do('DELETE FROM storage WHERE id = ?;',{}, $value->[0]); + $dbh->do('DELETE FROM storage WHERE id = ?;',{}, $value->[0]) unless ($self->api_name =~ /peek$/); _flush_by_name($name); return JSON->JSON2perl( $value->[1] ); } __PACKAGE__->register_method( + api_name => 'opensrf.persist.stack.peek', + method => 'shift_stack', + argc => 1, +); +__PACKAGE__->register_method( api_name => 'opensrf.persist.stack.pop', method => 'shift_stack', argc => 1, @@ -229,13 +292,18 @@ sub get_object { my $name_id = _get_name_id($name); my $value = $dbh->selectrow_arrayref('SELECT name_id, value FROM storage WHERE name_id = ? ORDER BY id DESC LIMIT 1;', {}, $name_id); - $dbh->do('DELETE FROM storage WHERE name_id = ?',{}, $value->[0]); + $dbh->do('DELETE FROM storage WHERE name_id = ?',{}, $value->[0]) unless ($self->api_name =~ /peek$/); _flush_by_name($name); return JSON->JSON2perl( $value->[1] ); } __PACKAGE__->register_method( + api_name => 'opensrf.persist.object.peek', + method => 'shift_stack', + argc => 1, +); +__PACKAGE__->register_method( api_name => 'opensrf.persist.object.get', method => 'shift_stack', argc => 1,