public Integer execute(ISession session, SeConnection connection) throws SeException,
IOException {
final SeQueryInfo queryInfo = qInfo;
SeQuery query = new SeQuery(connection);
try {
versioningHandler.setUpStream(session, query);
if (spatialFilters != null && spatialFilters.length > 0) {
final boolean calcMasks = true;// use the spatial query to calculate
// statistics.
final short searchOrder = SeQuery.SE_OPTIMIZE;
query.setSpatialConstraints(searchOrder, calcMasks, spatialFilters);
final SeDBMSInfo dbmsInfo = connection.getDBMSInfo();
final boolean unsupported = versioningHandler != ArcSdeVersionHandler.NONVERSIONED_HANDLER
&& dbmsInfo.dbmsId == SeDBMSInfo.SE_DBMS_IS_ORACLE;
if (unsupported) {
LOGGER.fine("ArcSDE on Oracle can't calculate count statistics "
+ "on versioned layers with spatial filters");
/*
* Despite the FeatureSource.getCount() contract saying it's ok to
* return -1 if count is too expensive to calculate, the GeoServer
* codebase is plagued of FeatureCollection.size() calls depending on
* actual result counts or some operations don't work at all. return -1;
*/
query.prepareQueryInfo(queryInfo);
query.execute();
int count = 0;
while (query.fetch() != null) {
count++;
}
return count;
}
}
final int defaultMaxDistinctValues = 0;
final SeTable.SeTableStats tableStats;
final String statsCol = colNames.get(0);
tableStats = query.calculateTableStatistics(statsCol,
SeTable.SeTableStats.SE_COUNT_STATS, queryInfo, defaultMaxDistinctValues);
int actualCount = tableStats.getCount();
return new Integer(actualCount);
} finally {
query.close();
}
}
};
final Integer count = session.issue(countCmd);