@Test public void testExecute() { final int neg1 = -1; final int neg2 = -2; final int neg4 = -4; final int neg9 = -9; final int neg11 = -11; final int neg12 = -12; Calendar day = Calendar.getInstance(); day.add(Calendar.DATE, neg2); Date twoDaysAgo = new Date(day.getTimeInMillis()); day = Calendar.getInstance(); day.add(Calendar.DATE, neg4); day.add(Calendar.MINUTE, neg1); Date fourDaysAgo = new Date(day.getTimeInMillis()); day = Calendar.getInstance(); day.add(Calendar.DATE, neg9); day.add(Calendar.MINUTE, neg1); Date nineDaysAgo = new Date(day.getTimeInMillis()); day = Calendar.getInstance(); day.add(Calendar.DATE, neg11); day.add(Calendar.MINUTE, neg1); Date elevenDaysAgo = new Date(day.getTimeInMillis()); day = Calendar.getInstance(); day.add(Calendar.DATE, neg12); day.add(Calendar.MINUTE, neg1); Date twelveDaysAgo = new Date(day.getTimeInMillis()); getEntityManager().createQuery("DELETE FROM UsageMetric").executeUpdate(); getEntityManager().createQuery("DELETE FROM DailyUsageSummary").executeUpdate(); getEntityManager().persist(new UsageMetric(1, true, true, 1L, twoDaysAgo)); getEntityManager().persist(new UsageMetric(1, true, true, 1L, twoDaysAgo)); getEntityManager().persist(new UsageMetric(1, true, true, 1L, twoDaysAgo)); getEntityManager().persist(new UsageMetric(2, true, true, 1L, fourDaysAgo)); getEntityManager().persist(new UsageMetric(2, true, true, 1L, fourDaysAgo)); getEntityManager().persist( new DailyUsageSummary(1, 2, 3, 4, 5, 6, 7, fourDaysAgo, 1308238511000L, 5L, 5L, 5L, 5L)); getEntityManager().persist( new DailyUsageSummary(1, 2, 3, 4, 5, 6, 7, nineDaysAgo, 1308238511000L, 5L, 5L, 5L, 5L)); getEntityManager().persist( new DailyUsageSummary(2, 2, 3, 4, 5, 6, 7, elevenDaysAgo, 1308238511000L, 5L, 5L, 5L, 5L)); getEntityManager().persist( new DailyUsageSummary(2, 2, 3, 4, 5, 6, 7, twelveDaysAgo, 1308238511000L, 5L, 5L, 5L, 5L)); getEntityManager().flush(); getEntityManager().clear(); sut.execute(0); List<UsageMetric> existingMetricData = getEntityManager().createQuery("FROM UsageMetric").getResultList(); Assert.assertEquals(3, existingMetricData.size()); assertEquals(1L, existingMetricData.get(0).getActorPersonId()); assertEquals(1L, existingMetricData.get(1).getActorPersonId()); List<DailyUsageSummary> existingSummaryData = getEntityManager().createQuery("FROM DailyUsageSummary") .getResultList(); Assert.assertEquals(2, existingSummaryData.size()); assertEquals(1L, existingSummaryData.get(0).getUniqueVisitorCount()); assertEquals(1L, existingSummaryData.get(1).getUniqueVisitorCount()); }
@Override public Serializable execute(final Serializable inRequest) { Calendar day; Date lastRetainDate; day = Calendar.getInstance(); day.add(Calendar.DATE, -daysOfMetricDataToRetain); lastRetainDate = DateDayExtractor.getStartOfDay(new Date(day.getTimeInMillis())); getEntityManager().createQuery("DELETE FROM UsageMetric WHERE created < :lastRetainDate").setParameter( "lastRetainDate", lastRetainDate).executeUpdate(); day = Calendar.getInstance(); day.add(Calendar.DATE, -daysOfSummaryDataToRetain); lastRetainDate = DateDayExtractor.getStartOfDay(new Date(day.getTimeInMillis())); getEntityManager().createQuery("DELETE FROM DailyUsageSummary WHERE usageDate < :lastRetainDate").setParameter( "lastRetainDate", lastRetainDate).executeUpdate(); return Boolean.TRUE; }
DeleteOldUsageMetricDataDbMapper extends BaseArgDomainMapper<Serializable, Serializable> { @Override public Serializable execute(final Serializable inRequest) { Calendar day; Date lastRetainDate; day = Calendar.getInstance(); day.add(Calendar.DATE, -daysOfMetricDataToRetain); lastRetainDate = DateDayExtractor.getStartOfDay(new Date(day.getTimeInMillis())); getEntityManager().createQuery("DELETE FROM UsageMetric WHERE created < :lastRetainDate").setParameter( "lastRetainDate", lastRetainDate).executeUpdate(); day = Calendar.getInstance(); day.add(Calendar.DATE, -daysOfSummaryDataToRetain); lastRetainDate = DateDayExtractor.getStartOfDay(new Date(day.getTimeInMillis())); getEntityManager().createQuery("DELETE FROM DailyUsageSummary WHERE usageDate < :lastRetainDate").setParameter( "lastRetainDate", lastRetainDate).executeUpdate(); return Boolean.TRUE; } }
DeleteOldUsageMetricDataDbMapper extends BaseArgDomainMapper<Serializable, Serializable> { @Override public Serializable execute(final Serializable inRequest) { Calendar day; Date lastRetainDate; day = Calendar.getInstance(); day.add(Calendar.DATE, -daysOfMetricDataToRetain); lastRetainDate = DateDayExtractor.getStartOfDay(new Date(day.getTimeInMillis())); getEntityManager().createQuery("DELETE FROM UsageMetric WHERE created < :lastRetainDate").setParameter( "lastRetainDate", lastRetainDate).executeUpdate(); day = Calendar.getInstance(); day.add(Calendar.DATE, -daysOfSummaryDataToRetain); lastRetainDate = DateDayExtractor.getStartOfDay(new Date(day.getTimeInMillis())); getEntityManager().createQuery("DELETE FROM DailyUsageSummary WHERE usageDate < :lastRetainDate").setParameter( "lastRetainDate", lastRetainDate).executeUpdate(); return Boolean.TRUE; } DeleteOldUsageMetricDataDbMapper(final int inDaysOfMetricDataToRetain, final int inDaysOfSummaryDataToRetain); }
DeleteOldUsageMetricDataDbMapper extends BaseArgDomainMapper<Serializable, Serializable> { @Override public Serializable execute(final Serializable inRequest) { Calendar day; Date lastRetainDate; day = Calendar.getInstance(); day.add(Calendar.DATE, -daysOfMetricDataToRetain); lastRetainDate = DateDayExtractor.getStartOfDay(new Date(day.getTimeInMillis())); getEntityManager().createQuery("DELETE FROM UsageMetric WHERE created < :lastRetainDate").setParameter( "lastRetainDate", lastRetainDate).executeUpdate(); day = Calendar.getInstance(); day.add(Calendar.DATE, -daysOfSummaryDataToRetain); lastRetainDate = DateDayExtractor.getStartOfDay(new Date(day.getTimeInMillis())); getEntityManager().createQuery("DELETE FROM DailyUsageSummary WHERE usageDate < :lastRetainDate").setParameter( "lastRetainDate", lastRetainDate).executeUpdate(); return Boolean.TRUE; } DeleteOldUsageMetricDataDbMapper(final int inDaysOfMetricDataToRetain, final int inDaysOfSummaryDataToRetain); @Override Serializable execute(final Serializable inRequest); }
DeleteOldUsageMetricDataDbMapper extends BaseArgDomainMapper<Serializable, Serializable> { @Override public Serializable execute(final Serializable inRequest) { Calendar day; Date lastRetainDate; day = Calendar.getInstance(); day.add(Calendar.DATE, -daysOfMetricDataToRetain); lastRetainDate = DateDayExtractor.getStartOfDay(new Date(day.getTimeInMillis())); getEntityManager().createQuery("DELETE FROM UsageMetric WHERE created < :lastRetainDate").setParameter( "lastRetainDate", lastRetainDate).executeUpdate(); day = Calendar.getInstance(); day.add(Calendar.DATE, -daysOfSummaryDataToRetain); lastRetainDate = DateDayExtractor.getStartOfDay(new Date(day.getTimeInMillis())); getEntityManager().createQuery("DELETE FROM DailyUsageSummary WHERE usageDate < :lastRetainDate").setParameter( "lastRetainDate", lastRetainDate).executeUpdate(); return Boolean.TRUE; } DeleteOldUsageMetricDataDbMapper(final int inDaysOfMetricDataToRetain, final int inDaysOfSummaryDataToRetain); @Override Serializable execute(final Serializable inRequest);  }