Skip to content

Commit 19c9e16

Browse files
authored
Make withDurability() return WithScope type for all operations. (#1340)
Some of the operations were mistakenly declared to return a WithCollection type, making it impossible to call the inScope() method. Closes #1329.
1 parent c7693ed commit 19c9e16

13 files changed

+71
-36
lines changed

src/main/java/org/springframework/data/couchbase/core/ExecutableInsertByIdOperation.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors
2+
* Copyright 2012-2022 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -117,10 +117,10 @@ interface InsertByIdInScope<T> extends InsertByIdInCollection<T>, InScope<T> {
117117
interface InsertByIdWithDurability<T> extends InsertByIdInScope<T>, WithDurability<T> {
118118

119119
@Override
120-
InsertByIdInCollection<T> withDurability(DurabilityLevel durabilityLevel);
120+
InsertByIdInScope<T> withDurability(DurabilityLevel durabilityLevel);
121121

122122
@Override
123-
InsertByIdInCollection<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);
123+
InsertByIdInScope<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);
124124

125125
}
126126

src/main/java/org/springframework/data/couchbase/core/ExecutableInsertByIdOperationSupport.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors
2+
* Copyright 2012-2022 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -100,14 +100,14 @@ public InsertByIdWithOptions<T> inCollection(final String collection) {
100100
}
101101

102102
@Override
103-
public InsertByIdInCollection<T> withDurability(final DurabilityLevel durabilityLevel) {
103+
public InsertByIdInScope<T> withDurability(final DurabilityLevel durabilityLevel) {
104104
Assert.notNull(durabilityLevel, "Durability Level must not be null.");
105105
return new ExecutableInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,
106106
durabilityLevel, expiry);
107107
}
108108

109109
@Override
110-
public InsertByIdInCollection<T> withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
110+
public InsertByIdInScope<T> withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
111111
Assert.notNull(persistTo, "PersistTo must not be null.");
112112
Assert.notNull(replicateTo, "ReplicateTo must not be null.");
113113
return new ExecutableInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,

src/main/java/org/springframework/data/couchbase/core/ExecutableRemoveByIdOperation.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors
2+
* Copyright 2012-2022 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -114,10 +114,10 @@ interface RemoveByIdInScope extends RemoveByIdInCollection, InScope<Object> {
114114
interface RemoveByIdWithDurability extends RemoveByIdInScope, WithDurability<RemoveResult> {
115115

116116
@Override
117-
RemoveByIdInCollection withDurability(DurabilityLevel durabilityLevel);
117+
RemoveByIdInScope withDurability(DurabilityLevel durabilityLevel);
118118

119119
@Override
120-
RemoveByIdInCollection withDurability(PersistTo persistTo, ReplicateTo replicateTo);
120+
RemoveByIdInScope withDurability(PersistTo persistTo, ReplicateTo replicateTo);
121121

122122
}
123123

src/main/java/org/springframework/data/couchbase/core/ExecutableRemoveByIdOperationSupport.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors
2+
* Copyright 2012-2022 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -92,14 +92,14 @@ public RemoveByIdWithOptions inCollection(final String collection) {
9292
}
9393

9494
@Override
95-
public RemoveByIdInCollection withDurability(final DurabilityLevel durabilityLevel) {
95+
public RemoveByIdInScope withDurability(final DurabilityLevel durabilityLevel) {
9696
Assert.notNull(durabilityLevel, "Durability Level must not be null.");
9797
return new ExecutableRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo,
9898
durabilityLevel, cas);
9999
}
100100

101101
@Override
102-
public RemoveByIdInCollection withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
102+
public RemoveByIdInScope withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
103103
Assert.notNull(persistTo, "PersistTo must not be null.");
104104
Assert.notNull(replicateTo, "ReplicateTo must not be null.");
105105
return new ExecutableRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo,

src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperation.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors
2+
* Copyright 2012-2022 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -113,10 +113,10 @@ interface InsertByIdInScope<T> extends InsertByIdInCollection<T>, InScope<T> {
113113
interface InsertByIdWithDurability<T> extends InsertByIdInScope<T>, WithDurability<T> {
114114

115115
@Override
116-
InsertByIdInCollection<T> withDurability(DurabilityLevel durabilityLevel);
116+
InsertByIdInScope<T> withDurability(DurabilityLevel durabilityLevel);
117117

118118
@Override
119-
InsertByIdInCollection<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);
119+
InsertByIdInScope<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);
120120

121121
}
122122

