AlertsDAO implements Cleanable { @Transactional public void create(AlertHistoryEntity alert) { m_entityManagerProvider.get().persist(alert); } @Inject  AlertsDAO(Configuration configuration); @RequiresSession AlertHistoryEntity findById(long alertId); @RequiresSession List<AlertHistoryEntity> findAll(); @RequiresSession List<AlertHistoryEntity> findAll(long clusterId); @RequiresSession List<AlertHistoryEntity> findAll(long clusterId,
      List<AlertState> alertStates); @RequiresSession List<AlertHistoryEntity> findAll(long clusterId, Date startDate,
      Date endDate); @RequiresSession List<AlertHistoryEntity> findAll(AlertHistoryRequest request); @Transactional List<AlertCurrentEntity> findAll(AlertCurrentRequest request); int getCount(Predicate predicate); @RequiresSession List<AlertCurrentEntity> findCurrent(); @RequiresSession AlertCurrentEntity findCurrentById(long alertId); @RequiresSession List<AlertCurrentEntity> findCurrentByDefinitionId(long definitionId); @RequiresSession List<AlertCurrentEntity> findCurrentByCluster(long clusterId); @RequiresSession AlertSummaryDTO findCurrentCounts(long clusterId, String serviceName, String hostName); @RequiresSession Map<String, AlertSummaryDTO> findCurrentPerHostCounts(long clusterId); @RequiresSession AlertHostSummaryDTO findCurrentHostCounts(long clusterId); @RequiresSession List<AlertCurrentEntity> findCurrentByService(long clusterId,
      String serviceName); AlertCurrentEntity findCurrentByHostAndName(long clusterId, String hostName,
      String alertName); @Transactional void removeByDefinitionId(long definitionId); @Transactional int removeCurrentByHistoryId(long historyId); @Transactional int removeCurrentDisabledAlerts(); @Transactional int removeCurrentByService(long clusterId, String serviceName); @Transactional int removeCurrentByHost(String hostName); @Transactional int removeCurrentByServiceComponentHost(long clusterId, String serviceName,
      String componentName, String hostName); @Transactional void create(AlertHistoryEntity alert); @Transactional void refresh(AlertHistoryEntity alert); @Transactional AlertHistoryEntity merge(AlertHistoryEntity alert); @Transactional void remove(AlertHistoryEntity alert); @Transactional void create(AlertCurrentEntity alert); @Transactional void refresh(AlertCurrentEntity alert); @Transactional AlertCurrentEntity merge(AlertCurrentEntity alert); AlertCurrentEntity merge(AlertCurrentEntity alert, boolean updateCacheOnly); @Transactional void remove(AlertCurrentEntity alert); @RequiresSession AlertSummaryDTO findAggregateCounts(long clusterId, String alertName); AlertCurrentEntity findCurrentByNameNoHost(long clusterId, String alertName); @Transactional void flushCachedEntitiesToJPA(); @Transactional @Override long cleanup(TimeBasedCleanupPolicy policy);  }
@Test public void testAlertCurrentUpdatesViaHistory() throws Exception { AlertDefinitionEntity hostDef = new AlertDefinitionEntity(); hostDef.setDefinitionName("Host Alert Definition "); hostDef.setServiceName("YARN"); hostDef.setComponentName(null); hostDef.setClusterId(m_cluster.getClusterId()); hostDef.setHash(UUID.randomUUID().toString()); hostDef.setScheduleInterval(Integer.valueOf(60)); hostDef.setScope(Scope.HOST); hostDef.setSource("{\"type\" : \"SCRIPT\"}"); hostDef.setSourceType(SourceType.SCRIPT); m_definitionDao.create(hostDef); AlertHistoryEntity history = new AlertHistoryEntity(); history.setServiceName(hostDef.getServiceName()); history.setClusterId(m_cluster.getClusterId()); history.setAlertDefinition(hostDef); history.setAlertLabel(hostDef.getDefinitionName()); history.setAlertText(hostDef.getDefinitionName()); history.setAlertTimestamp(Long.valueOf(1L)); history.setHostName("h2"); history.setAlertState(AlertState.OK); m_dao.create(history); AlertCurrentEntity current = new AlertCurrentEntity(); current.setOriginalTimestamp(1L); current.setLatestTimestamp(2L); current.setAlertHistory(history); m_dao.create(current); assertEquals(history.getAlertText(), current.getLatestText()); history.setAlertText("foobar!"); current.setAlertHistory(history); assertEquals(history.getAlertText(), current.getLatestText()); }