@Test public void testExecute() { DeleteOldStreamHashTagRecordsDbMapper sut = new DeleteOldStreamHashTagRecordsDbMapper(); sut.setEntityManager(getEntityManager()); final Integer hoursInDay = 24; Calendar calTwoDaysAgo = Calendar.getInstance(); calTwoDaysAgo.add(Calendar.HOUR, -hoursInDay * 2); Date twoDaysAgo = calTwoDaysAgo.getTime(); Calendar calOneDayAgo = Calendar.getInstance(); calOneDayAgo.add(Calendar.HOUR, -hoursInDay); Date oneDayAgo = calOneDayAgo.getTime(); getEntityManager().createQuery("UPDATE StreamHashTag SET activityDate = :activityDate").setParameter( "activityDate", twoDaysAgo).executeUpdate(); getEntityManager().createQuery("UPDATE StreamHashTag SET activityDate = :activityDate WHERE id IN (15,16)") .setParameter("activityDate", oneDayAgo).executeUpdate(); final Integer dayAndAHalfAgoHours = 36; Calendar calDayAndAHalfAgo = Calendar.getInstance(); calDayAndAHalfAgo.add(Calendar.HOUR, -dayAndAHalfAgoHours); Date dayAndAHalAgo = calDayAndAHalfAgo.getTime(); Long numberOfActivities = (Long) getEntityManager().createQuery("SELECT COUNT(*) FROM StreamHashTag") .getSingleResult(); Long numberOfRecordsDeleted = new Long(sut.execute(dayAndAHalAgo)); assertEquals(new Long(numberOfActivities - 2L), numberOfRecordsDeleted); List<StreamHashTag> streamHashTags = getEntityManager().createQuery("FROM StreamHashTag").getResultList(); assertEquals(2, streamHashTags.size()); final Long fifteen = 15L; final Long sixteen = 16L; boolean found15 = false; boolean found16 = false; for (StreamHashTag st : streamHashTags) { if (st.getId() == fifteen) { found15 = true; } if (st.getId() == sixteen) { found16 = true; } } assertTrue(found15); assertTrue(found16); }
@Override public Integer execute(final Date inStreamHashTagExpireDate) { int numberOfRecordsAffected = getEntityManager().createQuery( "DELETE FROM StreamHashTag WHERE activityDate < :activityDate").setParameter("activityDate", inStreamHashTagExpireDate).executeUpdate(); return numberOfRecordsAffected; }
DeleteOldStreamHashTagRecordsDbMapper extends BaseArgDomainMapper<Date, Integer> { @Override public Integer execute(final Date inStreamHashTagExpireDate) { int numberOfRecordsAffected = getEntityManager().createQuery( "DELETE FROM StreamHashTag WHERE activityDate < :activityDate").setParameter("activityDate", inStreamHashTagExpireDate).executeUpdate(); return numberOfRecordsAffected; } }
DeleteOldStreamHashTagRecordsDbMapper extends BaseArgDomainMapper<Date, Integer> { @Override public Integer execute(final Date inStreamHashTagExpireDate) { int numberOfRecordsAffected = getEntityManager().createQuery( "DELETE FROM StreamHashTag WHERE activityDate < :activityDate").setParameter("activityDate", inStreamHashTagExpireDate).executeUpdate(); return numberOfRecordsAffected; }  }
DeleteOldStreamHashTagRecordsDbMapper extends BaseArgDomainMapper<Date, Integer> { @Override public Integer execute(final Date inStreamHashTagExpireDate) { int numberOfRecordsAffected = getEntityManager().createQuery( "DELETE FROM StreamHashTag WHERE activityDate < :activityDate").setParameter("activityDate", inStreamHashTagExpireDate).executeUpdate(); return numberOfRecordsAffected; }  @Override Integer execute(final Date inStreamHashTagExpireDate); }
DeleteOldStreamHashTagRecordsDbMapper extends BaseArgDomainMapper<Date, Integer> { @Override public Integer execute(final Date inStreamHashTagExpireDate) { int numberOfRecordsAffected = getEntityManager().createQuery( "DELETE FROM StreamHashTag WHERE activityDate < :activityDate").setParameter("activityDate", inStreamHashTagExpireDate).executeUpdate(); return numberOfRecordsAffected; }  @Override Integer execute(final Date inStreamHashTagExpireDate);  }