DATACASS-416 - Add overrides on TypedIdCassandraRepository for methods returning Lists.

TypedIdCassandraRepository redeclares save() and findAll(…) methods returning List. Propagating the more specialized return type allows easier use of the collection result.
This commit is contained in:
Mark Paluch
2017-03-14 17:10:39 +01:00
parent a458bc6e57
commit 1da1c89fc0
2 changed files with 32 additions and 11 deletions

View File

@@ -70,6 +70,27 @@ import org.springframework.data.repository.NoRepositoryBean;
@NoRepositoryBean
public interface TypedIdCassandraRepository<T, ID extends Serializable> extends CrudRepository<T, ID> {
/*
* (non-Javadoc)
* @see org.springframework.data.repository.CrudRepository#save(java.lang.Iterable)
*/
@Override
<S extends T> List<S> save(Iterable<S> entites);
/*
* (non-Javadoc)
* @see org.springframework.data.repository.CrudRepository#findAll()
*/
@Override
List<T> findAll();
/*
* (non-Javadoc)
* @see org.springframework.data.repository.CrudRepository#findAll(java.lang.Iterable)
*/
@Override
List<T> findAll(Iterable<ID> ids);
/**
* Inserts the given entity. Assumes the instance to be new to be able to apply insertion optimizations. Use the
* returned instance for further operations as the save operation might have changed the entity instance completely.
@@ -91,5 +112,4 @@ public interface TypedIdCassandraRepository<T, ID extends Serializable> extends
* @since 2.0
*/
<S extends T> List<S> insert(Iterable<S> entities);
}

View File

@@ -18,6 +18,7 @@ package org.springframework.data.cassandra.repository.support;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
@@ -136,18 +137,18 @@ public class SimpleCassandraRepositoryIntegrationTests extends AbstractKeyspaceC
assertThat(person).isNull();
}
@Test // DATACASS-396
@Test // DATACASS-396, DATACASS-416
public void findAllShouldReturnAllResults() {
Iterable<Person> persons = repository.findAll();
List<Person> persons = repository.findAll();
assertThat(persons).hasSize(4);
}
@Test // DATACASS-396
@Test // DATACASS-396, DATACASS-416
public void findAllByIterableOfIdShouldReturnResults() {
Iterable<Person> persons = repository.findAll(Arrays.asList(dave.getId(), boyd.getId()));
List<Person> persons = repository.findAll(Arrays.asList(dave.getId(), boyd.getId()));
assertThat(persons).hasSize(2);
}
@@ -212,19 +213,19 @@ public class SimpleCassandraRepositoryIntegrationTests extends AbstractKeyspaceC
assertThat(loaded).isEqualTo(person);
}
@Test // DATACASS-396
@Test // DATACASS-396, DATACASS-416
public void saveIterableOfNewEntitiesShouldInsertEntity() {
repository.deleteAll();
Iterable<Person> saved = repository.save(Arrays.asList(dave, oliver, boyd));
List<Person> saved = repository.save(Arrays.asList(dave, oliver, boyd));
assertThat(saved).hasSize(3);
assertThat(repository.count()).isEqualTo(3);
}
@Test // DATACASS-396
@Test // DATACASS-396, DATACASS-416
public void saveIterableOfMixedEntitiesShouldInsertEntity() {
Person person = new Person("36", "Homer", "Simpson");
@@ -232,7 +233,7 @@ public class SimpleCassandraRepositoryIntegrationTests extends AbstractKeyspaceC
dave.setFirstname("Hello, Dave");
dave.setLastname("Bowman");
Iterable<Person> saved = repository.save(Arrays.asList(person, dave));
List<Person> saved = repository.save(Arrays.asList(person, dave));
assertThat(saved).hasSize(2);
@@ -243,12 +244,12 @@ public class SimpleCassandraRepositoryIntegrationTests extends AbstractKeyspaceC
assertThat(persistentHomer).isEqualTo(person);
}
@Test // DATACASS-396
@Test // DATACASS-396, DATACASS-416
public void deleteAllShouldRemoveEntities() {
repository.deleteAll();
Iterable<Person> result = repository.findAll();
List<Person> result = repository.findAll();
assertThat(result).isEmpty();
}