Skip to content

Commit 86281fb

Browse files
committed
DATACOUCH-675 - Factor out interfaces for common methods. (#293)
Added interfaces for apis on core objects which are common among many objects. For instance withExpiry and withExpirty on all the insert/replace/upsert/remove objects. The definition of an interface simplyfies testing of all the possible combinations - instead of having four (or eight, counting Reactive), there is one interface to test them all. Co-authored-by: mikereiche <michael.reiche@couchbase.com>
1 parent aaf9073 commit 86281fb

14 files changed

+228
-28
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,32 @@ public interface ExecutableInsertByIdOperation {
2626

2727
<T> ExecutableInsertById<T> insertById(Class<T> domainType);
2828

29-
interface TerminatingInsertById<T> {
29+
interface TerminatingInsertById<T> extends OneAndAll<T>{
3030

31+
@Override
3132
T one(T object);
3233

34+
@Override
3335
Collection<? extends T> all(Collection<? extends T> objects);
3436

3537
}
3638

37-
interface InsertByIdWithCollection<T> extends TerminatingInsertById<T> {
39+
interface InsertByIdWithCollection<T> extends TerminatingInsertById<T>, InCollection<T> {
3840

3941
TerminatingInsertById<T> inCollection(String collection);
4042
}
4143

42-
interface InsertByIdWithDurability<T> extends InsertByIdWithCollection<T> {
44+
interface InsertByIdWithDurability<T> extends InsertByIdWithCollection<T>, WithDurability<T> {
4345

4446
InsertByIdWithCollection<T> withDurability(DurabilityLevel durabilityLevel);
4547

4648
InsertByIdWithCollection<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);
4749

4850
}
4951

50-
interface InsertByIdWithExpiry<T> extends InsertByIdWithDurability<T> {
52+
interface InsertByIdWithExpiry<T> extends InsertByIdWithDurability<T>, WithExpiry<T> {
5153

54+
@Override
5255
InsertByIdWithDurability<T> withExpiry(Duration expiry);
5356
}
5457

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ interface TerminatingRemoveById {
3434

3535
}
3636

37-
interface RemoveByIdWithCollection extends TerminatingRemoveById {
37+
interface RemoveByIdWithCollection extends TerminatingRemoveById, InCollection {
3838

3939
TerminatingRemoveById inCollection(String collection);
4040
}
4141

42-
interface RemoveByIdWithDurability extends RemoveByIdWithCollection {
42+
interface RemoveByIdWithDurability extends RemoveByIdWithCollection, WithDurability {
4343

4444
RemoveByIdWithCollection withDurability(DurabilityLevel durabilityLevel);
4545

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,40 @@
1919
import java.util.Collection;
2020

2121
import com.couchbase.client.core.msg.kv.DurabilityLevel;
22+
import com.couchbase.client.java.kv.IncrementOptions;
2223
import com.couchbase.client.java.kv.PersistTo;
2324
import com.couchbase.client.java.kv.ReplicateTo;
2425

2526
public interface ExecutableReplaceByIdOperation {
2627

2728
<T> ExecutableReplaceById<T> replaceById(Class<T> domainType);
2829

29-
interface TerminatingReplaceById<T> {
30+
interface TerminatingReplaceById<T> extends OneAndAll<T> {
3031

32+
@Override
3133
T one(T object);
3234

35+
@Override
3336
Collection<? extends T> all(Collection<? extends T> objects);
3437

3538
}
3639

37-
interface ReplaceByIdWithCollection<T> extends TerminatingReplaceById<T> {
40+
interface ReplaceByIdWithCollection<T> extends TerminatingReplaceById<T> , InCollection<T> {
3841

3942
TerminatingReplaceById<T> inCollection(String collection);
4043
}
4144

42-
interface ReplaceByIdWithDurability<T> extends ReplaceByIdWithCollection<T> {
45+
interface ReplaceByIdWithDurability<T> extends ReplaceByIdWithCollection<T>, WithDurability<T> {
4346

4447
ReplaceByIdWithCollection<T> withDurability(DurabilityLevel durabilityLevel);
4548

4649
ReplaceByIdWithCollection<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);
4750

4851
}
4952

50-
interface ReplaceByIdWithExpiry<T> extends ReplaceByIdWithDurability<T> {
53+
interface ReplaceByIdWithExpiry<T> extends ReplaceByIdWithDurability<T>, WithExpiry<T> {
5154

55+
@Override
5256
ReplaceByIdWithDurability<T> withExpiry(final Duration expiry);
5357
}
5458

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,32 @@ public interface ExecutableUpsertByIdOperation {
2626

2727
<T> ExecutableUpsertById<T> upsertById(Class<T> domainType);
2828

29-
interface TerminatingUpsertById<T> {
29+
interface TerminatingUpsertById<T> extends OneAndAll<T>{
3030

31+
@Override
3132
T one(T object);
3233

34+
@Override
3335
Collection<? extends T> all(Collection<? extends T> objects);
3436

3537
}
3638

37-
interface UpsertByIdWithCollection<T> extends TerminatingUpsertById<T> {
39+
interface UpsertByIdWithCollection<T> extends TerminatingUpsertById<T>, InCollection<T> {
3840

3941
TerminatingUpsertById<T> inCollection(String collection);
4042
}
4143

42-
interface UpsertByIdWithDurability<T> extends UpsertByIdWithCollection<T> {
44+
interface UpsertByIdWithDurability<T> extends UpsertByIdWithCollection<T>, WithDurability<T> {
4345

4446
UpsertByIdWithCollection<T> withDurability(DurabilityLevel durabilityLevel);
4547

4648
UpsertByIdWithCollection<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);
4749

4850
}
4951

50-
interface UpsertByIdWithExpiry<T> extends UpsertByIdWithDurability<T> {
52+
interface UpsertByIdWithExpiry<T> extends UpsertByIdWithDurability<T>, WithExpiry<T> {
5153

54+
@Override
5255
UpsertByIdWithDurability<T> withExpiry(Duration expiry);
5356
}
5457

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2020 the original author or authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.couchbase.core;
17+
18+
/**
19+
* A common interface for all of Insert, Replace, Upsert that take collection
20+
*
21+
* @author Michael Reiche
22+
* @param <T> - the entity class
23+
*/
24+
public interface InCollection<T> {
25+
Object inCollection(String collection);
26+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2020 the original author or authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.couchbase.core;
17+
18+
import java.util.Collection;
19+
20+
/**
21+
* A common interface for all of Insert, Replace, Upsert
22+
*
23+
* @author Michael Reiche
24+
*
25+
* @param <T> - the entity class
26+
*/
27+
public interface OneAndAll<T> {
28+
29+
T one(T object);
30+
31+
Collection<? extends T> all(Collection<? extends T> objects);
32+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2020 the original author or authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.couchbase.core;
17+
18+
import reactor.core.publisher.Flux;
19+
import reactor.core.publisher.Mono;
20+
21+
import java.util.Collection;
22+
23+
/**
24+
* A common interface for all of Insert, Replace, Upsert
25+
*
26+
* @author Michael Reiche
27+
* @param <T> - the entity class
28+
*/
29+
30+
public interface OneAndAllReactive<T> {
31+
Mono<T> one(T object);
32+
33+
Flux<? extends T> all(Collection<? extends T> objects);
34+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,28 @@ public interface ReactiveInsertByIdOperation {
2929

3030
<T> ReactiveInsertById<T> insertById(Class<T> domainType);
3131

32-
interface TerminatingInsertById<T> {
32+
interface TerminatingInsertById<T> extends OneAndAllReactive<T>{
3333

3434
Mono<T> one(T object);
3535

3636
Flux<? extends T> all(Collection<? extends T> objects);
3737

3838
}
3939

40-
interface InsertByIdWithCollection<T> extends TerminatingInsertById<T> {
40+
interface InsertByIdWithCollection<T> extends TerminatingInsertById<T>, InCollection<T> {
4141

4242
TerminatingInsertById<T> inCollection(String collection);
4343
}
4444

45-
interface InsertByIdWithDurability<T> extends InsertByIdWithCollection<T> {
45+
interface InsertByIdWithDurability<T> extends InsertByIdWithCollection<T>, WithDurability<T> {
4646

4747
InsertByIdWithCollection<T> withDurability(DurabilityLevel durabilityLevel);
4848

4949
InsertByIdWithCollection<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);
5050

5151
}
5252

53-
interface InsertByIdWithExpiry<T> extends InsertByIdWithDurability<T> {
53+
interface InsertByIdWithExpiry<T> extends InsertByIdWithDurability<T>, WithExpiry<T>{
5454

5555
InsertByIdWithDurability<T> withExpiry(Duration expiry);
5656
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ interface TerminatingRemoveById {
3636

3737
}
3838

39-
interface RemoveByIdWithCollection extends TerminatingRemoveById {
39+
interface RemoveByIdWithCollection extends TerminatingRemoveById, InCollection {
4040

4141
TerminatingRemoveById inCollection(String collection);
4242
}
4343

44-
interface RemoveByIdWithDurability extends RemoveByIdWithCollection {
44+
interface RemoveByIdWithDurability extends RemoveByIdWithCollection, WithDurability {
4545

4646
RemoveByIdWithCollection withDurability(DurabilityLevel durabilityLevel);
4747

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,28 @@ public interface ReactiveReplaceByIdOperation {
2929

3030
<T> ReactiveReplaceById<T> replaceById(Class<T> domainType);
3131

32-
interface TerminatingReplaceById<T> {
32+
interface TerminatingReplaceById<T> extends OneAndAllReactive<T> {
3333

3434
Mono<T> one(T object);
3535

3636
Flux<? extends T> all(Collection<? extends T> objects);
3737

3838
}
3939

40-
interface ReplaceByIdWithCollection<T> extends TerminatingReplaceById<T> {
40+
interface ReplaceByIdWithCollection<T> extends TerminatingReplaceById<T>, InCollection<T> {
4141

4242
TerminatingReplaceById<T> inCollection(String collection);
4343
}
4444

45-
interface ReplaceByIdWithDurability<T> extends ReplaceByIdWithCollection<T> {
45+
interface ReplaceByIdWithDurability<T> extends ReplaceByIdWithCollection<T>, WithDurability<T> {
4646

4747
ReplaceByIdWithCollection<T> withDurability(DurabilityLevel durabilityLevel);
4848

4949
ReplaceByIdWithCollection<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);
5050

5151
}
5252

53-
interface ReplaceByIdWithExpiry<T> extends ReplaceByIdWithDurability<T> {
53+
interface ReplaceByIdWithExpiry<T> extends ReplaceByIdWithDurability<T>, WithExpiry<T> {
5454

5555
ReplaceByIdWithDurability<T> withExpiry(final Duration expiry);
5656
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,28 @@ public interface ReactiveUpsertByIdOperation {
2929

3030
<T> ReactiveUpsertById<T> upsertById(Class<T> domainType);
3131

32-
interface TerminatingUpsertById<T> {
32+
interface TerminatingUpsertById<T> extends OneAndAllReactive<T>{
3333

3434
Mono<T> one(T object);
3535

3636
Flux<? extends T> all(Collection<? extends T> objects);
3737

3838
}
3939

40-
interface UpsertByIdWithCollection<T> extends TerminatingUpsertById<T> {
40+
interface UpsertByIdWithCollection<T> extends TerminatingUpsertById<T>, InCollection<T> {
4141

4242
TerminatingUpsertById<T> inCollection(String collection);
4343
}
4444

45-
interface UpsertByIdWithDurability<T> extends UpsertByIdWithCollection<T> {
45+
interface UpsertByIdWithDurability<T> extends UpsertByIdWithCollection<T>, WithDurability<T> {
4646

4747
UpsertByIdWithCollection<T> withDurability(DurabilityLevel durabilityLevel);
4848

4949
UpsertByIdWithCollection<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);
5050

5151
}
5252

53-
interface UpsertByIdWithExpiry<T> extends UpsertByIdWithDurability<T> {
53+
interface UpsertByIdWithExpiry<T> extends UpsertByIdWithDurability<T>, WithExpiry<T> {
5454

5555
UpsertByIdWithDurability<T> withExpiry(Duration expiry);
5656
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2020 the original author or authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.couchbase.core;
17+
18+
import com.couchbase.client.core.msg.kv.DurabilityLevel;
19+
import com.couchbase.client.java.kv.PersistTo;
20+
import com.couchbase.client.java.kv.ReplicateTo;
21+
22+
/**
23+
* A common interface for all of Insert, Replace, Upsert that take Durability
24+
*
25+
* @author Michael Reiche
26+
* @param <T> - the entity class
27+
*/
28+
public interface WithDurability<T> {
29+
Object withDurability(DurabilityLevel durabilityLevel);
30+
31+
Object withDurability(PersistTo persistTo, ReplicateTo replicateTo);
32+
}

0 commit comments

Comments
 (0)