use of org.opennms.netmgt.dao.api.CountedObject in project opennms by OpenNMS.
the class EventCountDaoHibernate method getUeiCounts.
@Override
public Set<CountedObject<String>> getUeiCounts(final Integer limit) {
Set<CountedObject<String>> ueis = new TreeSet<CountedObject<String>>();
HibernateCallback<List<CountedObject<String>>> hc = new HibernateCallback<List<CountedObject<String>>>() {
@Override
public List<CountedObject<String>> doInHibernate(Session session) throws HibernateException {
Query queryObject = session.createQuery("SELECT event.eventUei, COUNT(event.eventUei) FROM OnmsEvent event GROUP BY event.eventUei ORDER BY COUNT(event.eventUei) desc");
queryObject.setMaxResults(limit);
SessionFactoryUtils.applyTransactionTimeout(queryObject, getSessionFactory());
List<CountedObject<String>> ueis = new ArrayList<CountedObject<String>>();
@SuppressWarnings("unchecked") final List<Object[]> l = queryObject.list();
for (final Object[] o : l) {
ueis.add(new CountedObject<String>((String) o[0], (Long) o[1]));
}
return ueis;
}
};
ueis.addAll((List<CountedObject<String>>) getHibernateTemplate().executeWithNativeSession(hc));
return ueis;
}
use of org.opennms.netmgt.dao.api.CountedObject in project opennms by OpenNMS.
the class MockEventDao method getUeiCounts.
@Override
public Set<CountedObject<String>> getUeiCounts(final Integer limit) {
final Map<String, Long> counts = new HashMap<String, Long>();
for (final OnmsEvent event : findAll()) {
final String eventUei = event.getEventUei();
if (!counts.containsKey(eventUei)) {
counts.put(eventUei, 0L);
}
counts.put(eventUei, counts.get(eventUei) + 1);
}
final Set<CountedObject<String>> countedObjects = new HashSet<CountedObject<String>>();
for (final String uei : counts.keySet()) {
countedObjects.add(new CountedObject<String>(uei, counts.get(uei)));
}
return countedObjects;
}
Aggregations