DATAKV-176 - Adapt to API changes in repository interfaces.
We now follow a more consistent naming scheme for the methods in repository that are driven by the following guidelines: * Methods referring to an identifier now all end on …ById(…). * Methods taking or returning a collection are named …All(…) Please see DATACMNS-944 for details.
This commit is contained in:
committed by
Oliver Gierke
parent
3f21f10d78
commit
aa6e412602
@@ -111,7 +111,7 @@ public class KeyValueRepositoryFactory extends RepositoryFactorySupport {
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T, ID extends Serializable> EntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
|
||||
public <T, ID> EntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
|
||||
|
||||
PersistentEntity<T, ?> entity = (PersistentEntity<T, ?>) context.getPersistentEntity(domainClass).get();
|
||||
PersistentEntityInformation<T, ID> entityInformation = new PersistentEntityInformation<>(entity);
|
||||
|
||||
@@ -107,7 +107,7 @@ public class SimpleKeyValueRepository<T, ID extends Serializable> implements Key
|
||||
* @see org.springframework.data.repository.CrudRepository#save(java.lang.Iterable)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Iterable<S> save(Iterable<S> entities) {
|
||||
public <S extends T> Iterable<S> saveAll(Iterable<S> entities) {
|
||||
|
||||
for (S entity : entities) {
|
||||
save(entity);
|
||||
@@ -121,7 +121,7 @@ public class SimpleKeyValueRepository<T, ID extends Serializable> implements Key
|
||||
* @see org.springframework.data.repository.CrudRepository#findOne(java.io.Serializable)
|
||||
*/
|
||||
@Override
|
||||
public Optional<T> findOne(ID id) {
|
||||
public Optional<T> findById(ID id) {
|
||||
return operations.findById(id, entityInformation.getJavaType());
|
||||
}
|
||||
|
||||
@@ -130,8 +130,8 @@ public class SimpleKeyValueRepository<T, ID extends Serializable> implements Key
|
||||
* @see org.springframework.data.repository.CrudRepository#exists(java.io.Serializable)
|
||||
*/
|
||||
@Override
|
||||
public boolean exists(ID id) {
|
||||
return findOne(id) != null;
|
||||
public boolean existsById(ID id) {
|
||||
return findById(id) != null;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -148,13 +148,13 @@ public class SimpleKeyValueRepository<T, ID extends Serializable> implements Key
|
||||
* @see org.springframework.data.repository.CrudRepository#findAll(java.lang.Iterable)
|
||||
*/
|
||||
@Override
|
||||
public Iterable<T> findAll(Iterable<ID> ids) {
|
||||
public Iterable<T> findAllById(Iterable<ID> ids) {
|
||||
|
||||
List<T> result = new ArrayList<>();
|
||||
|
||||
for (ID id : ids) {
|
||||
|
||||
Optional<T> candidate = findOne(id);
|
||||
Optional<T> candidate = findById(id);
|
||||
|
||||
if (candidate.isPresent()) {
|
||||
result.add(candidate.get());
|
||||
@@ -178,7 +178,7 @@ public class SimpleKeyValueRepository<T, ID extends Serializable> implements Key
|
||||
* @see org.springframework.data.repository.CrudRepository#delete(java.io.Serializable)
|
||||
*/
|
||||
@Override
|
||||
public void delete(ID id) {
|
||||
public void deleteById(ID id) {
|
||||
operations.delete(id, entityInformation.getJavaType());
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ public class SimpleKeyValueRepository<T, ID extends Serializable> implements Key
|
||||
*/
|
||||
@Override
|
||||
public void delete(T entity) {
|
||||
delete(entityInformation.getId(entity)
|
||||
deleteById(entityInformation.getId(entity)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Cannot delete entity with 'null' id.")));
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ public class SimpleKeyValueRepository<T, ID extends Serializable> implements Key
|
||||
* @see org.springframework.data.repository.CrudRepository#delete(java.lang.Iterable)
|
||||
*/
|
||||
@Override
|
||||
public void delete(Iterable<? extends T> entities) {
|
||||
public void deleteAll(Iterable<? extends T> entities) {
|
||||
|
||||
for (T entity : entities) {
|
||||
delete(entity);
|
||||
|
||||
@@ -83,7 +83,7 @@ public class SimpleKeyValueRepositoryUnitTests {
|
||||
Foo one = new Foo("one");
|
||||
Foo two = new Foo("one");
|
||||
|
||||
repo.save(Arrays.asList(one, two));
|
||||
repo.saveAll(Arrays.asList(one, two));
|
||||
verify(opsMock, times(1)).insert(eq(one));
|
||||
verify(opsMock, times(1)).insert(eq(two));
|
||||
}
|
||||
@@ -102,7 +102,7 @@ public class SimpleKeyValueRepositoryUnitTests {
|
||||
@Test // DATACMNS-525
|
||||
public void deleteById() {
|
||||
|
||||
repo.delete("one");
|
||||
repo.deleteById("one");
|
||||
|
||||
verify(opsMock, times(1)).delete(eq("one"), eq(Foo.class));
|
||||
}
|
||||
@@ -119,7 +119,7 @@ public class SimpleKeyValueRepositoryUnitTests {
|
||||
public void findAllIds() {
|
||||
|
||||
when(opsMock.findById(any(Serializable.class), any(Class.class))).thenReturn(Optional.empty());
|
||||
repo.findAll(Arrays.asList("one", "two", "three"));
|
||||
repo.findAllById(Arrays.asList("one", "two", "three"));
|
||||
|
||||
verify(opsMock, times(3)).findById(anyString(), eq(Foo.class));
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
@Test // DATACMNS-525
|
||||
public void findBy() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
assertThat(repository.findByAge(19), hasItems(CERSEI, JAIME));
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
@Test // DATAKV-137
|
||||
public void findByFirstname() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
assertThat(repository.findByFirstname(CERSEI.getFirstname()), hasItems(CERSEI));
|
||||
assertThat(repository.findByFirstname(JAIME.getFirstname()), hasItems(JAIME));
|
||||
@@ -87,7 +87,7 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
@Test // DATACMNS-525, DATAKV-137
|
||||
public void combindedFindUsingAnd() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
assertThat(repository.findByFirstnameAndAge(JAIME.getFirstname(), 19), hasItem(JAIME));
|
||||
assertThat(repository.findByFirstnameAndAge(TYRION.getFirstname(), 17), hasItem(TYRION));
|
||||
@@ -96,7 +96,7 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
@Test // DATACMNS-525
|
||||
public void findPage() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
Page<Person> page = repository.findByAge(19, PageRequest.of(0, 1));
|
||||
assertThat(page.hasNext(), is(true));
|
||||
@@ -112,7 +112,7 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
@Test // DATACMNS-525
|
||||
public void findByConnectingOr() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
assertThat(repository.findByAgeOrFirstname(19, TYRION.getFirstname()), hasItems(CERSEI, JAIME, TYRION));
|
||||
}
|
||||
@@ -120,7 +120,7 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
@Test // DATACMNS-525, DATAKV-137
|
||||
public void singleEntityExecution() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
assertThat(repository.findByAgeAndFirstname(TYRION.getAge(), TYRION.getFirstname()), is(TYRION));
|
||||
assertThat(repository.findByAgeAndFirstname(CERSEI.getAge(), CERSEI.getFirstname()), is(CERSEI));
|
||||
@@ -129,7 +129,7 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
@Test // DATACMNS-525
|
||||
public void findAllShouldRespectSort() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
assertThat(
|
||||
repository.findAll(Sort.by(new Sort.Order(Direction.ASC, "age"), new Sort.Order(Direction.DESC, "firstname"))),
|
||||
@@ -139,7 +139,7 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
@Test // DATACMNS-525
|
||||
public void derivedFinderShouldRespectSort() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
List<Person> result = repository.findByAgeGreaterThanOrderByAgeAscFirstnameDesc(2);
|
||||
|
||||
@@ -149,7 +149,7 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
@Test // DATAKV-121
|
||||
public void projectsResultToInterface() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
List<PersonSummary> result = repository.findByAgeGreaterThan(0, Sort.by("firstname"));
|
||||
|
||||
@@ -160,7 +160,7 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
@Test // DATAKV-121
|
||||
public void projectsResultToDynamicInterface() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
List<PersonSummary> result = repository.findByAgeGreaterThan(0, Sort.by("firstname"), PersonSummary.class);
|
||||
|
||||
@@ -171,7 +171,7 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
@Test // DATAKV-169
|
||||
public void findsByValueInCollectionCorrectly() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
List<Person> result = repository.findByFirstnameIn(Arrays.asList(CERSEI.getFirstname(), JAIME.getFirstname()));
|
||||
|
||||
@@ -182,7 +182,7 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
@Test // DATAKV-169
|
||||
public void findsByValueInCollectionCorrectlyWhenTargetPathContainsNullValue() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
repository.save(new Person(null, 10));
|
||||
|
||||
List<Person> result = repository.findByFirstnameIn(Arrays.asList(CERSEI.getFirstname(), JAIME.getFirstname()));
|
||||
@@ -194,7 +194,7 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
@Test // DATAKV-169
|
||||
public void findsByValueInCollectionCorrectlyWhenTargetPathAndCollectionContainNullValue() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
Person personWithNullAsFirstname = new Person(null, 10);
|
||||
repository.save(personWithNullAsFirstname);
|
||||
|
||||
@@ -47,7 +47,7 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT
|
||||
@Test // DATACMNS-525
|
||||
public void findOneIsExecutedCorrectly() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
Person result = repository.findOne(QPerson.person.firstname.eq(CERSEI.getFirstname()));
|
||||
assertThat(result, is(CERSEI));
|
||||
@@ -56,7 +56,7 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT
|
||||
@Test // DATACMNS-525
|
||||
public void findAllIsExecutedCorrectly() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
Iterable<Person> result = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()));
|
||||
assertThat(result, containsInAnyOrder(CERSEI, JAIME));
|
||||
@@ -65,7 +65,7 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT
|
||||
@Test // DATACMNS-525
|
||||
public void findWithPaginationWorksCorrectly() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
Page<Person> page1 = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()), PageRequest.of(0, 1));
|
||||
|
||||
assertThat(page1.getTotalElements(), is(2L));
|
||||
@@ -83,7 +83,7 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT
|
||||
@Test // DATACMNS-525
|
||||
public void findAllUsingOrderSpecifierWorksCorrectly() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
Iterable<Person> result = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()),
|
||||
QPerson.person.firstname.desc());
|
||||
@@ -94,7 +94,7 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT
|
||||
@Test // DATACMNS-525
|
||||
public void findAllUsingPageableWithSortWorksCorrectly() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
Iterable<Person> result = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()),
|
||||
PageRequest.of(0, 10, Direction.DESC, "firstname"));
|
||||
@@ -105,7 +105,7 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT
|
||||
@Test // DATACMNS-525
|
||||
public void findAllUsingPagableWithQSortWorksCorrectly() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
Iterable<Person> result = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()),
|
||||
PageRequest.of(0, 10, new QSort(QPerson.person.firstname.desc())));
|
||||
@@ -116,7 +116,7 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT
|
||||
@Test // DATAKV-90
|
||||
public void findAllWithOrderSpecifierWorksCorrectly() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
Iterable<Person> result = repository.findAll(new QSort(QPerson.person.firstname.desc()));
|
||||
|
||||
@@ -126,7 +126,7 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT
|
||||
@Test // DATAKV-90
|
||||
public void findAllShouldIgnoreNullOrderSpecifier() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
Iterable<Person> result = repository.findAll((QSort) null);
|
||||
|
||||
@@ -136,7 +136,7 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT
|
||||
@Test // DATAKV-95
|
||||
public void executesExistsCorrectly() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
assertThat(repository.exists(QPerson.person.age.eq(CERSEI.getAge())), is(true));
|
||||
}
|
||||
@@ -144,7 +144,7 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT
|
||||
@Test // DATAKV-96
|
||||
public void shouldSupportFindAllWithPredicateAndSort() {
|
||||
|
||||
repository.save(LENNISTERS);
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
List<Person> users = Lists.newArrayList(repository.findAll(person.age.gt(0), Sort.by(Direction.ASC, "firstname")));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user