DATAMONGO-1899 - 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.
This commit is contained in:
Mark Paluch
2018-03-12 16:25:04 +01:00
parent c2a91aa7b4
commit 297ff1587a
4 changed files with 5 additions and 8 deletions

View File

@@ -63,11 +63,10 @@ public class MongoRepositoryBean<T> extends CdiRepositoryBean<T> {
* @see org.springframework.data.repository.cdi.CdiRepositoryBean#create(javax.enterprise.context.spi.CreationalContext, java.lang.Class)
*/
@Override
protected T create(CreationalContext<T> creationalContext, Class<T> repositoryType, Optional<Object> customImplementation) {
protected T create(CreationalContext<T> creationalContext, Class<T> repositoryType) {
MongoOperations mongoOperations = getDependencyInstance(operations, MongoOperations.class);
MongoRepositoryFactory factory = new MongoRepositoryFactory(mongoOperations);
return customImplementation.isPresent() ? factory.getRepository(repositoryType, customImplementation.get()) : factory.getRepository(repositoryType);
return create(() -> new MongoRepositoryFactory(mongoOperations), repositoryType);
}
}

View File

@@ -13,13 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.mongodb.repository.cdi;
/**
* @author Mark Paluch
*/
interface SamplePersonRepositoryCustom {
interface SamplePersonFragment {
int returnOne();
}

View File

@@ -13,13 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.mongodb.repository.cdi;
/**
* @author Mark Paluch
*/
class SamplePersonRepositoryImpl implements SamplePersonRepositoryCustom {
class SamplePersonFragmentImpl implements SamplePersonFragment {
@Override
public int returnOne() {

View File

@@ -21,4 +21,4 @@ import org.springframework.data.repository.Repository;
/**
* @author Mark Paluch
*/
public interface SamplePersonRepository extends Repository<Person, Long>, SamplePersonRepositoryCustom {}
public interface SamplePersonRepository extends Repository<Person, Long>, SamplePersonFragment {}