Ограничить количество результатов в javax.jdo.Query - PullRequest
2 голосов
/ 15 июля 2010

Я хотел бы знать, как я могу ограничить число результатов с помощью javax.jdo.Query
Я попытался с setRange функцией без успеха.
Это мой текущий обходной путь

Object query_result = q.execute(locationId);
if(query_result!=null && ((List<BaseObject>) query_result).size()>0)
    return (PokerSession) ((List<BaseObject>) query_result).get(0);
return null; 

1 Ответ

5 голосов
/ 15 июля 2010
    Query query = pm.newQuery(PokerSession.class);
    query.setFilter("locationId == plocationId"); // My asumption. need to change accoring to your field name.
    query.declareParameters("String plocationId"); //Again my asumption put here correct data type

    /* Here x is startIndex and y is end index
     * For example if you want to start from 10 and want to get 50 records 
     * you put x=9 (index are zero based) and  y = x + 50 
     */
    query.setRange(x, y); 

    List<PokerSession>) query_result = q.execute(locationId);
    if(!query_result.isEmpty())
        return query_result.get(0);
    return null
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...