def _Dynamic_RunQuery(self, request, response): """Handle a RunQuery request. We handle RunQuery by executing a Query and a Next and returning the result of the Next request. """ runquery_response = datastore_pb.QueryResult() apiproxy_stub_map.MakeSyncCall('datastore_v3', 'RunQuery', request, runquery_response) next_request = datastore_pb.NextRequest() next_request.mutable_cursor().CopyFrom(runquery_response.cursor()) next_request.set_count(request.limit()) apiproxy_stub_map.MakeSyncCall('datastore_v3', 'Next', next_request, response)
def _to_pb(self, fetch_options=None): req = datastore_pb.NextRequest() if FetchOptions.produce_cursors(fetch_options, self.__query_options, self.__conn.config): req.set_compile(True) count = FetchOptions.batch_size(fetch_options, self.__query_options, self.__conn.config) if count is not None: req.set_count(count) if fetch_options is not None and fetch_options.offset: req.set_offset(fetch_options.offset) req.mutable_cursor().CopyFrom(self.__datastore_cursor) self.__datastore_cursor = None return req
def _Dynamic_RunQuery(self, request, response): """Handle a RunQuery request. We handle RunQuery by executing a Query and a Next and returning the result of the Next request. This method is DEPRECATED, but left in place for older clients. """ runquery_response = datastore_pb.QueryResult() self.__call('datastore_v3', 'RunQuery', request, runquery_response) if runquery_response.result_size() > 0: response.CopyFrom(runquery_response) return next_request = datastore_pb.NextRequest() next_request.mutable_cursor().CopyFrom(runquery_response.cursor()) next_request.set_count(request.limit()) self.__call('datastore_v3', 'Next', next_request, response)
def next_callback(rpc, entities, exception, callback=None): try: assert isinstance( rpc.request, datastore_pb.NextRequest), "request should be a query" assert isinstance( rpc.response, datastore_pb.QueryResult), "response should be a QueryResult" result = next_rpc_handler(rpc) entity_list = process_query_result(result) count = rpc.request.count() if len(entity_list) > count: del entity_list[count:] entities += entity_list if result.more_results() and len(entity_list) < count: # create rpc for running count = count - len(entity_list) req = datastore_pb.NextRequest() req.set_count(count) req.mutable_cursor().CopyFrom(rpc.response.cursor()) result = datastore_pb.QueryResult() nextrpc = create_rpc(deadline=rpc.deadline) nextrpc.callback = lambda: next_callback( nextrpc, entities, exception, callback=callback) rpc.runner.append(nextrpc) nextrpc.make_call('Next', req, result) if rpc.runner: rpc.runner.append(nextrpc) else: nextrpc.Wait() except (datastore_errors.Error, apiproxy_errors.Error), exp: logging.debug("Exception (Next):%s", exp) exception.append(exp) if callback: callback(rpc)
def _to_pb(self, fetch_options=None): req = datastore_pb.NextRequest() count = None produce_cursors = None if fetch_options is not None: if not isinstance(fetch_options, FetchOptions): raise datastore_errors.BadArgumentError( 'fetch_options argument should be datastore_query.FetchOptions ' '(%r)' % (fetch_options,)) count = fetch_options.batch_size produce_cursors = fetch_options.produce_cursors if fetch_options.offset: req.set_offset(fetch_options.offset) if produce_cursors is None: produce_cursors = self.__query_options.produce_cursors if count is None: count = self.__query_options.batch_size if isinstance(self.__conn.config, FetchOptions): if produce_cursors is None: produce_cursors = self.__conn.config.produce_cursors if count is None: count = self.__conn.config.batch_size req.mutable_cursor().CopyFrom(self.__datastore_cursor) self.__datastore_cursor = None if count is not None: req.set_count(count) if produce_cursors: req.set_compile(True) return req