def _GetQueryCursor(self, query, filters, orders, index_list,
                      filter_predicate=None):
    """Returns a query cursor for the provided query.

    Args:
      query: The datastore_pb.Query to run.
      filters: A list of filters that override the ones found on query.
      orders: A list of orders that override the ones found on query.
      index_list: A list of indexes used by the query.
      filter_predicate: an additional filter of type
          datastore_query.FilterPredicate. This is passed along to implement V4
          specific filters without changing the entire stub.

    Returns:
      A QueryCursor object.
    """
    if query.has_kind() and query.kind() in self._pseudo_kinds:
      cursor = self._pseudo_kinds[query.kind()].Query(query, filters, orders)
      datastore_stub_util.Check(cursor,
                                'Could not create query for pseudo-kind')
    else:
      orders = datastore_stub_util._GuessOrders(filters, orders)
      filter_info = self.__GenerateFilterInfo(filters, query)
      order_info = self.__GenerateOrderInfo(orders)

      for strategy in DatastoreSqliteStub._QUERY_STRATEGIES:
        result = strategy(self, query, filter_info, order_info)
        if result:
          break
      else:
        raise apiproxy_errors.ApplicationError(
            datastore_pb.Error.BAD_REQUEST,
            'No strategy found to satisfy query.')

      sql_stmt, params = result

      conn = self._GetConnection()
      try:
        if query.property_name_list():
          db_cursor = _ProjectionPartialEntityGenerator(
              conn.execute(sql_stmt, params))
        else:
          db_cursor = _DedupingEntityGenerator(conn.execute(sql_stmt, params))
        dsquery = datastore_stub_util._MakeQuery(query, filters, orders,
                                                 filter_predicate)

        filtered_entities = [r for r in db_cursor]


        if filter_predicate:
          filtered_entities = filter(filter_predicate, filtered_entities)

        cursor = datastore_stub_util.ListCursor(
            query, dsquery, orders, index_list, filtered_entities)
      finally:
        self._ReleaseConnection(conn)
    return cursor
  def _GetQueryCursor(self, query, filters, orders, index_list):
    """Returns a query cursor for the provided query.

    Args:
      query: The datastore_pb.Query to run.
      filters: A list of filters that override the ones found on query.
      orders: A list of orders that override the ones found on query.
      index_list: A list of indexes used by the query.

    Returns:
      A QueryCursor object.
    """
    if query.has_kind() and query.kind() in self._pseudo_kinds:

      datastore_stub_util.NormalizeCursors(query,
                                           datastore_pb.Query_Order.ASCENDING)
      cursor = self._pseudo_kinds[query.kind()].Query(query, filters, orders)
      datastore_stub_util.Check(cursor,
                                'Could not create query for pseudo-kind')
    else:
      orders = datastore_stub_util._GuessOrders(filters, orders)


      datastore_stub_util.NormalizeCursors(query, orders[0].direction())
      filter_info = self.__GenerateFilterInfo(filters, query)
      order_info = self.__GenerateOrderInfo(orders)

      for strategy in DatastoreSqliteStub._QUERY_STRATEGIES:
        result = strategy(self, query, filter_info, order_info)
        if result:
          break
      else:
        raise apiproxy_errors.ApplicationError(
            datastore_pb.Error.BAD_REQUEST,
            'No strategy found to satisfy query.')

      sql_stmt, params = result

      conn = self._GetConnection()
      try:
        if query.property_name_list():
          db_cursor = _ProjectionPartialEntityGenerator(
              conn.execute(sql_stmt, params))
        else:
          db_cursor = _DedupingEntityGenerator(conn.execute(sql_stmt, params))
        dsquery = datastore_stub_util._MakeQuery(query, filters, orders)

        cursor = datastore_stub_util.ListCursor(query, dsquery, orders,
                                                index_list, list(db_cursor))
      finally:
        self._ReleaseConnection(conn)
    return cursor
