DATACOUCH-504 - Make sure Reactive* repository take the reactive operations.
This commit is contained in:
@@ -19,7 +19,7 @@ package org.springframework.data.couchbase.repository.config;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.data.couchbase.core.CouchbaseOperations;
|
||||
import org.springframework.data.couchbase.core.ReactiveCouchbaseOperations;
|
||||
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity;
|
||||
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
@@ -30,50 +30,50 @@ import org.springframework.util.Assert;
|
||||
* @since 3.0
|
||||
*/
|
||||
public class ReactiveRepositoryOperationsMapping {
|
||||
private CouchbaseOperations defaultOperations;
|
||||
private Map<String, CouchbaseOperations> byRepository = new HashMap<>();
|
||||
private Map<String, CouchbaseOperations> byEntity = new HashMap<>();
|
||||
private ReactiveCouchbaseOperations defaultOperations;
|
||||
private Map<String, ReactiveCouchbaseOperations> byRepository = new HashMap<>();
|
||||
private Map<String, ReactiveCouchbaseOperations> byEntity = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Creates a new mapping, setting the default fallback to use by otherwise non mapped repositories.
|
||||
*
|
||||
* @param defaultOperations the default fallback reactive couchbase operations.
|
||||
*/
|
||||
public ReactiveRepositoryOperationsMapping(CouchbaseOperations defaultOperations) {
|
||||
Assert.notNull(defaultOperations);
|
||||
public ReactiveRepositoryOperationsMapping(ReactiveCouchbaseOperations defaultOperations) {
|
||||
Assert.notNull(defaultOperations, "ReactiveCouchbaseOperations");
|
||||
this.defaultOperations = defaultOperations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a highest priority mapping that will associate a specific repository interface with a given
|
||||
* {@link CouchbaseOperations}.
|
||||
* {@link ReactiveCouchbaseOperations}.
|
||||
*
|
||||
* @param repositoryInterface the repository interface {@link Class}.
|
||||
* @param operations the ReactiveCouchbaseOperations to use.
|
||||
* @return the mapping, for chaining.
|
||||
*/
|
||||
public ReactiveRepositoryOperationsMapping map(Class<?> repositoryInterface, CouchbaseOperations operations) {
|
||||
public ReactiveRepositoryOperationsMapping map(Class<?> repositoryInterface, ReactiveCouchbaseOperations operations) {
|
||||
byRepository.put(repositoryInterface.getName(), operations);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a middle priority mapping that will associate any un-mapped repository that deals with the given domain type
|
||||
* Class with a given {@link CouchbaseOperations}.
|
||||
* Class with a given {@link ReactiveCouchbaseOperations}.
|
||||
*
|
||||
* @param entityClass the domain type's {@link Class}.
|
||||
* @param operations the CouchbaseOperations to use.
|
||||
* @return the mapping, for chaining.
|
||||
*/
|
||||
public ReactiveRepositoryOperationsMapping mapEntity(Class<?> entityClass, CouchbaseOperations operations) {
|
||||
public ReactiveRepositoryOperationsMapping mapEntity(Class<?> entityClass, ReactiveCouchbaseOperations operations) {
|
||||
byEntity.put(entityClass.getName(), operations);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the configured default {@link CouchbaseOperations}.
|
||||
* @return the configured default {@link ReactiveCouchbaseOperations}.
|
||||
*/
|
||||
public CouchbaseOperations getDefault() {
|
||||
public ReactiveCouchbaseOperations getDefault() {
|
||||
return defaultOperations;
|
||||
}
|
||||
|
||||
@@ -83,15 +83,15 @@ public class ReactiveRepositoryOperationsMapping {
|
||||
* @param aDefault the new default couchbase operations.
|
||||
* @return the mapping, for chaining.
|
||||
*/
|
||||
public ReactiveRepositoryOperationsMapping setDefault(CouchbaseOperations aDefault) {
|
||||
Assert.notNull(aDefault);
|
||||
public ReactiveRepositoryOperationsMapping setDefault(ReactiveCouchbaseOperations aDefault) {
|
||||
Assert.notNull(aDefault, "ReactiveCouchbaseOperations");
|
||||
this.defaultOperations = aDefault;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link MappingContext} to use in repositories. It is extracted from the default
|
||||
* {@link CouchbaseOperations}.
|
||||
* {@link ReactiveCouchbaseOperations}.
|
||||
*
|
||||
* @return the mapping context.
|
||||
*/
|
||||
@@ -100,7 +100,7 @@ public class ReactiveRepositoryOperationsMapping {
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a repository interface and its domain type, resolves which {@link CouchbaseOperations} it should be backed
|
||||
* Given a repository interface and its domain type, resolves which {@link ReactiveCouchbaseOperations} it should be backed
|
||||
* with. Starts by looking for a direct mapping to the interface, then a common mapping for the domain type, then
|
||||
* falls back to the default CouchbaseOperations.
|
||||
*
|
||||
@@ -108,8 +108,8 @@ public class ReactiveRepositoryOperationsMapping {
|
||||
* @param domainType the repository's domain type / entity.
|
||||
* @return the CouchbaseOperations to back the repository.
|
||||
*/
|
||||
public CouchbaseOperations resolve(Class<?> repositoryInterface, Class<?> domainType) {
|
||||
CouchbaseOperations result = byRepository.get(repositoryInterface.getName());
|
||||
public ReactiveCouchbaseOperations resolve(Class<?> repositoryInterface, Class<?> domainType) {
|
||||
ReactiveCouchbaseOperations result = byRepository.get(repositoryInterface.getName());
|
||||
if (result != null) {
|
||||
return result;
|
||||
} else {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.couchbase.repository.query;
|
||||
|
||||
import org.springframework.data.couchbase.core.ReactiveCouchbaseOperations;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@@ -43,9 +44,9 @@ public abstract class ReactiveAbstractN1qlBasedQuery implements RepositoryQuery
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ReactiveAbstractN1qlBasedQuery.class);
|
||||
|
||||
protected final CouchbaseQueryMethod queryMethod;
|
||||
private final CouchbaseOperations couchbaseOperations;
|
||||
private final ReactiveCouchbaseOperations couchbaseOperations;
|
||||
|
||||
protected ReactiveAbstractN1qlBasedQuery(CouchbaseQueryMethod method, CouchbaseOperations operations) {
|
||||
protected ReactiveAbstractN1qlBasedQuery(CouchbaseQueryMethod method, ReactiveCouchbaseOperations operations) {
|
||||
this.queryMethod = method;
|
||||
this.couchbaseOperations = operations;
|
||||
}
|
||||
@@ -119,7 +120,7 @@ public abstract class ReactiveAbstractN1qlBasedQuery implements RepositoryQuery
|
||||
return this.queryMethod;
|
||||
}
|
||||
|
||||
protected CouchbaseOperations getCouchbaseOperations() {
|
||||
protected ReactiveCouchbaseOperations getCouchbaseOperations() {
|
||||
return this.couchbaseOperations;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.couchbase.repository.query;
|
||||
|
||||
import static org.springframework.data.couchbase.core.query.N1QLExpression.*;
|
||||
|
||||
import org.springframework.data.couchbase.core.CouchbaseOperations;
|
||||
import org.springframework.data.couchbase.core.ReactiveCouchbaseOperations;
|
||||
import org.springframework.data.couchbase.core.query.N1QLExpression;
|
||||
import org.springframework.data.couchbase.repository.query.support.N1qlUtils;
|
||||
import org.springframework.data.repository.query.ParameterAccessor;
|
||||
@@ -38,7 +38,7 @@ public class ReactivePartTreeN1qlBasedQuery extends ReactiveAbstractN1qlBasedQue
|
||||
private final PartTree partTree;
|
||||
private JsonValue placeHolderValues;
|
||||
|
||||
public ReactivePartTreeN1qlBasedQuery(CouchbaseQueryMethod queryMethod, CouchbaseOperations operations) {
|
||||
public ReactivePartTreeN1qlBasedQuery(CouchbaseQueryMethod queryMethod, ReactiveCouchbaseOperations operations) {
|
||||
super(queryMethod, operations);
|
||||
this.partTree = new PartTree(queryMethod.getName(), queryMethod.getEntityInformation().getJavaType());
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.couchbase.repository.query;
|
||||
|
||||
import static org.springframework.data.couchbase.core.query.N1QLExpression.*;
|
||||
|
||||
import org.springframework.data.couchbase.core.CouchbaseOperations;
|
||||
import org.springframework.data.couchbase.core.ReactiveCouchbaseOperations;
|
||||
import org.springframework.data.couchbase.core.query.N1QLExpression;
|
||||
import org.springframework.data.repository.query.ParameterAccessor;
|
||||
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
|
||||
@@ -47,8 +47,8 @@ public class ReactiveStringN1qlBasedQuery extends ReactiveAbstractN1qlBasedQuery
|
||||
private final QueryMethodEvaluationContextProvider evaluationContextProvider;
|
||||
|
||||
public ReactiveStringN1qlBasedQuery(String statement, CouchbaseQueryMethod queryMethod,
|
||||
CouchbaseOperations couchbaseOperations, SpelExpressionParser spelParser,
|
||||
QueryMethodEvaluationContextProvider evaluationContextProvider) {
|
||||
ReactiveCouchbaseOperations couchbaseOperations, SpelExpressionParser spelParser,
|
||||
QueryMethodEvaluationContextProvider evaluationContextProvider) {
|
||||
super(queryMethod, couchbaseOperations);
|
||||
|
||||
this.queryParser = new StringBasedN1qlQueryParser(statement, queryMethod, getCouchbaseOperations().getBucketName(),
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.couchbase.core.CouchbaseOperations;
|
||||
import org.springframework.data.couchbase.core.ReactiveCouchbaseOperations;
|
||||
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity;
|
||||
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty;
|
||||
import org.springframework.data.couchbase.repository.config.ReactiveRepositoryOperationsMapping;
|
||||
@@ -96,7 +96,7 @@ public class ReactiveCouchbaseRepositoryFactory extends ReactiveRepositoryFactor
|
||||
*/
|
||||
@Override
|
||||
protected final Object getTargetRepository(final RepositoryInformation metadata) {
|
||||
CouchbaseOperations couchbaseOperations = couchbaseOperationsMapping.resolve(metadata.getRepositoryInterface(),
|
||||
ReactiveCouchbaseOperations couchbaseOperations = couchbaseOperationsMapping.resolve(metadata.getRepositoryInterface(),
|
||||
metadata.getDomainType());
|
||||
// boolean isN1qlAvailable =
|
||||
// couchbaseOperations.getCouchbaseClusterConfig().clusterCapabilities().containsKey(ServiceType.QUERY);
|
||||
@@ -144,7 +144,7 @@ public class ReactiveCouchbaseRepositoryFactory extends ReactiveRepositoryFactor
|
||||
@Override
|
||||
public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory,
|
||||
NamedQueries namedQueries) {
|
||||
CouchbaseOperations couchbaseOperations = couchbaseOperationsMapping.resolve(metadata.getRepositoryInterface(),
|
||||
ReactiveCouchbaseOperations couchbaseOperations = couchbaseOperationsMapping.resolve(metadata.getRepositoryInterface(),
|
||||
metadata.getDomainType());
|
||||
|
||||
CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod(method, metadata, factory, mappingContext);
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.couchbase.repository.support;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.data.couchbase.core.CouchbaseOperations;
|
||||
import org.springframework.data.couchbase.core.ReactiveCouchbaseOperations;
|
||||
import org.springframework.data.couchbase.repository.config.ReactiveRepositoryOperationsMapping;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport;
|
||||
@@ -48,10 +48,10 @@ public class ReactiveCouchbaseRepositoryFactoryBean<T extends Repository<S, ID>,
|
||||
/**
|
||||
* Set the template reference.
|
||||
*
|
||||
* @param couchbaseOperationsMapping the reference to the operations template.
|
||||
* @param reactiveCouchbaseOperations the reference to the operations template.
|
||||
*/
|
||||
public void setCouchbaseOperations(final CouchbaseOperations couchbaseOperationsMapping) {
|
||||
setCouchbaseOperationsMapping(new ReactiveRepositoryOperationsMapping(couchbaseOperationsMapping));
|
||||
public void setCouchbaseOperations(final ReactiveCouchbaseOperations reactiveCouchbaseOperations) {
|
||||
setCouchbaseOperationsMapping(new ReactiveRepositoryOperationsMapping(reactiveCouchbaseOperations));
|
||||
}
|
||||
|
||||
public void setCouchbaseOperationsMapping(final ReactiveRepositoryOperationsMapping couchbaseOperationsMapping) {
|
||||
|
||||
Reference in New Issue
Block a user