|
| 1 | +/* |
| 2 | + * DISCLAIMER |
| 3 | + * |
| 4 | + * Copyright 2017 ArangoDB GmbH, Cologne, Germany |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + * |
| 18 | + * Copyright holder is ArangoDB GmbH, Cologne, Germany |
| 19 | + */ |
| 20 | + |
| 21 | +package com.arangodb.springframework.annotation; |
| 22 | + |
| 23 | +import com.arangodb.model.ComputedValue; |
| 24 | +import org.springframework.core.annotation.AliasFor; |
| 25 | + |
| 26 | +import java.lang.annotation.ElementType; |
| 27 | +import java.lang.annotation.Retention; |
| 28 | +import java.lang.annotation.RetentionPolicy; |
| 29 | +import java.lang.annotation.Target; |
| 30 | + |
| 31 | +/** |
| 32 | + * Annotation to mark a field representing an ArangoDB computed value. |
| 33 | + * If the property is mutable, then the field is automatically updated in place with the value coming from the server |
| 34 | + * for the following operations: |
| 35 | + * <ul> |
| 36 | + * <li>{@link com.arangodb.springframework.core.ArangoOperations#repsert(Object)}</li> |
| 37 | + * <li>{@link com.arangodb.springframework.core.ArangoOperations#repsertAll(Iterable, Class)}</li> |
| 38 | + * <li>{@link com.arangodb.springframework.repository.ArangoRepository#save(Object)}</li> |
| 39 | + * <li>{@link com.arangodb.springframework.repository.ArangoRepository#saveAll(Iterable)}</li> |
| 40 | + * </ul> |
| 41 | + * |
| 42 | + * @see <a href="https://docs.arangodb.com/stable/concepts/data-structure/documents/computed-values">Reference Doc</a> |
| 43 | + */ |
| 44 | +@Retention(RetentionPolicy.RUNTIME) |
| 45 | +@Target({ElementType.FIELD}) |
| 46 | +public @interface ComputedValueField { |
| 47 | + |
| 48 | + @AliasFor("expression") |
| 49 | + String value() default ""; |
| 50 | + |
| 51 | + /** |
| 52 | + * @return An AQL RETURN operation with an expression that computes the desired value. If empty, the computed value |
| 53 | + * data definition will not be set on collection creation. |
| 54 | + * @see ComputedValue#expression(String) |
| 55 | + */ |
| 56 | + @AliasFor("value") |
| 57 | + String expression() default ""; |
| 58 | + |
| 59 | + /** |
| 60 | + * @return Whether the computed value shall take precedence over a user-provided or existing attribute. |
| 61 | + * The default is false. |
| 62 | + * @see ComputedValue#overwrite(Boolean) |
| 63 | + */ |
| 64 | + boolean overwrite() default false; |
| 65 | + |
| 66 | + /** |
| 67 | + * @return An array of operations to define on which write operations the value shall be computed. |
| 68 | + * The default is ["insert", "update", "replace"]. |
| 69 | + * @see ComputedValue#computeOn(ComputedValue.ComputeOn...) |
| 70 | + */ |
| 71 | + ComputedValue.ComputeOn[] computeOn() default { |
| 72 | + ComputedValue.ComputeOn.insert, |
| 73 | + ComputedValue.ComputeOn.update, |
| 74 | + ComputedValue.ComputeOn.replace |
| 75 | + }; |
| 76 | + |
| 77 | + /** |
| 78 | + * @return Whether the target attribute shall be set if the expression evaluates to null. You can set the option to |
| 79 | + * false to not set (or unset) the target attribute if the expression returns null. The default is true. |
| 80 | + * @see ComputedValue#keepNull(Boolean) |
| 81 | + */ |
| 82 | + boolean keepNull() default true; |
| 83 | + |
| 84 | + /** |
| 85 | + * @return Whether to let the write operation fail if the expression produces a warning. |
| 86 | + * The default is false. |
| 87 | + * @see ComputedValue#failOnWarning(Boolean) |
| 88 | + */ |
| 89 | + boolean failOnWarning() default false; |
| 90 | +} |
0 commit comments