DATAKV-89 - KeyValueTemplate now throws DuplicateKeyException.

We now throw DuplicateKeyException instead of InvalidDataAccessApiUsageException in case an object with given id already exists.

Original pull request: spring-projects/spring-data-commons#106.
This commit is contained in:
Christoph Strobl
2014-11-27 14:29:50 +01:00
committed by Oliver Gierke
parent 42a13a7403
commit 5f62882a3e
3 changed files with 14 additions and 4 deletions

View File

@@ -24,6 +24,7 @@ import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.data.domain.Sort;
@@ -117,7 +118,8 @@ public class KeyValueTemplate implements KeyValueOperations {
String typeKey = resolveKeySpace(objectToInsert.getClass());
if (adapter.contains(id, typeKey)) {
throw new InvalidDataAccessApiUsageException("Cannot insert existing object. Please use update.");
throw new DuplicateKeyException(String.format(
"Cannot insert existing object with id %s!. Please use update.", id));
}
adapter.put(id, objectToInsert, typeKey);