예제 #3
0
  def _GetQueryCursor(self, query, filters, orders, index_list):
    """Returns a query cursor for the provided query.

    Args:
      query: The datastore_pb.Query to run.
      filters: A list of filters that override the ones found on query.
      orders: A list of orders that override the ones found on query.
      index_list: A list of indexes used by the query.

    Returns:
      A QueryCursor object.
    """
    if query.has_kind() and query.kind() in self._pseudo_kinds:

      datastore_stub_util.NormalizeCursors(query,
                                           datastore_pb.Query_Order.ASCENDING)
      cursor = self._pseudo_kinds[query.kind()].Query(query, filters, orders)
      datastore_stub_util.Check(cursor,
                                'Could not create query for pseudo-kind')
    else:
      orders = datastore_stub_util._GuessOrders(filters, orders)


      datastore_stub_util.NormalizeCursors(query, orders[0].direction())
      filter_info = self.__GenerateFilterInfo(filters, query)
      order_info = self.__GenerateOrderInfo(orders)

      for strategy in DatastoreSqliteStub._QUERY_STRATEGIES:
        result = strategy(self, query, filter_info, order_info)
        if result:
          break
      else:
        raise apiproxy_errors.ApplicationError(
            datastore_pb.Error.BAD_REQUEST,
            'No strategy found to satisfy query.')

      sql_stmt, params = result

      conn = self._GetConnection()
      try:
        if query.property_name_list():
          db_cursor = _ProjectionPartialEntityGenerator(
              conn.execute(sql_stmt, params))
        else:
          db_cursor = _DedupingEntityGenerator(conn.execute(sql_stmt, params))
        dsquery = datastore_stub_util._MakeQuery(query, filters, orders)

        cursor = datastore_stub_util.ListCursor(query, dsquery, orders,
                                                index_list, list(db_cursor))
      finally:
        self._ReleaseConnection(conn)
    return cursor
    def _GetQueryCursor(self, query, filters, orders, index_list):
        """Runs the given datastore_pb.Query and returns a QueryCursor for it.

        Args:
          query: The datastore_pb.Query to run.
          filters: A list of filters that override the ones found on query.
          orders: A list of orders that override the ones found on query.
          index_list: A list of indexes used by the query.

        Returns:
          An IteratorCursor that can be used to fetch query results.
        """
        db_cursor = self._mongods.query(query)
        orders = datastore_stub_util._GuessOrders(filters, orders)
        dsquery = datastore_stub_util._MakeQuery(query, filters, orders)
        cursor = datastore_stub_util.IteratorCursor(query, dsquery, orders, index_list, db_cursor)
        return cursor
예제 #5
0
    def _GetQueryCursor(self, query, filters, orders, index_list):
        """Returns a query cursor for the provided query.

    Args:
      conn: The SQLite connection.
      query: A datastore_pb.Query protocol buffer.
    Returns:
      A QueryCursor object.
    """
        if query.has_kind() and query.kind() in self._pseudo_kinds:
            cursor = self._pseudo_kinds[query.kind()].Query(
                query, filters, orders)
            datastore_stub_util.Check(
                cursor, 'Could not create query for pseudo-kind')
        else:
            orders = datastore_stub_util._GuessOrders(filters, orders)
            filter_info = self.__GenerateFilterInfo(filters, query)
            order_info = self.__GenerateOrderInfo(orders)

            for strategy in DatastoreSqliteStub._QUERY_STRATEGIES:
                result = strategy(self, query, filter_info, order_info)
                if result:
                    break
            else:
                raise apiproxy_errors.ApplicationError(
                    datastore_pb.Error.BAD_REQUEST,
                    'No strategy found to satisfy query.')

            sql_stmt, params = result

            if self.__verbose:
                logging.info("Executing statement '%s' with arguments %r",
                             sql_stmt, [str(x) for x in params])
            conn = self._GetConnection()

            try:
                db_cursor = _DedupingEntityIterator(
                    conn.execute(sql_stmt, params))
                dsquery = datastore_stub_util._MakeQuery(
                    query, filters, orders)
                cursor = datastore_stub_util.IteratorCursor(
                    query, dsquery, orders, index_list, db_cursor)
            finally:
                self._ReleaseConnection(conn)
        return cursor
  def _GetQueryCursor(self, query, filters, orders, index_list):
    """Returns a query cursor for the provided query.

    Args:
      conn: The SQLite connection.
      query: A datastore_pb.Query protocol buffer.
    Returns:
      A QueryCursor object.
    """
    if query.has_kind() and query.kind() in self._pseudo_kinds:
      cursor = self._pseudo_kinds[query.kind()].Query(query, filters, orders)
      datastore_stub_util.Check(cursor,
                                'Could not create query for pseudo-kind')
    else:
      orders = datastore_stub_util._GuessOrders(filters, orders)
      filter_info = self.__GenerateFilterInfo(filters, query)
      order_info = self.__GenerateOrderInfo(orders)

      for strategy in DatastoreSqliteStub._QUERY_STRATEGIES:
        result = strategy(self, query, filter_info, order_info)
        if result:
          break
      else:
        raise apiproxy_errors.ApplicationError(
            datastore_pb.Error.BAD_REQUEST,
            'No strategy found to satisfy query.')

      sql_stmt, params = result

      if self.__verbose:
        logging.info("Executing statement '%s' with arguments %r",
                     sql_stmt, [str(x) for x in params])
      conn = self._GetConnection()
      try:
        db_cursor = conn.execute(sql_stmt, params)
        dsquery = datastore_stub_util._MakeQuery(query, filters, orders)
        cursor = datastore_stub_util.IteratorCursor(
            query, dsquery, orders, index_list,
            _DedupingEntityIterator(db_cursor))
      finally:
        self._ReleaseConnection(conn)
    return cursor
