Skip to content

Rework the handling of annotations for scope and collection. #1467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors
* Copyright 2012-2022 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.
Expand All @@ -19,6 +19,7 @@
import java.util.Map;

import org.springframework.data.couchbase.core.ReactiveExistsByIdOperationSupport.ReactiveExistsByIdSupport;
import org.springframework.data.couchbase.core.query.OptionsBuilder;
import org.springframework.util.Assert;

import com.couchbase.client.java.kv.ExistsOptions;
Expand All @@ -39,7 +40,8 @@ public ExecutableExistsById existsById() {

@Override
public ExecutableExistsById existsById(Class<?> domainType) {
return new ExecutableExistsByIdSupport(template, domainType, null, null, null);
return new ExecutableExistsByIdSupport(template, domainType, OptionsBuilder.getScopeFrom(domainType),
OptionsBuilder.getCollectionFrom(domainType), null);
}

static class ExecutableExistsByIdSupport implements ExecutableExistsById {
Expand Down Expand Up @@ -74,7 +76,8 @@ public Map<String, Boolean> all(final Collection<String> ids) {

@Override
public ExistsByIdWithOptions inCollection(final String collection) {
return new ExecutableExistsByIdSupport(template, domainType, scope, collection, options);
return new ExecutableExistsByIdSupport(template, domainType, scope,
collection != null ? collection : this.collection, options);
}

@Override
Expand All @@ -85,7 +88,8 @@ public TerminatingExistsById withOptions(final ExistsOptions options) {

@Override
public ExistsByIdInCollection inScope(final String scope) {
return new ExecutableExistsByIdSupport(template, domainType, scope, collection, options);
return new ExecutableExistsByIdSupport(template, domainType, scope != null ? scope : this.scope, collection,
options);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors
* Copyright 2012-2022 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.
Expand All @@ -20,6 +20,7 @@

import org.springframework.data.couchbase.core.ReactiveFindByAnalyticsOperationSupport.ReactiveFindByAnalyticsSupport;
import org.springframework.data.couchbase.core.query.AnalyticsQuery;
import org.springframework.data.couchbase.core.query.OptionsBuilder;
import org.springframework.util.Assert;

import com.couchbase.client.java.analytics.AnalyticsOptions;
Expand All @@ -37,7 +38,8 @@ public ExecutableFindByAnalyticsOperationSupport(final CouchbaseTemplate templat

@Override
public <T> ExecutableFindByAnalytics<T> findByAnalytics(final Class<T> domainType) {
return new ExecutableFindByAnalyticsSupport<>(template, domainType, domainType, ALL_QUERY, null, null, null, null);
return new ExecutableFindByAnalyticsSupport<>(template, domainType, domainType, ALL_QUERY, null,
OptionsBuilder.getScopeFrom(domainType), OptionsBuilder.getCollectionFrom(domainType), null);
}

static class ExecutableFindByAnalyticsSupport<T> implements ExecutableFindByAnalytics<T> {
Expand Down Expand Up @@ -97,14 +99,14 @@ public FindByAnalyticsWithQuery<T> withOptions(final AnalyticsOptions options) {

@Override
public FindByAnalyticsInCollection<T> inScope(final String scope) {
return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope,
collection, options);
return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency,
scope != null ? scope : this.scope, collection, options);
}

@Override
public FindByAnalyticsWithConsistency<T> inCollection(final String collection) {
return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope,
collection, options);
collection != null ? collection : this.collection, options);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors
* Copyright 2012-2022 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.
Expand All @@ -21,6 +21,7 @@
import java.util.List;

import org.springframework.data.couchbase.core.ReactiveFindByIdOperationSupport.ReactiveFindByIdSupport;
import org.springframework.data.couchbase.core.query.OptionsBuilder;
import org.springframework.util.Assert;

import com.couchbase.client.java.kv.GetOptions;
Expand All @@ -35,7 +36,8 @@ public class ExecutableFindByIdOperationSupport implements ExecutableFindByIdOpe

@Override
public <T> ExecutableFindById<T> findById(Class<T> domainType) {
return new ExecutableFindByIdSupport<>(template, domainType, null, null, null, null, null);
return new ExecutableFindByIdSupport<>(template, domainType, OptionsBuilder.getScopeFrom(domainType),
OptionsBuilder.getCollectionFrom(domainType),null, null, null);
}

static class ExecutableFindByIdSupport<T> implements ExecutableFindById<T> {
Expand Down Expand Up @@ -80,12 +82,12 @@ public TerminatingFindById<T> withOptions(final GetOptions options) {

@Override
public FindByIdWithOptions<T> inCollection(final String collection) {
return new ExecutableFindByIdSupport<>(template, domainType, scope, collection, options, fields, expiry);
return new ExecutableFindByIdSupport<>(template, domainType, scope, collection != null ? collection : this.collection, options, fields, expiry);
}

@Override
public FindByIdInCollection<T> inScope(final String scope) {
return new ExecutableFindByIdSupport<>(template, domainType, scope, collection, options, fields, expiry);
return new ExecutableFindByIdSupport<>(template, domainType, scope != null ? scope : this.scope, collection, options, fields, expiry);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors
* Copyright 2012-2022 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.
Expand All @@ -19,6 +19,7 @@
import java.util.stream.Stream;

import org.springframework.data.couchbase.core.ReactiveFindByQueryOperationSupport.ReactiveFindByQuerySupport;
import org.springframework.data.couchbase.core.query.OptionsBuilder;
import org.springframework.data.couchbase.core.query.Query;
import org.springframework.util.Assert;

Expand All @@ -43,8 +44,8 @@ public ExecutableFindByQueryOperationSupport(final CouchbaseTemplate template) {

@Override
public <T> ExecutableFindByQuery<T> findByQuery(final Class<T> domainType) {
return new ExecutableFindByQuerySupport<T>(template, domainType, domainType, ALL_QUERY, null, null, null, null,
null, null);
return new ExecutableFindByQuerySupport<T>(template, domainType, domainType, ALL_QUERY, null,
OptionsBuilder.getScopeFrom(domainType), OptionsBuilder.getCollectionFrom(domainType), null, null, null);
}

static class ExecutableFindByQuerySupport<T> implements ExecutableFindByQuery<T> {
Expand Down Expand Up @@ -174,14 +175,14 @@ public TerminatingFindByQuery<T> withOptions(final QueryOptions options) {

@Override
public FindByQueryInCollection<T> inScope(final String scope) {
return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, scope,
collection, options, distinctFields, fields);
return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency,
scope != null ? scope : this.scope, collection, options, distinctFields, fields);
}

@Override
public FindByQueryWithConsistency<T> inCollection(final String collection) {
return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, scope,
collection, options, distinctFields, fields);
collection != null ? collection : this.collection, options, distinctFields, fields);
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors
* Copyright 2012-2022 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.
Expand All @@ -18,6 +18,7 @@
import java.util.Collection;

import org.springframework.data.couchbase.core.ReactiveFindFromReplicasByIdOperationSupport.ReactiveFindFromReplicasByIdSupport;
import org.springframework.data.couchbase.core.query.OptionsBuilder;
import org.springframework.util.Assert;

import com.couchbase.client.java.kv.GetAnyReplicaOptions;
Expand All @@ -32,7 +33,8 @@ public class ExecutableFindFromReplicasByIdOperationSupport implements Executabl

@Override
public <T> ExecutableFindFromReplicasById<T> findFromReplicasById(Class<T> domainType) {
return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, domainType, null, null, null);
return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, domainType,
OptionsBuilder.getScopeFrom(domainType), OptionsBuilder.getCollectionFrom(domainType), null);
}

static class ExecutableFindFromReplicasByIdSupport<T> implements ExecutableFindFromReplicasById<T> {
Expand Down Expand Up @@ -75,12 +77,14 @@ public TerminatingFindFromReplicasById<T> withOptions(final GetAnyReplicaOptions

@Override
public FindFromReplicasByIdWithOptions<T> inCollection(final String collection) {
return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, returnType, scope, collection, options);
return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, returnType, scope,
collection != null ? collection : this.collection, options);
}

@Override
public FindFromReplicasByIdInCollection<T> inScope(final String scope) {
return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, returnType, scope, collection, options);
return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, returnType,
scope != null ? scope : this.scope, collection, options);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Collection;

import org.springframework.data.couchbase.core.ReactiveInsertByIdOperationSupport.ReactiveInsertByIdSupport;
import org.springframework.data.couchbase.core.query.OptionsBuilder;
import org.springframework.util.Assert;

import com.couchbase.client.core.msg.kv.DurabilityLevel;
Expand All @@ -37,8 +38,9 @@ public ExecutableInsertByIdOperationSupport(final CouchbaseTemplate template) {
@Override
public <T> ExecutableInsertById<T> insertById(final Class<T> domainType) {
Assert.notNull(domainType, "DomainType must not be null!");
return new ExecutableInsertByIdSupport<>(template, domainType, null, null, null, PersistTo.NONE, ReplicateTo.NONE,
DurabilityLevel.NONE, null);
return new ExecutableInsertByIdSupport<>(template, domainType, OptionsBuilder.getScopeFrom(domainType),
OptionsBuilder.getCollectionFrom(domainType), null, PersistTo.NONE, ReplicateTo.NONE, DurabilityLevel.NONE,
null);
}

static class ExecutableInsertByIdSupport<T> implements ExecutableInsertById<T> {
Expand Down Expand Up @@ -89,14 +91,14 @@ public TerminatingInsertById<T> withOptions(final InsertOptions options) {

@Override
public InsertByIdInCollection<T> inScope(final String scope) {
return new ExecutableInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,
durabilityLevel, expiry);
return new ExecutableInsertByIdSupport<>(template, domainType, scope != null ? scope : this.scope, collection,
options, persistTo, replicateTo, durabilityLevel, expiry);
}

@Override
public InsertByIdWithOptions<T> inCollection(final String collection) {
return new ExecutableInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,
durabilityLevel, expiry);
return new ExecutableInsertByIdSupport<>(template, domainType, scope,
collection != null ? collection : this.collection, options, persistTo, replicateTo, durabilityLevel, expiry);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;

import org.springframework.data.couchbase.core.ReactiveRemoveByIdOperationSupport.ReactiveRemoveByIdSupport;
import org.springframework.data.couchbase.core.query.OptionsBuilder;
import org.springframework.util.Assert;

import com.couchbase.client.core.msg.kv.DurabilityLevel;
Expand All @@ -42,7 +43,9 @@ public ExecutableRemoveById removeById() {

@Override
public ExecutableRemoveById removeById(Class<?> domainType) {
return new ExecutableRemoveByIdSupport(template, domainType, null, null, null, PersistTo.NONE, ReplicateTo.NONE,

return new ExecutableRemoveByIdSupport(template, domainType, OptionsBuilder.getScopeFrom(domainType),
OptionsBuilder.getCollectionFrom(domainType), null, PersistTo.NONE, ReplicateTo.NONE,
DurabilityLevel.NONE, null);
}

Expand Down Expand Up @@ -87,7 +90,7 @@ public List<RemoveResult> all(final Collection<String> ids) {

@Override
public RemoveByIdWithOptions inCollection(final String collection) {
return new ExecutableRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo,
return new ExecutableRemoveByIdSupport(template, domainType, scope, collection != null ? collection : this.collection, options, persistTo, replicateTo,
durabilityLevel, cas);
}

Expand Down Expand Up @@ -115,7 +118,7 @@ public TerminatingRemoveById withOptions(final RemoveOptions options) {

@Override
public RemoveByIdInCollection inScope(final String scope) {
return new ExecutableRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo,
return new ExecutableRemoveByIdSupport(template, domainType, scope != null ? scope : this.scope, collection, options, persistTo, replicateTo,
durabilityLevel, cas);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors
* Copyright 2012-2022 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.
Expand All @@ -18,6 +18,7 @@
import java.util.List;

import org.springframework.data.couchbase.core.ReactiveRemoveByQueryOperationSupport.ReactiveRemoveByQuerySupport;
import org.springframework.data.couchbase.core.query.OptionsBuilder;
import org.springframework.data.couchbase.core.query.Query;
import org.springframework.util.Assert;

Expand All @@ -36,7 +37,8 @@ public ExecutableRemoveByQueryOperationSupport(final CouchbaseTemplate template)

@Override
public <T> ExecutableRemoveByQuery<T> removeByQuery(Class<T> domainType) {
return new ExecutableRemoveByQuerySupport<>(template, domainType, ALL_QUERY, null, null, null, null);
return new ExecutableRemoveByQuerySupport<>(template, domainType, ALL_QUERY, null,
OptionsBuilder.getScopeFrom(domainType), OptionsBuilder.getCollectionFrom(domainType), null);
}

static class ExecutableRemoveByQuerySupport<T> implements ExecutableRemoveByQuery<T> {
Expand Down Expand Up @@ -89,8 +91,8 @@ public RemoveByQueryConsistentWith<T> withConsistency(final QueryScanConsistency

@Override
public RemoveByQueryWithConsistency<T> inCollection(final String collection) {
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency, scope, collection,
options);
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency, scope,
collection != null ? collection : this.collection, options);
}

@Override
Expand All @@ -102,8 +104,8 @@ public RemoveByQueryWithQuery<T> withOptions(final QueryOptions options) {

@Override
public RemoveByQueryInCollection<T> inScope(final String scope) {
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency, scope, collection,
options);
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency,
scope != null ? scope : this.scope, collection, options);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors
* Copyright 2012-2022 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.
Expand All @@ -19,6 +19,7 @@
import java.util.Collection;

import org.springframework.data.couchbase.core.ReactiveReplaceByIdOperationSupport.ReactiveReplaceByIdSupport;
import org.springframework.data.couchbase.core.query.OptionsBuilder;
import org.springframework.util.Assert;

import com.couchbase.client.core.msg.kv.DurabilityLevel;
Expand All @@ -37,8 +38,9 @@ public ExecutableReplaceByIdOperationSupport(final CouchbaseTemplate template) {
@Override
public <T> ExecutableReplaceById<T> replaceById(final Class<T> domainType) {
Assert.notNull(domainType, "DomainType must not be null!");
return new ExecutableReplaceByIdSupport<>(template, domainType, null, null, null, PersistTo.NONE, ReplicateTo.NONE,
DurabilityLevel.NONE, null);
return new ExecutableReplaceByIdSupport<>(template, domainType, OptionsBuilder.getScopeFrom(domainType),
OptionsBuilder.getCollectionFrom(domainType), null, PersistTo.NONE, ReplicateTo.NONE, DurabilityLevel.NONE,
null);
}

static class ExecutableReplaceByIdSupport<T> implements ExecutableReplaceById<T> {
Expand Down Expand Up @@ -82,8 +84,8 @@ public Collection<? extends T> all(Collection<? extends T> objects) {

@Override
public ReplaceByIdWithOptions<T> inCollection(final String collection) {
return new ExecutableReplaceByIdSupport<>(template, domainType, scope, collection, options, persistTo,
replicateTo, durabilityLevel, expiry);
return new ExecutableReplaceByIdSupport<>(template, domainType, scope,
collection != null ? collection : this.collection, options, persistTo, replicateTo, durabilityLevel, expiry);
}

@Override
Expand Down Expand Up @@ -117,8 +119,8 @@ public TerminatingReplaceById<T> withOptions(final ReplaceOptions options) {

@Override
public ReplaceByIdInCollection<T> inScope(final String scope) {
return new ExecutableReplaceByIdSupport<>(template, domainType, scope, collection, options, persistTo,
replicateTo, durabilityLevel, expiry);
return new ExecutableReplaceByIdSupport<>(template, domainType, scope != null ? scope : this.scope, collection,
options, persistTo, replicateTo, durabilityLevel, expiry);
}

}
Expand Down
Loading