@Test public void testExecute() { String comment1key = CacheKeys.COMMENT_BY_ID + 1; String comment2key = CacheKeys.COMMENT_BY_ID + 2; String comment3key = CacheKeys.COMMENT_BY_ID + 3; final List<Long> params = new ArrayList<Long>(3); params.add(1L); params.add(3L); params.add(2L); assertNull(memcachedCache.get(comment1key)); assertNull(memcachedCache.get(comment2key)); assertNull(memcachedCache.get(comment3key)); List<CommentDTO> results = sut.execute(params); assertEquals(3, results.size()); assertEquals(1L, results.get(0).getId()); assertEquals(2L, results.get(1).getId()); assertEquals(3L, results.get(2).getId()); assertNotNull(memcachedCache.get(comment1key)); assertNotNull(memcachedCache.get(comment2key)); assertNotNull(memcachedCache.get(comment3key)); }
@Override public List<CommentDTO> execute(final List<Long> inCommentIds) { if (inCommentIds == null || inCommentIds.size() == 0) { return new ArrayList<CommentDTO>(0); } Map<String, CommentDTO> cachedComments = getCachedComments(inCommentIds); List<CommentDTO> commentDTOs = getCommentDTOsFromDataSource(getUncachedIds(inCommentIds, cachedComments)); commentDTOPopulator.execute(commentDTOs, getCache()); commentDTOs.addAll(cachedComments.values()); Collections.sort(commentDTOs, comparator); Date currentDate = new Date(); for (CommentDTO currentComment : commentDTOs) { currentComment.setServerDateTime(currentDate); } return commentDTOs; }
GetCommentsById extends CachedDomainMapper implements DomainMapper<List<Long>, List<CommentDTO>> { @Override public List<CommentDTO> execute(final List<Long> inCommentIds) { if (inCommentIds == null || inCommentIds.size() == 0) { return new ArrayList<CommentDTO>(0); } Map<String, CommentDTO> cachedComments = getCachedComments(inCommentIds); List<CommentDTO> commentDTOs = getCommentDTOsFromDataSource(getUncachedIds(inCommentIds, cachedComments)); commentDTOPopulator.execute(commentDTOs, getCache()); commentDTOs.addAll(cachedComments.values()); Collections.sort(commentDTOs, comparator); Date currentDate = new Date(); for (CommentDTO currentComment : commentDTOs) { currentComment.setServerDateTime(currentDate); } return commentDTOs; } }
GetCommentsById extends CachedDomainMapper implements DomainMapper<List<Long>, List<CommentDTO>> { @Override public List<CommentDTO> execute(final List<Long> inCommentIds) { if (inCommentIds == null || inCommentIds.size() == 0) { return new ArrayList<CommentDTO>(0); } Map<String, CommentDTO> cachedComments = getCachedComments(inCommentIds); List<CommentDTO> commentDTOs = getCommentDTOsFromDataSource(getUncachedIds(inCommentIds, cachedComments)); commentDTOPopulator.execute(commentDTOs, getCache()); commentDTOs.addAll(cachedComments.values()); Collections.sort(commentDTOs, comparator); Date currentDate = new Date(); for (CommentDTO currentComment : commentDTOs) { currentComment.setServerDateTime(currentDate); } return commentDTOs; } GetCommentsById(final CommentDTOPopulator inCommentDTOPopulator); }
GetCommentsById extends CachedDomainMapper implements DomainMapper<List<Long>, List<CommentDTO>> { @Override public List<CommentDTO> execute(final List<Long> inCommentIds) { if (inCommentIds == null || inCommentIds.size() == 0) { return new ArrayList<CommentDTO>(0); } Map<String, CommentDTO> cachedComments = getCachedComments(inCommentIds); List<CommentDTO> commentDTOs = getCommentDTOsFromDataSource(getUncachedIds(inCommentIds, cachedComments)); commentDTOPopulator.execute(commentDTOs, getCache()); commentDTOs.addAll(cachedComments.values()); Collections.sort(commentDTOs, comparator); Date currentDate = new Date(); for (CommentDTO currentComment : commentDTOs) { currentComment.setServerDateTime(currentDate); } return commentDTOs; } GetCommentsById(final CommentDTOPopulator inCommentDTOPopulator); @Override List<CommentDTO> execute(final List<Long> inCommentIds); }
GetCommentsById extends CachedDomainMapper implements DomainMapper<List<Long>, List<CommentDTO>> { @Override public List<CommentDTO> execute(final List<Long> inCommentIds) { if (inCommentIds == null || inCommentIds.size() == 0) { return new ArrayList<CommentDTO>(0); } Map<String, CommentDTO> cachedComments = getCachedComments(inCommentIds); List<CommentDTO> commentDTOs = getCommentDTOsFromDataSource(getUncachedIds(inCommentIds, cachedComments)); commentDTOPopulator.execute(commentDTOs, getCache()); commentDTOs.addAll(cachedComments.values()); Collections.sort(commentDTOs, comparator); Date currentDate = new Date(); for (CommentDTO currentComment : commentDTOs) { currentComment.setServerDateTime(currentDate); } return commentDTOs; } GetCommentsById(final CommentDTOPopulator inCommentDTOPopulator); @Override List<CommentDTO> execute(final List<Long> inCommentIds);  }