You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DATACMNS-567 - Fixed some glitches in the Asciidoctor files.
Added missing closing backtick in auditing.adoc. Added copyright line to index.adoc and switched to relative level offsets. Use two blank lines at the end of each file consistently. Extracted preface document and added project metadata.
Copy file name to clipboardExpand all lines: src/main/asciidoc/auditing.adoc
+5-4Lines changed: 5 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -26,11 +26,11 @@ class Customer {
26
26
----
27
27
====
28
28
29
-
As you can see, the annotations can be applied selectively, depending on which information you'd like to capture. For the annotations capturing the points in time can be used on properties of type `org.joda.time.DateTime`, `java.util.Date` as well as `long`/`Long`.
29
+
As you can see, the annotations can be applied selectively, depending on which information you'd like to capture. For the annotations capturing the points in time can be used on properties of type JodaTimes `DateTime`, legacy Java `Date` and `Calendar`, JDK8 date/time types as well as `long`/`Long`.
30
30
31
31
[[auditing.interfaces]]
32
32
=== Interface-based auditing metadata
33
-
In case you don't want to use annotations to define auditing metadata you can let your domain class implement the Auditable interface. It exposes setter methods for all of the auditing properties.
33
+
In case you don't want to use annotations to define auditing metadata you can let your domain class implement the `Auditable` interface. It exposes setter methods for all of the auditing properties.
34
34
35
35
There's also a convenience base class `AbstractAuditable` which you can extend to avoid the need to manually implement the interface methods. Be aware that this increases the coupling of your domain classes to Spring Data which might be something you want to avoid. Usually the annotation based way of defining auditing metadata is preferred as it is less invasive and more flexible.
36
36
@@ -41,7 +41,7 @@ In case you use either `@CreatedBy` or `@LastModifiedBy`, the auditing infrastru
41
41
42
42
Here's an example implementation of the interface using Spring Security's `Authentication` object:
43
43
44
-
.Implementation of `AuditorAware` based on Spring Security
44
+
.Implementation of AuditorAware based on Spring Security
45
45
====
46
46
[source, java]
47
47
----
@@ -61,4 +61,5 @@ class SpringSecurityAuditorAware implements AuditorAware<User> {
61
61
----
62
62
====
63
63
64
-
The implementation is accessing the `Authentication` object provided by Spring Security and looks up the custom `UserDetails` instance from it that you have created in your `UserDetailsService` implementation. We're assuming here that you are exposing the domain user through that `UserDetails` implementation but you could also look it up from anywhere based on the `Authentication found.
64
+
The implementation is accessing the `Authentication` object provided by Spring Security and looks up the custom `UserDetails` instance from it that you have created in your `UserDetailsService` implementation. We're assuming here that you are exposing the domain user through that `UserDetails` implementation but you could also look it up from anywhere based on the `Authentication` found.
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.
8
11
9
-
[[preface]]
10
-
[preface]
11
-
= Preface
12
-
The Spring Data Commons project applies core Spring concepts to the development of solutions using many relational and non-relational data stores.
@@ -280,7 +282,7 @@ If your property names contain underscores (e.g. `first_name`) you can escape th
280
282
=== Special parameter handling
281
283
To handle parameters in your query you simply define method parameters as already seen in the examples above. Besides that the infrastructure will recognize certain specific types like `Pageable` and `Sort` to apply pagination and sorting to your queries dynamically.
282
284
283
-
.Using `Pageable` and Sort in query methods
285
+
.Using Pageable, Slice and Sort in query methods
284
286
====
285
287
[source, java]
286
288
----
@@ -301,11 +303,11 @@ Sorting options are handled through the `Pageable` instance too. If you only nee
301
303
NOTE: To find out how many pages you get for a query entirely you have to trigger an additional count query. By default this query will be derived from the query you actually trigger.
302
304
303
305
[[repositories.create-instances]]
304
-
=== Creating repository instances
306
+
== Creating repository instances
305
307
In this section you create instances and bean definitions for the repository interfaces defined. One way to do so is using the Spring namespace that is shipped with each Spring Data module that supports the repository mechanism although we generally recommend to use the Java-Config style configuration.
306
308
307
309
[[repositories.create-instances.spring]]
308
-
==== XML configuration
310
+
=== XML configuration
309
311
Each Spring Data module includes a repositories element that allows you to simply define a base package that Spring scans for you.
310
312
311
313
.Enabling Spring Data repositories via XML
@@ -329,7 +331,7 @@ Each Spring Data module includes a repositories element that allows you to simpl
329
331
330
332
In the preceding example, Spring is instructed to scan `com.acme.repositories` and all its sub-packages for interfaces extending `Repository` or one of its sub-interfaces. For each interface found, the infrastructure registers the persistence technology-specific `FactoryBean` to create the appropriate proxies that handle invocations of the query methods. Each bean is registered under a bean name that is derived from the interface name, so an interface of `UserRepository` would be registered under `userRepository`. The `base-package` attribute allows wildcards, so that you can define a pattern of scanned packages.
331
333
332
-
===== Using filters
334
+
==== Using filters
333
335
By default the infrastructure picks up every interface extending the persistence technology-specific `Repository` sub-interface located under the configured base package and creates a bean instance for it. However, you might want more fine-grained control over which interfaces bean instances get created for. To do this you use `<include-filter />` and `<exclude-filter />` elements inside `<repositories />`. The semantics are exactly equivalent to the elements in Spring's context namespace. For details, see link:{spring-framework-docs}/beans.html#beans-scanning-filters[Spring reference documentation] on these elements.
334
336
335
337
For example, to exclude certain interfaces from instantiation as repository, you could use the following configuration:
@@ -371,7 +373,7 @@ class ApplicationConfiguration {
371
373
NOTE: The sample uses the JPA-specific annotation, which you would change according to the store module you actually use. The same applies to the definition of the `EntityManagerFactory` bean. Consult the sections covering the store-specific configuration.
372
374
373
375
[[repositories.create-instances.standalone]]
374
-
==== Standalone usage
376
+
=== Standalone usage
375
377
You can also use the repository infrastructure outside of a Spring container, e.g. in CDI environments. You still need some Spring libraries in your classpath, but generally you can set up repositories programmatically as well. The Spring Data modules that provide repository support ship a persistence technology-specific RepositoryFactory that you can use as follows.
376
378
377
379
.Standalone usage of repository factory
@@ -572,7 +574,7 @@ This section documents a set of Spring Data extensions that enable Spring Data u
572
574
573
575
NOTE: This section contains the documentation for the Spring Data web support as it is implemented as of Spring Data Commons in the 1.6 range. As it the newly introduced support changes quite a lot of things we kept the documentation of the former behavior in <<web.legacy>>.
574
576
575
-
Spring Data modules ships with a variety of web support if the module supports the repository programming model. The web related stuff requires Spring MVC JARs on the classpath, some of them even provide integration with Spring HATEOAS footnote:[Spring HATEOAS - link:$$https://github.com/SpringSource/spring-hateoas$$[https://github.com/SpringSource/spring-hateoas]]. In general, the integration support is enabled by using the `@EnableSpringDataWebSupport annotation in your JavaConfig configuration class.
577
+
Spring Data modules ships with a variety of web support if the module supports the repository programming model. The web related stuff requires Spring MVC JARs on the classpath, some of them even provide integration with Spring HATEOAS footnote:[Spring HATEOAS - link:$$https://github.com/SpringSource/spring-hateoas$$[https://github.com/SpringSource/spring-hateoas]]. In general, the integration support is enabled by using the `@EnableSpringDataWebSupport` annotation in your JavaConfig configuration class.
576
578
577
579
.Enabling Spring Data web support
578
580
====
@@ -658,10 +660,11 @@ public class UserController {
658
660
This method signature will cause Spring MVC try to derive a Pageable instance from the request parameters using the following default configuration:
659
661
660
662
.Request parameters evaluated for Pageable instances
663
+
[options = "autowidth"]
661
664
|===============
662
665
|`page`|Page you want to retrieve.
663
666
|`size`|Size of the page you want to retrieve.
664
-
|`sort`|Properties that should be sorted by in the format `property,property(,ASC|DESC)`. Default sort direction is ascending. Use multiple sort` parameters if you want to switch directions, e.g. `?sort=firstname&sort=lastname,asc`.
667
+
|`sort`|Properties that should be sorted by in the format `property,property(,ASC\|DESC)`. Default sort direction is ascending. Use multiple `sort` parameters if you want to switch directions, e.g. `?sort=firstname&sort=lastname,asc`.
665
668
|===============
666
669
667
670
To customize this behavior extend either `SpringDataWebConfiguration` or the HATEOAS-enabled equivalent and override the `pageableResolver()` or `sortResolver()` methods and import your customized configuration file instead of using the `@Enable`-annotation.
@@ -972,21 +975,24 @@ public class UserController {
972
975
973
976
The `PageableArgumentResolver` automatically resolves request parameters to build a `PageRequest` instance. By default it expects the following structure for the request parameters.
974
977
975
-
.Request parameters evaluated by `PageableHandlerMethodArgumentResolver`
976
-
978
+
.Request parameters evaluated by PageableHandlerMethodArgumentResolver
979
+
[options = "autowidth"]
977
980
|===============
978
981
|`page`|Page you want to retrieve, 0 indexed and defaults to 0.
979
982
|`size`|Size of the page you want to retrieve, defaults to 20.
980
-
|`sort`|A collection of sort directives in the format `($propertyname,)[asc|desc]?`.
983
+
|`sort`|A collection of sort directives in the format `($propertyname,)[asc\|desc]?`.
981
984
|===============
982
985
983
-
.Pagination URL Parameter Examples
984
-
====
986
+
.Pagination URL parameter examples
987
+
985
988
To retrieve the third page with a maximum page size of 100 with the data sorted by the email property in ascending order use the following url parameter:
989
+
====
986
990
----
987
991
?page=2&size=100&sort=email,asc
988
992
----
993
+
====
989
994
To sort the data by multiple properties in different sort order use the following URL parameter:
995
+
====
990
996
----
991
997
?sort=foo,asc&sort=bar,desc
992
998
----
@@ -1003,7 +1009,7 @@ public String showUsers(Model model,
1003
1009
1004
1010
you have to populate `foo_page` and `bar_page` and the related subproperties.
1005
1011
1006
-
Configuring a global default on bean declaration the `PageableArgumentResolver` will use a `PageRequest` with the first page and a page size of 10 by default. It will use that value if it cannot resolve a `PageRequest` from the request (because of missing parameters, for example). You can configure a global default on the bean declaration directly. If you might need controller method specific defaults for the `Pageable`, annotate the method parameter with @PageableDefaults and specify page (through `pageNumber`), page size (through `value`), `sort` (list of properties to sort by), and `sortDir` (the direction to sort by) as annotation attributes:
1012
+
Configuring a global default on bean declaration the `PageableArgumentResolver` will use a `PageRequest` with the first page and a page size of 10 by default. It will use that value if it cannot resolve a `PageRequest` from the request (because of missing parameters, for example). You can configure a global default on the bean declaration directly. If you might need controller method specific defaults for the `Pageable`, annotate the method parameter with `@PageableDefaults` and specify page (through `pageNumber`), page size (through `value`), `sort` (list of properties to sort by), and `sortDir` (the direction to sort by) as annotation attributes:
0 commit comments