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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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() {
|
||||
@@ -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 {}
|
||||
|
||||
Reference in New Issue
Block a user