diff --git a/src/integration/java/org/springframework/data/couchbase/repository/cdi/CdiPersonRepositoryCustom.java b/src/integration/java/org/springframework/data/couchbase/repository/cdi/CdiPersonFragment.java similarity index 87% rename from src/integration/java/org/springframework/data/couchbase/repository/cdi/CdiPersonRepositoryCustom.java rename to src/integration/java/org/springframework/data/couchbase/repository/cdi/CdiPersonFragment.java index ddf5d76b..4ef9f3c3 100644 --- a/src/integration/java/org/springframework/data/couchbase/repository/cdi/CdiPersonRepositoryCustom.java +++ b/src/integration/java/org/springframework/data/couchbase/repository/cdi/CdiPersonFragment.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2018 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. @@ -13,13 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.couchbase.repository.cdi; /** * @author Mark Paluch */ -public interface CdiPersonRepositoryCustom { +public interface CdiPersonFragment { int returnTwo(); diff --git a/src/integration/java/org/springframework/data/couchbase/repository/cdi/CdiPersonRepositoryImpl.java b/src/integration/java/org/springframework/data/couchbase/repository/cdi/CdiPersonFragmentImpl.java similarity index 84% rename from src/integration/java/org/springframework/data/couchbase/repository/cdi/CdiPersonRepositoryImpl.java rename to src/integration/java/org/springframework/data/couchbase/repository/cdi/CdiPersonFragmentImpl.java index d963bc71..85af8b0a 100644 --- a/src/integration/java/org/springframework/data/couchbase/repository/cdi/CdiPersonRepositoryImpl.java +++ b/src/integration/java/org/springframework/data/couchbase/repository/cdi/CdiPersonFragmentImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2018 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. @@ -13,13 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.couchbase.repository.cdi; /** * @author Mark Paluch */ -public class CdiPersonRepositoryImpl implements CdiPersonRepositoryCustom { +public class CdiPersonFragmentImpl implements CdiPersonFragment { @Override public int returnTwo() { diff --git a/src/integration/java/org/springframework/data/couchbase/repository/cdi/CdiPersonRepository.java b/src/integration/java/org/springframework/data/couchbase/repository/cdi/CdiPersonRepository.java index 4e29e7d0..f2c73c30 100644 --- a/src/integration/java/org/springframework/data/couchbase/repository/cdi/CdiPersonRepository.java +++ b/src/integration/java/org/springframework/data/couchbase/repository/cdi/CdiPersonRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2018 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. @@ -13,15 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.couchbase.repository.cdi; import org.springframework.data.couchbase.repository.CouchbaseRepository; -import org.springframework.data.couchbase.repository.User; /** * @author Mark Paluch */ -public interface CdiPersonRepository extends CouchbaseRepository, CdiPersonRepositoryCustom { +public interface CdiPersonRepository extends CouchbaseRepository, CdiPersonFragment { } diff --git a/src/main/java/org/springframework/data/couchbase/repository/cdi/CouchbaseRepositoryBean.java b/src/main/java/org/springframework/data/couchbase/repository/cdi/CouchbaseRepositoryBean.java index 8d27d59d..6f6c7fc8 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/cdi/CouchbaseRepositoryBean.java +++ b/src/main/java/org/springframework/data/couchbase/repository/cdi/CouchbaseRepositoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -13,15 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.couchbase.repository.cdi; +import java.lang.annotation.Annotation; +import java.util.Optional; +import java.util.Set; + import javax.enterprise.context.spi.CreationalContext; import javax.enterprise.inject.spi.Bean; import javax.enterprise.inject.spi.BeanManager; -import java.lang.annotation.Annotation; -import java.util.Optional; -import java.util.Set; import org.springframework.data.couchbase.core.CouchbaseOperations; import org.springframework.data.couchbase.repository.config.RepositoryOperationsMapping; @@ -33,50 +33,48 @@ import org.springframework.util.Assert; /** * A bean which represents a Couchbase repository. + * * @author Mark Paluch */ public class CouchbaseRepositoryBean extends CdiRepositoryBean { - private final Bean couchbaseOperationsBean; + private final Bean couchbaseOperationsBean; - /** - * Creates a new {@link CouchbaseRepositoryBean}. - * - * @param operations must not be {@literal null}. - * @param qualifiers must not be {@literal null}. - * @param repositoryType must not be {@literal null}. - * @param beanManager must not be {@literal null}. - * @param detector detector for the custom {@link org.springframework.data.repository.Repository} implementations - * {@link org.springframework.data.repository.config.CustomRepositoryImplementationDetector}, can be {@literal null}. - */ - public CouchbaseRepositoryBean(Bean operations, Set qualifiers, Class repositoryType, - BeanManager beanManager, CustomRepositoryImplementationDetector detector) { - super(qualifiers, repositoryType, beanManager, Optional.of(detector)); + /** + * Creates a new {@link CouchbaseRepositoryBean}. + * + * @param operations must not be {@literal null}. + * @param qualifiers must not be {@literal null}. + * @param repositoryType must not be {@literal null}. + * @param beanManager must not be {@literal null}. + * @param detector detector for the custom {@link org.springframework.data.repository.Repository} implementations + * {@link org.springframework.data.repository.config.CustomRepositoryImplementationDetector}, can be + * {@literal null}. + */ + public CouchbaseRepositoryBean(Bean operations, Set qualifiers, + Class repositoryType, BeanManager beanManager, CustomRepositoryImplementationDetector detector) { + super(qualifiers, repositoryType, beanManager, Optional.of(detector)); - Assert.notNull(operations, "Cannot create repository with 'null' for CouchbaseOperations."); - this.couchbaseOperationsBean = operations; - } + Assert.notNull(operations, "Cannot create repository with 'null' for CouchbaseOperations."); + this.couchbaseOperationsBean = operations; + } /* * (non-Javadoc) - * @see org.springframework.data.repository.cdi.CdiRepositoryBean#create(javax.enterprise.context.spi.CreationalContext, java.lang.Class, java.lang.Object) - */ - @Override - protected T create(CreationalContext creationalContext, Class repositoryType, Optional customImplementation) { + * @see org.springframework.data.repository.cdi.CdiRepositoryBean#create(javax.enterprise.context.spi.CreationalContext, java.lang.Class) + */ + @Override + protected T create(CreationalContext creationalContext, Class repositoryType) { - CouchbaseOperations couchbaseOperations = getDependencyInstance(couchbaseOperationsBean, CouchbaseOperations.class); - RepositoryOperationsMapping couchbaseOperationsMapping = new RepositoryOperationsMapping(couchbaseOperations); - IndexManager indexManager = new IndexManager(); + CouchbaseOperations couchbaseOperations = getDependencyInstance(couchbaseOperationsBean, CouchbaseOperations.class); + RepositoryOperationsMapping couchbaseOperationsMapping = new RepositoryOperationsMapping(couchbaseOperations); + IndexManager indexManager = new IndexManager(); - CouchbaseRepositoryFactory factory = - new CouchbaseRepositoryFactory(couchbaseOperationsMapping, indexManager); + return create(() -> new CouchbaseRepositoryFactory(couchbaseOperationsMapping, indexManager), repositoryType); + } - return customImplementation.map(o -> factory.getRepository(repositoryType, o)) - .orElseGet(() -> factory.getRepository(repositoryType)); - } - - @Override - public Class getScope() { - return couchbaseOperationsBean.getScope(); - } + @Override + public Class getScope() { + return couchbaseOperationsBean.getScope(); + } }