protected boolean isCountVisitor(FeatureVisitor visitor) { if (visitor instanceof CountVisitor) { // is count visitor nothing else to test return true; } // the visitor maybe wrapper by a group by visitor return isGroupByVisitor(visitor) && ((GroupByVisitor) visitor).getAggregateVisitor() instanceof CountVisitor; }
private Expression getAggregateExpression(FeatureVisitor visitor) { // if is a group by visitor we need to use the internal aggregate visitor FeatureVisitor aggregateVisitor = isGroupByVisitor(visitor) ? ((GroupByVisitor) visitor).getAggregateVisitor() : visitor; Expression expression = getExpression(aggregateVisitor); if (expression == null) { // no aggregate attribute available, NULL will be returned LOGGER.info("Visitor " + visitor.getClass() + " has no aggregate attribute."); return null; } return expression; }
/** * Helper method that will try to match a feature visitor with an aggregate function. If no * aggregate function machs the visitor NULL will be returned. * * @param visitor the feature visitor * @return the match aggregate function name, or NULL if no match */ protected String matchAggregateFunction(FeatureVisitor visitor) { // if is a group by visitor we use use the internal aggregate visitor class otherwise we use // the visitor class Class visitorClass = isGroupByVisitor(visitor) ? ((GroupByVisitor) visitor).getAggregateVisitor().getClass() : visitor.getClass(); String function = null; // try to find a matching aggregate function walking up the hierarchy if necessary while (function == null && visitorClass != null) { function = getAggregateFunctions().get(visitorClass); visitorClass = visitorClass.getSuperclass(); } if (function == null) { // this visitor don't match any aggregate function NULL will be returned LOGGER.info( "Unable to find aggregate function matching visitor: " + visitor.getClass()); } return function; }