10000 [DE-604] [DE-779] Spring Data: documented computed values by rashtao · Pull Request #477 · arangodb/docs-hugo · GitHub
[go: up one dir, main page]

Skip to content

[DE-604] [DE-779] Spring Data: documented computed values #477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Apply to 3.13
  • Loading branch information
Simran-B committed Jun 21, 2024
commit a6d69b2c0dd09091d28f8a16ec613fcb9424f0c4
Original file line number Diff line number Diff line change
Expand Up @@ -137,33 +137,35 @@ exceptions when reading the entities from the DB.

### Annotation overview

| annotation | level | description |
|-------------------------| ------------------------- |-----------------------------------------------------------------------------------------------------------------------------------------------------|
| @Document | class | marks this class as a candidate for mapping |
| @Edge | class | marks this class as a candidate for mapping |
| @Id | field | stores the field as the system field \_key |
| @ArangoId | field | stores the field as the system field \_id |
| @Rev | field | stores the field as the system field \_rev |
| @Field("alt-name") | field | stores the field with an alternative name |
| @Ref | field | stores the \_id of the referenced document and not the nested document |
| @From | field | stores the \_id of the referenced document as the system field \_from |
| @To | field | stores the \_id of the referenced document as the system field \_to |
| @Relations | field | vertices which are connected over edges |
| @Transient | field, method, annotation | marks a field to be transient for the mapping framework, thus the property will not be persisted and not further inspected by the mapping framework |
| @PersistenceConstructor | constructor | marks a given constructor - even a package protected one - to use when instantiating the object from the database |
| @TypeAlias("alias") | class | set a type alias for the class when persisted to the DB |
| @PersistentIndex | class | describes a persistent index |
| @PersistentIndexed | field | describes how to index the field |
| @GeoIndex | class | describes a geo index |
| @GeoIndexed | field | describes how to index the field |
| @FulltextIndex | class | describes a fulltext index |
| @FulltextIndexed | field | describes how to index the field |
| @TtlIndex | class | describes a TTL index |
| @TtlIndexed | field | describes how to index the field |
| @CreatedBy | field | Declares a field as the one representing the principal that created the entity containing the field. |
| @CreatedDate | field | Declares a field as the one representing the date the entity containing the field was created. |
| @LastModifiedBy | field | Declares a field as the one representing the principal that recently modified the entity containing the field. |
| @LastModifiedDate | field | Declares a field as the one representing the date the entity containing the field was recently modified. |
| annotation | level | description |
|--------------------------------| ------------------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| @Document | class | marks this class as a candidate for mapping |
| @Edge | class | marks this class as a candidate for mapping |
| @Id | field | stores the field as the system field \_key |
| @ArangoId | field | stores the field as the system field \_id |
| @Rev | field | stores the field as the system field \_rev |
| @Field("alt-name") | field | stores the field with an alternative name |
| @Ref | field | stores the \_id of the referenced document and not the nested document |
| @From | field | stores the \_id of the referenced document as the system field \_from |
| @To | field | stores the \_id of the referenced document as the system field \_to |
| @Relations | field | vertices which are connected over edges |
| @Transient | field, method, annotation | marks a field to be transient for the mapping framework, thus the property is not persisted and not further inspected by the mapping framework |
| @PersistenceConstructor | constructor | marks a given constructor - even a package protected one - to use when instantiating the object from the database |
| @TypeAlias("alias") | class | set a type alias for the class when persisted to the DB |
| @ArangoComputedValueDefinition | class | describes a computed value data definition |
| @ArangoComputedValue | field | marks the field for the mapping framework so that the property is updated with the value coming from the server and optionally describes a computed value data definition |
| @PersistentIndex | class | describes a persistent index |
| @PersistentIndexed | field | describes how to index the field |
| @GeoIndex | class | describes a geo index |
| @GeoIndexed | field | describes how to index the field |
| @FulltextIndex | class | describes a fulltext index |
| @FulltextIndexed | field | describes how to index the field |
| @TtlIndex | class | describes a TTL index |
| @TtlIndexed | field | describes how to index the field |
| @CreatedBy | field | Declares a field as the one representing the principal that created the entity containing the field. |
| @CreatedDate | field | Declares a field as the one representing the date the entity containing the field was created. |
| @LastModifiedBy | field | Declares a field as the one representing the principal that recently modified the entity containing the field. |
| @LastModifiedDate | field | Declares a field as the one representing the date the entity containing the field was recently modified. |

## Invoking conversion manually

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
title: Computed Values
menuTitle: Computed Values
weight: 27
description: ''
archetype: default
---
Spring Data ArangoDB provides annotations to allow mapping computed values to
entity properties and to include computed values data definitions during
collection creation.

For reference, see the [computed values](../../../../../concepts/data-structure/documents/computed-values.md)
documentation.

## Mapping

Computed values can be mapped to entity properties by annotating the related
fields with `@ArangoComputedValue`.

If the property is mutable, then the field is automatically updated in place
with the value coming from the server in the following methods:
- `ArangoOperations#repsert(Object)`
- `ArangoOperations#repsertAll(Iterable, Class)`
- `ArangoRepository#save(Object)`
- `ArangoRepository#saveAll(Iterable)`

## Data Definitions

Computed values data definitions can be specified through parameters of the
following annotations:
- `@ArangoComputedValue` on fields
- `@ArangoComputedValueDefinition` on classes (optionally within `@ArangoComputedValueDefinitions`)

**Example**

```java
@Document
@ArangoComputedValueDefinition(
name = "username",
expression = "RETURN \"unknown\"",
computeOn = ComputedValue.ComputeOn.insert
)
class MyEntity {

@ArangoComputedValue
String username;

@ArangoComputedValue("RETURN 0")
int age;

// ...

}
```

On database collection creation, the computed values metadata is included.
Note that the data definitions are not updated in case the database collection
already exists.
0