/** Convenient method to just calculate the result count of a given query. */ public static int calculateResultCount( final ISession session, final FeatureTypeInfo typeInfo, final Query query, final ArcSdeVersionHandler versioningHandler) throws IOException { ArcSDEQuery countQuery = null; final int count; try { final SimpleFeatureType fullSchema = typeInfo.getFeatureType(); if (typeInfo.isInProcessView()) { final SeQueryInfo definitionQuery = typeInfo.getSdeDefinitionQuery(); final PlainSelect viewSelectStatement = typeInfo.getDefinitionQuery(); countQuery = createInprocessViewQuery( session, fullSchema, query, definitionQuery, viewSelectStatement); } else { final FIDReader fidStrategy = typeInfo.getFidStrategy(); countQuery = createQuery(session, fullSchema, query, fidStrategy, versioningHandler); } count = countQuery.calculateResultCount(); } finally { if (countQuery != null) { countQuery.close(); } } return count; }
/** Convenient method to just calculate the resulting bound box of a given query. */ public static Envelope calculateQueryExtent( final ISession session, final FeatureTypeInfo typeInfo, final Query query, final ArcSdeVersionHandler versioningHandler) throws IOException { final SimpleFeatureType fullSchema = typeInfo.getFeatureType(); final GeometryDescriptor geometryDescriptor = fullSchema.getGeometryDescriptor(); if (geometryDescriptor == null) { return null; } final String defaultGeomAttName = geometryDescriptor.getLocalName(); // we're calculating the bounds, so we'd better be sure and add the // spatial column to the query's propertynames final Query realQuery = new Query(query); realQuery.setPropertyNames(new String[] {defaultGeomAttName}); final ArcSDEQuery boundsQuery; if (typeInfo.isInProcessView()) { final SeQueryInfo definitionQuery = typeInfo.getSdeDefinitionQuery(); final PlainSelect viewSelectStatement = typeInfo.getDefinitionQuery(); boundsQuery = createInprocessViewQuery( session, fullSchema, realQuery, definitionQuery, viewSelectStatement); } else { final FIDReader fidStrategy = typeInfo.getFidStrategy(); boundsQuery = createQuery(session, fullSchema, realQuery, fidStrategy, versioningHandler); } Envelope queryExtent = null; try { Filter unsupportedFilter = boundsQuery.getFilters().getUnsupportedFilter(); if (unsupportedFilter == Filter.INCLUDE) { // we can only use an optimized bounds calculation if the // query is fully supported by sde queryExtent = boundsQuery.calculateQueryExtent(); } } finally { boundsQuery.close(); } return queryExtent; }