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

Spring APIs - Document newly supported interfaces and update existing examples #43451

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions docs/src/main/asciidoc/spring-data-jpa.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,12 @@

* `org.springframework.data.repository.Repository`
* `org.springframework.data.repository.CrudRepository`
* `org.springframework.data.repository.ListCrudRepository`
* `org.springframework.data.repository.PagingAndSortingRepository`
* `org.springframework.data.repository.ListPagingAndSortingRepository`
* `org.springframework.data.jpa.repository.JpaRepository`

The generated repositories are also registered as beans so they can be injected into any other bean.

Check warning on line 424 in docs/src/main/asciidoc/spring-data-jpa.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'. Raw Output: {"message": "[Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'.", "location": {"path": "docs/src/main/asciidoc/spring-data-jpa.adoc", "range": {"start": {"line": 424, "column": 37}}}, "severity": "INFO"}
Furthermore, the methods that update the database are automatically annotated with `@Transactional`.

==== Fine-tuning of repository definition
Expand Down
17 changes: 15 additions & 2 deletions docs/src/main/asciidoc/spring-data-rest.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,15 @@
If a database contains many entities, it might not be a great idea to return them all at once.
`PagingAndSortingRepository` allows the `spring-data-rest` extension to access data in chunks.

Replace the `CrudRepository` with `PagingAndSortingRepository` in the `FruitsRepository`:
So, you can extend the `PagingAndSortingRepository`:

[source,java]
----
package org.acme.spring.data.rest;

import org.springframework.data.repository.PagingAndSortingRepository;

public interface FruitsRepository extends PagingAndSortingRepository<Fruit, Long> {
public interface FruitsRepository extends CrudRepository<Fruit, Long>, PagingAndSortingRepository<Fruit, Long> {
}
----

Expand All @@ -362,9 +362,22 @@

For paged responses, `spring-data-rest` also returns a set of link headers that can be used to access other pages: first, previous, next and last.

Additionally, rather than extending both `PagingAndSortingRepository` and `CrudRepository`, you can use `JpaRepository`, which is a higher-level abstraction tailored for JPA. Since `JpaRepository` already extends both `PagingAndSortingRepository` and `CrudRepository`, it can replace `CrudRepository` directly.

[source,java]
----
package org.acme.spring.data.rest;

import org.springframework.data.repository.PagingAndSortingRepository;

public interface FruitsRepository extends JpaRepository<Fruit, Long> {
}
----


==== Fine tuning endpoints generation

This allows user to specify which methods should be exposed and what path should be used to access them.

Check warning on line 380 in docs/src/main/asciidoc/spring-data-rest.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsSuggestions] Depending on the context, consider using ', which (non restrictive clause preceded by a comma)' or 'that (restrictive clause without a comma)' rather than 'which'. Raw Output: {"message": "[Quarkus.TermsSuggestions] Depending on the context, consider using ', which (non restrictive clause preceded by a comma)' or 'that (restrictive clause without a comma)' rather than 'which'.", "location": {"path": "docs/src/main/asciidoc/spring-data-rest.adoc", "range": {"start": {"line": 380, "column": 6}}}, "severity": "INFO"}
Spring Data REST provides two annotations that can be used: `@RepositoryRestResource` and `@RestResource`.
`spring-data-rest` extension supports the `exported`, `path` `collectionResourceRel` attributes of these annotations.

Expand Down