@Override public void updateComment(Comment comment) throws NonExistingEntityException, IllegalArgumentException { if (comment == null) { throw new IllegalArgumentException("Comment is null."); } if (comment.getId() == null) { throw new IllegalArgumentException("Comment id is null."); } commentCache = provider.getCacheContainer().getCache("commentcache"); if (!commentCache.containsKey(comment.getId())) { throw new NonExistingEntityException("Comment does not exist in cache."); } try { userTransaction.begin(); commentCache.put(comment.getId(), comment); userTransaction.commit(); logger.info("Comment with id: " + comment.getId() + " was updated in cache store."); } catch (Exception e) { if (userTransaction != null) { try { userTransaction.rollback(); } catch (Exception e1) { e1.printStackTrace(); } } logger.error("Error while updating comment.", e); throw new CacheException(e); } }
@Override public void createComment(Comment comment) throws IllegalEntityException, IllegalArgumentException, CacheException { if (comment == null) { throw new IllegalArgumentException("Comment is null."); } if (comment.getId() != null) { throw new IllegalEntityException( "Comment id is not null, Comment entity cannot be put into cache."); } commentCache = provider.getCacheContainer().getCache("commentcache"); comment.setId(UUIDStringGenerator.generateCommentId()); try { userTransaction.begin(); commentCache.put(comment.getId(), comment); userTransaction.commit(); logger.info( "Comment with id: " + comment.getId() + ", songID" + comment.getSongId() + " was inserted to cache store."); } catch (Exception e) { if (userTransaction != null) { try { userTransaction.rollback(); } catch (Exception e1) { e1.printStackTrace(); } } logger.error("Error while putting comment to the comment cache.", e); throw new CacheException(e); } }