diff --git a/src/main/java/org/springframework/data/couchbase/SimpleCouchbaseClientFactory.java b/src/main/java/org/springframework/data/couchbase/SimpleCouchbaseClientFactory.java index 61242dd2..1c63cc5c 100644 --- a/src/main/java/org/springframework/data/couchbase/SimpleCouchbaseClientFactory.java +++ b/src/main/java/org/springframework/data/couchbase/SimpleCouchbaseClientFactory.java @@ -16,20 +16,20 @@ package org.springframework.data.couchbase; -import com.couchbase.client.core.env.OwnedSupplier; -import com.couchbase.client.java.env.ClusterEnvironment; +import java.util.function.Supplier; + import org.springframework.dao.support.PersistenceExceptionTranslator; import org.springframework.data.couchbase.core.CouchbaseExceptionTranslator; import com.couchbase.client.core.env.Authenticator; +import com.couchbase.client.core.env.OwnedSupplier; import com.couchbase.client.core.io.CollectionIdentifier; import com.couchbase.client.java.Bucket; import com.couchbase.client.java.Cluster; import com.couchbase.client.java.ClusterOptions; import com.couchbase.client.java.Collection; import com.couchbase.client.java.Scope; - -import java.util.function.Supplier; +import com.couchbase.client.java.env.ClusterEnvironment; public class SimpleCouchbaseClientFactory implements CouchbaseClientFactory { @@ -45,19 +45,24 @@ public class SimpleCouchbaseClientFactory implements CouchbaseClientFactory { public SimpleCouchbaseClientFactory(final String connectionString, final Authenticator authenticator, final String bucketName, final String scopeName) { - this(new OwnedSupplier<>(Cluster.connect(connectionString, ClusterOptions.clusterOptions(authenticator))), bucketName, scopeName); + this(new OwnedSupplier<>(Cluster.connect(connectionString, ClusterOptions.clusterOptions(authenticator))), + bucketName, scopeName); } public SimpleCouchbaseClientFactory(final String connectionString, final Authenticator authenticator, - final String bucketName, final String scopeName, final ClusterEnvironment environment) { - this(new OwnedSupplier<>(Cluster.connect(connectionString, ClusterOptions.clusterOptions(authenticator).environment(environment))), bucketName, scopeName); + final String bucketName, final String scopeName, final ClusterEnvironment environment) { + this( + new OwnedSupplier<>( + Cluster.connect(connectionString, ClusterOptions.clusterOptions(authenticator).environment(environment))), + bucketName, scopeName); } public SimpleCouchbaseClientFactory(final Cluster cluster, final String bucketName, final String scopeName) { this(() -> cluster, bucketName, scopeName); } - private SimpleCouchbaseClientFactory(final Supplier cluster, final String bucketName, final String scopeName) { + private SimpleCouchbaseClientFactory(final Supplier cluster, final String bucketName, + final String scopeName) { this.cluster = cluster; this.bucket = cluster.get().bucket(bucketName); this.scope = scopeName == null ? bucket.defaultScope() : bucket.scope(scopeName); diff --git a/src/main/java/org/springframework/data/couchbase/cache/CouchbaseCacheManager.java b/src/main/java/org/springframework/data/couchbase/cache/CouchbaseCacheManager.java index b33d90ea..a96c8e16 100644 --- a/src/main/java/org/springframework/data/couchbase/cache/CouchbaseCacheManager.java +++ b/src/main/java/org/springframework/data/couchbase/cache/CouchbaseCacheManager.java @@ -48,9 +48,9 @@ public class CouchbaseCacheManager extends AbstractTransactionSupportingCacheMan * @param allowInFlightCacheCreation allow create unconfigured caches. */ private CouchbaseCacheManager(final CouchbaseCacheWriter cacheWriter, - final CouchbaseCacheConfiguration defaultCacheConfiguration, - final Map initialCacheConfiguration, - final boolean allowInFlightCacheCreation) { + final CouchbaseCacheConfiguration defaultCacheConfiguration, + final Map initialCacheConfiguration, + final boolean allowInFlightCacheCreation) { Assert.notNull(cacheWriter, "CacheWriter must not be null!"); Assert.notNull(defaultCacheConfiguration, "DefaultCacheConfiguration must not be null!"); @@ -70,7 +70,7 @@ public class CouchbaseCacheManager extends AbstractTransactionSupportingCacheMan public static CouchbaseCacheManager create(CouchbaseClientFactory clientFactory) { Assert.notNull(clientFactory, "ConnectionFactory must not be null!"); return new CouchbaseCacheManager(new DefaultCouchbaseCacheWriter(clientFactory), - CouchbaseCacheConfiguration.defaultCacheConfig(), new LinkedHashMap<>(), true); + CouchbaseCacheConfiguration.defaultCacheConfig(), new LinkedHashMap<>(), true); } /** @@ -126,10 +126,10 @@ public class CouchbaseCacheManager extends AbstractTransactionSupportingCacheMan public static class CouchbaseCacheManagerBuilder { private final CouchbaseCacheWriter cacheWriter; - private CouchbaseCacheConfiguration defaultCacheConfiguration = CouchbaseCacheConfiguration.defaultCacheConfig(); private final Map initialCaches = new LinkedHashMap<>(); - private boolean enableTransactions; boolean allowInFlightCacheCreation = true; + private CouchbaseCacheConfiguration defaultCacheConfiguration = CouchbaseCacheConfiguration.defaultCacheConfig(); + private boolean enableTransactions; private CouchbaseCacheManagerBuilder(CouchbaseCacheWriter cacheWriter) { this.cacheWriter = cacheWriter; @@ -170,7 +170,8 @@ public class CouchbaseCacheManager extends AbstractTransactionSupportingCacheMan } /** - * Enable {@link CouchbaseCache}s to synchronize cache put/evict operations with ongoing Spring-managed transactions. + * Enable {@link CouchbaseCache}s to synchronize cache put/evict operations with ongoing Spring-managed + * transactions. * * @return this {@link CouchbaseCacheManagerBuilder}. */ @@ -200,11 +201,11 @@ public class CouchbaseCacheManager extends AbstractTransactionSupportingCacheMan * @return this {@link CouchbaseCacheManagerBuilder}. */ public CouchbaseCacheManagerBuilder withInitialCacheConfigurations( - Map cacheConfigurations) { + Map cacheConfigurations) { Assert.notNull(cacheConfigurations, "CacheConfigurations must not be null!"); cacheConfigurations.forEach((cacheName, configuration) -> Assert.notNull(configuration, - String.format("CouchbaseCacheConfiguration for cache %s must not be null!", cacheName))); + String.format("CouchbaseCacheConfiguration for cache %s must not be null!", cacheName))); this.initialCaches.putAll(cacheConfigurations); return this; @@ -216,7 +217,7 @@ public class CouchbaseCacheManager extends AbstractTransactionSupportingCacheMan * @return this {@link CouchbaseCacheManagerBuilder}. */ public CouchbaseCacheManagerBuilder withCacheConfiguration(String cacheName, - CouchbaseCacheConfiguration cacheConfiguration) { + CouchbaseCacheConfiguration cacheConfiguration) { Assert.notNull(cacheName, "CacheName must not be null!"); Assert.notNull(cacheConfiguration, "CacheConfiguration must not be null!"); @@ -267,7 +268,7 @@ public class CouchbaseCacheManager extends AbstractTransactionSupportingCacheMan */ public CouchbaseCacheManager build() { CouchbaseCacheManager cm = new CouchbaseCacheManager(cacheWriter, defaultCacheConfiguration, initialCaches, - allowInFlightCacheCreation); + allowInFlightCacheCreation); cm.setTransactionAware(enableTransactions); return cm; } diff --git a/src/main/java/org/springframework/data/couchbase/config/AbstractCouchbaseConfiguration.java b/src/main/java/org/springframework/data/couchbase/config/AbstractCouchbaseConfiguration.java index 6af72f6f..c85b9268 100644 --- a/src/main/java/org/springframework/data/couchbase/config/AbstractCouchbaseConfiguration.java +++ b/src/main/java/org/springframework/data/couchbase/config/AbstractCouchbaseConfiguration.java @@ -16,11 +16,12 @@ package org.springframework.data.couchbase.config; +import static com.couchbase.client.java.ClusterOptions.*; + import java.util.Collections; import java.util.HashSet; import java.util.Set; -import com.couchbase.client.java.Cluster; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; @@ -49,11 +50,10 @@ import org.springframework.util.StringUtils; import com.couchbase.client.core.deps.com.fasterxml.jackson.databind.DeserializationFeature; import com.couchbase.client.core.env.Authenticator; import com.couchbase.client.core.env.PasswordAuthenticator; +import com.couchbase.client.java.Cluster; import com.couchbase.client.java.env.ClusterEnvironment; import com.couchbase.client.java.json.JacksonTransformers; -import static com.couchbase.client.java.ClusterOptions.*; - /** * Base class for Spring Data Couchbase configuration using JavaConfig. * @@ -88,10 +88,8 @@ public abstract class AbstractCouchbaseConfiguration { @Bean(destroyMethod = "disconnect") public Cluster couchbaseCluster(ClusterEnvironment couchbaseClusterEnvironment) { - return Cluster.connect( - getConnectionString(), - clusterOptions(authenticator()).environment(couchbaseClusterEnvironment) - ); + return Cluster.connect(getConnectionString(), + clusterOptions(authenticator()).environment(couchbaseClusterEnvironment)); } @Bean(destroyMethod = "shutdown") @@ -107,13 +105,13 @@ public abstract class AbstractCouchbaseConfiguration { @Bean(name = BeanNames.COUCHBASE_TEMPLATE) public CouchbaseTemplate couchbaseTemplate(CouchbaseClientFactory couchbaseClientFactory, - MappingCouchbaseConverter mappingCouchbaseConverter) { + MappingCouchbaseConverter mappingCouchbaseConverter) { return new CouchbaseTemplate(couchbaseClientFactory, mappingCouchbaseConverter); } @Bean(name = BeanNames.REACTIVE_COUCHBASE_TEMPLATE) public ReactiveCouchbaseTemplate reactiveCouchbaseTemplate(CouchbaseClientFactory couchbaseClientFactory, - MappingCouchbaseConverter mappingCouchbaseConverter) { + MappingCouchbaseConverter mappingCouchbaseConverter) { return new ReactiveCouchbaseTemplate(couchbaseClientFactory, mappingCouchbaseConverter); } @@ -137,9 +135,11 @@ public abstract class AbstractCouchbaseConfiguration { } @Bean(name = BeanNames.REACTIVE_COUCHBASE_OPERATIONS_MAPPING) - public ReactiveRepositoryOperationsMapping reactiveCouchbaseRepositoryOperationsMapping(ReactiveCouchbaseTemplate reactiveCouchbaseTemplate) { + public ReactiveRepositoryOperationsMapping reactiveCouchbaseRepositoryOperationsMapping( + ReactiveCouchbaseTemplate reactiveCouchbaseTemplate) { // create a base mapping that associates all repositories to the default template - ReactiveRepositoryOperationsMapping baseMapping = new ReactiveRepositoryOperationsMapping(reactiveCouchbaseTemplate); + ReactiveRepositoryOperationsMapping baseMapping = new ReactiveRepositoryOperationsMapping( + reactiveCouchbaseTemplate); // let the user tune it configureReactiveRepositoryOperationsMapping(baseMapping); return baseMapping; @@ -179,8 +179,8 @@ public abstract class AbstractCouchbaseConfiguration { /** * Determines the name of the field that will store the type information for complex types when using the - * {@link #mappingCouchbaseConverter(CouchbaseMappingContext, CouchbaseCustomConversions)}. Defaults - * to {@value MappingCouchbaseConverter#TYPEKEY_DEFAULT}. + * {@link #mappingCouchbaseConverter(CouchbaseMappingContext, CouchbaseCustomConversions)}. Defaults to + * {@value MappingCouchbaseConverter#TYPEKEY_DEFAULT}. * * @see MappingCouchbaseConverter#TYPEKEY_DEFAULT * @see MappingCouchbaseConverter#TYPEKEY_SYNCGATEWAY_COMPATIBLE @@ -196,7 +196,7 @@ public abstract class AbstractCouchbaseConfiguration { */ @Bean public MappingCouchbaseConverter mappingCouchbaseConverter(CouchbaseMappingContext couchbaseMappingContext, - CouchbaseCustomConversions couchbaseCustomConversions) { + CouchbaseCustomConversions couchbaseCustomConversions) { MappingCouchbaseConverter converter = new MappingCouchbaseConverter(couchbaseMappingContext, typeKey()); converter.setCustomConversions(couchbaseCustomConversions); return converter; @@ -234,8 +234,7 @@ public abstract class AbstractCouchbaseConfiguration { } /** - * Configure whether to automatically create indices for domain types by deriving the - * from the entity or not. + * Configure whether to automatically create indices for domain types by deriving the from the entity or not. */ protected boolean autoIndexCreation() { return false; diff --git a/src/main/java/org/springframework/data/couchbase/config/BeanNames.java b/src/main/java/org/springframework/data/couchbase/config/BeanNames.java index d2ee2c0b..696afab7 100644 --- a/src/main/java/org/springframework/data/couchbase/config/BeanNames.java +++ b/src/main/java/org/springframework/data/couchbase/config/BeanNames.java @@ -16,12 +16,6 @@ package org.springframework.data.couchbase.config; -import org.springframework.core.convert.converter.Converter; -import org.springframework.data.couchbase.CouchbaseClientFactory; -import org.springframework.data.couchbase.core.CouchbaseOperations; -import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter; -import org.springframework.data.couchbase.core.convert.translation.TranslationService; - /** * Contains default bean names for Couchbase beans. These are the names of the beans used by Spring Data Couchbase, * unless an explicit id is given to the bean either in the xml configuration or the diff --git a/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java b/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java index 3e4a6fcf..7819c02e 100644 --- a/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java +++ b/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java @@ -24,8 +24,6 @@ import org.springframework.dao.DataAccessException; import org.springframework.dao.support.PersistenceExceptionTranslator; import org.springframework.data.couchbase.CouchbaseClientFactory; import org.springframework.data.couchbase.core.convert.CouchbaseConverter; - -import com.couchbase.client.java.Collection; import org.springframework.data.couchbase.core.index.CouchbasePersistentEntityIndexCreator; import org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext; import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity; @@ -33,6 +31,8 @@ import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProper import org.springframework.data.mapping.context.MappingContext; import org.springframework.lang.Nullable; +import com.couchbase.client.java.Collection; + public class CouchbaseTemplate implements CouchbaseOperations, ApplicationContextAware { private final CouchbaseClientFactory clientFactory; @@ -43,7 +43,6 @@ public class CouchbaseTemplate implements CouchbaseOperations, ApplicationContex private final ReactiveCouchbaseTemplate reactiveCouchbaseTemplate; private @Nullable CouchbasePersistentEntityIndexCreator indexCreator; - public CouchbaseTemplate(final CouchbaseClientFactory clientFactory, final CouchbaseConverter converter) { this.clientFactory = clientFactory; this.converter = converter; @@ -168,7 +167,8 @@ public class CouchbaseTemplate implements CouchbaseOperations, ApplicationContex String[] indexCreators = context.getBeanNamesForType(CouchbasePersistentEntityIndexCreator.class); for (String creator : indexCreators) { - CouchbasePersistentEntityIndexCreator creatorBean = context.getBean(creator, CouchbasePersistentEntityIndexCreator.class); + CouchbasePersistentEntityIndexCreator creatorBean = context.getBean(creator, + CouchbasePersistentEntityIndexCreator.class); if (creatorBean.isIndexCreatorFor(mappingContext)) { return; } diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveFindByQueryOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveFindByQueryOperationSupport.java index c4c953ed..68029df0 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveFindByQueryOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveFindByQueryOperationSupport.java @@ -15,11 +15,11 @@ */ package org.springframework.data.couchbase.core; -import org.springframework.data.couchbase.core.query.QueryCriteria; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import org.springframework.data.couchbase.core.query.Query; +import org.springframework.data.couchbase.core.query.QueryCriteria; import com.couchbase.client.java.query.QueryOptions; import com.couchbase.client.java.query.QueryScanConsistency; diff --git a/src/main/java/org/springframework/data/couchbase/core/index/CouchbasePersistentEntityIndexCreator.java b/src/main/java/org/springframework/data/couchbase/core/index/CouchbasePersistentEntityIndexCreator.java index 63a8e7e9..17d2753c 100644 --- a/src/main/java/org/springframework/data/couchbase/core/index/CouchbasePersistentEntityIndexCreator.java +++ b/src/main/java/org/springframework/data/couchbase/core/index/CouchbasePersistentEntityIndexCreator.java @@ -15,26 +15,24 @@ */ package org.springframework.data.couchbase.core.index; -import com.couchbase.client.core.error.IndexExistsException; -import com.couchbase.client.java.Cluster; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationListener; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.data.couchbase.core.CouchbaseOperations; +import org.springframework.data.couchbase.core.index.CouchbasePersistentEntityIndexResolver.IndexDefinitionHolder; import org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext; import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity; import org.springframework.data.couchbase.core.mapping.Document; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.mapping.context.MappingContextEvent; -import org.springframework.data.couchbase.core.index.CouchbasePersistentEntityIndexResolver.IndexDefinitionHolder; -import org.springframework.util.StringUtils; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; +import com.couchbase.client.core.error.IndexExistsException; +import com.couchbase.client.java.Cluster; public class CouchbasePersistentEntityIndexCreator implements ApplicationListener> { @@ -46,7 +44,7 @@ public class CouchbasePersistentEntityIndexCreator implements ApplicationListene private final CouchbaseOperations couchbaseOperations; public CouchbasePersistentEntityIndexCreator(final CouchbaseMappingContext mappingContext, - final CouchbaseOperations operations) { + final CouchbaseOperations operations) { this.mappingContext = mappingContext; this.couchbaseOperations = operations; this.indexResolver = QueryIndexResolver.create(mappingContext, operations); @@ -85,8 +83,9 @@ public class CouchbasePersistentEntityIndexCreator implements ApplicationListene for (IndexDefinition indexDefinition : indexResolver.resolveIndexFor(entity.getTypeInformation())) { IndexDefinitionHolder indexToCreate = indexDefinition instanceof IndexDefinitionHolder - ? (IndexDefinitionHolder) indexDefinition - : new IndexDefinitionHolder(indexDefinition.getIndexFields(), indexDefinition.getIndexName(), indexDefinition.getIndexPredicate()); + ? (IndexDefinitionHolder) indexDefinition + : new IndexDefinitionHolder(indexDefinition.getIndexFields(), indexDefinition.getIndexName(), + indexDefinition.getIndexPredicate()); createIndex(indexToCreate); } @@ -96,13 +95,9 @@ public class CouchbasePersistentEntityIndexCreator implements ApplicationListene private void createIndex(final IndexDefinitionHolder indexToCreate) { Cluster cluster = couchbaseOperations.getCouchbaseClientFactory().getCluster(); - StringBuilder statement = new StringBuilder("CREATE INDEX ") - .append(indexToCreate.getIndexName()) - .append(" ON `") - .append(couchbaseOperations.getBucketName()) - .append("` (") - .append(String.join(",", indexToCreate.getIndexFields())) - .append(")"); + StringBuilder statement = new StringBuilder("CREATE INDEX ").append(indexToCreate.getIndexName()).append(" ON `") + .append(couchbaseOperations.getBucketName()).append("` (") + .append(String.join(",", indexToCreate.getIndexFields())).append(")"); if (indexToCreate.getIndexPredicate() != null && !indexToCreate.getIndexPredicate().isEmpty()) { statement.append(" WHERE ").append(indexToCreate.getIndexPredicate()); @@ -114,8 +109,8 @@ public class CouchbasePersistentEntityIndexCreator implements ApplicationListene // ignored on purpose, rest is propagated LOGGER.debug("Index \"" + indexToCreate.getIndexName() + "\" already exists, ignoring."); } catch (Exception ex) { - throw new DataIntegrityViolationException("Could not auto-create index with statement: " - + statement.toString(), ex); + throw new DataIntegrityViolationException("Could not auto-create index with statement: " + statement.toString(), + ex); } } diff --git a/src/main/java/org/springframework/data/couchbase/core/index/CouchbasePersistentEntityIndexResolver.java b/src/main/java/org/springframework/data/couchbase/core/index/CouchbasePersistentEntityIndexResolver.java index b1742745..4ef36a4d 100644 --- a/src/main/java/org/springframework/data/couchbase/core/index/CouchbasePersistentEntityIndexResolver.java +++ b/src/main/java/org/springframework/data/couchbase/core/index/CouchbasePersistentEntityIndexResolver.java @@ -15,6 +15,11 @@ */ package org.springframework.data.couchbase.core.index; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + import org.springframework.data.couchbase.core.CouchbaseOperations; import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity; import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty; @@ -27,21 +32,14 @@ import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - public class CouchbasePersistentEntityIndexResolver implements QueryIndexResolver { private final MappingContext, CouchbasePersistentProperty> mappingContext; private final CouchbaseOperations operations; public CouchbasePersistentEntityIndexResolver( - final MappingContext, CouchbasePersistentProperty> mappingContext, - CouchbaseOperations operations) { + final MappingContext, CouchbasePersistentProperty> mappingContext, + CouchbaseOperations operations) { this.mappingContext = mappingContext; this.operations = operations; } @@ -55,29 +53,27 @@ public class CouchbasePersistentEntityIndexResolver implements QueryIndexResolve Assert.notNull(root, "CouchbasePersistentEntity must not be null!"); Document document = root.findAnnotation(Document.class); Assert.notNull(document, () -> String - .format("Entity %s is not a collection root. Make sure to annotate it with @Document!", root.getName())); + .format("Entity %s is not a collection root. Make sure to annotate it with @Document!", root.getName())); List indexInformation = new ArrayList<>(); root.doWithProperties((PropertyHandler) property -> this - .potentiallyAddIndexForProperty(root, property, indexInformation)); + .potentiallyAddIndexForProperty(root, property, indexInformation)); return indexInformation; } private void potentiallyAddIndexForProperty(final CouchbasePersistentEntity root, - final CouchbasePersistentProperty persistentProperty, - final List indexes) { + final CouchbasePersistentProperty persistentProperty, final List indexes) { List indexDefinitions = createIndexDefinitionHolderForProperty( - persistentProperty.getFieldName(), root, persistentProperty); + persistentProperty.getFieldName(), root, persistentProperty); if (!indexDefinitions.isEmpty()) { indexes.addAll(indexDefinitions); } } private List createIndexDefinitionHolderForProperty(final String dotPath, - final CouchbasePersistentEntity persistentEntity, - final CouchbasePersistentProperty persistentProperty) { + final CouchbasePersistentEntity persistentEntity, final CouchbasePersistentProperty persistentProperty) { List indices = new ArrayList<>(); @@ -86,7 +82,7 @@ public class CouchbasePersistentEntityIndexResolver implements QueryIndexResolve } if (persistentEntity.isAnnotationPresent(CompositeQueryIndex.class) - || persistentEntity.isAnnotationPresent(CompositeQueryIndexes.class)) { + || persistentEntity.isAnnotationPresent(CompositeQueryIndexes.class)) { indices.addAll(createCompositeQueryIndexDefinitions(persistentEntity, persistentProperty)); } @@ -95,7 +91,7 @@ public class CouchbasePersistentEntityIndexResolver implements QueryIndexResolve @Nullable protected IndexDefinitionHolder createFieldQueryIndexDefinition(final CouchbasePersistentEntity entity, - final CouchbasePersistentProperty property) { + final CouchbasePersistentProperty property) { QueryIndexed index = property.findAnnotation(QueryIndexed.class); if (index == null) { return null; @@ -113,7 +109,7 @@ public class CouchbasePersistentEntityIndexResolver implements QueryIndexResolve } protected List createCompositeQueryIndexDefinitions(final CouchbasePersistentEntity entity, - final CouchbasePersistentProperty property) { + final CouchbasePersistentProperty property) { List indexAnnotations = new ArrayList<>(); @@ -128,34 +124,22 @@ public class CouchbasePersistentEntityIndexResolver implements QueryIndexResolve String predicate = getPredicate(entityInfo); - - return indexAnnotations - .stream() - .map(ann -> { - List fields = Arrays.asList(ann.fields()); - String fieldsIndexName = String - .join("_", fields) - .toLowerCase() - .replace(" ", "") - .replace("asc", "") + return indexAnnotations.stream().map(ann -> { + List fields = Arrays.asList(ann.fields()); + String fieldsIndexName = String.join("_", fields).toLowerCase().replace(" ", "").replace("asc", "") .replace("desc", ""); - String indexName = "idx_" - + StringUtils.uncapitalize(entity.getType().getSimpleName()) - + "_" - + fieldsIndexName; - return new IndexDefinitionHolder(fields, indexName, predicate); - }) - .collect(Collectors.toList()); + String indexName = "idx_" + StringUtils.uncapitalize(entity.getType().getSimpleName()) + "_" + fieldsIndexName; + return new IndexDefinitionHolder(fields, indexName, predicate); + }).collect(Collectors.toList()); } private String getPredicate(final MappingCouchbaseEntityInformation entityInfo) { String typeKey = operations.getConverter().getTypeKey(); String typeValue = entityInfo.getJavaType().getName(); - return "`" + typeKey + "` = \"" + typeValue + "\""; + return "`" + typeKey + "` = \"" + typeValue + "\""; } - public static class IndexDefinitionHolder implements IndexDefinition { private final List fields; diff --git a/src/main/java/org/springframework/data/couchbase/core/index/IndexDefinition.java b/src/main/java/org/springframework/data/couchbase/core/index/IndexDefinition.java index f8bb4412..911ff80e 100644 --- a/src/main/java/org/springframework/data/couchbase/core/index/IndexDefinition.java +++ b/src/main/java/org/springframework/data/couchbase/core/index/IndexDefinition.java @@ -16,7 +16,6 @@ package org.springframework.data.couchbase.core.index; import java.util.List; -import java.util.Map; /** * @author Jon Brisbin diff --git a/src/main/java/org/springframework/data/couchbase/core/index/QueryIndexResolver.java b/src/main/java/org/springframework/data/couchbase/core/index/QueryIndexResolver.java index 112e529f..27b3f45c 100644 --- a/src/main/java/org/springframework/data/couchbase/core/index/QueryIndexResolver.java +++ b/src/main/java/org/springframework/data/couchbase/core/index/QueryIndexResolver.java @@ -42,8 +42,8 @@ public interface QueryIndexResolver { * @since 2.2 */ static QueryIndexResolver create( - MappingContext, CouchbasePersistentProperty> mappingContext, - CouchbaseOperations operations) { + MappingContext, CouchbasePersistentProperty> mappingContext, + CouchbaseOperations operations) { Assert.notNull(mappingContext, "CouchbaseMappingContext must not be null!"); return new CouchbasePersistentEntityIndexResolver(mappingContext, operations); } diff --git a/src/main/java/org/springframework/data/couchbase/core/query/N1qlSecondaryIndexed.java b/src/main/java/org/springframework/data/couchbase/core/query/N1qlSecondaryIndexed.java index 7e2bd0fb..bafb9cc3 100644 --- a/src/main/java/org/springframework/data/couchbase/core/query/N1qlSecondaryIndexed.java +++ b/src/main/java/org/springframework/data/couchbase/core/query/N1qlSecondaryIndexed.java @@ -24,23 +24,23 @@ import java.lang.annotation.Target; import org.springframework.data.couchbase.repository.CouchbaseRepository; /** - * This annotation is targeted at {@link CouchbaseRepository Repository} interfaces, indicating that - * the framework should ensure a N1QL Secondary Index is present when the repository is instantiated. + * This annotation is targeted at {@link CouchbaseRepository Repository} interfaces, indicating that the framework + * should ensure a N1QL Secondary Index is present when the repository is instantiated. *

- * Said index will relate to the "type" field (the one bearing type information) and restrict on documents - * that match the repository's entity class. + * Said index will relate to the "type" field (the one bearing type information) and restrict on documents that match + * the repository's entity class. *

* Be sure to also use {@link N1qlPrimaryIndexed} to make sure the PRIMARY INDEX is there as well. * * @author Simon Baslé */ -@Target({ElementType.TYPE}) +@Target({ ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) public @interface N1qlSecondaryIndexed { - /** - * the name of the index to be created, in the repository's associated bucket namespace. - */ - String indexName(); + /** + * the name of the index to be created, in the repository's associated bucket namespace. + */ + String indexName(); } diff --git a/src/main/java/org/springframework/data/couchbase/core/query/Query.java b/src/main/java/org/springframework/data/couchbase/core/query/Query.java index 5061012e..80d7f727 100644 --- a/src/main/java/org/springframework/data/couchbase/core/query/Query.java +++ b/src/main/java/org/springframework/data/couchbase/core/query/Query.java @@ -1,20 +1,18 @@ package org.springframework.data.couchbase.core.query; +import java.util.ArrayList; +import java.util.List; + import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.util.Assert; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - public class Query { + private final List criteria = new ArrayList<>(); private long skip; private int limit; private Sort sort = Sort.unsorted(); - private final List criteria = new ArrayList<>(); public Query() {} @@ -27,12 +25,12 @@ public class Query { return this; } - /** - * Set number of documents to skip before returning results. - * - * @param skip - * @return - */ + /** + * Set number of documents to skip before returning results. + * + * @param skip + * @return + */ public Query skip(long skip) { this.skip = skip; return this; @@ -126,5 +124,4 @@ public class Query { return sb.toString(); } - } diff --git a/src/main/java/org/springframework/data/couchbase/core/query/QueryCriteria.java b/src/main/java/org/springframework/data/couchbase/core/query/QueryCriteria.java index 9e1637d7..b321bb2c 100644 --- a/src/main/java/org/springframework/data/couchbase/core/query/QueryCriteria.java +++ b/src/main/java/org/springframework/data/couchbase/core/query/QueryCriteria.java @@ -1,25 +1,23 @@ package org.springframework.data.couchbase.core.query; -import org.springframework.lang.Nullable; - import java.util.ArrayList; import java.util.Formatter; import java.util.LinkedList; import java.util.List; +import org.springframework.lang.Nullable; + public class QueryCriteria implements QueryCriteriaDefinition { + private final String key; /** * Holds the chain itself, the current operator being always the last one. */ private List criteriaChain; - /** * Represents how the chain is hung together, null only for the first element. */ private ChainOperator chainOperator; - - private final String key; private String operator; private Object[] value; private String format; @@ -29,10 +27,11 @@ public class QueryCriteria implements QueryCriteriaDefinition { } QueryCriteria(List chain, String key, Object value, ChainOperator chainOperator) { - this(chain, key, new Object[]{value}, chainOperator, null, null); + this(chain, key, new Object[] { value }, chainOperator, null, null); } - QueryCriteria(List chain, String key, Object[] value, ChainOperator chainOperator, String operator, String format) { + QueryCriteria(List chain, String key, Object[] value, ChainOperator chainOperator, String operator, + String format) { this.criteriaChain = chain; criteriaChain.add(this); this.key = key; @@ -49,6 +48,12 @@ public class QueryCriteria implements QueryCriteriaDefinition { return new QueryCriteria(new ArrayList<>(), key, null, null); } + private static QueryCriteria wrap(QueryCriteria criteria) { + QueryCriteria qc = new QueryCriteria(new LinkedList(), criteria.key, criteria.value, null, + criteria.operator, criteria.format); + return qc; + } + public QueryCriteria and(String key) { return new QueryCriteria(this.criteriaChain, key, null, ChainOperator.AND); } @@ -65,54 +70,43 @@ public class QueryCriteria implements QueryCriteriaDefinition { return new QueryCriteria(this.criteriaChain, key, null, ChainOperator.OR); } - private static QueryCriteria wrap(QueryCriteria criteria) { - QueryCriteria qc = new QueryCriteria( - new LinkedList(), - criteria.key, - criteria.value, - null, - criteria.operator, - criteria.format); - return qc; - } - public QueryCriteria eq(@Nullable Object o) { return is(o); } public QueryCriteria is(@Nullable Object o) { operator = "="; - value = new Object[]{o}; + value = new Object[] { o }; return this; } public QueryCriteria ne(@Nullable Object o) { operator = "!="; - value = new Object[]{o}; + value = new Object[] { o }; return this; } public QueryCriteria lt(@Nullable Object o) { operator = "<"; - value = new Object[]{o}; + value = new Object[] { o }; return this; } public QueryCriteria lte(@Nullable Object o) { operator = "<="; - value = new Object[]{o}; + value = new Object[] { o }; return this; } public QueryCriteria gt(@Nullable Object o) { operator = ">"; - value = new Object[]{o}; + value = new Object[] { o }; return this; } public QueryCriteria gte(@Nullable Object o) { operator = ">="; - value = new Object[]{o}; + value = new Object[] { o }; return this; } @@ -128,7 +122,7 @@ public class QueryCriteria implements QueryCriteriaDefinition { public QueryCriteria plus(@Nullable Object o) { operator = "PLUS"; - value = new Object[]{o}; + value = new Object[] { o }; format = "(%1$s + %3$s)"; return this; } @@ -145,20 +139,20 @@ public class QueryCriteria implements QueryCriteriaDefinition { public QueryCriteria regex(@Nullable Object o) { operator = "REGEXP_LIKE"; - value = new Object[]{o}; + value = new Object[] { o }; format = "regexp_like(%1$s, %3$s)"; return this; } public QueryCriteria containing(@Nullable Object o) { operator = "CONTAINS"; - value = new Object[]{o}; + value = new Object[] { o }; format = "contains(%1$s, %3$s)"; return this; } public QueryCriteria notContaining(@Nullable Object o) { - value = new QueryCriteria[]{wrap(containing(o))}; + value = new QueryCriteria[] { wrap(containing(o)) }; operator = "NOT"; format = format = "not( %3$s )"; return this; @@ -166,13 +160,13 @@ public class QueryCriteria implements QueryCriteriaDefinition { public QueryCriteria like(@Nullable Object o) { operator = "LIKE"; - value = new Object[]{o}; + value = new Object[] { o }; format = "%1$s like %3$s"; return this; } public QueryCriteria notLike(@Nullable Object o) { - value = new QueryCriteria[]{wrap(like(o))}; + value = new QueryCriteria[] { wrap(like(o)) }; operator = "NOT"; format = format = "not( %3$s )"; return (QueryCriteria) this; @@ -222,14 +216,14 @@ public class QueryCriteria implements QueryCriteriaDefinition { public QueryCriteria within(@Nullable Object o) { operator = "WITHIN"; - value = new Object[]{o}; + value = new Object[] { o }; format = "%1$s within $3$s"; return (QueryCriteria) this; } public QueryCriteria between(@Nullable Object o1, @Nullable Object o2) { operator = "BETWEEN"; - value = new Object[]{o1, o2}; + value = new Object[] { o1, o2 }; format = "%1$s between %3$s and %4$s"; return (QueryCriteria) this; } @@ -239,15 +233,16 @@ public class QueryCriteria implements QueryCriteriaDefinition { value = o; StringBuilder sb = new StringBuilder("%1$s in ( [ "); for (int i = 1; i <= value.length; i++) { // format indices start at 1 - if (i > 1) sb.append(", "); - sb.append("%" + (i + 2) + "$s"); // the first is fieldName, second is operator, args start at 3 + if (i > 1) + sb.append(", "); + sb.append("%" + (i + 2) + "$s"); // the first is fieldName, second is operator, args start at 3 } format = sb.append(" ] )").toString(); return (QueryCriteria) this; } public QueryCriteria notIn(@Nullable Object... o) { - value = new QueryCriteria[]{wrap(in(o))}; + value = new QueryCriteria[] { wrap(in(o)) }; operator = "NOT"; format = format = "not( %3$s )"; // field = 1$, operator = 2$, value=$3, $4, ... return (QueryCriteria) this; @@ -261,7 +256,7 @@ public class QueryCriteria implements QueryCriteriaDefinition { } public QueryCriteria FALSE() { - value = new QueryCriteria[]{wrap(TRUE())}; + value = new QueryCriteria[] { wrap(TRUE()) }; operator = "not"; format = format = "not( %3$s )"; return (QueryCriteria) this; @@ -312,7 +307,6 @@ public class QueryCriteria implements QueryCriteriaDefinition { return sb; } - private String maybeWrapValue(Object value) { if (value instanceof String) { return "\"" + value + "\""; @@ -332,8 +326,7 @@ public class QueryCriteria implements QueryCriteriaDefinition { } enum ChainOperator { - AND("and"), - OR("or"); + AND("and"), OR("or"); private final String representation; @@ -347,4 +340,3 @@ public class QueryCriteria implements QueryCriteriaDefinition { } } - diff --git a/src/main/java/org/springframework/data/couchbase/core/query/QueryCriteriaDefinition.java b/src/main/java/org/springframework/data/couchbase/core/query/QueryCriteriaDefinition.java index f29b6732..518996ae 100644 --- a/src/main/java/org/springframework/data/couchbase/core/query/QueryCriteriaDefinition.java +++ b/src/main/java/org/springframework/data/couchbase/core/query/QueryCriteriaDefinition.java @@ -15,8 +15,6 @@ */ package org.springframework.data.couchbase.core.query; -import org.springframework.lang.Nullable; - /** * @author Oliver Gierke * @author Christoph Strobl diff --git a/src/main/java/org/springframework/data/couchbase/repository/CouchbaseRepository.java b/src/main/java/org/springframework/data/couchbase/repository/CouchbaseRepository.java index 19f0ed05..6e8d6b61 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/CouchbaseRepository.java +++ b/src/main/java/org/springframework/data/couchbase/repository/CouchbaseRepository.java @@ -18,7 +18,6 @@ package org.springframework.data.couchbase.repository; import java.util.List; -import org.springframework.data.couchbase.core.CouchbaseOperations; import org.springframework.data.domain.Sort; import org.springframework.data.repository.NoRepositoryBean; import org.springframework.data.repository.PagingAndSortingRepository; diff --git a/src/main/java/org/springframework/data/couchbase/repository/config/ReactiveRepositoryOperationsMapping.java b/src/main/java/org/springframework/data/couchbase/repository/config/ReactiveRepositoryOperationsMapping.java index 9313d018..a1e09d46 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/config/ReactiveRepositoryOperationsMapping.java +++ b/src/main/java/org/springframework/data/couchbase/repository/config/ReactiveRepositoryOperationsMapping.java @@ -100,9 +100,9 @@ public class ReactiveRepositoryOperationsMapping { } /** - * 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. + * 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. * * @param repositoryInterface the repository's interface. * @param domainType the repository's domain type / entity. diff --git a/src/main/java/org/springframework/data/couchbase/repository/query/AbstractN1qlBasedQuery.java b/src/main/java/org/springframework/data/couchbase/repository/query/AbstractN1qlBasedQuery.java index e36288f8..19fd444d 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/query/AbstractN1qlBasedQuery.java +++ b/src/main/java/org/springframework/data/couchbase/repository/query/AbstractN1qlBasedQuery.java @@ -97,7 +97,7 @@ public abstract class AbstractN1qlBasedQuery implements RepositoryQuery { if (queryMethod.hasConsistencyAnnotation()) { return queryMethod.getConsistencyAnnotation().value(); } - + return getCouchbaseOperations().getDefaultConsistency().n1qlConsistency();*/ } diff --git a/src/main/java/org/springframework/data/couchbase/repository/query/CouchbaseQueryMethod.java b/src/main/java/org/springframework/data/couchbase/repository/query/CouchbaseQueryMethod.java index 734a711d..0cbe6f94 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/query/CouchbaseQueryMethod.java +++ b/src/main/java/org/springframework/data/couchbase/repository/query/CouchbaseQueryMethod.java @@ -153,8 +153,8 @@ public class CouchbaseQueryMethod extends QueryMethod { } /** - * Returns the query string declared in a {@link Query} annotation or {@literal null} if neither the annotation - * found nor the attribute was specified. + * Returns the query string declared in a {@link Query} annotation or {@literal null} if neither the annotation found + * nor the attribute was specified. * * @return the query statement if present. */ diff --git a/src/main/java/org/springframework/data/couchbase/repository/query/N1qlQueryCreator.java b/src/main/java/org/springframework/data/couchbase/repository/query/N1qlQueryCreator.java index f9673258..23c9c544 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/query/N1qlQueryCreator.java +++ b/src/main/java/org/springframework/data/couchbase/repository/query/N1qlQueryCreator.java @@ -1,8 +1,12 @@ package org.springframework.data.couchbase.repository.query; +import static org.springframework.data.couchbase.core.query.QueryCriteria.*; + +import java.util.Iterator; + import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty; -import org.springframework.data.couchbase.core.query.QueryCriteria; import org.springframework.data.couchbase.core.query.Query; +import org.springframework.data.couchbase.core.query.QueryCriteria; import org.springframework.data.domain.Sort; import org.springframework.data.mapping.PersistentPropertyPath; import org.springframework.data.mapping.context.MappingContext; @@ -11,17 +15,13 @@ import org.springframework.data.repository.query.parser.AbstractQueryCreator; import org.springframework.data.repository.query.parser.Part; import org.springframework.data.repository.query.parser.PartTree; -import java.util.Iterator; - -import static org.springframework.data.couchbase.core.query.QueryCriteria.*; - public class N1qlQueryCreator extends AbstractQueryCreator { private final ParameterAccessor accessor; private final MappingContext context; public N1qlQueryCreator(final PartTree tree, final ParameterAccessor accessor, - final MappingContext context) { + final MappingContext context) { super(tree, accessor); this.accessor = accessor; this.context = context; @@ -57,13 +57,13 @@ public class N1qlQueryCreator extends AbstractQueryCreator } private QueryCriteria from(final Part part, final CouchbasePersistentProperty property, final QueryCriteria criteria, - final Iterator parameters) { + final Iterator parameters) { final Part.Type type = part.getType(); -/* - NEAR(new String[]{"IsNear", "Near"}), - WITHIN(new String[]{"IsWithin", "Within"}), - */ + /* + NEAR(new String[]{"IsNear", "Near"}), + WITHIN(new String[]{"IsWithin", "Within"}), + */ switch (type) { case GREATER_THAN: case AFTER: diff --git a/src/main/java/org/springframework/data/couchbase/repository/query/N1qlRepositoryQueryExecutor.java b/src/main/java/org/springframework/data/couchbase/repository/query/N1qlRepositoryQueryExecutor.java index 1bffa9bd..c7ba7af4 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/query/N1qlRepositoryQueryExecutor.java +++ b/src/main/java/org/springframework/data/couchbase/repository/query/N1qlRepositoryQueryExecutor.java @@ -1,5 +1,7 @@ package org.springframework.data.couchbase.repository.query; +import java.util.List; + import org.springframework.data.couchbase.core.CouchbaseOperations; import org.springframework.data.couchbase.core.query.Query; import org.springframework.data.repository.query.ParameterAccessor; @@ -7,8 +9,6 @@ import org.springframework.data.repository.query.ParametersParameterAccessor; import org.springframework.data.repository.query.QueryMethod; import org.springframework.data.repository.query.parser.PartTree; -import java.util.List; - public class N1qlRepositoryQueryExecutor { private final CouchbaseOperations operations; diff --git a/src/main/java/org/springframework/data/couchbase/repository/query/OldN1qlQueryCreator.java b/src/main/java/org/springframework/data/couchbase/repository/query/OldN1qlQueryCreator.java index 73102b06..0bda1358 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/query/OldN1qlQueryCreator.java +++ b/src/main/java/org/springframework/data/couchbase/repository/query/OldN1qlQueryCreator.java @@ -91,7 +91,7 @@ public class OldN1qlQueryCreator extends AbstractQueryCreator"SELECT * FROM test WHERE test = true AND #{{@value SPEL_FILTER}}". */ public static final String SPEL_FILTER = "#" + SPEL_PREFIX + ".filter"; @@ -97,6 +97,7 @@ public class StringBasedN1qlQueryParser { private final N1qlSpelValues statementContext; private final N1qlSpelValues countContext; private final CouchbaseConverter couchbaseConverter; + public StringBasedN1qlQueryParser(String statement, QueryMethod queryMethod, String bucketName, CouchbaseConverter couchbaseConverter, String typeField, Class typeValue) { this.statement = statement; diff --git a/src/main/java/org/springframework/data/couchbase/repository/support/CouchbaseRepositoryFactory.java b/src/main/java/org/springframework/data/couchbase/repository/support/CouchbaseRepositoryFactory.java index 9f940339..f00c0661 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/support/CouchbaseRepositoryFactory.java +++ b/src/main/java/org/springframework/data/couchbase/repository/support/CouchbaseRepositoryFactory.java @@ -25,10 +25,7 @@ import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty; import org.springframework.data.couchbase.repository.config.RepositoryOperationsMapping; import org.springframework.data.couchbase.repository.query.CouchbaseEntityInformation; -import org.springframework.data.couchbase.repository.query.CouchbaseQueryMethod; import org.springframework.data.couchbase.repository.query.CouchbaseRepositoryQuery; -import org.springframework.data.couchbase.repository.query.PartTreeN1qlBasedQuery; -import org.springframework.data.couchbase.repository.query.StringN1qlBasedQuery; import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.projection.ProjectionFactory; import org.springframework.data.repository.core.NamedQueries; @@ -161,9 +158,9 @@ public class CouchbaseRepositoryFactory extends RepositoryFactorySupport { /*CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod(method, metadata, factory, mappingContext); String namedQueryName = queryMethod.getNamedQueryName(); - + if (queryMethod.hasN1qlAnnotation()) { - + if (queryMethod.hasInlineN1qlQuery()) { return new StringN1qlBasedQuery(queryMethod.getInlineN1qlQuery(), queryMethod, couchbaseOperations, SPEL_PARSER, evaluationContextProvider); @@ -172,9 +169,9 @@ public class CouchbaseRepositoryFactory extends RepositoryFactorySupport { return new StringN1qlBasedQuery(namedQuery, queryMethod, couchbaseOperations, SPEL_PARSER, evaluationContextProvider); } - + } - + return new PartTreeN1qlBasedQuery(queryMethod, couchbaseOperations);*/ } } diff --git a/src/main/java/org/springframework/data/couchbase/repository/support/ReactiveCouchbaseRepositoryFactory.java b/src/main/java/org/springframework/data/couchbase/repository/support/ReactiveCouchbaseRepositoryFactory.java index ef13c520..54c9db63 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/support/ReactiveCouchbaseRepositoryFactory.java +++ b/src/main/java/org/springframework/data/couchbase/repository/support/ReactiveCouchbaseRepositoryFactory.java @@ -19,17 +19,12 @@ 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; import org.springframework.data.couchbase.repository.query.CouchbaseEntityInformation; -import org.springframework.data.couchbase.repository.query.CouchbaseQueryMethod; -import org.springframework.data.couchbase.repository.query.CouchbaseRepositoryQuery; import org.springframework.data.couchbase.repository.query.ReactiveCouchbaseRepositoryQuery; -import org.springframework.data.couchbase.repository.query.ReactivePartTreeN1qlBasedQuery; -import org.springframework.data.couchbase.repository.query.ReactiveStringN1qlBasedQuery; import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.projection.ProjectionFactory; import org.springframework.data.repository.core.NamedQueries; @@ -95,7 +90,7 @@ public class ReactiveCouchbaseRepositoryFactory extends ReactiveRepositoryFactor @Override public CouchbaseEntityInformation getEntityInformation(Class domainClass) { CouchbasePersistentEntity entity = (CouchbasePersistentEntity) mappingContext - .getRequiredPersistentEntity(domainClass); + .getRequiredPersistentEntity(domainClass); return new MappingCouchbaseEntityInformation<>(entity); } @@ -110,11 +105,11 @@ public class ReactiveCouchbaseRepositoryFactory extends ReactiveRepositoryFactor */ @Override protected final Object getTargetRepository(final RepositoryInformation metadata) { - ReactiveCouchbaseOperations couchbaseOperations = couchbaseOperationsMapping.resolve(metadata.getRepositoryInterface(), - metadata.getDomainType()); + ReactiveCouchbaseOperations couchbaseOperations = couchbaseOperationsMapping + .resolve(metadata.getRepositoryInterface(), metadata.getDomainType()); CouchbaseEntityInformation entityInformation = getEntityInformation(metadata.getDomainType()); SimpleReactiveCouchbaseRepository repository = getTargetRepositoryViaReflection(metadata, entityInformation, - couchbaseOperations); + couchbaseOperations); repository.setRepositoryMethodMetadata(crudMethodMetadataPostProcessor.getCrudMethodMetadata()); return repository; } @@ -154,7 +149,7 @@ public class ReactiveCouchbaseRepositoryFactory extends ReactiveRepositoryFactor public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory, NamedQueries namedQueries) { final ReactiveCouchbaseOperations couchbaseOperations = couchbaseOperationsMapping - .resolve(metadata.getRepositoryInterface(), metadata.getDomainType()); + .resolve(metadata.getRepositoryInterface(), metadata.getDomainType()); return new ReactiveCouchbaseRepositoryQuery(couchbaseOperations, new QueryMethod(method, metadata, factory)); } diff --git a/src/main/java/org/springframework/data/couchbase/repository/support/ReactiveCouchbaseRepositoryFactoryBean.java b/src/main/java/org/springframework/data/couchbase/repository/support/ReactiveCouchbaseRepositoryFactoryBean.java index bafa69ca..6b76f765 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/support/ReactiveCouchbaseRepositoryFactoryBean.java +++ b/src/main/java/org/springframework/data/couchbase/repository/support/ReactiveCouchbaseRepositoryFactoryBean.java @@ -54,7 +54,8 @@ public class ReactiveCouchbaseRepositoryFactoryBean, setReactiveCouchbaseOperationsMapping(new ReactiveRepositoryOperationsMapping(reactiveCouchbaseOperations)); } - public void setReactiveCouchbaseOperationsMapping(final ReactiveRepositoryOperationsMapping couchbaseOperationsMapping) { + public void setReactiveCouchbaseOperationsMapping( + final ReactiveRepositoryOperationsMapping couchbaseOperationsMapping) { this.couchbaseOperationsMapping = couchbaseOperationsMapping; setMappingContext(couchbaseOperationsMapping.getMappingContext()); } diff --git a/src/main/java/org/springframework/data/couchbase/repository/support/SimpleReactiveCouchbaseRepository.java b/src/main/java/org/springframework/data/couchbase/repository/support/SimpleReactiveCouchbaseRepository.java index fcf7e379..6acb8f60 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/support/SimpleReactiveCouchbaseRepository.java +++ b/src/main/java/org/springframework/data/couchbase/repository/support/SimpleReactiveCouchbaseRepository.java @@ -16,7 +16,6 @@ package org.springframework.data.couchbase.repository.support; -import com.couchbase.client.java.query.QueryScanConsistency; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -34,6 +33,8 @@ import org.springframework.data.domain.Sort; import org.springframework.data.util.Streamable; import org.springframework.util.Assert; +import com.couchbase.client.java.query.QueryScanConsistency; + /** * Reactive repository base implementation for Couchbase. * @@ -199,7 +200,8 @@ public class SimpleReactiveCouchbaseRepository implements ReactiveCouchba } private Flux findAll(final Query query) { - return operations.findByQuery(entityInformation.getJavaType()).consistentWith(buildQueryScanConsistency()).matching(query).all(); + return operations.findByQuery(entityInformation.getJavaType()).consistentWith(buildQueryScanConsistency()) + .matching(query).all(); } private QueryScanConsistency buildQueryScanConsistency() { diff --git a/src/main/java/org/springframework/data/couchbase/repository/support/ViewMetadataProvider.java b/src/main/java/org/springframework/data/couchbase/repository/support/ViewMetadataProvider.java index 654f1d66..091992e6 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/support/ViewMetadataProvider.java +++ b/src/main/java/org/springframework/data/couchbase/repository/support/ViewMetadataProvider.java @@ -24,11 +24,11 @@ import org.springframework.data.couchbase.core.query.View; */ public interface ViewMetadataProvider { - /** - * Returns the {@link View} to be used. - * - * @return the View, or null if the method hasn't been annotated with @View. - */ - View getView(); + /** + * Returns the {@link View} to be used. + * + * @return the View, or null if the method hasn't been annotated with @View. + */ + View getView(); } diff --git a/src/main/java/org/springframework/data/couchbase/repository/support/ViewPostProcessor.java b/src/main/java/org/springframework/data/couchbase/repository/support/ViewPostProcessor.java index e3e6db9b..34851e30 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/support/ViewPostProcessor.java +++ b/src/main/java/org/springframework/data/couchbase/repository/support/ViewPostProcessor.java @@ -16,6 +16,10 @@ package org.springframework.data.couchbase.repository.support; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.springframework.aop.framework.ProxyFactory; @@ -26,91 +30,87 @@ import org.springframework.data.couchbase.core.query.View; import org.springframework.data.repository.core.RepositoryInformation; import org.springframework.data.repository.core.support.RepositoryProxyPostProcessor; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; - /** - * {@link RepositoryProxyPostProcessor} that sets up an interceptor to read {@link View} information from the - * invoked method. This is necessary to allow redeclaration of CRUD methods in repository interfaces and configure - * view information on them. + * {@link RepositoryProxyPostProcessor} that sets up an interceptor to read {@link View} information from the invoked + * method. This is necessary to allow redeclaration of CRUD methods in repository interfaces and configure view + * information on them. * * @author David Harrigan * @author Oliver Gierke */ public enum ViewPostProcessor implements RepositoryProxyPostProcessor { - INSTANCE; + INSTANCE; - private static final ThreadLocal> VIEW_METADATA = new NamedThreadLocal>("View Metadata"); + private static final ThreadLocal> VIEW_METADATA = new NamedThreadLocal>( + "View Metadata"); - /* - * (non-Javadoc) - * @see org.springframework.data.repository.core.support.RepositoryProxyPostProcessor#postProcess(org.springframework.aop.framework.ProxyFactory, org.springframework.data.repository.core.RepositoryInformation) - */ - @Override - public void postProcess(ProxyFactory factory, RepositoryInformation repositoryInformation) { - - factory.addAdvice(ExposeInvocationInterceptor.INSTANCE); - factory.addAdvice(ViewInterceptor.INSTANCE); - } + /* + * (non-Javadoc) + * @see org.springframework.data.repository.core.support.RepositoryProxyPostProcessor#postProcess(org.springframework.aop.framework.ProxyFactory, org.springframework.data.repository.core.RepositoryInformation) + */ + @Override + public void postProcess(ProxyFactory factory, RepositoryInformation repositoryInformation) { - public ViewMetadataProvider getViewMetadataProvider() { - return ThreadBoundViewMetadata.INSTANCE; - } + factory.addAdvice(ExposeInvocationInterceptor.INSTANCE); + factory.addAdvice(ViewInterceptor.INSTANCE); + } - /** - * {@link MethodInterceptor} to inspect the currently invoked {@link Method} for a {@link View} annotation. - *

- * If a View annotation is found, it will bind it to a locally held ThreadLocal for later lookup in the - * SimpleCouchbaseRepository class. - * - * @author David Harrigan. - */ - static enum ViewInterceptor implements MethodInterceptor { + public ViewMetadataProvider getViewMetadataProvider() { + return ThreadBoundViewMetadata.INSTANCE; + } - INSTANCE; + /** + * {@link MethodInterceptor} to inspect the currently invoked {@link Method} for a {@link View} annotation. + *

+ * If a View annotation is found, it will bind it to a locally held ThreadLocal for later lookup in the + * SimpleCouchbaseRepository class. + * + * @author David Harrigan. + */ + static enum ViewInterceptor implements MethodInterceptor { - @Override - public Object invoke(final MethodInvocation invocation) throws Throwable { + INSTANCE; - final View view = AnnotationUtils.getAnnotation(invocation.getMethod(), View.class); - if (view != null) { - Map map = VIEW_METADATA.get(); - if (map == null) { - map = new HashMap(); - VIEW_METADATA.set(map); - } - map.put(invocation.getMethod(), view); - } - try { - return invocation.proceed(); - } finally { - VIEW_METADATA.remove(); - } + @Override + public Object invoke(final MethodInvocation invocation) throws Throwable { - } + final View view = AnnotationUtils.getAnnotation(invocation.getMethod(), View.class); + if (view != null) { + Map map = VIEW_METADATA.get(); + if (map == null) { + map = new HashMap(); + VIEW_METADATA.set(map); + } + map.put(invocation.getMethod(), view); + } + try { + return invocation.proceed(); + } finally { + VIEW_METADATA.remove(); + } - } + } - /** - * {@link ViewMetadataProvider} that looks up a bound View from a locally held ThreadLocal, using - * the current method invocationas as the key. If not bound View is found, a null is returned. - * - * @author David Harrigan. - */ - private static enum ThreadBoundViewMetadata implements ViewMetadataProvider { + } - INSTANCE; + /** + * {@link ViewMetadataProvider} that looks up a bound View from a locally held ThreadLocal, using the current method + * invocationas as the key. If not bound View is found, a null is returned. + * + * @author David Harrigan. + */ + private static enum ThreadBoundViewMetadata implements ViewMetadataProvider { - @Override - public View getView() { - final MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation(); - final Map map = VIEW_METADATA.get(); - return (map == null) ? null : (View) map.get(invocation.getMethod()); - } + INSTANCE; - } + @Override + public View getView() { + final MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation(); + final Map map = VIEW_METADATA.get(); + return (map == null) ? null : (View) map.get(invocation.getMethod()); + } + } } diff --git a/src/main/kotlin/org/springframework/data/couchbase/core/CouchbaseOperationsExtensions.kt b/src/main/kotlin/org/springframework/data/couchbase/core/CouchbaseOperationsExtensions.kt deleted file mode 100644 index 630387c9..00000000 --- a/src/main/kotlin/org/springframework/data/couchbase/core/CouchbaseOperationsExtensions.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2018-2019 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 - * - * https://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.couchbase.core - -/** - * Kotlin extensions for [CouchbaseOperations] - * - * @author Subhashni Balakrishnan - */ \ No newline at end of file diff --git a/src/main/kotlin/org/springframework/data/couchbase/core/ReactiveJavaCouchbaseOperationsExtensions.kt b/src/main/kotlin/org/springframework/data/couchbase/core/ReactiveJavaCouchbaseOperationsExtensions.kt deleted file mode 100644 index 0221abe5..00000000 --- a/src/main/kotlin/org/springframework/data/couchbase/core/ReactiveJavaCouchbaseOperationsExtensions.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2018-2019 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 - * - * https://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.couchbase.core - -/** - * Kotlin extensions for [ReactiveJavaCouchbaseOperations] - * - * @author Subhashni Balakrishnan - */