Skip to content

Make withDurability() return WithScope type for all operations. #1340

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
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 Down Expand Up @@ -117,10 +117,10 @@ interface InsertByIdInScope<T> extends InsertByIdInCollection<T>, InScope<T> {
interface InsertByIdWithDurability<T> extends InsertByIdInScope<T>, WithDurability<T> {

@Override
InsertByIdInCollection<T> withDurability(DurabilityLevel durabilityLevel);
InsertByIdInScope<T> withDurability(DurabilityLevel durabilityLevel);

@Override
InsertByIdInCollection<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);
InsertByIdInScope<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);

}

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 Down Expand Up @@ -100,14 +100,14 @@ public InsertByIdWithOptions<T> inCollection(final String collection) {
}

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

@Override
public InsertByIdInCollection<T> withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
public InsertByIdInScope<T> withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
Assert.notNull(persistTo, "PersistTo must not be null.");
Assert.notNull(replicateTo, "ReplicateTo must not be null.");
return new ExecutableInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,
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 Down Expand Up @@ -114,10 +114,10 @@ interface RemoveByIdInScope extends RemoveByIdInCollection, InScope<Object> {
interface RemoveByIdWithDurability extends RemoveByIdInScope, WithDurability<RemoveResult> {

@Override
RemoveByIdInCollection withDurability(DurabilityLevel durabilityLevel);
RemoveByIdInScope withDurability(DurabilityLevel durabilityLevel);

@Override
RemoveByIdInCollection withDurability(PersistTo persistTo, ReplicateTo replicateTo);
RemoveByIdInScope withDurability(PersistTo persistTo, ReplicateTo replicateTo);

}

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 Down Expand Up @@ -92,14 +92,14 @@ public RemoveByIdWithOptions inCollection(final String collection) {
}

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

@Override
public RemoveByIdInCollection withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
public RemoveByIdInScope withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
Assert.notNull(persistTo, "PersistTo must not be null.");
Assert.notNull(replicateTo, "ReplicateTo must not be null.");
return new ExecutableRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo,
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 Down Expand Up @@ -113,10 +113,10 @@ interface InsertByIdInScope<T> extends InsertByIdInCollection<T>, InScope<T> {
interface InsertByIdWithDurability<T> extends InsertByIdInScope<T>, WithDurability<T> {

@Override
InsertByIdInCollection<T> withDurability(DurabilityLevel durabilityLevel);
InsertByIdInScope<T> withDurability(DurabilityLevel durabilityLevel);

@Override
InsertByIdInCollection<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);
InsertByIdInScope<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);

}

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 Down Expand Up @@ -125,14 +125,14 @@ public InsertByIdWithOptions<T> inCollection(final String collection) {
}

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

@Override
public InsertByIdInCollection<T> withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
public InsertByIdInScope<T> withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
Assert.notNull(persistTo, "PersistTo must not be null.");
Assert.notNull(replicateTo, "ReplicateTo must not be null.");
return new ReactiveInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,
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 Down Expand Up @@ -112,10 +112,10 @@ interface RemoveByIdInScope extends RemoveByIdInCollection, InScope<Object> {

interface RemoveByIdWithDurability extends RemoveByIdInScope, WithDurability<RemoveResult> {
@Override
RemoveByIdInCollection withDurability(DurabilityLevel durabilityLevel);
RemoveByIdInScope withDurability(DurabilityLevel durabilityLevel);

@Override
RemoveByIdInCollection withDurability(PersistTo persistTo, ReplicateTo replicateTo);
RemoveByIdInScope withDurability(PersistTo persistTo, ReplicateTo replicateTo);

}

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 Down Expand Up @@ -105,14 +105,14 @@ private RemoveOptions buildRemoveOptions(RemoveOptions options) {
}

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

@Override
public RemoveByIdInCollection withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
public RemoveByIdInScope withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
Assert.notNull(persistTo, "PersistTo must not be null.");
Assert.notNull(replicateTo, "ReplicateTo must not be null.");
return new ReactiveRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo,
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 Down Expand Up @@ -116,9 +116,9 @@ interface ReplaceByIdInScope<T> extends ReplaceByIdInCollection<T>, InScope<Obje

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

ReplaceByIdInCollection<T> withDurability(DurabilityLevel durabilityLevel);
ReplaceByIdInScope<T> withDurability(DurabilityLevel durabilityLevel);

ReplaceByIdInCollection<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);
ReplaceByIdInScope<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);

}

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 Down Expand Up @@ -126,14 +126,14 @@ public ReplaceByIdInCollection<T> inScope(final String scope) {
}

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

@Override
public ReplaceByIdInCollection<T> withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
public ReplaceByIdInScope<T> withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
Assert.notNull(persistTo, "PersistTo must not be null.");
Assert.notNull(replicateTo, "ReplicateTo must not be null.");
return new ReactiveReplaceByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,
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 Down Expand Up @@ -118,10 +118,10 @@ interface UpsertByIdInScope<T> extends UpsertByIdInCollection<T>, InScope<Object

interface UpsertByIdWithDurability<T> extends UpsertByIdInScope<T>, WithDurability<T> {
@Override
UpsertByIdInCollection<T> withDurability(DurabilityLevel durabilityLevel);
UpsertByIdInScope<T> withDurability(DurabilityLevel durabilityLevel);

@Override
UpsertByIdInCollection<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);
UpsertByIdInScope<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);

}

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 Down Expand Up @@ -125,14 +125,14 @@ public UpsertByIdInCollection<T> inScope(final String scope) {
}

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

@Override
public UpsertByIdInCollection<T> withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
public UpsertByIdInScope<T> withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
Assert.notNull(persistTo, "PersistTo must not be null.");
Assert.notNull(replicateTo, "ReplicateTo must not be null.");
return new ReactiveUpsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.UUID;
import java.util.stream.Collectors;

import com.couchbase.client.core.msg.kv.DurabilityLevel;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -800,4 +801,38 @@ public void testScopeCollectionRepoWith() {
} catch (DataRetrievalFailureException drfe) {}
}
}

@Test
void testFluentApi() {
User user1 = new User(UUID.randomUUID().toString(), "user1", "user1");
DurabilityLevel dl = DurabilityLevel.NONE;
User result;
RemoveResult rr;
result = couchbaseTemplate.insertById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName)
.one(user1);
assertEquals(user1,result);
result = couchbaseTemplate.upsertById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName)
.one(user1);
assertEquals(user1,result);
result = couchbaseTemplate.replaceById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName)
.one(user1);
assertEquals(user1,result);
rr = couchbaseTemplate.removeById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName)
.one(user1.getId());
assertEquals(rr.getId(), user1.getId());
assertEquals(user1,result);
result = reactiveCouchbaseTemplate.insertById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName)
.one(user1).block();
assertEquals(user1,result);
result = reactiveCouchbaseTemplate.upsertById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName)
.one(user1).block();
assertEquals(user1,result);
result = reactiveCouchbaseTemplate.replaceById(User.class).withDurability(dl).inScope(scopeName)
.inCollection(collectionName).one(user1).block();
assertEquals(user1,result);
rr = reactiveCouchbaseTemplate.removeById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName)
.one(user1.getId()).block();
assertEquals(rr.getId(), user1.getId());
}

}