From 01d174f735ccc7fe13342e976f4b17fc9dabc203 Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 5 Feb 2007 21:57:22 +0000 Subject: [PATCH] added a json_query wrapper git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_0@6895 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Utils/CStoreEditor.pm | 35 ++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Utils/CStoreEditor.pm b/Open-ILS/src/perlmods/OpenILS/Utils/CStoreEditor.pm index 71a9117b7c..fa4a142464 100644 --- a/Open-ILS/src/perlmods/OpenILS/Utils/CStoreEditor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Utils/CStoreEditor.pm @@ -473,13 +473,13 @@ sub runmethod { my $method = $self->app.".direct.$type.$action"; if( $action eq 'search' ) { - $method = "$method.atomic"; + $method .= '.atomic'; } elsif( $action eq 'batch_retrieve' ) { $action = 'search'; @arg = ( { id => $arg } ); $method =~ s/batch_retrieve/search/o; - $method = "$method.atomic"; + $method .= '.atomic'; } elsif( $action eq 'retrieve_all' ) { $action = 'search'; @@ -488,12 +488,12 @@ sub runmethod { $tt =~ s/\./::/og; my $fmobj = "Fieldmapper::$tt"; @arg = ( { $fmobj->Identity => { '!=' => undef } } ); - $method = "$method.atomic"; + $method .= '.atomic'; } $method =~ s/search/id_list/o if $options->{idlist}; - $method =~ s/\.atomic$//o if $self->substream($$options{substream} || 0); + $method =~ s/\.atomic$//o if $self->substream($$options{substream} || 0); # remove any stale events $self->clear_event; @@ -561,7 +561,7 @@ sub runmethod { return undef; } - if( $action eq 'search' or $action eq 'batch_retrieve' or $action eq 'retrieve_all') { + if( $action eq 'search' ) { $self->log(I, "$type.$action : returned ".scalar(@$obj). " result(s)"); $self->event(_mk_not_found($type, $arg)) unless @$obj; } @@ -640,6 +640,31 @@ for my $object (keys %$map) { eval $retrieveallf; } +sub json_query { + my( $self, $arg, $options ) = @_; + $options ||= {}; + my @arg = ( ref($arg) eq 'ARRAY' ) ? @$arg : ($arg); + my $method = $self->app.'.json_query.atomic'; + $method =~ s/\.atomic$//o if $self->substream($$options{substream} || 0); + $self->clear_event; + my $obj; + my $err; + + try { + $obj = $self->request($method, @arg); + } catch Error with { $err = shift; }; + + if( $err ) { + $self->event( + OpenILS::Event->new( 'DATABASE_QUERY_FAILED', + payload => $arg, debug => "$err" )); + return undef; + } + + $self->log(I, "json_query : returned ".scalar(@$obj). " result(s)"); + return $obj; +} + 1; -- 2.11.0