diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/cdi/MongoRepositoryBean.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/cdi/MongoRepositoryBean.java index 27cc34fd9..fbb89a506 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/cdi/MongoRepositoryBean.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/cdi/MongoRepositoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,6 +31,7 @@ import org.springframework.util.Assert; * {@link CdiRepositoryBean} to create Mongo repository instances. * * @author Oliver Gierke + * @author Mark Paluch */ public class MongoRepositoryBean extends CdiRepositoryBean { @@ -43,11 +44,13 @@ public class MongoRepositoryBean extends CdiRepositoryBean { * @param qualifiers must not be {@literal null}. * @param repositoryType must not be {@literal null}. * @param beanManager must not be {@literal null}. + * @param customImplementationBean the bean for the custom implementation of the + * {@link org.springframework.data.repository.Repository}, can be {@literal null}. */ public MongoRepositoryBean(Bean operations, Set qualifiers, Class repositoryType, - BeanManager beanManager) { + BeanManager beanManager, Bean customImplementationBean) { - super(qualifiers, repositoryType, beanManager); + super(qualifiers, repositoryType, beanManager, customImplementationBean); Assert.notNull(operations); this.operations = operations; @@ -58,11 +61,11 @@ public class MongoRepositoryBean extends CdiRepositoryBean { * @see org.springframework.data.repository.cdi.CdiRepositoryBean#create(javax.enterprise.context.spi.CreationalContext, java.lang.Class) */ @Override - protected T create(CreationalContext creationalContext, Class repositoryType) { + protected T create(CreationalContext creationalContext, Class repositoryType, Object customImplementation) { MongoOperations mongoOperations = getDependencyInstance(operations, MongoOperations.class); MongoRepositoryFactory factory = new MongoRepositoryFactory(mongoOperations); - return factory.getRepository(repositoryType); + return factory.getRepository(repositoryType, customImplementation); } } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/cdi/MongoRepositoryExtension.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/cdi/MongoRepositoryExtension.java index e6f5c802e..16e9a5ed9 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/cdi/MongoRepositoryExtension.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/cdi/MongoRepositoryExtension.java @@ -40,6 +40,7 @@ import org.springframework.data.repository.cdi.CdiRepositoryExtensionSupport; * CDI extension to export Mongo repositories. * * @author Oliver Gierke + * @author Mark Paluch */ public class MongoRepositoryExtension extends CdiRepositoryExtensionSupport { @@ -109,7 +110,10 @@ public class MongoRepositoryExtension extends CdiRepositoryExtensionSupport { MongoOperations.class.getName(), qualifiers)); } + Bean customImplementationBean = getCustomImplementationBean(repositoryType, beanManager, qualifiers); + // Construct and return the repository bean. - return new MongoRepositoryBean(mongoOperations, qualifiers, repositoryType, beanManager); + return new MongoRepositoryBean(mongoOperations, qualifiers, repositoryType, beanManager, + customImplementationBean); } } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/CdiExtensionIntegrationTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/CdiExtensionIntegrationTests.java index 5f05ccac6..eef044847 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/CdiExtensionIntegrationTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/CdiExtensionIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import org.springframework.data.mongodb.repository.Person; * Integration tests for {@link MongoRepositoryExtension}. * * @author Oliver Gierke + * @author Mark Paluch */ public class CdiExtensionIntegrationTests { @@ -61,4 +62,15 @@ public class CdiExtensionIntegrationTests { assertThat(result, is(notNullValue())); assertThat(repository.findOne(person.getId()).getId(), is(result.getId())); } + + /** + * @see DATAMONGO-1017 + */ + @Test + public void returnOneFromCustomImpl() { + + RepositoryClient repositoryConsumer = container.getInstance(RepositoryClient.class); + assertThat(repositoryConsumer.getSamplePersonRepository().returnOne(), is(1)); + } + } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/RepositoryClient.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/RepositoryClient.java index 643418bb1..cb93f59c2 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/RepositoryClient.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/RepositoryClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,10 +19,12 @@ import javax.inject.Inject; /** * @author Oliver Gierke + * @author Mark Paluch */ class RepositoryClient { @Inject CdiPersonRepository repository; + @Inject SamplePersonRepository samplePersonRepository; /** * @return the repository @@ -30,4 +32,8 @@ class RepositoryClient { public CdiPersonRepository getRepository() { return repository; } + + public SamplePersonRepository getSamplePersonRepository() { + return samplePersonRepository; + } } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/SamplePersonRepository.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/SamplePersonRepository.java new file mode 100644 index 000000000..224a7ed3b --- /dev/null +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/SamplePersonRepository.java @@ -0,0 +1,25 @@ +/* + * Copyright 2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.mongodb.repository.cdi; + +import org.springframework.data.mongodb.core.Person; +import org.springframework.data.repository.Repository; + +/** + * @author Mark Paluch + * @see DATAMONGO-1017 + */ +public interface SamplePersonRepository extends Repository, SamplePersonRepositoryCustom {} diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/SamplePersonRepositoryCustom.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/SamplePersonRepositoryCustom.java new file mode 100644 index 000000000..a545d3591 --- /dev/null +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/SamplePersonRepositoryCustom.java @@ -0,0 +1,26 @@ +/* + * Copyright 2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.data.mongodb.repository.cdi; + +/** + * @see DATAMONGO-1017 + * @author Mark Paluch + */ +interface SamplePersonRepositoryCustom { + + int returnOne(); +} \ No newline at end of file diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/SamplePersonRepositoryImpl.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/SamplePersonRepositoryImpl.java new file mode 100644 index 000000000..46a22cb6e --- /dev/null +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/SamplePersonRepositoryImpl.java @@ -0,0 +1,29 @@ +/* + * Copyright 2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.data.mongodb.repository.cdi; + +/** + * @see DATAMONGO-1017 + * @author Mark Paluch + */ +class SamplePersonRepositoryImpl implements SamplePersonRepositoryCustom { + + @Override + public int returnOne() { + return 1; + } +} \ No newline at end of file