コード例 #1
0
 @Override
 public Category update(Long id, String name) {
   Category category = get(id);
   if (repository.findByName(name) != null) {
     throw new EntityAlreadyExistsException(
         String.format("There already exists a category with name=%s!", name));
   }
   category.setName(name);
   repository.save(category);
   return category;
 }
コード例 #2
0
 @Override
 public Category create(Category category) {
   if (category.getId() != null && repository.findOne(category.getId()) != null) {
     throw new EntityAlreadyExistsException(
         String.format("There already exists a category with id=%d!", category.getId()));
   } else if (repository.findByName(category.getName()) != null) {
     throw new EntityAlreadyExistsException(
         String.format("There already exists a category with name=%s!", category.getName()));
   } else {
     repository.save(category);
   }
   return category;
 }