diff --git a/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java b/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java index 48445d2c6..1b3b936dd 100644 --- a/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java +++ b/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java @@ -74,4 +74,9 @@ public interface JpaRepository extends PagingAndSort * @param entities */ void deleteInBatch(Iterable entities); + + /** + * Deletes all entites in a batch call. + */ + void deleteAllInBatch(); } diff --git a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java index 823513b67..82a5a59a6 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java @@ -171,6 +171,18 @@ public class SimpleJpaRepository implements JpaRepos */ @Transactional public void deleteAll() { + + for (T element : findAll()) { + delete(element); + } + } + + /* + * (non-Javadoc) + * @see org.springframework.data.jpa.repository.JpaRepository#deleteAllInBatch() + */ + @Transactional + public void deleteAllInBatch() { em.createQuery(getDeleteAllQueryString()).executeUpdate(); } diff --git a/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java b/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java index a399d31d4..105cd2a13 100644 --- a/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java @@ -32,7 +32,6 @@ import javax.persistence.PersistenceContext; import javax.persistence.Query; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -296,6 +295,19 @@ public class UserRepositoryTests { assertThat(repository.count(), is(0L)); } + /** + * @see DATAJPA-137 + */ + @Test + public void deleteAllInBatch() { + + flushTestUsers(); + + repository.deleteAllInBatch(); + + assertThat(repository.count(), is(0L)); + } + /** * Tests cascading persistence. */ @@ -443,16 +455,6 @@ public class UserRepositoryTests { Arrays.asList(firstUser, secondUser))); } - @Test - @Ignore - public void executesMethodWithNamedParametersCorrectly() throws Exception { - - firstUser = repository.save(firstUser); - secondUser = repository.save(secondUser); - - assertThat(repository.findByLastnameOrFirstnameUnannotated("Oliver", "Arrasz"), hasItems(firstUser, secondUser)); - } - @Test public void executesMethodWithNamedParametersCorrectlyOnMethodsWithQueryCreation() throws Exception {