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 6ab0ea948..761f2e74c 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ExecutableInsertByIdOperation.java +++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableInsertByIdOperation.java @@ -26,20 +26,22 @@ public interface ExecutableInsertByIdOperation { ExecutableInsertById insertById(Class domainType); - interface TerminatingInsertById { + interface TerminatingInsertById extends OneAndAll{ + @Override T one(T object); + @Override Collection all(Collection objects); } - interface InsertByIdWithCollection extends TerminatingInsertById { + interface InsertByIdWithCollection extends TerminatingInsertById, InCollection { TerminatingInsertById inCollection(String collection); } - interface InsertByIdWithDurability extends InsertByIdWithCollection { + interface InsertByIdWithDurability extends InsertByIdWithCollection, WithDurability { InsertByIdWithCollection withDurability(DurabilityLevel durabilityLevel); @@ -47,8 +49,9 @@ interface InsertByIdWithDurability extends InsertByIdWithCollection { } - interface InsertByIdWithExpiry extends InsertByIdWithDurability { + interface InsertByIdWithExpiry extends InsertByIdWithDurability, WithExpiry { + @Override InsertByIdWithDurability withExpiry(Duration expiry); } 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 7287f6966..94a6cf682 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ExecutableRemoveByIdOperation.java +++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableRemoveByIdOperation.java @@ -34,12 +34,12 @@ interface TerminatingRemoveById { } - interface RemoveByIdWithCollection extends TerminatingRemoveById { + interface RemoveByIdWithCollection extends TerminatingRemoveById, InCollection { TerminatingRemoveById inCollection(String collection); } - interface RemoveByIdWithDurability extends RemoveByIdWithCollection { + interface RemoveByIdWithDurability extends RemoveByIdWithCollection, WithDurability { RemoveByIdWithCollection withDurability(DurabilityLevel durabilityLevel); diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableReplaceByIdOperation.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableReplaceByIdOperation.java index 98fc758da..b89c7ae89 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ExecutableReplaceByIdOperation.java +++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableReplaceByIdOperation.java @@ -19,6 +19,7 @@ import java.util.Collection; import com.couchbase.client.core.msg.kv.DurabilityLevel; +import com.couchbase.client.java.kv.IncrementOptions; import com.couchbase.client.java.kv.PersistTo; import com.couchbase.client.java.kv.ReplicateTo; @@ -26,20 +27,22 @@ public interface ExecutableReplaceByIdOperation { ExecutableReplaceById replaceById(Class domainType); - interface TerminatingReplaceById { + interface TerminatingReplaceById extends OneAndAll { + @Override T one(T object); + @Override Collection all(Collection objects); } - interface ReplaceByIdWithCollection extends TerminatingReplaceById { + interface ReplaceByIdWithCollection extends TerminatingReplaceById , InCollection { TerminatingReplaceById inCollection(String collection); } - interface ReplaceByIdWithDurability extends ReplaceByIdWithCollection { + interface ReplaceByIdWithDurability extends ReplaceByIdWithCollection, WithDurability { ReplaceByIdWithCollection withDurability(DurabilityLevel durabilityLevel); @@ -47,8 +50,9 @@ interface ReplaceByIdWithDurability extends ReplaceByIdWithCollection { } - interface ReplaceByIdWithExpiry extends ReplaceByIdWithDurability { + interface ReplaceByIdWithExpiry extends ReplaceByIdWithDurability, WithExpiry { + @Override ReplaceByIdWithDurability withExpiry(final Duration expiry); } diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableUpsertByIdOperation.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableUpsertByIdOperation.java index 3d919a8c2..a21ba69d7 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ExecutableUpsertByIdOperation.java +++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableUpsertByIdOperation.java @@ -26,20 +26,22 @@ public interface ExecutableUpsertByIdOperation { ExecutableUpsertById upsertById(Class domainType); - interface TerminatingUpsertById { + interface TerminatingUpsertById extends OneAndAll{ + @Override T one(T object); + @Override Collection all(Collection objects); } - interface UpsertByIdWithCollection extends TerminatingUpsertById { + interface UpsertByIdWithCollection extends TerminatingUpsertById, InCollection { TerminatingUpsertById inCollection(String collection); } - interface UpsertByIdWithDurability extends UpsertByIdWithCollection { + interface UpsertByIdWithDurability extends UpsertByIdWithCollection, WithDurability { UpsertByIdWithCollection withDurability(DurabilityLevel durabilityLevel); @@ -47,8 +49,9 @@ interface UpsertByIdWithDurability extends UpsertByIdWithCollection { } - interface UpsertByIdWithExpiry extends UpsertByIdWithDurability { + interface UpsertByIdWithExpiry extends UpsertByIdWithDurability, WithExpiry { + @Override UpsertByIdWithDurability withExpiry(Duration expiry); } diff --git a/src/main/java/org/springframework/data/couchbase/core/InCollection.java b/src/main/java/org/springframework/data/couchbase/core/InCollection.java new file mode 100644 index 000000000..7566af480 --- /dev/null +++ b/src/main/java/org/springframework/data/couchbase/core/InCollection.java @@ -0,0 +1,26 @@ +/* + * Copyright 2020 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.couchbase.core; + +/** + * A common interface for all of Insert, Replace, Upsert that take collection + * + * @author Michael Reiche + * @param - the entity class + */ +public interface InCollection { + Object inCollection(String collection); +} diff --git a/src/main/java/org/springframework/data/couchbase/core/OneAndAll.java b/src/main/java/org/springframework/data/couchbase/core/OneAndAll.java new file mode 100644 index 000000000..7b9292c81 --- /dev/null +++ b/src/main/java/org/springframework/data/couchbase/core/OneAndAll.java @@ -0,0 +1,32 @@ +/* + * Copyright 2020 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.couchbase.core; + +import java.util.Collection; + +/** + * A common interface for all of Insert, Replace, Upsert + * + * @author Michael Reiche + * + * @param - the entity class + */ +public interface OneAndAll { + + T one(T object); + + Collection all(Collection objects); +} diff --git a/src/main/java/org/springframework/data/couchbase/core/OneAndAllReactive.java b/src/main/java/org/springframework/data/couchbase/core/OneAndAllReactive.java new file mode 100644 index 000000000..f486aec00 --- /dev/null +++ b/src/main/java/org/springframework/data/couchbase/core/OneAndAllReactive.java @@ -0,0 +1,34 @@ +/* + * Copyright 2020 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.couchbase.core; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.util.Collection; + +/** + * A common interface for all of Insert, Replace, Upsert + * + * @author Michael Reiche + * @param - the entity class + */ + +public interface OneAndAllReactive { + Mono one(T object); + + Flux all(Collection objects); +} 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 54e10163c..4bc9ffa2f 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperation.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperation.java @@ -29,7 +29,7 @@ public interface ReactiveInsertByIdOperation { ReactiveInsertById insertById(Class domainType); - interface TerminatingInsertById { + interface TerminatingInsertById extends OneAndAllReactive{ Mono one(T object); @@ -37,12 +37,12 @@ interface TerminatingInsertById { } - interface InsertByIdWithCollection extends TerminatingInsertById { + interface InsertByIdWithCollection extends TerminatingInsertById, InCollection { TerminatingInsertById inCollection(String collection); } - interface InsertByIdWithDurability extends InsertByIdWithCollection { + interface InsertByIdWithDurability extends InsertByIdWithCollection, WithDurability { InsertByIdWithCollection withDurability(DurabilityLevel durabilityLevel); @@ -50,7 +50,7 @@ interface InsertByIdWithDurability extends InsertByIdWithCollection { } - interface InsertByIdWithExpiry extends InsertByIdWithDurability { + interface InsertByIdWithExpiry extends InsertByIdWithDurability, WithExpiry{ InsertByIdWithDurability withExpiry(Duration expiry); } 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 d26519af9..d1cc5fa65 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperation.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperation.java @@ -36,12 +36,12 @@ interface TerminatingRemoveById { } - interface RemoveByIdWithCollection extends TerminatingRemoveById { + interface RemoveByIdWithCollection extends TerminatingRemoveById, InCollection { TerminatingRemoveById inCollection(String collection); } - interface RemoveByIdWithDurability extends RemoveByIdWithCollection { + interface RemoveByIdWithDurability extends RemoveByIdWithCollection, WithDurability { RemoveByIdWithCollection withDurability(DurabilityLevel durabilityLevel); 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 acdf825f1..89bf0ca52 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperation.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperation.java @@ -29,7 +29,7 @@ public interface ReactiveReplaceByIdOperation { ReactiveReplaceById replaceById(Class domainType); - interface TerminatingReplaceById { + interface TerminatingReplaceById extends OneAndAllReactive { Mono one(T object); @@ -37,12 +37,12 @@ interface TerminatingReplaceById { } - interface ReplaceByIdWithCollection extends TerminatingReplaceById { + interface ReplaceByIdWithCollection extends TerminatingReplaceById, InCollection { TerminatingReplaceById inCollection(String collection); } - interface ReplaceByIdWithDurability extends ReplaceByIdWithCollection { + interface ReplaceByIdWithDurability extends ReplaceByIdWithCollection, WithDurability { ReplaceByIdWithCollection withDurability(DurabilityLevel durabilityLevel); @@ -50,7 +50,7 @@ interface ReplaceByIdWithDurability extends ReplaceByIdWithCollection { } - interface ReplaceByIdWithExpiry extends ReplaceByIdWithDurability { + interface ReplaceByIdWithExpiry extends ReplaceByIdWithDurability, WithExpiry { ReplaceByIdWithDurability withExpiry(final Duration expiry); } 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 da0df85bd..b2c3c700d 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperation.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperation.java @@ -29,7 +29,7 @@ public interface ReactiveUpsertByIdOperation { ReactiveUpsertById upsertById(Class domainType); - interface TerminatingUpsertById { + interface TerminatingUpsertById extends OneAndAllReactive{ Mono one(T object); @@ -37,12 +37,12 @@ interface TerminatingUpsertById { } - interface UpsertByIdWithCollection extends TerminatingUpsertById { + interface UpsertByIdWithCollection extends TerminatingUpsertById, InCollection { TerminatingUpsertById inCollection(String collection); } - interface UpsertByIdWithDurability extends UpsertByIdWithCollection { + interface UpsertByIdWithDurability extends UpsertByIdWithCollection, WithDurability { UpsertByIdWithCollection withDurability(DurabilityLevel durabilityLevel); @@ -50,7 +50,7 @@ interface UpsertByIdWithDurability extends UpsertByIdWithCollection { } - interface UpsertByIdWithExpiry extends UpsertByIdWithDurability { + interface UpsertByIdWithExpiry extends UpsertByIdWithDurability, WithExpiry { UpsertByIdWithDurability withExpiry(Duration expiry); } diff --git a/src/main/java/org/springframework/data/couchbase/core/WithDurability.java b/src/main/java/org/springframework/data/couchbase/core/WithDurability.java new file mode 100644 index 000000000..170d13c2e --- /dev/null +++ b/src/main/java/org/springframework/data/couchbase/core/WithDurability.java @@ -0,0 +1,32 @@ +/* + * Copyright 2020 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.couchbase.core; + +import com.couchbase.client.core.msg.kv.DurabilityLevel; +import com.couchbase.client.java.kv.PersistTo; +import com.couchbase.client.java.kv.ReplicateTo; + +/** + * A common interface for all of Insert, Replace, Upsert that take Durability + * + * @author Michael Reiche + * @param - the entity class + */ +public interface WithDurability { + Object withDurability(DurabilityLevel durabilityLevel); + + Object withDurability(PersistTo persistTo, ReplicateTo replicateTo); +} diff --git a/src/main/java/org/springframework/data/couchbase/core/WithExpiry.java b/src/main/java/org/springframework/data/couchbase/core/WithExpiry.java new file mode 100644 index 000000000..000eafecf --- /dev/null +++ b/src/main/java/org/springframework/data/couchbase/core/WithExpiry.java @@ -0,0 +1,28 @@ +/* + * Copyright 2020 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.couchbase.core; + +import java.time.Duration; + +/** + * A common interface for all of Insert, Replace, Upsert that take expiry + * + * @author Michael Reiche + * @param - the entity class + */ +public interface WithExpiry { + Object withExpiry(Duration expiry); +} diff --git a/src/test/java/org/springframework/data/couchbase/domain/UserAnnotated2.java b/src/test/java/org/springframework/data/couchbase/domain/UserAnnotated2.java new file mode 100644 index 000000000..72d05a549 --- /dev/null +++ b/src/test/java/org/springframework/data/couchbase/domain/UserAnnotated2.java @@ -0,0 +1,38 @@ +/* + * Copyright 2020 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.data.couchbase.domain; + +import java.util.concurrent.TimeUnit; + +import org.springframework.data.couchbase.core.mapping.Document; + +/** + * Annotated User entity for tests + * + * @author Michael Reiche + */ + +@Document(expiryExpression = "${myExpiryExpression}", expiryUnit = TimeUnit.SECONDS) +public class UserAnnotated2 extends User { + static { + System.setProperty("myExpiryExpression", "2"); + } + + public UserAnnotated2(String id, String firstname, String lastname) { + super(id, firstname, lastname); + } +}