@Test public void testExecuteForAllStreams() { getEntityManager().persist(new UsageMetric(1L, true, true, 1L, new Date(apri8th2011))); getEntityManager().persist(new UsageMetric(3L, true, false, 2L, new Date(apri8th2011 + 3))); getEntityManager().persist(new UsageMetric(6L, true, false, null, new Date(apri8th2011))); getEntityManager().persist(new UsageMetric(2L, true, true, 3L, new Date(apri8th2011 + 5))); getEntityManager().persist(new UsageMetric(4L, true, true, 4L, new Date(apri8th2011))); getEntityManager().persist(new UsageMetric(5L, true, true, 5L, new Date(apri8th2011))); getEntityManager().persist(new UsageMetric(6L, true, true, 1L, new Date(april7th2011))); getEntityManager().persist(new UsageMetric(5L, true, true, 2L, new Date(april7th2011))); getEntityManager().persist(new UsageMetric(4L, true, true, 3L, new Date(april7th2011))); getEntityManager().persist(new UsageMetric(3L, true, false, null, new Date(april7th2011))); getEntityManager().flush(); getEntityManager().clear(); Assert.assertEquals(4L, (long) sut.execute(new UsageMetricDailyStreamInfoRequest(new Date(apri8th2011), null))); }
@Override public Long execute(final UsageMetricDailyStreamInfoRequest inRequest) { Query q; Date startOfDay, endOfDay; startOfDay = DateDayExtractor.getStartOfDay(inRequest.getMetricsDate()); endOfDay = DateDayExtractor.getEndOfDay(inRequest.getMetricsDate()); if (inRequest.getStreamRecipientStreamScopeId() == null) { q = getEntityManager().createQuery( "SELECT COUNT(id) FROM UsageMetric " + "WHERE isStreamView = true AND created >= :startDate AND created <= :endDate") .setParameter("startDate", startOfDay).setParameter("endDate", endOfDay); } else { q = getEntityManager().createQuery( "SELECT COUNT(id) FROM UsageMetric " + "WHERE isStreamView = true AND created >= :startDate AND created <= :endDate " + "AND streamViewStreamScopeId = :streamViewStreamScopeId").setParameter("startDate", startOfDay).setParameter("endDate", endOfDay).setParameter("streamViewStreamScopeId", inRequest.getStreamRecipientStreamScopeId()); } return (Long) q.getSingleResult(); }
GetDailyStreamViewCountDbMapper extends BaseArgDomainMapper<UsageMetricDailyStreamInfoRequest, Long> { @Override public Long execute(final UsageMetricDailyStreamInfoRequest inRequest) { Query q; Date startOfDay, endOfDay; startOfDay = DateDayExtractor.getStartOfDay(inRequest.getMetricsDate()); endOfDay = DateDayExtractor.getEndOfDay(inRequest.getMetricsDate()); if (inRequest.getStreamRecipientStreamScopeId() == null) { q = getEntityManager().createQuery( "SELECT COUNT(id) FROM UsageMetric " + "WHERE isStreamView = true AND created >= :startDate AND created <= :endDate") .setParameter("startDate", startOfDay).setParameter("endDate", endOfDay); } else { q = getEntityManager().createQuery( "SELECT COUNT(id) FROM UsageMetric " + "WHERE isStreamView = true AND created >= :startDate AND created <= :endDate " + "AND streamViewStreamScopeId = :streamViewStreamScopeId").setParameter("startDate", startOfDay).setParameter("endDate", endOfDay).setParameter("streamViewStreamScopeId", inRequest.getStreamRecipientStreamScopeId()); } return (Long) q.getSingleResult(); } }
GetDailyStreamViewCountDbMapper extends BaseArgDomainMapper<UsageMetricDailyStreamInfoRequest, Long> { @Override public Long execute(final UsageMetricDailyStreamInfoRequest inRequest) { Query q; Date startOfDay, endOfDay; startOfDay = DateDayExtractor.getStartOfDay(inRequest.getMetricsDate()); endOfDay = DateDayExtractor.getEndOfDay(inRequest.getMetricsDate()); if (inRequest.getStreamRecipientStreamScopeId() == null) { q = getEntityManager().createQuery( "SELECT COUNT(id) FROM UsageMetric " + "WHERE isStreamView = true AND created >= :startDate AND created <= :endDate") .setParameter("startDate", startOfDay).setParameter("endDate", endOfDay); } else { q = getEntityManager().createQuery( "SELECT COUNT(id) FROM UsageMetric " + "WHERE isStreamView = true AND created >= :startDate AND created <= :endDate " + "AND streamViewStreamScopeId = :streamViewStreamScopeId").setParameter("startDate", startOfDay).setParameter("endDate", endOfDay).setParameter("streamViewStreamScopeId", inRequest.getStreamRecipientStreamScopeId()); } return (Long) q.getSingleResult(); }  }
GetDailyStreamViewCountDbMapper extends BaseArgDomainMapper<UsageMetricDailyStreamInfoRequest, Long> { @Override public Long execute(final UsageMetricDailyStreamInfoRequest inRequest) { Query q; Date startOfDay, endOfDay; startOfDay = DateDayExtractor.getStartOfDay(inRequest.getMetricsDate()); endOfDay = DateDayExtractor.getEndOfDay(inRequest.getMetricsDate()); if (inRequest.getStreamRecipientStreamScopeId() == null) { q = getEntityManager().createQuery( "SELECT COUNT(id) FROM UsageMetric " + "WHERE isStreamView = true AND created >= :startDate AND created <= :endDate") .setParameter("startDate", startOfDay).setParameter("endDate", endOfDay); } else { q = getEntityManager().createQuery( "SELECT COUNT(id) FROM UsageMetric " + "WHERE isStreamView = true AND created >= :startDate AND created <= :endDate " + "AND streamViewStreamScopeId = :streamViewStreamScopeId").setParameter("startDate", startOfDay).setParameter("endDate", endOfDay).setParameter("streamViewStreamScopeId", inRequest.getStreamRecipientStreamScopeId()); } return (Long) q.getSingleResult(); }  @Override Long execute(final UsageMetricDailyStreamInfoRequest inRequest); }
GetDailyStreamViewCountDbMapper extends BaseArgDomainMapper<UsageMetricDailyStreamInfoRequest, Long> { @Override public Long execute(final UsageMetricDailyStreamInfoRequest inRequest) { Query q; Date startOfDay, endOfDay; startOfDay = DateDayExtractor.getStartOfDay(inRequest.getMetricsDate()); endOfDay = DateDayExtractor.getEndOfDay(inRequest.getMetricsDate()); if (inRequest.getStreamRecipientStreamScopeId() == null) { q = getEntityManager().createQuery( "SELECT COUNT(id) FROM UsageMetric " + "WHERE isStreamView = true AND created >= :startDate AND created <= :endDate") .setParameter("startDate", startOfDay).setParameter("endDate", endOfDay); } else { q = getEntityManager().createQuery( "SELECT COUNT(id) FROM UsageMetric " + "WHERE isStreamView = true AND created >= :startDate AND created <= :endDate " + "AND streamViewStreamScopeId = :streamViewStreamScopeId").setParameter("startDate", startOfDay).setParameter("endDate", endOfDay).setParameter("streamViewStreamScopeId", inRequest.getStreamRecipientStreamScopeId()); } return (Long) q.getSingleResult(); }  @Override Long execute(final UsageMetricDailyStreamInfoRequest inRequest);  }