@Override
  public void deleteComment(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.remove(comment.getId());
      userTransaction.commit();
      logger.info("Comment was deleted from cache store.");
    } catch (Exception e) {
      if (userTransaction != null) {
        try {
          userTransaction.rollback();
        } catch (Exception e1) {
          e1.printStackTrace();
        }
      }
      logger.error("Error while deleting comment.", e);
      throw new CacheException(e);
    }
  }
Exemplo n.º 2
0
 public String removeCar(String numberPlate) {
   carCache = provider.getCacheContainer().getCache(CACHE_NAME);
   carCache.remove(encode(numberPlate));
   List<String> carNumbers = getNumberPlateList();
   carNumbers.remove(numberPlate);
   carCache.replace(CAR_NUMBERS_KEY, carNumbers);
   return null;
 }