How can I get the number of rows on a specific table? I'm using Kodo JDO 3.1.5 with Oracle.
I want to know how many rows there are in the table before to execute the final query. I want to do this because when there are 100.000 rows or more I get a java.lang.OutOfMemoryError. So I don't to want to execute the final query if there are too many rows.
protected Collection execute(Class type,
String filter) {
final Extent extent = getPersistenceManager().getExtent(type, true);
query = pm.newQuery(extent, filter);
query.setOrdering(orderBy + " " +
(orderAscending ? "ascending" : "decending"));
// TODO
// Get the number of rows
numberOfRows = Xxxxxxxxxxxxx;
if (numberOfRows > MAX_PER_COLLECTION) {
throw new XxxxxxException("Too Many Rows: " + result.size());
}
// TODO
final Collection result = (Collection) query.execute();
if (log.isDebugEnabled()) {
log.debug("Found " + result.size() + " match(es)");
}
return result;
}