diff --git a/src/main/java/org/springframework/data/gemfire/repository/GemfireRepository.java b/src/main/java/org/springframework/data/gemfire/repository/GemfireRepository.java index 65446e44..db6b3257 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/GemfireRepository.java +++ b/src/main/java/org/springframework/data/gemfire/repository/GemfireRepository.java @@ -15,8 +15,6 @@ */ package org.springframework.data.gemfire.repository; -import java.io.Serializable; - import org.springframework.data.domain.Sort; import org.springframework.data.repository.CrudRepository; @@ -28,8 +26,7 @@ import org.springframework.data.repository.CrudRepository; * @see java.io.Serializable * @see org.springframework.data.repository.CrudRepository */ -@SuppressWarnings("unused") -public interface GemfireRepository extends CrudRepository { +public interface GemfireRepository extends CrudRepository { /** * Returns all entities sorted by the given options. diff --git a/src/main/java/org/springframework/data/gemfire/repository/Wrapper.java b/src/main/java/org/springframework/data/gemfire/repository/Wrapper.java index 31cb06d5..699ab6da 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/Wrapper.java +++ b/src/main/java/org/springframework/data/gemfire/repository/Wrapper.java @@ -15,88 +15,17 @@ */ package org.springframework.data.gemfire.repository; -import java.io.Serializable; - -import org.springframework.util.Assert; -import org.springframework.util.ObjectUtils; +import lombok.NonNull; +import lombok.Value; /** * Simple value object to hold an entity alongside an external key the entity shall be stored under. * * @author Oliver Gierke */ -public final class Wrapper { - - private final KEY key; - private final T entity; - - /** - * The entity to handle as well as the key. - * - * @param entity the application domain object/entity to wrap. - * @param key must not be {@literal null}. - */ - public Wrapper(T entity, KEY key) { - Assert.notNull(key); - - this.entity = entity; - this.key = key; - } - - /** - * @return the key - */ - public KEY getKey() { - return key; - } - - /** - * @return the entity - */ - public T getEntity() { - return entity; - } - - /* - * (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object value) { - if (value == this) { - return true; - } - - if (!(value instanceof Wrapper)) { - return false; - } - - Wrapper that = (Wrapper) value; - - return (this.key.equals(that.key) && ObjectUtils.nullSafeEquals(this.entity, that.entity)); - } - - /* - * (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - int result = 17; - - result += 31 * key.hashCode(); - result += 31 * ObjectUtils.nullSafeHashCode(entity); - - return result; - } - - /* - * (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return ObjectUtils.nullSafeToString(getEntity()); - } +@Value +public class Wrapper { + T entity; + @NonNull KEY key; } diff --git a/src/main/java/org/springframework/data/gemfire/repository/query/DefaultGemfireEntityInformation.java b/src/main/java/org/springframework/data/gemfire/repository/query/DefaultGemfireEntityInformation.java index d95b5975..e40c18ab 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/query/DefaultGemfireEntityInformation.java +++ b/src/main/java/org/springframework/data/gemfire/repository/query/DefaultGemfireEntityInformation.java @@ -16,8 +16,6 @@ package org.springframework.data.gemfire.repository.query; -import java.io.Serializable; - import org.springframework.data.gemfire.mapping.GemfirePersistentEntity; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.repository.core.support.PersistentEntityInformation; @@ -32,7 +30,7 @@ import org.springframework.data.repository.core.support.PersistentEntityInformat * @see org.springframework.data.gemfire.repository.query.GemfireEntityInformation * @see org.springframework.data.repository.core.support.PersistentEntityInformation */ -public class DefaultGemfireEntityInformation extends PersistentEntityInformation +public class DefaultGemfireEntityInformation extends PersistentEntityInformation implements GemfireEntityInformation { private final GemfirePersistentEntity entity; diff --git a/src/main/java/org/springframework/data/gemfire/repository/query/GemfireEntityInformation.java b/src/main/java/org/springframework/data/gemfire/repository/query/GemfireEntityInformation.java index 0fdc90e3..ecf8c4f6 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/query/GemfireEntityInformation.java +++ b/src/main/java/org/springframework/data/gemfire/repository/query/GemfireEntityInformation.java @@ -15,8 +15,6 @@ */ package org.springframework.data.gemfire.repository.query; -import java.io.Serializable; - import org.apache.geode.cache.Region; import org.springframework.data.repository.core.EntityInformation; @@ -25,7 +23,7 @@ import org.springframework.data.repository.core.EntityInformation; * * @author Oliver Gierke */ -public interface GemfireEntityInformation extends EntityInformation { +public interface GemfireEntityInformation extends EntityInformation { /** * Returns the name of the {@link Region} the entity is held in. diff --git a/src/main/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactory.java b/src/main/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactory.java index 3b3610e8..ea101144 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactory.java +++ b/src/main/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactory.java @@ -16,7 +16,7 @@ package org.springframework.data.gemfire.repository.support; -import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalArgumentException; +import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.*; import java.io.Serializable; import java.lang.reflect.Method; @@ -81,7 +81,8 @@ public class GemfireRepositoryFactory extends RepositoryFactorySupport { */ @Override @SuppressWarnings("unchecked") - public GemfireEntityInformation getEntityInformation(Class domainClass) { + public GemfireEntityInformation getEntityInformation(Class domainClass) { + GemfirePersistentEntity entity = (GemfirePersistentEntity) mappingContext.getPersistentEntity(domainClass) .orElseThrow(() -> newIllegalArgumentException("Unable to resolve PersistentEntity for type [%s]", domainClass)); diff --git a/src/main/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepository.java b/src/main/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepository.java index f25464b0..7db55359 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepository.java +++ b/src/main/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepository.java @@ -16,10 +16,7 @@ package org.springframework.data.gemfire.repository.support; -import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalArgumentException; - import java.io.Serializable; -import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -41,6 +38,8 @@ import org.springframework.data.gemfire.repository.Wrapper; import org.springframework.data.gemfire.repository.query.QueryString; import org.springframework.data.gemfire.util.CollectionUtils; import org.springframework.data.repository.core.EntityInformation; +import org.springframework.data.util.StreamUtils; +import org.springframework.data.util.Streamable; import org.springframework.util.Assert; /** @@ -81,8 +80,8 @@ public class SimpleGemfireRepository implements Gemf */ @Override public U save(U entity) { - ID id = entityInformation.getId(entity).orElseThrow( - () -> newIllegalArgumentException("ID for entity [%s] is required", entity)); + + ID id = entityInformation.getRequiredId(entity); template.put(id, entity); @@ -94,16 +93,14 @@ public class SimpleGemfireRepository implements Gemf * @see org.springframework.data.repository.CrudRepository#save(java.lang.Iterable) */ @Override - public Iterable save(Iterable entities) { + public Iterable saveAll(Iterable entities) { + Map entitiesToSave = new HashMap<>(); - for (U entity : entities) { - ID id = entityInformation.getId(entity).orElseThrow( - () -> newIllegalArgumentException("ID for entity [%s] is required", entity)); - - entitiesToSave.put(id, entity); - } - + entities.forEach(entity -> { + entitiesToSave.put(entityInformation.getRequiredId(entity), entity); + }); + template.putAll(entitiesToSave); return entitiesToSave.values(); @@ -134,20 +131,19 @@ public class SimpleGemfireRepository implements Gemf /* * (non-Javadoc) - * @see org.springframework.data.repository.CrudRepository#exists(java.io.Serializable) + * @see org.springframework.data.repository.CrudRepository#existsById(java.lang.Object) */ @Override - public boolean exists(ID id) { - return findOne(id).isPresent(); + public boolean existsById(ID id) { + return findById(id).isPresent(); } /* * (non-Javadoc) - * @see org.springframework.data.repository.CrudRepository#findOne(java.io.Serializable) + * @see org.springframework.data.repository.CrudRepository#findById(java.lang.Object) */ @Override - @SuppressWarnings("unchecked") - public Optional findOne(ID id) { + public Optional findById(ID id) { return Optional.ofNullable(template.get(id)); } @@ -180,16 +176,12 @@ public class SimpleGemfireRepository implements Gemf /* * (non-Javadoc) - * @see org.springframework.data.repository.CrudRepository#findAll(java.lang.Iterable) + * @see org.springframework.data.repository.CrudRepository#findAllById(java.lang.Iterable) */ @Override - @SuppressWarnings("unchecked") - public Collection findAll(Iterable ids) { - List parameters = new ArrayList<>(); - - for (ID id : ids) { - parameters.add(id); - } + public Collection findAllById(Iterable ids) { + + List parameters = Streamable.of(ids).stream().collect(StreamUtils.toUnmodifiableList()); return CollectionUtils.nullSafeMap(template.getAll(parameters)).values().stream() .filter(Objects::nonNull).collect(Collectors.toList()); @@ -197,10 +189,10 @@ public class SimpleGemfireRepository implements Gemf /* * (non-Javadoc) - * @see org.springframework.data.repository.CrudRepository#delete(java.io.Serializable) + * @see org.springframework.data.repository.CrudRepository#deleteById(java.lang.Object) */ @Override - public void delete(ID id) { + public void deleteById(ID id) { template.remove(id); } @@ -210,7 +202,7 @@ public class SimpleGemfireRepository implements Gemf */ @Override public void delete(T entity) { - delete(entityInformation.getId(entity).orElseThrow(() -> new IllegalArgumentException("ID is required"))); + deleteById(entityInformation.getRequiredId(entity)); } /* @@ -218,10 +210,8 @@ public class SimpleGemfireRepository implements Gemf * @see org.springframework.data.repository.CrudRepository#delete(java.lang.Iterable) */ @Override - public void delete(Iterable entities) { - for (T entity : entities) { - delete(entity); - } + public void deleteAll(Iterable entities) { + entities.forEach(this::delete); } /* @@ -229,7 +219,7 @@ public class SimpleGemfireRepository implements Gemf * @see org.apache.geode.cache.Region#getAttributes() * @see org.apache.geode.cache.RegionAttributes#getDataPolicy() */ - boolean isPartitioned(Region region) { + boolean isPartitioned(Region region) { return (region != null && region.getAttributes() != null && isPartitioned(region.getAttributes().getDataPolicy())); } @@ -247,7 +237,7 @@ public class SimpleGemfireRepository implements Gemf * @see org.apache.geode.cache.Region#getRegionService() * @see org.apache.geode.cache.Cache#getCacheTransactionManager() */ - boolean isTransactionPresent(Region region) { + boolean isTransactionPresent(Region region) { return (region.getRegionService() instanceof Cache && isTransactionPresent(((Cache) region.getRegionService()).getCacheTransactionManager())); } @@ -261,8 +251,7 @@ public class SimpleGemfireRepository implements Gemf } /* (non-Javadoc) */ - @SuppressWarnings("unchecked") - void doRegionClear(Region region) { + void doRegionClear(Region region) { region.removeAll(region.keySet()); } diff --git a/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceIntegrationTests.java index 457ee8eb..177b853d 100644 --- a/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceIntegrationTests.java @@ -12,7 +12,7 @@ */ package org.springframework.data.gemfire.client; -import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.*; import java.util.Arrays; import java.util.List; @@ -82,7 +82,6 @@ public class GemFireDataSourceIntegrationTests extends ClientServerIntegrationTe } @Test - @SuppressWarnings("unused") public void gemfireServerDataSourceCreated() { Pool pool = applicationContext.getBean("gemfirePool", Pool.class); @@ -108,7 +107,7 @@ public class GemFireDataSourceIntegrationTests extends ClientServerIntegrationTe assertThat(repository.save(daveMathews)).isSameAs(daveMathews); - Optional result = repository.findOne(1L); + Optional result = repository.findById(1L); assertThat(result.isPresent()).isTrue(); assertThat(result.get().getFirstname()).isEqualTo("Dave"); diff --git a/src/test/java/org/springframework/data/gemfire/repository/cdi/RepositoryClient.java b/src/test/java/org/springframework/data/gemfire/repository/cdi/RepositoryClient.java index 9a06724d..e5bfe439 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/cdi/RepositoryClient.java +++ b/src/test/java/org/springframework/data/gemfire/repository/cdi/RepositoryClient.java @@ -49,7 +49,7 @@ public class RepositoryClient { } public Person find(Long id) { - return getPersonRepository().findOne(id).orElse(null); + return getPersonRepository().findById(id).orElse(null); } public Person save(Person person) { diff --git a/src/test/java/org/springframework/data/gemfire/repository/sample/AnimalRepositoryTest.java b/src/test/java/org/springframework/data/gemfire/repository/sample/AnimalRepositoryTest.java index 92862a62..94be6513 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/sample/AnimalRepositoryTest.java +++ b/src/test/java/org/springframework/data/gemfire/repository/sample/AnimalRepositoryTest.java @@ -16,7 +16,7 @@ package org.springframework.data.gemfire.repository.sample; -import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.*; import java.util.Optional; @@ -72,7 +72,7 @@ public class AnimalRepositoryTest { assertThat(catRepo.count()).isEqualTo(3L); assertThat(dogRepo.count()).isEqualTo(2L); - Optional foundFelix = catRepo.findOne(1L); + Optional foundFelix = catRepo.findById(1L); assertThat(foundFelix.isPresent()).isTrue(); assertThat(foundFelix.get()).isEqualTo(felix); @@ -85,7 +85,7 @@ public class AnimalRepositoryTest { assertThat(foundCerberusTheCat).isEqualTo(cerberus); assertThat(catRepo.findBy("Cerberus")).isEqualTo(foundCerberusTheCat); - assertThat(catRepo.findOne(3L).orElse(null)).isEqualTo(foundCerberusTheCat); + assertThat(catRepo.findById(3L).orElse(null)).isEqualTo(foundCerberusTheCat); Animal foundFido = dogRepo.findBy("Fido"); @@ -95,6 +95,6 @@ public class AnimalRepositoryTest { assertThat(foundCerberusTheDog).isEqualTo(cerberus); assertThat(dogRepo.findBy("Cerberus")).isEqualTo(foundCerberusTheDog); - assertThat(dogRepo.findOne(3L).orElse(null)).isEqualTo(foundCerberusTheDog); + assertThat(dogRepo.findById(3L).orElse(null)).isEqualTo(foundCerberusTheDog); } } diff --git a/src/test/java/org/springframework/data/gemfire/repository/sample/SubRegionRepositoryIntegrationTest.java b/src/test/java/org/springframework/data/gemfire/repository/sample/SubRegionRepositoryIntegrationTest.java index 8ae69dbd..ad057e82 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/sample/SubRegionRepositoryIntegrationTest.java +++ b/src/test/java/org/springframework/data/gemfire/repository/sample/SubRegionRepositoryIntegrationTest.java @@ -17,10 +17,7 @@ package org.springframework.data.gemfire.repository.sample; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.util.ArrayList; import java.util.Collections; @@ -207,7 +204,7 @@ public class SubRegionRepositoryIntegrationTest { @Test public void testSubregionRepositoryInteractions() { - assertThat(programmersRepo.findOne("JamesGosling").orElse(null)).isEqualTo(PROGRAMMER_USER_DATA.get("JamesGosling")); + assertThat(programmersRepo.findById("JamesGosling").orElse(null)).isEqualTo(PROGRAMMER_USER_DATA.get("JamesGosling")); List javaProgrammers = programmersRepo.findDistinctByProgrammingLanguageOrderByUsernameAsc("Java"); @@ -256,8 +253,8 @@ public class SubRegionRepositoryIntegrationTest { @Test public void testIdenticallyNamedSubregionDataAccess() { - assertThat(adminUserRepo.findOne("supertool").orElse(null)).isEqualTo(getAdminUser("supertool")); - assertThat(guestUserRepo.findOne("joeblow").orElse(null)).isEqualTo(getGuestUser("joeblow")); + assertThat(adminUserRepo.findById("supertool").orElse(null)).isEqualTo(getAdminUser("supertool")); + assertThat(guestUserRepo.findById("joeblow").orElse(null)).isEqualTo(getGuestUser("joeblow")); List rootUsers = adminUserRepo.findDistinctByUsername("zeus"); diff --git a/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryIntegrationTests.java index d3e510d2..516b5ca2 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryIntegrationTests.java @@ -16,7 +16,7 @@ package org.springframework.data.gemfire.repository.support; -import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.*; import java.util.Arrays; import java.util.Collection; @@ -97,7 +97,7 @@ public class SimpleGemfireRepositoryIntegrationTests { template.put(carter.getId(), carter); template.put(leroi.getId(), leroi); - Collection result = repository.findAll(Arrays.asList(carter.getId(), leroi.getId())); + Collection result = repository.findAllById(Arrays.asList(carter.getId(), leroi.getId())); assertThat(result).isNotNull(); assertThat(result.size()).isEqualTo(2); @@ -106,7 +106,7 @@ public class SimpleGemfireRepositoryIntegrationTests { @Test public void findAllWithIdsReturnsNoMatches() { - Collection results = repository.findAll(Arrays.asList(1L, 2L)); + Collection results = repository.findAllById(Arrays.asList(1L, 2L)); assertThat(results).isNotNull(); assertThat(results).isEmpty(); @@ -121,7 +121,7 @@ public class SimpleGemfireRepositoryIntegrationTests { template.put(kurt.getId(), kurt); template.put(eddie.getId(), eddie); - Collection results = repository.findAll(Arrays.asList(0L, 1L, 2L, 4L)); + Collection results = repository.findAllById(Arrays.asList(0L, 1L, 2L, 4L)); assertThat(results).isNotNull(); assertThat(results).hasSize(2); @@ -148,13 +148,13 @@ public class SimpleGemfireRepositoryIntegrationTests { assertThat(repository.save(oliverGierke)).isEqualTo(oliverGierke); assertThat(repository.count()).isEqualTo(1L); - assertThat(repository.findOne(oliverGierke.getId()).orElse(null)).isEqualTo(oliverGierke); + assertThat(repository.findById(oliverGierke.getId()).orElse(null)).isEqualTo(oliverGierke); assertThat(repository.findAll()).isEqualTo(Collections.singletonList(oliverGierke)); repository.delete(oliverGierke); assertThat(repository.count()).isEqualTo(0L); - assertThat(repository.findOne(oliverGierke.getId()).orElse(null)).isNull(); + assertThat(repository.findById(oliverGierke.getId()).orElse(null)).isNull(); assertThat(repository.findAll()).isEmpty(); } @@ -166,7 +166,7 @@ public class SimpleGemfireRepositoryIntegrationTests { Person jonBloom = new Person(2L, "Jon", "Bloom"); Person juanBlume = new Person(3L, "Juan", "Blume"); - repository.save(Arrays.asList(johnBlum, jonBloom, juanBlume)); + repository.saveAll(Arrays.asList(johnBlum, jonBloom, juanBlume)); assertThat(template.getRegion().size()).isEqualTo(3); assertThat(template.get(johnBlum.getId())).isEqualTo(johnBlum); diff --git a/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryTransactionalIntegrationTest.java b/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryTransactionalIntegrationTest.java index 74693df2..06ddf31d 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryTransactionalIntegrationTest.java +++ b/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryTransactionalIntegrationTest.java @@ -16,10 +16,7 @@ package org.springframework.data.gemfire.repository.support; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.io.Serializable; import java.util.ArrayList; @@ -152,7 +149,7 @@ public class SimpleGemfireRepositoryTransactionalIntegrationTest { public void saveAll(final Iterable customers) { transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(final TransactionStatus status) { - customerRepository.save(customers); + customerRepository.saveAll(customers); } }); } diff --git a/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryUnitTests.java b/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryUnitTests.java index 68fa34c0..f949daef 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryUnitTests.java +++ b/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryUnitTests.java @@ -16,19 +16,11 @@ package org.springframework.data.gemfire.repository.support; -import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.assertj.core.api.Assertions.*; +import static org.hamcrest.Matchers.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; import java.util.ArrayList; import java.util.Arrays; @@ -38,7 +30,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import java.util.concurrent.atomic.AtomicLong; import java.util.function.Function; @@ -120,21 +111,21 @@ public class SimpleGemfireRepositoryUnitTests { protected EntityInformation mockEntityInformation() { EntityInformation mockEntityInformation = mock(EntityInformation.class); - doAnswer(new Answer>() { + doAnswer(new Answer() { private final AtomicLong idSequence = new AtomicLong(0L); @Override - public Optional answer(InvocationOnMock invocation) throws Throwable { + public Long answer(InvocationOnMock invocation) throws Throwable { Animal argument = invocation.getArgument(0); argument.setId(resolveId(argument.getId())); - return Optional.of(argument.getId()); + return argument.getId(); } private Long resolveId(Long id) { return (id != null ? id : idSequence.incrementAndGet()); } - }).when(mockEntityInformation).getId(any(Animal.class)); + }).when(mockEntityInformation).getRequiredId(any(Animal.class)); return mockEntityInformation; } @@ -213,7 +204,7 @@ public class SimpleGemfireRepositoryUnitTests { SimpleGemfireRepository repository = new SimpleGemfireRepository<>(newGemfireTemplate(mockRegion), mockEntityInformation()); - Iterable savedAnimals = repository.save(animals); + Iterable savedAnimals = repository.saveAll(animals); assertThat(savedAnimals).isNotNull(); @@ -267,8 +258,8 @@ public class SimpleGemfireRepositoryUnitTests { SimpleGemfireRepository repository = new SimpleGemfireRepository<>(newGemfireTemplate(mockRegion), mockEntityInformation()); - assertThat(repository.exists(1L)).isTrue(); - assertThat(repository.exists(10L)).isFalse(); + assertThat(repository.existsById(1L)).isTrue(); + assertThat(repository.existsById(10L)).isFalse(); } @Test @@ -283,8 +274,8 @@ public class SimpleGemfireRepositoryUnitTests { SimpleGemfireRepository repository = new SimpleGemfireRepository<>(newGemfireTemplate(mockRegion), mockEntityInformation()); - assertThat(repository.findOne(1L).orElse(null)).isEqualTo(dog); - assertThat(repository.findOne(10L).isPresent()).isFalse(); + assertThat(repository.findById(1L).orElse(null)).isEqualTo(dog); + assertThat(repository.findById(10L).isPresent()).isFalse(); } @Test @@ -305,7 +296,7 @@ public class SimpleGemfireRepositoryUnitTests { SimpleGemfireRepository repository = new SimpleGemfireRepository<>( newGemfireTemplate(mockRegion), mockEntityInformation()); - Collection animalsFound = repository.findAll(Arrays.asList(1L, 3L)); + Collection animalsFound = repository.findAllById(Arrays.asList(1L, 3L)); assertThat(animalsFound).isNotNull(); assertThat(animalsFound).hasSize(2); @@ -332,7 +323,7 @@ public class SimpleGemfireRepositoryUnitTests { SimpleGemfireRepository repository = new SimpleGemfireRepository<>(newGemfireTemplate(mockRegion), mockEntityInformation()); - Collection animalsFound = repository.findAll(Arrays.asList(1L, 2L, 3L)); + Collection animalsFound = repository.findAllById(Arrays.asList(1L, 2L, 3L)); assertThat(animalsFound).isNotNull(); assertThat(animalsFound).isEmpty(); @@ -362,7 +353,7 @@ public class SimpleGemfireRepositoryUnitTests { SimpleGemfireRepository repository = new SimpleGemfireRepository<>(newGemfireTemplate(mockRegion), mockEntityInformation()); - Collection animalsFound = repository.findAll(Arrays.asList(0L, 1L, 2L, 4L)); + Collection animalsFound = repository.findAllById(Arrays.asList(0L, 1L, 2L, 4L)); assertThat(animalsFound).isNotNull(); assertThat(animalsFound).hasSize(2); @@ -378,7 +369,7 @@ public class SimpleGemfireRepositoryUnitTests { SimpleGemfireRepository repository = new SimpleGemfireRepository<>(newGemfireTemplate(mockRegion), mockEntityInformation()); - repository.delete(1L); + repository.deleteById(1L); verify(mockRegion, times(1)).remove(eq(1L)); } @@ -402,7 +393,7 @@ public class SimpleGemfireRepositoryUnitTests { SimpleGemfireRepository repository = new SimpleGemfireRepository<>(newGemfireTemplate(mockRegion), mockEntityInformation()); - repository.delete(Arrays.asList(newAnimal(1L, "bird"), newAnimal(2L, "cat"), + repository.deleteAll(Arrays.asList(newAnimal(1L, "bird"), newAnimal(2L, "cat"), newAnimal(3L, "dog"))); verify(mockRegion, times(1)).remove(eq(1L));