コード例 #1
0
    def batch_size(value):
        """The number of results to attempt to retrieve in a batch.

    Raises:
      BadArgumentError if value is not a integer or is not greater than zero.
    """
        datastore_types.ValidateInteger(value, 'batch_size',
                                        datastore_errors.BadArgumentError)
        return value
コード例 #2
0
  def prefetch_size(value):
    """Number of results to attempt to return on the initial request.

    Raises:
      BadArgumentError if value is not an integer or is not greater than zero.
    """
    datastore_types.ValidateInteger(value,
                                    'prefetch_size',
                                    datastore_errors.BadArgumentError,
                                    zero_ok=True)
    return value
コード例 #3
0
  def limit(value):
    """Limit on the number of results to return.

    Raises:
      BadArgumentError if value is not an integer or is less than zero.
    """
    datastore_types.ValidateInteger(value,
                                    'limit',
                                    datastore_errors.BadArgumentError,
                                    zero_ok=True)
    return value
コード例 #4
0
  def offset(value):
    """The number of results to skip before returning the first result.

    Only applies to the first request it is used with and is ignored if present
    on datastore_rpc.Connection.config.

    Raises:
      BadArgumentError if value is not a integer or is less than zero.
    """
    datastore_types.ValidateInteger(value,
                                    'offset',
                                    datastore_errors.BadArgumentError,
                                    zero_ok=True)
    return value
コード例 #5
0
    def next_batch(self, min_batch_size):
        """Get the next batch.

    The batch returned by this function cannot be used to fetch the next batch
    (through Batch.next_batch()). Instead this function will always return None.
    To retrieve the next batch use .next() or .next_batch(N).

    This function may return a batch larger than min_to_fetch, but will never
    return smaller unless there are no more results.

    Args:
      min_batch_size: The minimum number of results to retrieve.

    Returns:
      The next Batch of results.
    """
        datastore_types.ValidateInteger(min_batch_size,
                                        'min_batch_size',
                                        datastore_errors.BadArgumentError,
                                        zero_ok=True)
        if not self.__next_batch:
            raise StopIteration

        batch = self.__next_batch.get_result()
        self.__next_batch = None
        self.__skipped_results += batch.skipped_results

        needed_results = min_batch_size - len(batch.results)
        while (batch.more_results
               and (self.__skipped_results < self.__initial_offset
                    or needed_results > 0)):
            if batch.query_options.batch_size:

                batch_size = max(batch.query_options.batch_size,
                                 needed_results)
            elif needed_results:

                batch_size = needed_results
            else:
                batch_size = None
            next_batch = batch.next_batch(
                FetchOptions(offset=max(
                    0, self.__initial_offset - self.__skipped_results),
                             batch_size=batch_size))
            self.__skipped_results += next_batch.skipped_results
            needed_results = max(0, needed_results - len(next_batch.results))
            batch._extend(next_batch)

        self.__next_batch = batch.next_batch_async()
        return batch
コード例 #6
0
  def advance(self, offset, query, conn):
    """Advances a Cursor by the given offset.

    Args:
      offset: The amount to advance the current query.
      query: A Query identical to the one this cursor was created from.
      conn: The datastore_rpc.Connection to use.

    Returns:
      A new cursor that is advanced by offset using the given query.
    """
    datastore_types.ValidateInteger(offset,
                                    'offset',
                                    datastore_errors.BadArgumentError)
    if not isinstance(query, Query):
      raise datastore_errors.BadArgumentError(
          'query argument should be datastore_query.Query (%r)' % (query,))

    query_options = QueryOptions(
        start_cursor=self, offset=offset, limit=0, produce_cursors=True)
    return query.run(conn, query_options).next_batch(0).cursor(0)