DATAJPA-594 - Polished Asciidoctor documentation.

This commit is contained in:
Oliver Gierke
2014-08-22 14:26:12 +02:00
parent 1b45d7fd22
commit f52167ed40
5 changed files with 39 additions and 26 deletions

View File

@@ -43,3 +43,4 @@ Currently I have implemented a repository layer based on `HibernateDaoSupport`.
[qanda]
I want to use Spring Data JPA auditing capabilities but have my database already set up to set modification and creation date on entities. How to prevent Spring Data from setting the date programmatically.::
Just use the `set-dates` attribute of the `auditing` namespace element to false.

View File

@@ -28,3 +28,4 @@ JPA::
Spring::
Java application framework - link:$$http://projects.spring.io/spring-framework$$[http://projects.spring.io/spring-framework]

View File

@@ -1,28 +1,38 @@
= Spring Data JPA - Reference Documentation
Oliver Gierke; Thomas Darimont; Christoph Strobl
{version}
:revnumber: {version}
:revdate: {localdate}
:toc:
:toc-placement!:
:spring-data-commons-docs: https://raw.githubusercontent.com/spring-projects/spring-data-commons/master/src/main/asciidoc
:spring-framework-docs: http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html
(C) 2008-2014 The original authors.
NOTE: Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically.
toc::[]
include::preface.adoc[]
:leveloffset: +1
include::{spring-data-commons-docs}/repositories.adoc[]
:leveloffset: -1
[[reference]]
= Reference Documentation
:leveloffset: 1
include::{spring-data-commons-docs}/repositories.adoc[]
:leveloffset: +1
include::jpa.adoc[]
:leveloffset: 0
:leveloffset: -1
[[appendix]]
= Appendix
:numbered!:
:leveloffset: 1
:leveloffset: +1
include::{spring-data-commons-docs}/repository-namespace-reference.adoc[]
include::{spring-data-commons-docs}/repository-populator-namespace-reference.adoc[]
include::{spring-data-commons-docs}/repository-query-keywords-reference.adoc[]
include::faq.adoc[]
include::glossary.adoc[]
:leveloffset: 0
:leveloffset: -1

View File

