use of io.apiman.manager.api.jdbc.handlers.UsageHistogramHandler in project apiman by apiman.
the class JdbcMetricsAccessor method getUsage.
/**
* @see io.apiman.manager.api.core.IMetricsAccessor#getUsage(java.lang.String, java.lang.String, java.lang.String, io.apiman.manager.api.beans.metrics.HistogramIntervalType, org.joda.time.DateTime, org.joda.time.DateTime)
*/
@Override
public UsageHistogramBean getUsage(String organizationId, String apiId, String version, HistogramIntervalType interval, DateTime from, DateTime to) {
UsageHistogramBean rval = new UsageHistogramBean();
Map<Long, UsageDataPoint> index = MetricsAccessorHelper.generateHistogramSkeleton(rval, from, to, interval, UsageDataPoint.class, Long.class);
try {
QueryRunner run = new QueryRunner(ds);
String gbColumn = groupByColumn(interval);
// $NON-NLS-1$ //$NON-NLS-2$
String sql = "SELECT " + gbColumn + ", count(*) FROM gw_requests WHERE api_org_id = ? AND api_id = ? AND api_version = ? AND rstart >= ? AND rstart < ? GROUP BY " + gbColumn;
ResultSetHandler<UsageHistogramBean> handler = new UsageHistogramHandler(rval, index);
run.query(sql, handler, organizationId, apiId, version, from.getMillis(), to.getMillis());
} catch (SQLException e) {
e.printStackTrace();
}
return rval;
}
Aggregations