From d8396689a0f8f5d9f1959bfc794c2d2006b0847a Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 12 Mar 2018 16:58:53 +0100 Subject: [PATCH] DATAGEODE-89 - Export composable repositories via CDI. We now export composable repositories through our CDI extension. Repositories can now be customized either by a single custom implementation (as it was before) and by providing fragment interfaces along their fragment implementation. This change aligns CDI support with the existing RepositoryFactory support we provide within a Spring application context. --- .../repository/cdi/GemfireRepositoryBean.java | 12 +++--------- ...toryImpl.java => CustomPersonRepositoryImpl.java} | 3 ++- .../repository/cdi/GemfireRepositoryBeanTest.java | 2 +- .../repository/cdi/SamplePersonRepository.java | 2 +- 4 files changed, 7 insertions(+), 12 deletions(-) rename src/test/java/org/springframework/data/gemfire/repository/cdi/{SamplePersonRepositoryImpl.java => CustomPersonRepositoryImpl.java} (92%) diff --git a/src/main/java/org/springframework/data/gemfire/repository/cdi/GemfireRepositoryBean.java b/src/main/java/org/springframework/data/gemfire/repository/cdi/GemfireRepositoryBean.java index a70169a6..5a983805 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/cdi/GemfireRepositoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/repository/cdi/GemfireRepositoryBean.java @@ -38,6 +38,7 @@ import org.springframework.data.repository.config.CustomRepositoryImplementation * A CDI-based bean that represents a GemFire Repository. * * @author John Blum + * @author Mark Paluch * @param class type of the Repository. * @see javax.enterprise.context.spi.CreationalContext * @see javax.enterprise.inject.spi.Bean @@ -143,18 +144,11 @@ class GemfireRepositoryBean extends CdiRepositoryBean { * @param creationalContext operations used by the {@link javax.enterprise.context.spi.Contextual} implementation * during creation of the bean instance. * @param repositoryType the actual class type of the SD (GemFire) Repository. - * @param customImplementation the supporting custom Repository implementing class. - * @return a factory used to create instance of {@link org.springframework.data.gemfire.repository.GemfireRepository}. * @see javax.enterprise.context.spi.Contextual#create(javax.enterprise.context.spi.CreationalContext) * @see #newGemfireRepositoryFactory() */ @Override - @SuppressWarnings("all") - protected T create(CreationalContext creationalContext, Class repositoryType, - Optional customImplementation) { - - return (customImplementation.isPresent() - ? newGemfireRepositoryFactory().getRepository(repositoryType, customImplementation.get()) - : newGemfireRepositoryFactory().getRepository(repositoryType)); + protected T create(CreationalContext creationalContext, Class repositoryType) { + return create(this::newGemfireRepositoryFactory, repositoryType); } } diff --git a/src/test/java/org/springframework/data/gemfire/repository/cdi/SamplePersonRepositoryImpl.java b/src/test/java/org/springframework/data/gemfire/repository/cdi/CustomPersonRepositoryImpl.java similarity index 92% rename from src/test/java/org/springframework/data/gemfire/repository/cdi/SamplePersonRepositoryImpl.java rename to src/test/java/org/springframework/data/gemfire/repository/cdi/CustomPersonRepositoryImpl.java index 11bda0b9..6fb59ef7 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/cdi/SamplePersonRepositoryImpl.java +++ b/src/test/java/org/springframework/data/gemfire/repository/cdi/CustomPersonRepositoryImpl.java @@ -22,10 +22,11 @@ package org.springframework.data.gemfire.repository.cdi; * supporting additional data access (CRUD) operations on people. * * @author John Blum + * @author Mark Paluch * @see org.springframework.data.gemfire.repository.cdi.CustomPersonRepository * @since 1.8.0 */ -public class SamplePersonRepositoryImpl implements CustomPersonRepository { +public class CustomPersonRepositoryImpl implements CustomPersonRepository { public int returnOne() { return 1; diff --git a/src/test/java/org/springframework/data/gemfire/repository/cdi/GemfireRepositoryBeanTest.java b/src/test/java/org/springframework/data/gemfire/repository/cdi/GemfireRepositoryBeanTest.java index 5424fa3e..fece4973 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/cdi/GemfireRepositoryBeanTest.java +++ b/src/test/java/org/springframework/data/gemfire/repository/cdi/GemfireRepositoryBeanTest.java @@ -335,7 +335,7 @@ public class GemfireRepositoryBeanTest { }; GemfireRepository gemfireRepository = - repositoryBean.create(null, PersonRepository.class, Optional.empty()); + repositoryBean.create(null, PersonRepository.class); assertThat(gemfireRepository, is(notNullValue())); assertThat(repositoryProxyPostProcessed.get(), is(true)); diff --git a/src/test/java/org/springframework/data/gemfire/repository/cdi/SamplePersonRepository.java b/src/test/java/org/springframework/data/gemfire/repository/cdi/SamplePersonRepository.java index 9b92b9c1..556718a9 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/cdi/SamplePersonRepository.java +++ b/src/test/java/org/springframework/data/gemfire/repository/cdi/SamplePersonRepository.java @@ -28,7 +28,7 @@ import org.springframework.data.gemfire.repository.sample.Person; * @author John Blum * @see org.springframework.data.gemfire.repository.GemfireRepository * @see org.springframework.data.gemfire.repository.cdi.CustomPersonRepository - * @see org.springframework.data.gemfire.repository.cdi.SamplePersonRepositoryImpl + * @see org.springframework.data.gemfire.repository.cdi.CustomPersonRepositoryImpl * @see org.springframework.data.gemfire.repository.sample.Person * @since 1.8.0 */