@Override public int getCount() { if (query.getFilter().equals(Filter.INCLUDE)) { // GEOWAVE-60 optimization final Map<StatisticsId, InternalDataStatistics<SimpleFeature, ?, ?>> statsMap = reader.getTransaction().getDataStatistics(); StatisticsId id = CountDataStatistics.STATS_TYPE.newBuilder().build().getId(); if (statsMap.containsKey(id)) { final CountDataStatistics stats = (CountDataStatistics) statsMap.get(id); if ((stats != null) && stats.isSet()) { return (int) stats.getCount(); } } } else if (query.getFilter().equals(Filter.EXCLUDE)) { return 0; } QueryConstraints constraints; try { constraints = getQueryConstraints(); return (int) reader.getCountInternal( constraints.jtsBounds, constraints.timeBounds, getFilter(query), constraints.limit); } catch (TransformException | FactoryException e) { LOGGER.warn("Unable to transform geometry, can't get count", e); } // fallback return 0; }
@SuppressWarnings("rawtypes") @Override protected int getCountInternal(final Query query) throws IOException { final Map<StatisticsId, InternalDataStatistics<SimpleFeature, ?, ?>> stats = new GeoWaveEmptyTransaction(components).getDataStatistics(); final InternalDataStatistics<SimpleFeature, ?, ?> countStats = stats.get(VectorStatisticsQueryBuilder.newBuilder().factory().count().build().getId()); if ((countStats != null) && query.getFilter().equals(Filter.INCLUDE)) { return (int) ((CountDataStatistics) countStats).getCount(); } else { try (GeoWaveFeatureReader reader = new GeoWaveFeatureReader(query, new GeoWaveEmptyTransaction(components), components)) { return (int) reader.getCount(); } } }