From 1fa489efe0e23a3db94ec88cf5a7e1fd48a54e7b Mon Sep 17 00:00:00 2001 From: Michael Reiche Date: Thu, 10 Feb 2022 16:14:12 -0800 Subject: [PATCH] Make withDurability() return WithScope type for all operations. Some of the operations were mistakenly declared to return a WithCollection type, making it impossible to call the inScope() method. Closes #1329. --- .../core/ExecutableInsertByIdOperation.java | 6 ++-- .../ExecutableInsertByIdOperationSupport.java | 6 ++-- .../core/ExecutableRemoveByIdOperation.java | 6 ++-- .../ExecutableRemoveByIdOperationSupport.java | 6 ++-- .../core/ReactiveInsertByIdOperation.java | 6 ++-- .../ReactiveInsertByIdOperationSupport.java | 6 ++-- .../core/ReactiveRemoveByIdOperation.java | 6 ++-- .../ReactiveRemoveByIdOperationSupport.java | 6 ++-- .../core/ReactiveReplaceByIdOperation.java | 6 ++-- .../ReactiveReplaceByIdOperationSupport.java | 6 ++-- .../core/ReactiveUpsertByIdOperation.java | 6 ++-- .../ReactiveUpsertByIdOperationSupport.java | 6 ++-- ...mplateQueryCollectionIntegrationTests.java | 35 +++++++++++++++++++ 13 files changed, 71 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableInsertByIdOperation.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableInsertByIdOperation.java index cb1985602..0465d5022 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ExecutableInsertByIdOperation.java +++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableInsertByIdOperation.java @@ -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. @@ -117,10 +117,10 @@ interface InsertByIdInScope extends InsertByIdInCollection, InScope { interface InsertByIdWithDurability extends InsertByIdInScope, WithDurability { @Override - InsertByIdInCollection withDurability(DurabilityLevel durabilityLevel); + InsertByIdInScope withDurability(DurabilityLevel durabilityLevel); @Override - InsertByIdInCollection withDurability(PersistTo persistTo, ReplicateTo replicateTo); + InsertByIdInScope withDurability(PersistTo persistTo, ReplicateTo replicateTo); } diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableInsertByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableInsertByIdOperationSupport.java index 52031af21..8eb4b99f5 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ExecutableInsertByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableInsertByIdOperationSupport.java @@ -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. @@ -100,14 +100,14 @@ public InsertByIdWithOptions inCollection(final String collection) { } @Override - public InsertByIdInCollection withDurability(final DurabilityLevel durabilityLevel) { + public InsertByIdInScope 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 withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) { + public InsertByIdInScope 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, diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableRemoveByIdOperation.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableRemoveByIdOperation.java index eb9cb214e..02381669e 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ExecutableRemoveByIdOperation.java +++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableRemoveByIdOperation.java @@ -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. @@ -114,10 +114,10 @@ interface RemoveByIdInScope extends RemoveByIdInCollection, InScope { interface RemoveByIdWithDurability extends RemoveByIdInScope, WithDurability { @Override - RemoveByIdInCollection withDurability(DurabilityLevel durabilityLevel); + RemoveByIdInScope withDurability(DurabilityLevel durabilityLevel); @Override - RemoveByIdInCollection withDurability(PersistTo persistTo, ReplicateTo replicateTo); + RemoveByIdInScope withDurability(PersistTo persistTo, ReplicateTo replicateTo); } diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableRemoveByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableRemoveByIdOperationSupport.java index 9f79dad3e..e0721ce5a 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ExecutableRemoveByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableRemoveByIdOperationSupport.java @@ -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. @@ -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, diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperation.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperation.java index 953eff0e1..6439879fe 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperation.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperation.java @@ -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. @@ -113,10 +113,10 @@ interface InsertByIdInScope extends InsertByIdInCollection, InScope { interface InsertByIdWithDurability extends InsertByIdInScope, WithDurability { @Override - InsertByIdInCollection withDurability(DurabilityLevel durabilityLevel); + InsertByIdInScope withDurability(DurabilityLevel durabilityLevel); @Override - InsertByIdInCollection withDurability(PersistTo persistTo, ReplicateTo replicateTo); + InsertByIdInScope withDurability(PersistTo persistTo, ReplicateTo replicateTo); } diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java index 7514e8baf..0d319fb4a 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java @@ -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. @@ -125,14 +125,14 @@ public InsertByIdWithOptions inCollection(final String collection) { } @Override - public InsertByIdInCollection withDurability(final DurabilityLevel durabilityLevel) { + public InsertByIdInScope 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 withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) { + public InsertByIdInScope 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, diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperation.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperation.java index 561be70e6..a9abaa178 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperation.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperation.java @@ -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. @@ -112,10 +112,10 @@ interface RemoveByIdInScope extends RemoveByIdInCollection, InScope { interface RemoveByIdWithDurability extends RemoveByIdInScope, WithDurability { @Override - RemoveByIdInCollection withDurability(DurabilityLevel durabilityLevel); + RemoveByIdInScope withDurability(DurabilityLevel durabilityLevel); @Override - RemoveByIdInCollection withDurability(PersistTo persistTo, ReplicateTo replicateTo); + RemoveByIdInScope withDurability(PersistTo persistTo, ReplicateTo replicateTo); } diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperationSupport.java index b4f64ed72..547c561e5 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperationSupport.java @@ -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. @@ -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, diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperation.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperation.java index 1f206772c..0341096cb 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperation.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperation.java @@ -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. @@ -116,9 +116,9 @@ interface ReplaceByIdInScope extends ReplaceByIdInCollection, InScope extends ReplaceByIdInScope, WithDurability { - ReplaceByIdInCollection withDurability(DurabilityLevel durabilityLevel); + ReplaceByIdInScope withDurability(DurabilityLevel durabilityLevel); - ReplaceByIdInCollection withDurability(PersistTo persistTo, ReplicateTo replicateTo); + ReplaceByIdInScope withDurability(PersistTo persistTo, ReplicateTo replicateTo); } diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperationSupport.java index 55aebd4dc..ba96de24c 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperationSupport.java @@ -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. @@ -126,14 +126,14 @@ public ReplaceByIdInCollection inScope(final String scope) { } @Override - public ReplaceByIdInCollection withDurability(final DurabilityLevel durabilityLevel) { + public ReplaceByIdInScope 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 withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) { + public ReplaceByIdInScope 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, diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperation.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperation.java index 5ec888d1a..05249e198 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperation.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperation.java @@ -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. @@ -118,10 +118,10 @@ interface UpsertByIdInScope extends UpsertByIdInCollection, InScope extends UpsertByIdInScope, WithDurability { @Override - UpsertByIdInCollection withDurability(DurabilityLevel durabilityLevel); + UpsertByIdInScope withDurability(DurabilityLevel durabilityLevel); @Override - UpsertByIdInCollection withDurability(PersistTo persistTo, ReplicateTo replicateTo); + UpsertByIdInScope withDurability(PersistTo persistTo, ReplicateTo replicateTo); } diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperationSupport.java index b2433e10b..e84fe1fca 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperationSupport.java @@ -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. @@ -125,14 +125,14 @@ public UpsertByIdInCollection inScope(final String scope) { } @Override - public UpsertByIdInCollection withDurability(final DurabilityLevel durabilityLevel) { + public UpsertByIdInScope 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 withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) { + public UpsertByIdInScope 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, diff --git a/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateQueryCollectionIntegrationTests.java b/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateQueryCollectionIntegrationTests.java index 1307cabbf..dcd13b5ab 100644 --- a/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateQueryCollectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateQueryCollectionIntegrationTests.java @@ -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; @@ -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()); + } + }