0

私は何千ものことを試しました。今のところ、私が何かを照会する唯一の方法は、リスト全体を取得して、そのように調べることです! これには非常に時間がかかります。たとえば、100票を超えるエンティティのみをプルするなど、Google App Engineで何かを照会するにはどうすればよいですか。

三目並べの例https://github.com/GoogleCloudPlatform/appengine-endpoints-tictactoe-javaおよびhttps://developers.google.com/eclipse/docs/endpoints-addentitiesに従ってい ます引用のためのメモ。

たとえば、これが非同期タスクであるエンティティを取得する方法と、時間がかかる各エンティティをロードする方法に関する私の現在のコードを次に示します

 protected CollectionResponseQuotes doInBackground(Context... contexts) {

      Quotesendpoint.Builder endpointBuilder = new Quotesendpoint.Builder(
          AndroidHttp.newCompatibleTransport(),
          new JacksonFactory(),
          new HttpRequestInitializer() {
          public void initialize(HttpRequest httpRequest) { }
          });
  Quotesendpoint endpoint = CloudEndpointUtils.updateBuilder(
  endpointBuilder).build();
  try {


      quotes = endpoint.listquotes().execute();

       for (Quotes quote : quotes.getItems()) {

           if (quote.getVotes() > 3) {

           quoteList.add(quote);

            }  

 }

エンドポイントを作成したときに Google がアプリ エンジンで生成したコードを次に示します。何らかの形でクエリを実行するように見えますが、わかりません。これらは 2 つの異なるプロジェクトです。

@Api(name = "quotesendpoint", namespace = @ApiNamespace(ownerDomain = "projectquotes.com", ownerName = "projectquotes.com", packagePath = ""))
public class quotesEndpoint {

/**
 * This method lists all the entities inserted in datastore.
 * It uses HTTP GET method and paging support.
 *
 * @return A CollectionResponse class containing the list of all entities
 * persisted and a cursor to the next page.
 */
@SuppressWarnings({ "unchecked", "unused" })
@ApiMethod(name = "listquotes")
public CollectionResponse<quotes> listquotes(
        @Nullable @Named("cursor") String cursorString,
        @Nullable @Named("limit") Integer limit) {

    EntityManager mgr = null;
    Cursor cursor = null;
    List<quotes> execute = null;

    try {
        mgr = getEntityManager();
        Query query = mgr.createQuery("select from quotes as quotes");
        if (cursorString != null && cursorString != "") {
            cursor = Cursor.fromWebSafeString(cursorString);
            query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
        }

        if (limit != null) {
            query.setFirstResult(0);
            query.setMaxResults(limit);
        }

        execute = (List<quotes>) query.getResultList();
        cursor = JPACursorHelper.getCursor(execute);
        if (cursor != null)
            cursorString = cursor.toWebSafeString();

        // Tight loop for fetching all entities from datastore and accomodate
        // for lazy fetch.
        for (quotes obj : execute)
            ;
    } finally {
        mgr.close();
    }

    return CollectionResponse.<quotes> builder().setItems(execute)
            .setNextPageToken(cursorString).build();
}

/**
 * This method gets the entity having primary key id. It uses HTTP GET method.
 *
 * @param id the primary key of the java bean.
 * @return The entity with primary key id.
 */
@ApiMethod(name = "getquotes")
public quotes getquotes(@Named("id") String id) {
    EntityManager mgr = getEntityManager();
    quotes quotes = null;
    try {
        quotes = mgr.find(quotes.class, id);
    } finally {
        mgr.close();
    }
    return quotes;
}

ユーザーカーソルを試してみましたが、どのように機能するかわかりました。私はもう試した

  Cursor cursor = db.rawQuery("select * from Votes WHERE Votes >" + 250 , null);
  quotes = endpoint.listquotes().setCursor(cursor).execute();
4

1 に答える 1

1

パラメータを endpoint.listquotes() に渡そうとしましたか? 具体的には、結果の数を制限するパラメーター「制限」と、選択基準を変更するパラメーター「カーソル」ですか?

于 2013-07-19T00:11:27.233 に答える