예제 #7
0
  def _GetQueryCursor(self, query, filters, orders, index_list):
    """Returns a query cursor for the provided query.

    Args:
      conn: The SQLite connection.
      query: A datastore_pb.Query protobuf.
    Returns:
      A QueryCursor object.
    """
    if query.has_kind() and query.kind() in self._pseudo_kinds:
      cursor = self._pseudo_kinds[query.kind()].Query(query, filters, orders)
      datastore_stub_util.Check(cursor,
                                'Could not create query for pseudo-kind')
    else:
      orders = datastore_stub_util._GuessOrders(filters, orders)
      filter_info = self.__GenerateFilterInfo(filters, query)
      order_info = self.__GenerateOrderInfo(orders)

      for strategy in DatastoreSqliteStub._QUERY_STRATEGIES:
        result = strategy(self, query, filter_info, order_info)
        if result:
          break
      else:
        raise apiproxy_errors.ApplicationError(
            datastore_pb.Error.BAD_REQUEST,
            'No strategy found to satisfy query.')

      sql_stmt, params = result

      conn = self._GetConnection()
      try:
        if query.property_name_list():
          db_cursor = _ProjectionPartialEntityGenerator(
              conn.execute(sql_stmt, params))
        else:
          db_cursor = _DedupingEntityGenerator(conn.execute(sql_stmt, params))
        dsquery = datastore_stub_util._MakeQuery(query, filters, orders)
        cursor = datastore_stub_util.IteratorCursor(
            query, dsquery, orders, index_list, db_cursor)
      finally:
        self._ReleaseConnection(conn)
    return cursor
예제 #8
0
    def _GetQueryCursor(self,
                        query,
                        filters,
                        orders,
                        index_list,
                        filter_predicate=None):
        """Returns a query cursor for the provided query.

    Args:
      query: The datastore_pb.Query to run.
      filters: A list of filters that override the ones found on query.
      orders: A list of orders that override the ones found on query.
      index_list: A list of indexes used by the query.
      filter_predicate: an additional filter of type
          datastore_query.FilterPredicate. This is passed along to implement V4
          specific filters without changing the entire stub.

    Returns:
      A QueryCursor object.
    """
        if query.has_kind() and query.kind() in self._pseudo_kinds:
            cursor = self._pseudo_kinds[query.kind()].Query(
                query, filters, orders)
            datastore_stub_util.Check(
                cursor, 'Could not create query for pseudo-kind')
        else:
            orders = datastore_stub_util._GuessOrders(filters, orders)
            filter_info = self.__GenerateFilterInfo(filters, query)
            order_info = self.__GenerateOrderInfo(orders)

            for strategy in DatastoreSqliteStub._QUERY_STRATEGIES:
                result = strategy(self, query, filter_info, order_info)
                if result:
                    break
            else:
                raise apiproxy_errors.ApplicationError(
                    datastore_pb.Error.BAD_REQUEST,
                    'No strategy found to satisfy query.')

            sql_stmt, params = result

            conn = self._GetConnection()
            try:
                if query.property_name_list():
                    db_cursor = _ProjectionPartialEntityGenerator(
                        conn.execute(sql_stmt, params))
                else:
                    db_cursor = _DedupingEntityGenerator(
                        conn.execute(sql_stmt, params))
                dsquery = datastore_stub_util._MakeQuery(
                    query, filters, orders, filter_predicate)

                filtered_entities = [r for r in db_cursor]

                if filter_predicate:
                    filtered_entities = list(
                        filter(filter_predicate, filtered_entities))

                cursor = datastore_stub_util.ListCursor(
                    query, dsquery, orders, index_list, filtered_entities)
            finally:
                self._ReleaseConnection(conn)
        return cursor