Skip to content
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

[DE-539] Spring Data: documented object mapping behavior #476

Merged
merged 5 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ Spring Boot support is offered by [Spring Boot Starter ArangoDB](https://github.
{{< tabs "spring-data" >}}

{{< tab "Version 4" >}}
- Java Record classes and Kotlin Data classes are not supported (DE-539)
- GraalVM Native Image (available with Spring Boot 3) is not supported (DE-677)
- Spring Data REST is not supported (DE-43)
- Spring Data Reactive is not supported (DE-678)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,64 @@ ArangoConverter arangoConverter;
// ...
MyEntity entity = converter.read(MyEntity.class, jn);
```

## Object Mapping

Spring Data ArangoDB delegates object mapping, object creation, field and property access to
[Spring Data Commons](https://docs.spring.io/spring-data/data-commons/docs/current/reference/html/#mapping.fundamentals).

Methods in `ArangoOperations` try modifying the domain objects accepted as parameters,
updating the properties potentially modified by the server side, if the related fields
are mutable. This applies to the fields annotated with:
- `@ArangoId`
- `@Id`
- `@Rev`

In addition, the following methods also try to update the fields annotated with
`@ArangoComputedValue`:
- `ArangoOperations#repsert(Object)`
- `ArangoOperations#repsertAll(Iterable<Object>, Class<?>)`

## Object Identity

The most of the methods in `ArangoOperations` and `ArangoRepository` return new
entity instances, except the following:
- `ArangoRepository#save(Object)`
- `ArangoRepository#saveAll(Iterable<Object>)`

These methods return by default the same instance(s) of the domain object(s)
accepted as parameter(s) and update the properties potentially modified by the
server side, if the related fields are mutable.
This applies to the fields annotated with:
- `@ArangoId`
- `@Id`
- `@Rev`
- `@ArangoComputedValue`

This behavior can be changed by overriding `ArangoConfiguration#returnOriginalEntities()`,
which by default returns `true`. For example:

```java
@Configuration
@EnableArangoRepositories
public class MyConfiguration implements ArangoConfiguration {

// ...

@Override
public boolean returnOriginalEntities() {
return false;
}

}
```

Note that also in this case, input parameters properties are still updated, if mutable.

## Working with immutable objects

Spring Data ArangoDB can work with immutable entity classes, like Java Records,
Kotlin data classes and final classes with immutable properties. In this case,
to use `ArangoRepository#save(Object)` and `ArangoRepository#saveAll(Iterable<Object>)`
is required overriding `ArangoConfiguration#returnOriginalEntities()` to make it
return `false`, see [Object Identity](#object-identity).
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ Spring Boot support is offered by [Spring Boot Starter ArangoDB](https://github.
{{< tabs "spring-data" >}}

{{< tab "Version 4" >}}
- Java Record classes and Kotlin Data classes are not supported (DE-539)
- GraalVM Native Image (available with Spring Boot 3) is not supported (DE-677)
- Spring Data REST is not supported (DE-43)
- Spring Data Reactive is not supported (DE-678)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,64 @@ ArangoConverter arangoConverter;
// ...
MyEntity entity = converter.read(MyEntity.class, jn);
```

## Object Mapping

Spring Data ArangoDB delegates object mapping, object creation, field and property access to
[Spring Data Commons](https://docs.spring.io/spring-data/data-commons/docs/current/reference/html/#mapping.fundamentals).

Methods in `ArangoOperations` try modifying the domain objects accepted as parameters,
updating the properties potentially modified by the server side, if the related fields
are mutable. This applies to the fields annotated with:
- `@ArangoId`
- `@Id`
- `@Rev`

In addition, the following methods also try to update the fields annotated with
`@ArangoComputedValue`:
- `ArangoOperations#repsert(Object)`
- `ArangoOperations#repsertAll(Iterable<Object>, Class<?>)`

## Object Identity

The most of the methods in `ArangoOperations` and `ArangoRepository` return new
entity instances, except the following:
- `ArangoRepository#save(Object)`
- `ArangoRepository#saveAll(Iterable<Object>)`

These methods return by default the same instance(s) of the domain object(s)
accepted as parameter(s) and update the properties potentially modified by the
server side, if the related fields are mutable.
This applies to the fields annotated with:
- `@ArangoId`
- `@Id`
- `@Rev`
- `@ArangoComputedValue`

This behavior can be changed by overriding `ArangoConfiguration#returnOriginalEntities()`,
which by default returns `true`. For example:

```java
@Configuration
@EnableArangoRepositories
public class MyConfiguration implements ArangoConfiguration {

// ...

@Override
public boolean returnOriginalEntities() {
return false;
}

}
```

Note that also in this case, input parameters properties are still updated, if mutable.

## Working with immutable objects

Spring Data ArangoDB can work with immutable entity classes, like Java Records,
Kotlin data classes and final classes with immutable properties. In this case,
to use `ArangoRepository#save(Object)` and `ArangoRepository#saveAll(Iterable<Object>)`
is required overriding `ArangoConfiguration#returnOriginalEntities()` to make it
return `false`, see [Object Identity](#object-identity).
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ Spring Boot support is offered by [Spring Boot Starter ArangoDB](https://github.
{{< tabs "spring-data" >}}

{{< tab "Version 4" >}}
- Java Record classes and Kotlin Data classes are not supported (DE-539)
- GraalVM Native Image (available with Spring Boot 3) is not supported (DE-677)
- Spring Data REST is not supported (DE-43)
- Spring Data Reactive is not supported (DE-678)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,64 @@ ArangoConverter arangoConverter;
// ...
MyEntity entity = converter.read(MyEntity.class, jn);
```

## Object Mapping

Spring Data ArangoDB delegates object mapping, object creation, field and property access to
[Spring Data Commons](https://docs.spring.io/spring-data/data-commons/docs/current/reference/html/#mapping.fundamentals).

Methods in `ArangoOperations` try modifying the domain objects accepted as parameters,
updating the properties potentially modified by the server side, if the related fields
are mutable. This applies to the fields annotated with:
- `@ArangoId`
- `@Id`
- `@Rev`

In addition, the following methods also try to update the fields annotated with
`@ArangoComputedValue`:
- `ArangoOperations#repsert(Object)`
- `ArangoOperations#repsertAll(Iterable<Object>, Class<?>)`

## Object Identity

The most of the methods in `ArangoOperations` and `ArangoRepository` return new
entity instances, except the following:
- `ArangoRepository#save(Object)`
- `ArangoRepository#saveAll(Iterable<Object>)`

These methods return by default the same instance(s) of the domain object(s)
accepted as parameter(s) and update the properties potentially modified by the
server side, if the related fields are mutable.
This applies to the fields annotated with:
- `@ArangoId`
- `@Id`
- `@Rev`
- `@ArangoComputedValue`

This behavior can be changed by overriding `ArangoConfiguration#returnOriginalEntities()`,
which by default returns `true`. For example:

```java
@Configuration
@EnableArangoRepositories
public class MyConfiguration implements ArangoConfiguration {

// ...

@Override
public boolean returnOriginalEntities() {
return false;
}

}
```

Note that also in this case, input parameters properties are still updated, if mutable.

## Working with immutable objects

Spring Data ArangoDB can work with immutable entity classes, like Java Records,
Kotlin data classes and final classes with immutable properties. In this case,
to use `ArangoRepository#save(Object)` and `ArangoRepository#saveAll(Iterable<Object>)`
is required overriding `ArangoConfiguration#returnOriginalEntities()` to make it
return `false`, see [Object Identity](#object-identity).