src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors
2+
* Copyright 2012-2022 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -125,14 +125,14 @@ public InsertByIdWithOptions<T> inCollection(final String collection) {
125125
}
126126

127127
@Override
128-
public InsertByIdInCollection<T> withDurability(final DurabilityLevel durabilityLevel) {
128+
public InsertByIdInScope<T> withDurability(final DurabilityLevel durabilityLevel) {
129129
Assert.notNull(durabilityLevel, "Durability Level must not be null.");
130130
return new ReactiveInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,
131131
durabilityLevel, expiry, support);
132132
}
133133

134134
@Override
135-
public InsertByIdInCollection<T> withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
135+
public InsertByIdInScope<T> withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
136136
Assert.notNull(persistTo, "PersistTo must not be null.");
137137
Assert.notNull(replicateTo, "ReplicateTo must not be null.");
138138
return new ReactiveInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,

src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperation.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors
2+
* Copyright 2012-2022 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -112,10 +112,10 @@ interface RemoveByIdInScope extends RemoveByIdInCollection, InScope<Object> {
112112

113113
interface RemoveByIdWithDurability extends RemoveByIdInScope, WithDurability<RemoveResult> {
114114
@Override
115-
RemoveByIdInCollection withDurability(DurabilityLevel durabilityLevel);
115+
RemoveByIdInScope withDurability(DurabilityLevel durabilityLevel);
116116

117117
@Override
118-
RemoveByIdInCollection withDurability(PersistTo persistTo, ReplicateTo replicateTo);
118+
RemoveByIdInScope withDurability(PersistTo persistTo, ReplicateTo replicateTo);
119119

120120
}
121121

src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperationSupport.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors
2+
* Copyright 2012-2022 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -105,14 +105,14 @@ private RemoveOptions buildRemoveOptions(RemoveOptions options) {
105105
}
106106

107107
@Override
108-
public RemoveByIdInCollection withDurability(final DurabilityLevel durabilityLevel) {
108+
public RemoveByIdInScope withDurability(final DurabilityLevel durabilityLevel) {
109109
Assert.notNull(durabilityLevel, "Durability Level must not be null.");
110110
return new ReactiveRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo,
111111
durabilityLevel, cas);
112112
}
113113

114114
@Override
115-
public RemoveByIdInCollection withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
115+
public RemoveByIdInScope withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
116116
Assert.notNull(persistTo, "PersistTo must not be null.");
117117
Assert.notNull(replicateTo, "ReplicateTo must not be null.");
118118
return new ReactiveRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo,

src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperation.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors
2+
* Copyright 2012-2022 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -116,9 +116,9 @@ interface ReplaceByIdInScope<T> extends ReplaceByIdInCollection<T>, InScope<Obje
116116

117117
interface ReplaceByIdWithDurability<T> extends ReplaceByIdInScope<T>, WithDurability<T> {
118118

119-
ReplaceByIdInCollection<T> withDurability(DurabilityLevel durabilityLevel);
119+
ReplaceByIdInScope<T> withDurability(DurabilityLevel durabilityLevel);
120120

121-
ReplaceByIdInCollection<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);
121+
ReplaceByIdInScope<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);
122122

123123
}
124124

src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperationSupport.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors
2+
* Copyright 2012-2022 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -126,14 +126,14 @@ public ReplaceByIdInCollection<T> inScope(final String scope) {
126126
}
127127

128128
@Override
129-
public ReplaceByIdInCollection<T> withDurability(final DurabilityLevel durabilityLevel) {
129+
public ReplaceByIdInScope<T> withDurability(final DurabilityLevel durabilityLevel) {
130130
Assert.notNull(durabilityLevel, "Durability Level must not be null.");
131131
return new ReactiveReplaceByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,
132132
durabilityLevel, expiry, support);
133133
}
134134

