SGF-609 - Adapt to changes in the Spring Data Commons API.

This commit is contained in:
John Blum
2017-03-31 12:33:21 -07:00
parent 4a46ee4c9c
commit 1a3909e948
9 changed files with 40 additions and 27 deletions

View File

@@ -17,7 +17,8 @@
package org.springframework.data.gemfire.domain;
import org.springframework.core.convert.converter.Converter;
import java.util.function.Function;
import org.springframework.data.domain.Page;
/**
@@ -56,7 +57,7 @@ public final class EmptyPage<T> extends EmptySlice<T> implements Page<T> {
*/
@Override
@SuppressWarnings("unchecked")
public <S> Page<S> map(Converter<? super T, ? extends S> converter) {
public <S> Page<S> map(Function<? super T, ? extends S> converter) {
return (Page<S>) EMPTY_PAGE;
}
}

View File

@@ -19,8 +19,8 @@ package org.springframework.data.gemfire.domain;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
@@ -104,7 +104,7 @@ public abstract class EmptySlice<T> extends AbstractSliceSupport<T> {
*/
@Override
@SuppressWarnings("unchecked")
public <S> Slice<S> map(Converter<? super T, ? extends S> converter) {
public <S> Slice<S> map(Function<? super T, ? extends S> converter) {
return (Slice<S>) EMPTY_SLICE;
}
}

View File

@@ -22,9 +22,9 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort;
import org.springframework.data.gemfire.domain.support.AbstractPageSupport;
@@ -163,7 +163,7 @@ public class ListablePage<T> extends AbstractPageSupport<T> {
* @inheritDoc
*/
@Override
public <S> Page<S> map(Converter<? super T, ? extends S> converter) {
return newListablePage(getContent().stream().map(converter::convert).collect(Collectors.toList()));
public <S> Page<S> map(Function<? super T, ? extends S> converter) {
return newListablePage(getContent().stream().map(converter::apply).collect(Collectors.toList()));
}
}

View File

@@ -19,7 +19,8 @@ package org.springframework.data.gemfire.domain.support;
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newUnsupportedOperationException;
import org.springframework.core.convert.converter.Converter;
import java.util.function.Function;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Slice;
import org.springframework.data.gemfire.util.RuntimeExceptionFactory;
@@ -58,7 +59,7 @@ public abstract class AbstractPageSupport<T> extends AbstractSliceSupport<T> imp
* @inheritDoc
*/
@Override
public <S> Page<S> map(Converter<? super T, ? extends S> converter) {
public <S> Page<S> map(Function<? super T, ? extends S> converter) {
throw newUnsupportedOperationException(RuntimeExceptionFactory.NOT_IMPLEMENTED);
}
}

View File

@@ -24,8 +24,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
@@ -153,7 +153,7 @@ public abstract class AbstractSliceSupport<T> implements Slice<T> {
* @inheritDoc
*/
@Override
public <S> Slice<S> map(Converter<? super T, ? extends S> converter) {
public <S> Slice<S> map(Function<? super T, ? extends S> converter) {
throw newUnsupportedOperationException(RuntimeExceptionFactory.NOT_IMPLEMENTED);
}

View File

@@ -57,6 +57,17 @@ public class GemfireRepositoryFactoryBean<T extends Repository<S, ID>, S, ID ext
private MappingContext<? extends GemfirePersistentEntity<?>, GemfirePersistentProperty> mappingContext;
/**
* Creates a new {@link GemfireRepositoryFactoryBean} for the given {@link Repository} {@link Class interface}.
*
* @param repositoryInterface {@link Class interface type} specifying the application data access operations
* contract; must not be {@literal null}.
* @see java.lang.Class
*/
public GemfireRepositoryFactoryBean(Class<? extends T> repositoryInterface) {
super(repositoryInterface);
}
/**
* Sets a reference to the Spring {@link ApplicationContext} in which this object runs.
*

View File

@@ -23,11 +23,11 @@ import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.geode.cache.lucene.LuceneResultStruct;
import org.apache.geode.cache.lucene.PageableLuceneQueryResults;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.domain.Page;
import org.springframework.data.gemfire.domain.support.AbstractPageSupport;
import org.springframework.data.gemfire.search.lucene.ProjectingLuceneAccessor;
@@ -327,7 +327,7 @@ public class LucenePage<T, K, V> extends AbstractPageSupport<T> {
* @inheritDoc
*/
@Override
public <S> Page<S> map(Converter<? super T, ? extends S> converter) {
return newListablePage(getContent().stream().map(converter::convert).collect(Collectors.toList()));
public <S> Page<S> map(Function<? super T, ? extends S> converter) {
return newListablePage(getContent().stream().map(converter::apply).collect(Collectors.toList()));
}
}

View File

@@ -182,10 +182,9 @@ public class CompoundCachePutCacheEvictIntegrationTests {
@Bean
GemfireRepositoryFactoryBean<PersonRepository, Person, Long> personRepository() {
GemfireRepositoryFactoryBean<PersonRepository, Person, Long> personRepository =
new GemfireRepositoryFactoryBean<PersonRepository, Person, Long>();
new GemfireRepositoryFactoryBean<>(PersonRepository.class);
personRepository.setGemfireMappingContext(new GemfireMappingContext());
personRepository.setRepositoryInterface(PersonRepository.class);
return personRepository;
}

View File

@@ -55,12 +55,11 @@ public class GemfireRepositoryFactoryBeanTest {
@Before
public void setup() {
repositoryFactoryBean = new GemfireRepositoryFactoryBean();
repositoryFactoryBean = new GemfireRepositoryFactoryBean<>(PersonRepository.class);
}
@Test
public void rejectsMappingContextNotSet() {
exception.expect(IllegalStateException.class);
exception.expectMessage("GemfireMappingContext");
@@ -70,19 +69,21 @@ public class GemfireRepositoryFactoryBeanTest {
@Test
@SuppressWarnings("unchecked")
public void initializesWithMappingContext() {
RegionAttributes<?, ?> mockRegionAttributes = mock(RegionAttributes.class);
RegionAttributes<?, ?> attributes = mock(RegionAttributes.class);
doReturn(Long.class).when(attributes).getKeyConstraint();
doReturn(Long.class).when(mockRegionAttributes).getKeyConstraint();
Region<?, ?> region = mock(Region.class);
doReturn("simple").when(region).getName();
doReturn(attributes).when(region).getAttributes();
Region<?, ?> mockRegion = mock(Region.class);
ApplicationContext applicationContext = mock(ApplicationContext.class);
doReturn(Collections.singletonMap("simple", region)).when(applicationContext).getBeansOfType(Region.class);
doReturn("simple").when(mockRegion).getName();
doReturn(mockRegionAttributes).when(mockRegion).getAttributes();
repositoryFactoryBean.setApplicationContext(applicationContext);
repositoryFactoryBean.setRepositoryInterface(PersonRepository.class);
ApplicationContext mockApplicationContext = mock(ApplicationContext.class);
doReturn(Collections.singletonMap("simple", mockRegion))
.when(mockApplicationContext).getBeansOfType(Region.class);
repositoryFactoryBean.setApplicationContext(mockApplicationContext);
repositoryFactoryBean.setGemfireMappingContext(new GemfireMappingContext());
repositoryFactoryBean.afterPropertiesSet();