From: <pn...@hy...> - 2009-12-11 00:46:13
|
Author: pnguyen Date: 2009-12-10 16:14:46 -0800 (Thu, 10 Dec 2009) New Revision: 14071 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=14071 Modified: trunk/src/org/hyperic/hq/events/server/session/AlertDAO.java trunk/src/org/hyperic/hq/events/server/session/AlertManagerEJBImpl.java Log: [HQ-1799] Get all last unfixed alerts in 1 query, instead of per resource (X queries) Modified: trunk/src/org/hyperic/hq/events/server/session/AlertDAO.java =================================================================== --- trunk/src/org/hyperic/hq/events/server/session/AlertDAO.java 2009-12-10 22:31:46 UTC (rev 14070) +++ trunk/src/org/hyperic/hq/events/server/session/AlertDAO.java 2009-12-11 00:14:46 UTC (rev 14071) @@ -254,6 +254,35 @@ return null; } } + + /** + * Return all last unfixed alerts + * + * @return + */ + public Map findAllLastUnfixed() { + String hql = + new StringBuilder() + .append("select a ") + .append("from Alert a ") + .append("join a.alertDefinition ad ") + .append("where ad.deleted = false ") + .append("and a.fixed = false ") + .append("order by a.ctime ") + .toString(); + + List alerts = createQuery(hql).list(); + + Map lastAlerts = new HashMap(alerts.size()); + for (Iterator it=alerts.iterator(); it.hasNext(); ) { + Alert a = (Alert) it.next(); + // since it is ordered by ctime in ascending order, the + // last alert will eventually be put into the map + lastAlerts.put(a.getAlertDefinition().getId(), a); + } + + return lastAlerts; + } /** * Return all last fixed alerts for the given resource Modified: trunk/src/org/hyperic/hq/events/server/session/AlertManagerEJBImpl.java =================================================================== --- trunk/src/org/hyperic/hq/events/server/session/AlertManagerEJBImpl.java 2009-12-10 22:31:46 UTC (rev 14070) +++ trunk/src/org/hyperic/hq/events/server/session/AlertManagerEJBImpl.java 2009-12-11 00:14:46 UTC (rev 14071) @@ -247,6 +247,29 @@ } /** + * Find all last unfixed alerts + * + * @ejb:interface-method + */ + public Map findAllLastUnfixed() { + StopWatch watch = new StopWatch(); + Map unfixedAlerts = null; + try { + unfixedAlerts = + getAlertDAO().findAllLastUnfixed(); + } catch (Exception e) { + unfixedAlerts = Collections.EMPTY_MAP; + _log.error("Error finding all last unfixed alerts", e); + } finally { + if (_log.isDebugEnabled()) { + _log.debug("findAllLastUnfixed: " + watch); + } + } + + return unfixedAlerts; + } + + /** * Find the last alerts for the given resource * * @ejb:interface-method |