@@ -1,7 +1,7 @@
[[jpa.repositories]]
= JPA Repositories
This chapter includes details of the JPA repository implementation.
This chapter will point out the specialties for repository support for JPA. This builds on the core repository support explained in <<repositories>>. So make sure you've got a sound understanding of the basic concepts explained there.
[[jpa.introduction]]
== Introduction
@@ -36,7 +36,7 @@ Using this element looks up Spring Data repositories as described in <<repositor
Beyond the default attributes of the `repositories` element the JPA namespace offers additional attributes to gain more detailed control over the setup of the repositories:
.Custom JPA-specific attributes of the repositories element
[cols="1,3"]
[options = "autowidth"]
|===============
|`entity-manager-factory-ref`|Explicitly wire the `EntityManagerFactory` to be used with the repositories being detected by the `repositories` element. Usually used if multiple `EntityManagerFactory` beans are used within the application. If not configured we will automatically lookup the `EntityManagerFactory` bean with the name `entityManagerFactory` in the `ApplicationContext`.
|`transaction-manager-ref`|Explicitly wire the `PlatformTransactionManager` to be used with the repositories being detected by the `repositories` element. Usually only necessary if multiple transaction managers and/or `EntityManagerFactory` beans have been configured. Default to a single defined `PlatformTransactionManager` inside the current `ApplicationContext`.
@@ -104,7 +104,7 @@ Saving an entity can be performed via the `CrudRepository.save(…)`-Method. It
Spring Data JPA offers the following strategies to detect whether an entity is new or not:
.Options for detection whether an entity is new in Spring Data JPA
[cols="1,3"]
[options = "autowidth"]
|===============
|Id-Property inspection (*default*)|By default Spring Data JPA inspects the identifier property of the given entity. If the identifier property is `null`, then the entity will be assumed as new, otherwise as not new.
|Implementing `Persistable`|If an entity implements `Persistable`, Spring Data JPA will delegate the new detection to the `isNew(…)` method of the entity. See the link:$$http://docs.spring.io/spring-data/data-commons/docs/current/api/index.html?org/springframework/data/domain/Persistable.html$$[JavaDoc] for details.
@@ -120,7 +120,7 @@ Spring Data JPA offers the following strategies to detect whether an entity is n
The JPA module supports defining a query manually as String or have it being derived from the method name.
==== Declared queries
Although getting a query derived from the method name is quite convenient, one might face the situation in which either the method name parser does not support the keyword one wants to use or the method name would get unnecessarily ugly. So you can either use JPA named queries through a naming convention (see <<jpa.query-methods.named-queries>> for more information) or rather annotate your query method with @Query (see <<jpa.query-methods.at-query>> for details).
Although getting a query derived from the method name is quite convenient, one might face the situation in which either the method name parser does not support the keyword one wants to use or the method name would get unnecessarily ugly. So you can either use JPA named queries through a naming convention (see <<jpa.query-methods.named-queries>> for more information) or rather annotate your query method with `@Query` (see <<jpa.query-methods.at-query>> for details).
[[jpa.query-methods.query-creation]]
=== Query creation
@@ -139,7 +139,7 @@ We will create a query using the JPA criteria API from this but essentially this
====
.Supported keywords inside method names
[options="header", cols="1,1,2"]
[options = "header, autowidth"]
|===============
|Keyword|Sample|JPQL snippet
|`And`|`findByLastnameAndFirstname`|`… where x.lastname = ?1 and x.firstname = ?2`
@@ -251,7 +251,7 @@ public interface UserRepository extends JpaRepository<User, Long> {
Using advanced `LIKE` expressionsThe query execution mechanism for manually defined queries using @Query allow the definition of advanced `LIKE` expressions inside the query definition.
.Advanced `LIKE` expressions in @Query
.Advanced like-expressions in @Query
====
[source, java]
----
@@ -273,7 +273,7 @@ Native queriesThe `@Query` annotation allows to execute native queries by settin
----
public interface UserRepository extends JpaRepository<User, Long> {
@Query(value = "SELECT * FROM USERS WHERE EMAIL`ADDRESS = ?0", nativeQuery = true)
@Query(value = "SELECT * FROM USERS WHERE EMAIL_ADDRESS = ?0", nativeQuery = true)
User findByEmailAddress(String emailAddress);
}
----
@@ -296,8 +296,8 @@ public interface UserRepository extends JpaRepository<User, Long> {
@Param("firstname") String firstname);
}
----
Note that the method parameters are switched according to the occurrence in the query defined.
====
Note that the method parameters are switched according to the occurrence in the query defined.
[[jpa.query.spel-expressions]]
=== Using SpEL expressions
@@ -305,13 +305,13 @@ Note that the method parameters are switched according to the occurrence in the
As of Spring Data JPA release 1.4 we support the usage of restricted SpEL template expressions in manually defined queries via `@Query`. Upon query execution these expressions are evaluated against a predefined set of variables. We support the following list of variables to be used in a manual query.
.Supported variables inside SpEL based query templates
[options="header", cols="1,3"]
[options="header, autowidth"]
|===============
|Variable|Usage|Description
|`entityName`|`select x from #{#entityName} x`|Inserts the `entityName` of the domain type associated with the given Repository. The `entityName` is resolved as follows: If the domain type has set the name property on the `@Entity` annotation then it will be used. Otherwise the simple class-name of the domain type will be used.
|===============
The following example demonstrates one use case for the `#{#entityName}` expression in a query string where you want to define a repository interface with a query method with a manually defined query. In order not to have to state the actual entity name in the query string of a `@Query` annotation one can use the `#{#entityName}` Variable.
The following example demonstrates one use case for the `+#{#entityName}+` expression in a query string where you want to define a repository interface with a query method with a manually defined query. In order not to have to state the actual entity name in the query string of a `@Query` annotation one can use the `+#{#entityName}+` Variable.
[NOTE]
====
@@ -405,8 +405,8 @@ public interface UserRepository extends Repository<User, Long> {
Page<User> findByLastname(String lastname, Pageable pageable);
}
----
The just shown declaration would apply the configured `@QueryHint` for that actually query but omit applying it to the count query triggered to calculate the total number of pages.
====
The just shown declaration would apply the configured `@QueryHint` for that actually query but omit applying it to the count query triggered to calculate the total number of pages.
[[jpa.entity-graph]]
=== Configuring Fetch- and LoadGraphs
@@ -716,9 +716,9 @@ interface UserRepository extends Repository<User, Long> {
----
====
:leveloffset: 2
:leveloffset: +1
include::{spring-data-commons-docs}/auditing.adoc[]
:leveloffset: 0
:leveloffset: -1
[[jpa.auditing]]
== JPA Auditing
@@ -883,3 +883,4 @@ class RepositoryClient {
}
}
----

View File

@@ -1,13 +1,13 @@
[[preface]]
[preface]
= Preface
[[project]]
[preface]
== Project metadata
[options="compact"]
- Version control - link:$$git://github.com/spring-projects/spring-data-jpa.git$$[git://github.com/spring-projects/spring-data-jpa.git]
- Bugtracker - link:$$https://jira.springsource.org/browse/DATAJPA$$[https://jira.springsource.org/browse/DATAJPA]
- Release repository - link:$$http://repo.spring.io/libs-release$$[http://repo.spring.io/libs-release]
- Milestone repository - link:$$http://repo.spring.io/libs-milestone$$[http://repo.spring.io/libs-milestone]
- Snapshot repository - link:$$http://repo.spring.io/libs-snapshot$$[http://repo.spring.io/libs-snapshot]
* Version control - http://github.com/spring-projects/spring-data-jpa
* Bugtracker - https://jira.spring.io/browse/DATAJPA
* Release repository - https://repo.spring.io/libs-release
* Milestone repository - https://repo.spring.io/libs-milestone
* Snapshot repository - https://repo.spring.io/libs-snapshot