如何在TopLink中获取Count查询的结果?

时间:2011-04-29 08:54:13

标签: java count toplink

我有这个:

ReportQuery query = new ReportQuery(OpenedFilesReport.class,
  generateExpressionOpenedFilesReport());
query.addCount();

Object result = getTopLinkTemplate().executeQuery(query, true);

正如我所看到的,结果是一个Vector,并且有一个ReportQueryResult类型的结果。是否有一种更聪明的方法来获得结果

((ReportQueryResult)((Vector)result).get(0)).getResults()//.. do additional class casts/getter calls

1 个答案:

答案 0 :(得分:1)

query.setShouldReturnSingleValue(真);

Number result =(Number)getTopLinkTemplate()。executeQuery(query,true);

以下是EclipseLink JavaDocs的链接:

http://www.eclipse.org/eclipselink/api/2.2/org/eclipse/persistence/queries/ReportQuery.html#setShouldReturnSingleValue%28boolean%29

道格