From 0731b72ea5e1a7855a5b6cf73a44b6bc85bc881e Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Tue, 11 Dec 2018 09:36:02 +0100 Subject: [PATCH] DATACMNS-1444 - Polishing. Removed references to Serializable in repository interface declarations. Reformatting to waste less space with lines only containing ellipsis. --- src/main/asciidoc/repositories.adoc | 62 +++++++++-------------------- 1 file changed, 18 insertions(+), 44 deletions(-) diff --git a/src/main/asciidoc/repositories.adoc b/src/main/asciidoc/repositories.adoc index ba7b9c924..2ca5cb790 100644 --- a/src/main/asciidoc/repositories.adoc +++ b/src/main/asciidoc/repositories.adoc @@ -22,8 +22,7 @@ The central interface in the Spring Data repository abstraction is `Repository`. ==== [source, java] ---- -public interface CrudRepository - extends Repository { +public interface CrudRepository extends Repository { S save(S entity); <1> @@ -56,8 +55,7 @@ On top of the `CrudRepository`, there is a `PagingAndSortingRepository` abstract ==== [source, java] ---- -public interface PagingAndSortingRepository - extends CrudRepository { +public interface PagingAndSortingRepository extends CrudRepository { Iterable findAll(Sort sort); @@ -135,7 +133,7 @@ interface PersonRepository extends Repository { import org.springframework.data.jpa.repository.config.EnableJpaRepositories; @EnableJpaRepositories -class Config {} +class Config { … } ---- @@ -208,7 +206,7 @@ The following example shows how to selectively expose CRUD methods (`findById` a [source, java] ---- @NoRepositoryBean -interface MyBaseRepository extends Repository { +interface MyBaseRepository extends Repository { Optional findById(ID id); @@ -243,13 +241,9 @@ The following example shows a repository that uses module-specific interfaces (J interface MyRepository extends JpaRepository { } @NoRepositoryBean -interface MyBaseRepository extends JpaRepository { - … -} +interface MyBaseRepository extends JpaRepository { … } -interface UserRepository extends MyBaseRepository { - … -} +interface UserRepository extends MyBaseRepository { … } ---- `MyRepository` and `UserRepository` extend `JpaRepository` in their type hierarchy. They are valid candidates for the Spring Data JPA module. ==== @@ -260,18 +254,12 @@ The following example shows a repository that uses generic interfaces: ==== [source, java] ---- -interface AmbiguousRepository extends Repository { - … -} +interface AmbiguousRepository extends Repository { … } @NoRepositoryBean -interface MyBaseRepository extends CrudRepository { - … -} +interface MyBaseRepository extends CrudRepository { … } -interface AmbiguousUserRepository extends MyBaseRepository { - … -} +interface AmbiguousUserRepository extends MyBaseRepository { … } ---- `AmbiguousRepository` and `AmbiguousUserRepository` extend only `Repository` and `CrudRepository` in their type hierarchy. While this is perfectly fine when using a unique Spring Data module, multiple modules cannot distinguish to which particular Spring Data these repositories should be bound. ==== @@ -283,23 +271,15 @@ The following example shows a repository that uses domain classes with annotatio ==== [source, java] ---- -interface PersonRepository extends Repository { - … -} +interface PersonRepository extends Repository { … } @Entity -class Person { - … -} +class Person { … } -interface UserRepository extends Repository { - … -} +interface UserRepository extends Repository { … } @Document -class User { - … -} +class User { … } ---- `PersonRepository` references `Person`, which is annotated with the JPA `@Entity` annotation, so this repository clearly belongs to Spring Data JPA. `UserRepository` references `User`, which is annotated with Spring Data MongoDB's `@Document` annotation. ==== @@ -310,19 +290,13 @@ The following bad example shows a repository that uses domain classes with mixed ==== [source, java] ---- -interface JpaPersonRepository extends Repository { - … -} +interface JpaPersonRepository extends Repository { … } -interface MongoDBPersonRepository extends Repository { - … -} +interface MongoDBPersonRepository extends Repository { … } @Entity @Document -class Person { - … -} +class Person { … } ---- This example shows a domain class using both JPA and Spring Data MongoDB annotations. It defines two repositories, `JpaPersonRepository` and `MongoDBPersonRepository`. One is intended for JPA and the other for MongoDB usage. Spring Data is no longer able to tell the repositories apart, which leads to undefined behavior. ==== @@ -339,7 +313,7 @@ The following example shows annotation-driven configuration of base packages: ---- @EnableJpaRepositories(basePackages = "com.acme.repositories.jpa") @EnableMongoRepositories(basePackages = "com.acme.repositories.mongo") -interface Configuration { } +class Configuration { … } ---- ==== @@ -1002,7 +976,7 @@ The approach described in the <> r ==== [source, java] ---- -class MyRepositoryImpl +class MyRepositoryImpl extends SimpleJpaRepository { private final EntityManager entityManager;