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.
This commit is contained in:
Michael Reiche
2022-02-11 08:22:04 -08:00
committed by Michael Reiche
parent 8eb7231965
commit bcbcd5cb73
13 changed files with 71 additions and 36 deletions

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -117,10 +117,10 @@ public interface ExecutableInsertByIdOperation {
interface InsertByIdWithDurability<T> extends InsertByIdInScope<T>, WithDurability<T> { interface InsertByIdWithDurability<T> extends InsertByIdInScope<T>, WithDurability<T> {
@Override @Override
InsertByIdInCollection<T> withDurability(DurabilityLevel durabilityLevel); InsertByIdInScope<T> withDurability(DurabilityLevel durabilityLevel);
@Override @Override
InsertByIdInCollection<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo); InsertByIdInScope<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -100,14 +100,14 @@ public class ExecutableInsertByIdOperationSupport implements ExecutableInsertByI
} }
@Override @Override
public InsertByIdInCollection<T> withDurability(final DurabilityLevel durabilityLevel) { public InsertByIdInScope<T> withDurability(final DurabilityLevel durabilityLevel) {
Assert.notNull(durabilityLevel, "Durability Level must not be null."); Assert.notNull(durabilityLevel, "Durability Level must not be null.");
return new ExecutableInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo, return new ExecutableInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,
durabilityLevel, expiry); durabilityLevel, expiry);
} }
@Override @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(persistTo, "PersistTo must not be null.");
Assert.notNull(replicateTo, "ReplicateTo must not be null."); Assert.notNull(replicateTo, "ReplicateTo must not be null.");
return new ExecutableInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo, return new ExecutableInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -114,10 +114,10 @@ public interface ExecutableRemoveByIdOperation {
interface RemoveByIdWithDurability extends RemoveByIdInScope, WithDurability<RemoveResult> { interface RemoveByIdWithDurability extends RemoveByIdInScope, WithDurability<RemoveResult> {
@Override @Override
RemoveByIdInCollection withDurability(DurabilityLevel durabilityLevel); RemoveByIdInScope withDurability(DurabilityLevel durabilityLevel);
@Override @Override
RemoveByIdInCollection withDurability(PersistTo persistTo, ReplicateTo replicateTo); RemoveByIdInScope withDurability(PersistTo persistTo, ReplicateTo replicateTo);
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -92,14 +92,14 @@ public class ExecutableRemoveByIdOperationSupport implements ExecutableRemoveByI
} }
@Override @Override
public RemoveByIdInCollection withDurability(final DurabilityLevel durabilityLevel) { public RemoveByIdInScope withDurability(final DurabilityLevel durabilityLevel) {
Assert.notNull(durabilityLevel, "Durability Level must not be null."); Assert.notNull(durabilityLevel, "Durability Level must not be null.");
return new ExecutableRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo, return new ExecutableRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo,
durabilityLevel, cas); durabilityLevel, cas);
} }
@Override @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(persistTo, "PersistTo must not be null.");
Assert.notNull(replicateTo, "ReplicateTo must not be null."); Assert.notNull(replicateTo, "ReplicateTo must not be null.");
return new ExecutableRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo, return new ExecutableRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo,

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -113,10 +113,10 @@ public interface ReactiveInsertByIdOperation {
interface InsertByIdWithDurability<T> extends InsertByIdInScope<T>, WithDurability<T> { interface InsertByIdWithDurability<T> extends InsertByIdInScope<T>, WithDurability<T> {
@Override @Override
InsertByIdInCollection<T> withDurability(DurabilityLevel durabilityLevel); InsertByIdInScope<T> withDurability(DurabilityLevel durabilityLevel);
@Override @Override
InsertByIdInCollection<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo); InsertByIdInScope<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -125,14 +125,14 @@ public class ReactiveInsertByIdOperationSupport implements ReactiveInsertByIdOpe
} }
@Override @Override
public InsertByIdInCollection<T> withDurability(final DurabilityLevel durabilityLevel) { public InsertByIdInScope<T> withDurability(final DurabilityLevel durabilityLevel) {
Assert.notNull(durabilityLevel, "Durability Level must not be null."); Assert.notNull(durabilityLevel, "Durability Level must not be null.");
return new ReactiveInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo, return new ReactiveInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,
durabilityLevel, expiry, support); durabilityLevel, expiry, support);
} }
@Override @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(persistTo, "PersistTo must not be null.");
Assert.notNull(replicateTo, "ReplicateTo must not be null."); Assert.notNull(replicateTo, "ReplicateTo must not be null.");
return new ReactiveInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo, return new ReactiveInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -112,10 +112,10 @@ public interface ReactiveRemoveByIdOperation {
interface RemoveByIdWithDurability extends RemoveByIdInScope, WithDurability<RemoveResult> { interface RemoveByIdWithDurability extends RemoveByIdInScope, WithDurability<RemoveResult> {
@Override @Override
RemoveByIdInCollection withDurability(DurabilityLevel durabilityLevel); RemoveByIdInScope withDurability(DurabilityLevel durabilityLevel);
@Override @Override
RemoveByIdInCollection withDurability(PersistTo persistTo, ReplicateTo replicateTo); RemoveByIdInScope withDurability(PersistTo persistTo, ReplicateTo replicateTo);
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -105,14 +105,14 @@ public class ReactiveRemoveByIdOperationSupport implements ReactiveRemoveByIdOpe
} }
@Override @Override
public RemoveByIdInCollection withDurability(final DurabilityLevel durabilityLevel) { public RemoveByIdInScope withDurability(final DurabilityLevel durabilityLevel) {
Assert.notNull(durabilityLevel, "Durability Level must not be null."); Assert.notNull(durabilityLevel, "Durability Level must not be null.");
return new ReactiveRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo, return new ReactiveRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo,
durabilityLevel, cas); durabilityLevel, cas);
} }
@Override @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(persistTo, "PersistTo must not be null.");
Assert.notNull(replicateTo, "ReplicateTo must not be null."); Assert.notNull(replicateTo, "ReplicateTo must not be null.");
return new ReactiveRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo, return new ReactiveRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo,

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -116,9 +116,9 @@ public interface ReactiveReplaceByIdOperation {
interface ReplaceByIdWithDurability<T> extends ReplaceByIdInScope<T>, WithDurability<T> { 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);
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -126,14 +126,14 @@ public class ReactiveReplaceByIdOperationSupport implements ReactiveReplaceByIdO
} }
@Override @Override
public ReplaceByIdInCollection<T> withDurability(final DurabilityLevel durabilityLevel) { public ReplaceByIdInScope<T> withDurability(final DurabilityLevel durabilityLevel) {
Assert.notNull(durabilityLevel, "Durability Level must not be null."); Assert.notNull(durabilityLevel, "Durability Level must not be null.");
return new ReactiveReplaceByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo, return new ReactiveReplaceByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,
durabilityLevel, expiry, support); durabilityLevel, expiry, support);
} }
@Override @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(persistTo, "PersistTo must not be null.");
Assert.notNull(replicateTo, "ReplicateTo must not be null."); Assert.notNull(replicateTo, "ReplicateTo must not be null.");
return new ReactiveReplaceByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo, return new ReactiveReplaceByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -118,10 +118,10 @@ public interface ReactiveUpsertByIdOperation {
interface UpsertByIdWithDurability<T> extends UpsertByIdInScope<T>, WithDurability<T> { interface UpsertByIdWithDurability<T> extends UpsertByIdInScope<T>, WithDurability<T> {
@Override @Override
UpsertByIdInCollection<T> withDurability(DurabilityLevel durabilityLevel); UpsertByIdInScope<T> withDurability(DurabilityLevel durabilityLevel);
@Override @Override
UpsertByIdInCollection<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo); UpsertByIdInScope<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo);
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -125,14 +125,14 @@ public class ReactiveUpsertByIdOperationSupport implements ReactiveUpsertByIdOpe
} }
@Override @Override
public UpsertByIdInCollection<T> withDurability(final DurabilityLevel durabilityLevel) { public UpsertByIdInScope<T> withDurability(final DurabilityLevel durabilityLevel) {
Assert.notNull(durabilityLevel, "Durability Level must not be null."); Assert.notNull(durabilityLevel, "Durability Level must not be null.");
return new ReactiveUpsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo, return new ReactiveUpsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,
durabilityLevel, expiry, support); durabilityLevel, expiry, support);
} }
@Override @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(persistTo, "PersistTo must not be null.");
Assert.notNull(replicateTo, "ReplicateTo must not be null."); Assert.notNull(replicateTo, "ReplicateTo must not be null.");
return new ReactiveUpsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo, return new ReactiveUpsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,

View File

@@ -30,6 +30,7 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.couchbase.client.core.msg.kv.DurabilityLevel;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
@@ -800,4 +801,38 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
} catch (DataRetrievalFailureException drfe) {} } 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());
}
} }