135135
@Override
136-
public ReplaceByIdInCollection<T> withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
136+
public ReplaceByIdInScope<T> withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
137137
Assert.notNull(persistTo, "PersistTo must not be null.");
138138
Assert.notNull(replicateTo, "ReplicateTo must not be null.");
139139
return new ReactiveReplaceByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,

src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperation.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors
2+
* Copyright 2012-2022 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -118,10 +118,10 @@ interface UpsertByIdInScope<T> extends UpsertByIdInCollection<T>, InScope<Object
118118

119119
interface UpsertByIdWithDurability<T> extends UpsertByIdInScope<T>, WithDurability<T> {
120120
@Override
121-
UpsertByIdInCollection<T> withDurability(DurabilityLevel durabilityLevel);
121+
UpsertByIdInScope<T> withDurability(DurabilityLevel durabilityLevel);
122122

123123
@Override
124-
UpsertByIdInCollection<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);
124+
UpsertByIdInScope<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);
125125

126126
}
127127

src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperationSupport.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors
2+
* Copyright 2012-2022 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -125,14 +125,14 @@ public UpsertByIdInCollection<T> inScope(final String scope) {
125125
}
126126

127127
@Override
128-
public UpsertByIdInCollection<T> withDurability(final DurabilityLevel durabilityLevel) {
128+
public UpsertByIdInScope<T> withDurability(final DurabilityLevel durabilityLevel) {
129129
Assert.notNull(durabilityLevel, "Durability Level must not be null.");
130130
return new ReactiveUpsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,
131131
durabilityLevel, expiry, support);
132132
}
133133

134134
@Override
135-
public UpsertByIdInCollection<T> withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
135+
public UpsertByIdInScope<T> withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
136136
Assert.notNull(persistTo, "PersistTo must not be null.");
137137
Assert.notNull(replicateTo, "ReplicateTo must not be null.");
138138
return new ReactiveUpsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,

src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateQueryCollectionIntegrationTests.java

+35
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.UUID;
3131
import java.util.stream.Collectors;
3232

33+
import com.couchbase.client.core.msg.kv.DurabilityLevel;
3334
import org.junit.jupiter.api.AfterAll;
3435
import org.junit.jupiter.api.AfterEach;
3536
import org.junit.jupiter.api.BeforeAll;
@@ -800,4 +801,38 @@ public void testScopeCollectionRepoWith() {
800801
} catch (DataRetrievalFailureException drfe) {}
801802
}
802803
}
804+
805+
@Test
806+
void testFluentApi() {
807+
User user1 = new User(UUID.randomUUID().toString(), "user1", "user1");
808+
DurabilityLevel dl = DurabilityLevel.NONE;
809+
User result;
810+
RemoveResult rr;
811+
result = couchbaseTemplate.insertById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName)
812+
.one(user1);
813+
assertEquals(user1,result);
814+
result = couchbaseTemplate.upsertById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName)
815+
.one(user1);
816+
assertEquals(user1,result);
817+
result = couchbaseTemplate.replaceById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName)
818+
.one(user1);
819+
assertEquals(user1,result);
820+
rr = couchbaseTemplate.removeById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName)
821+
.one(user1.getId());
822+
assertEquals(rr.getId(), user1.getId());
823+
assertEquals(user1,result);
824+
result = reactiveCouchbaseTemplate.insertById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName)
825+
.one(user1).block();
826+
assertEquals(user1,result);
827+
result = reactiveCouchbaseTemplate.upsertById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName)
828+
.one(user1).block();
829+
assertEquals(user1,result);
830+
result = reactiveCouchbaseTemplate.replaceById(User.class).withDurability(dl).inScope(scopeName)
831+
.inCollection(collectionName).one(user1).block();
832+
assertEquals(user1,result);
833+
rr = reactiveCouchbaseTemplate.removeById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName)
834+
.one(user1.getId()).block();
835+
assertEquals(rr.getId(), user1.getId());
836+
}
837+
803838
}

0 commit comments

Comments
 (0)