@SuppressWarnings("unchecked") @Test public void testExecute() { final int commentCount = 10; final long activity1 = 6791L; final long activity2 = 6792L; final long activity3 = 6793L; final long comment4 = 4; final long comment8 = 8; final long comment9 = 9; final long comment10 = 10; getCache().setList(CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activity1, Arrays.asList(comment8)); getCache().setList(CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activity2, Arrays.asList(comment4)); getCache().setList(CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activity3, Arrays.asList(comment9, comment10)); Query activityQuery = getEntityManager().createQuery("from Activity"); Query commentQuery = getEntityManager().createQuery("from Comment"); List<Activity> activities = activityQuery.getResultList(); assertEquals(5, activities.size()); List<Comment> comments = commentQuery.getResultList(); assertEquals(commentCount, comments.size()); sut.execute(Arrays.asList(activity1, activity2, activity3)); activities = activityQuery.getResultList(); assertEquals(2, activities.size()); comments = commentQuery.getResultList(); assertEquals(6, comments.size()); }
public void execute(final List<Long> expiredActivityIds) { if (expiredActivityIds.size() == 0) { return; } getEntityManager().createQuery("DELETE FROM Comment c WHERE c.target.id in (:expiredActivityIds)") .setParameter("expiredActivityIds", expiredActivityIds).executeUpdate(); for (long activityId : expiredActivityIds) { List<Long> commentIds = getCache().getList(CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activityId); if (commentIds != null && commentIds.size() > 0) { for (long commentId : commentIds) { getCache().delete(CacheKeys.COMMENT_BY_ID + commentId); } } getCache().delete(CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activityId); getCache().delete(CacheKeys.ACTIVITY_BY_ID + activityId); } getEntityManager().createQuery("DELETE FROM StreamHashTag WHERE activity.id in (:expiredActivityIds)") .setParameter("expiredActivityIds", expiredActivityIds).executeUpdate(); getEntityManager().createQuery("DELETE FROM Activity WHERE id in (:expiredActivityIds)").setParameter( "expiredActivityIds", expiredActivityIds).executeUpdate(); }
RemoveExpiredActivities extends CachedDomainMapper { public void execute(final List<Long> expiredActivityIds) { if (expiredActivityIds.size() == 0) { return; } getEntityManager().createQuery("DELETE FROM Comment c WHERE c.target.id in (:expiredActivityIds)") .setParameter("expiredActivityIds", expiredActivityIds).executeUpdate(); for (long activityId : expiredActivityIds) { List<Long> commentIds = getCache().getList(CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activityId); if (commentIds != null && commentIds.size() > 0) { for (long commentId : commentIds) { getCache().delete(CacheKeys.COMMENT_BY_ID + commentId); } } getCache().delete(CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activityId); getCache().delete(CacheKeys.ACTIVITY_BY_ID + activityId); } getEntityManager().createQuery("DELETE FROM StreamHashTag WHERE activity.id in (:expiredActivityIds)") .setParameter("expiredActivityIds", expiredActivityIds).executeUpdate(); getEntityManager().createQuery("DELETE FROM Activity WHERE id in (:expiredActivityIds)").setParameter( "expiredActivityIds", expiredActivityIds).executeUpdate(); } }
RemoveExpiredActivities extends CachedDomainMapper { public void execute(final List<Long> expiredActivityIds) { if (expiredActivityIds.size() == 0) { return; } getEntityManager().createQuery("DELETE FROM Comment c WHERE c.target.id in (:expiredActivityIds)") .setParameter("expiredActivityIds", expiredActivityIds).executeUpdate(); for (long activityId : expiredActivityIds) { List<Long> commentIds = getCache().getList(CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activityId); if (commentIds != null && commentIds.size() > 0) { for (long commentId : commentIds) { getCache().delete(CacheKeys.COMMENT_BY_ID + commentId); } } getCache().delete(CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activityId); getCache().delete(CacheKeys.ACTIVITY_BY_ID + activityId); } getEntityManager().createQuery("DELETE FROM StreamHashTag WHERE activity.id in (:expiredActivityIds)") .setParameter("expiredActivityIds", expiredActivityIds).executeUpdate(); getEntityManager().createQuery("DELETE FROM Activity WHERE id in (:expiredActivityIds)").setParameter( "expiredActivityIds", expiredActivityIds).executeUpdate(); }  }
RemoveExpiredActivities extends CachedDomainMapper { public void execute(final List<Long> expiredActivityIds) { if (expiredActivityIds.size() == 0) { return; } getEntityManager().createQuery("DELETE FROM Comment c WHERE c.target.id in (:expiredActivityIds)") .setParameter("expiredActivityIds", expiredActivityIds).executeUpdate(); for (long activityId : expiredActivityIds) { List<Long> commentIds = getCache().getList(CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activityId); if (commentIds != null && commentIds.size() > 0) { for (long commentId : commentIds) { getCache().delete(CacheKeys.COMMENT_BY_ID + commentId); } } getCache().delete(CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activityId); getCache().delete(CacheKeys.ACTIVITY_BY_ID + activityId); } getEntityManager().createQuery("DELETE FROM StreamHashTag WHERE activity.id in (:expiredActivityIds)") .setParameter("expiredActivityIds", expiredActivityIds).executeUpdate(); getEntityManager().createQuery("DELETE FROM Activity WHERE id in (:expiredActivityIds)").setParameter( "expiredActivityIds", expiredActivityIds).executeUpdate(); }  void execute(final List<Long> expiredActivityIds); }
RemoveExpiredActivities extends CachedDomainMapper { public void execute(final List<Long> expiredActivityIds) { if (expiredActivityIds.size() == 0) { return; } getEntityManager().createQuery("DELETE FROM Comment c WHERE c.target.id in (:expiredActivityIds)") .setParameter("expiredActivityIds", expiredActivityIds).executeUpdate(); for (long activityId : expiredActivityIds) { List<Long> commentIds = getCache().getList(CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activityId); if (commentIds != null && commentIds.size() > 0) { for (long commentId : commentIds) { getCache().delete(CacheKeys.COMMENT_BY_ID + commentId); } } getCache().delete(CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activityId); getCache().delete(CacheKeys.ACTIVITY_BY_ID + activityId); } getEntityManager().createQuery("DELETE FROM StreamHashTag WHERE activity.id in (:expiredActivityIds)") .setParameter("expiredActivityIds", expiredActivityIds).executeUpdate(); getEntityManager().createQuery("DELETE FROM Activity WHERE id in (:expiredActivityIds)").setParameter( "expiredActivityIds", expiredActivityIds).executeUpdate(); }  void execute(final List<Long> expiredActivityIds);  }