|
| 1 | +/* |
| 2 | + * Copyright 2012-2023 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.MutateInOptions; |
| 20 | +import com.couchbase.client.java.kv.PersistTo; |
| 21 | +import com.couchbase.client.java.kv.ReplicateTo; |
| 22 | +import org.springframework.data.couchbase.core.support.*; |
| 23 | +import reactor.core.publisher.Flux; |
| 24 | +import reactor.core.publisher.Mono; |
| 25 | + |
| 26 | +import java.time.Duration; |
| 27 | +import java.util.Collection; |
| 28 | + |
| 29 | +/** |
| 30 | + * Mutate In Operations |
| 31 | + * |
| 32 | + * @author Tigran Babloyan |
| 33 | + * @since 5.1 |
| 34 | + */ |
| 35 | +public interface ExecutableMutateInByIdOperation { |
| 36 | + |
| 37 | + /** |
| 38 | + * Mutate using the KV service. |
| 39 | + * |
| 40 | + * @param domainType the entity type to mutate. |
| 41 | + */ |
| 42 | + <T> ExecutableMutateInById<T> mutateInById(Class<T> domainType); |
| 43 | + |
| 44 | + /** |
| 45 | + * Terminating operations invoking the actual execution. |
| 46 | + */ |
| 47 | + interface TerminatingMutateInById<T> extends OneAndAllEntity<T> { |
| 48 | + |
| 49 | + /** |
| 50 | + * Insert one entity. |
| 51 | + * |
| 52 | + * @return Inserted entity. |
| 53 | + */ |
| 54 | + @Override |
| 55 | + T one(T object); |
| 56 | + |
| 57 | + /** |
| 58 | + * Insert a collection of entities. |
| 59 | + * |
| 60 | + * @return Inserted entities |
| 61 | + */ |
| 62 | + @Override |
| 63 | + Collection<? extends T> all(Collection<? extends T> objects); |
| 64 | + |
| 65 | + } |
| 66 | + |
| 67 | + interface MutateInByIdWithPaths<T> extends TerminatingMutateInById<T>, WithMutateInPaths<T> { |
| 68 | + /** |
| 69 | + * Adds given paths to remove mutations. |
| 70 | + * See {@link com.couchbase.client.java.kv.Remove} for more details. |
| 71 | + * @param removePaths The property paths to removed from document. |
| 72 | + */ |
| 73 | + @Override |
| 74 | + MutateInByIdWithPaths<T> withRemovePaths(final String... removePaths); |
| 75 | + /** |
| 76 | + * Adds given paths to insert mutations. |
| 77 | + * See {@link com.couchbase.client.java.kv.Insert} for more details. |
| 78 | + * @param insertPaths The property paths to be inserted into the document. |
| 79 | + */ |
| 80 | + @Override |
| 81 | + MutateInByIdWithPaths<T> withInsertPaths(final String... insertPaths); |
| 82 | + /** |
| 83 | + * Adds given paths to upsert mutations. |
| 84 | + * See {@link com.couchbase.client.java.kv.Upsert} for more details. |
| 85 | + * @param upsertPaths The property paths to be upserted into the document. |
| 86 | + */ |
| 87 | + @Override |
| 88 | + MutateInByIdWithPaths<T> withUpsertPaths(final String... upsertPaths); |
| 89 | + /** |
| 90 | + * Adds given paths to replace mutations. |
| 91 | + * See {@link com.couchbase.client.java.kv.Replace} for more details. |
| 92 | + * @param replacePaths The property paths to be replaced in the document. |
| 93 | + */ |
| 94 | + @Override |
| 95 | + MutateInByIdWithPaths<T> withReplacePaths(final String... replacePaths); |
| 96 | + /** |
| 97 | + * Marks that the CAS value should be provided with the mutations to protect against concurrent modifications. |
| 98 | + * By default the CAS value is not provided. |
| 99 | + */ |
| 100 | + MutateInByIdWithPaths<T> withCasProvided(); |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * Fluent method to specify options. |
| 105 | + * |
| 106 | + * @param <T> the entity type to use. |
| 107 | + */ |
| 108 | + interface MutateInByIdWithOptions<T> extends MutateInByIdWithPaths<T>, WithMutateInOptions<T> { |
| 109 | + /** |
| 110 | + * Fluent method to specify options to use for execution |
| 111 | + * |
| 112 | + * @param options to use for execution |
| 113 | + */ |
| 114 | + @Override |
| 115 | + TerminatingMutateInById<T> withOptions(MutateInOptions options); |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * Fluent method to specify the collection. |
| 120 | + * |
| 121 | + * @param <T> the entity type to use for the results. |
| 122 | + */ |
| 123 | + interface MutateInByIdInCollection<T> extends MutateInByIdWithOptions<T>, InCollection<Object> { |
| 124 | + /** |
| 125 | + * With a different collection |
| 126 | + * |
| 127 | + * @param collection the collection to use. |
| 128 | + */ |
| 129 | + @Override |
| 130 | + MutateInByIdWithOptions<T> inCollection(String collection); |
| 131 | + } |
| 132 | + |
| 133 | + /** |
| 134 | + * Fluent method to specify the scope. |
| 135 | + * |
| 136 | + * @param <T> the entity type to use for the results. |
| 137 | + */ |
| 138 | + interface MutateInByIdInScope<T> extends MutateInByIdInCollection<T>, InScope<Object> { |
| 139 | + /** |
| 140 | + * With a different scope |
| 141 | + * |
| 142 | + * @param scope the scope to use. |
| 143 | + */ |
| 144 | + @Override |
| 145 | + MutateInByIdInCollection<T> inScope(String scope); |
| 146 | + } |
| 147 | + |
| 148 | + interface MutateInByIdWithDurability<T> extends MutateInByIdInScope<T>, WithDurability<T> { |
| 149 | + @Override |
| 150 | + MutateInByIdInScope<T> withDurability(DurabilityLevel durabilityLevel); |
| 151 | + |
| 152 | + @Override |
| 153 | + MutateInByIdInScope<T> withDurability(PersistTo persistTo, ReplicateTo replicateTo); |
| 154 | + |
| 155 | + } |
| 156 | + |
| 157 | + interface MutateInByIdWithExpiry<T> extends MutateInByIdWithDurability<T>, WithExpiry<T> { |
| 158 | + @Override |
| 159 | + MutateInByIdWithDurability<T> withExpiry(Duration expiry); |
| 160 | + } |
| 161 | + |
| 162 | + /** |
| 163 | + * Provides methods for constructing KV operations in a fluent way. |
| 164 | + * |
| 165 | + * @param <T> the entity type to upsert |
| 166 | + */ |
| 167 | + interface ExecutableMutateInById<T> extends MutateInByIdWithExpiry<T> {} |
| 168 | + |
| 169 | +} |
0 commit comments