Search in sources :

Example 1 with CountedObject

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;
}
Also used : Query(org.hibernate.Query) ArrayList(java.util.ArrayList) TreeSet(java.util.TreeSet) CountedObject(org.opennms.netmgt.dao.api.CountedObject) ArrayList(java.util.ArrayList) List(java.util.List) HibernateCallback(org.springframework.orm.hibernate3.HibernateCallback) CountedObject(org.opennms.netmgt.dao.api.CountedObject) Session(org.hibernate.Session)

Example 2 with CountedObject

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;
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) CountedObject(org.opennms.netmgt.dao.api.CountedObject)

Aggregations

CountedObject (org.opennms.netmgt.dao.api.CountedObject)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 Query (org.hibernate.Query)1 Session (org.hibernate.Session)1 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)1 HibernateCallback (org.springframework.orm.hibernate3.HibernateCallback)1