我想知道如何使用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;
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1964 次 |
| 最近记录: |