added a json_query wrapper
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 5 Feb 2007 21:57:22 +0000 (21:57 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 5 Feb 2007 21:57:22 +0000 (21:57 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_0@6895 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Utils/CStoreEditor.pm

index 71a9117..fa4a142 100644 (file)
@@ -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;