@Test public void testExecuteRemoveFirstComment() { loadAndVerifyInitialActivity(); assertTrue(sut.execute(1L)); ActivityDTO activity = activityDAO.execute(new ArrayList<Long>() { { add(activityId); } }).get(0); assertEquals(2, activity.getFirstComment().getId()); assertEquals(3, activity.getLastComment().getId()); assertEquals(2, activity.getCommentCount()); }
@Override public Boolean execute(final Long inCommentId) { CommentDTO comment = getCommentById(inCommentId); if (comment == null) { return true; } long activityId = comment.getActivityId(); getEntityManager().createQuery("DELETE FROM Comment WHERE id = :commentId").setParameter("commentId", inCommentId).executeUpdate(); Cache cache = getCache(); cache.delete(CacheKeys.COMMENT_BY_ID + inCommentId); String commentsByActivityKey = CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activityId; cache.removeFromList(commentsByActivityKey, inCommentId); String activityByIdKey = CacheKeys.ACTIVITY_BY_ID + activityId; ActivityDTO activityDTO = (ActivityDTO) cache.get(activityByIdKey); if (activityDTO != null) { List<Long> commentIds = cache.getList(commentsByActivityKey); updateActivityDTO(activityDTO, inCommentId, commentIds); getCache().set(activityByIdKey, activityDTO); } final Activity activity = (Activity) getHibernateSession().load(Activity.class, activityId); Search.getFullTextSession((Session) getEntityManager().getDelegate()).index(activity); return true; }
DeleteActivityComment extends BaseArgCachedDomainMapper<Long, Boolean> { @Override public Boolean execute(final Long inCommentId) { CommentDTO comment = getCommentById(inCommentId); if (comment == null) { return true; } long activityId = comment.getActivityId(); getEntityManager().createQuery("DELETE FROM Comment WHERE id = :commentId").setParameter("commentId", inCommentId).executeUpdate(); Cache cache = getCache(); cache.delete(CacheKeys.COMMENT_BY_ID + inCommentId); String commentsByActivityKey = CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activityId; cache.removeFromList(commentsByActivityKey, inCommentId); String activityByIdKey = CacheKeys.ACTIVITY_BY_ID + activityId; ActivityDTO activityDTO = (ActivityDTO) cache.get(activityByIdKey); if (activityDTO != null) { List<Long> commentIds = cache.getList(commentsByActivityKey); updateActivityDTO(activityDTO, inCommentId, commentIds); getCache().set(activityByIdKey, activityDTO); } final Activity activity = (Activity) getHibernateSession().load(Activity.class, activityId); Search.getFullTextSession((Session) getEntityManager().getDelegate()).index(activity); return true; } }
DeleteActivityComment extends BaseArgCachedDomainMapper<Long, Boolean> { @Override public Boolean execute(final Long inCommentId) { CommentDTO comment = getCommentById(inCommentId); if (comment == null) { return true; } long activityId = comment.getActivityId(); getEntityManager().createQuery("DELETE FROM Comment WHERE id = :commentId").setParameter("commentId", inCommentId).executeUpdate(); Cache cache = getCache(); cache.delete(CacheKeys.COMMENT_BY_ID + inCommentId); String commentsByActivityKey = CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activityId; cache.removeFromList(commentsByActivityKey, inCommentId); String activityByIdKey = CacheKeys.ACTIVITY_BY_ID + activityId; ActivityDTO activityDTO = (ActivityDTO) cache.get(activityByIdKey); if (activityDTO != null) { List<Long> commentIds = cache.getList(commentsByActivityKey); updateActivityDTO(activityDTO, inCommentId, commentIds); getCache().set(activityByIdKey, activityDTO); } final Activity activity = (Activity) getHibernateSession().load(Activity.class, activityId); Search.getFullTextSession((Session) getEntityManager().getDelegate()).index(activity); return true; } DeleteActivityComment(final DomainMapper<List<Long>, List<CommentDTO>> inCommentByIdDAO); }
DeleteActivityComment extends BaseArgCachedDomainMapper<Long, Boolean> { @Override public Boolean execute(final Long inCommentId) { CommentDTO comment = getCommentById(inCommentId); if (comment == null) { return true; } long activityId = comment.getActivityId(); getEntityManager().createQuery("DELETE FROM Comment WHERE id = :commentId").setParameter("commentId", inCommentId).executeUpdate(); Cache cache = getCache(); cache.delete(CacheKeys.COMMENT_BY_ID + inCommentId); String commentsByActivityKey = CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activityId; cache.removeFromList(commentsByActivityKey, inCommentId); String activityByIdKey = CacheKeys.ACTIVITY_BY_ID + activityId; ActivityDTO activityDTO = (ActivityDTO) cache.get(activityByIdKey); if (activityDTO != null) { List<Long> commentIds = cache.getList(commentsByActivityKey); updateActivityDTO(activityDTO, inCommentId, commentIds); getCache().set(activityByIdKey, activityDTO); } final Activity activity = (Activity) getHibernateSession().load(Activity.class, activityId); Search.getFullTextSession((Session) getEntityManager().getDelegate()).index(activity); return true; } DeleteActivityComment(final DomainMapper<List<Long>, List<CommentDTO>> inCommentByIdDAO); @Override Boolean execute(final Long inCommentId); }
DeleteActivityComment extends BaseArgCachedDomainMapper<Long, Boolean> { @Override public Boolean execute(final Long inCommentId) { CommentDTO comment = getCommentById(inCommentId); if (comment == null) { return true; } long activityId = comment.getActivityId(); getEntityManager().createQuery("DELETE FROM Comment WHERE id = :commentId").setParameter("commentId", inCommentId).executeUpdate(); Cache cache = getCache(); cache.delete(CacheKeys.COMMENT_BY_ID + inCommentId); String commentsByActivityKey = CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activityId; cache.removeFromList(commentsByActivityKey, inCommentId); String activityByIdKey = CacheKeys.ACTIVITY_BY_ID + activityId; ActivityDTO activityDTO = (ActivityDTO) cache.get(activityByIdKey); if (activityDTO != null) { List<Long> commentIds = cache.getList(commentsByActivityKey); updateActivityDTO(activityDTO, inCommentId, commentIds); getCache().set(activityByIdKey, activityDTO); } final Activity activity = (Activity) getHibernateSession().load(Activity.class, activityId); Search.getFullTextSession((Session) getEntityManager().getDelegate()).index(activity); return true; } DeleteActivityComment(final DomainMapper<List<Long>, List<CommentDTO>> inCommentByIdDAO); @Override Boolean execute(final Long inCommentId);  }