{
ObjectManager om = query.getObjectManager();
if (query.getCompilation().getQueryLanguage().equalsIgnoreCase("JDOQL"))
{
// JDOQL : "count(this)" query
Query countQuery = om.getOMFContext().getQueryManager().newQuery("JDOQL", om, query);
countQuery.setResult("count(this)");
countQuery.setOrdering(null);
Map queryParams = query.getInputParameters();
long count;
if (queryParams != null)
{
count = ((Long)countQuery.executeWithMap(queryParams)).longValue();
}
else
{
count = ((Long)countQuery.execute()).longValue();
}
countQuery.closeAll();
return (int)count;
}
else if (query.getCompilation().getQueryLanguage().equalsIgnoreCase("JPQL"))
{
// JPQL : "count()" query
Query countQuery = om.getOMFContext().getQueryManager().newQuery("JPQL", om, query);
countQuery.setResult("count(" + query.getCompilation().getCandidateAlias() + ")");
countQuery.setOrdering(null);
Map queryParams = query.getInputParameters();
long count;
if (queryParams != null)
{
count = ((Long)countQuery.executeWithMap(queryParams)).longValue();
}
else
{
count = ((Long)countQuery.execute()).longValue();
}
countQuery.closeAll();
return (int)count;
}
}
throw new NucleusUserException("datanucleus.query.resultSizeMethod of \"COUNT\" is only valid" +