Skip to content

Commit 8219c96

Browse files
committed
Restructure content to include partials from Commons.
See #3080
1 parent 016be28 commit 8219c96

29 files changed

+286
-245
lines changed

src/main/antora/antora-playbook.yml

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ content:
1515
branches: HEAD
1616
start_path: src/main/antora
1717
worktrees: true
18+
- url: https://github.com/spring-projects/spring-data-commons
19+
# Refname matching:
20+
# https://docs.antora.org/antora/latest/playbook/content-refname-matching/
21+
branches: [main, 3.2.x]
22+
start_path: src/main/antora
1823
asciidoc:
1924
attributes:
2025
page-pagination: ''

src/main/antora/modules/ROOT/nav.adoc

+21-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
11
* xref:index.adoc[Overview]
2+
** xref:commons/upgrade.adoc[]
3+
* xref:repositories/introduction.adoc[]
4+
** xref:repositories/core-concepts.adoc[]
5+
** xref:repositories/definition.adoc[]
6+
** xref:repositories/create-instances.adoc[]
7+
** xref:repositories/query-methods-details.adoc[]
8+
** xref:repositories/custom-implementations.adoc[]
9+
** xref:repositories/core-domain-events.adoc[]
10+
** xref:repositories/core-extensions.adoc[]
11+
** xref:repositories/null-handling.adoc[]
12+
** xref:repositories/query-keywords-reference.adoc[]
13+
** xref:repositories/query-return-types-reference.adoc[]
214
* xref:jpa.adoc[]
3-
** xref:jpa/introduction.adoc[]
15+
** xref:jpa/configuration.adoc[]
416
** xref:jpa/entity-persistence.adoc[]
517
** xref:jpa/query-methods.adoc[]
618
** xref:jpa/stored-procedures.adoc[]
719
** xref:jpa/specifications.adoc[]
8-
** xref:jpa/query-by-example.adoc[]
20+
** xref:query-by-example.adoc[]
921
** xref:jpa/transactions.adoc[]
1022
** xref:jpa/locking.adoc[]
11-
** xref:jpa/auditing.adoc[]
23+
** xref:auditing.adoc[]
1224
** xref:jpa/misc-context.adoc[]
1325
** xref:jpa/misc-merging-persistence-units.adoc[]
1426
** xref:jpa/jpd-misc-cdi-integration.adoc[]
27+
** xref:jpa/faq.adoc[]
28+
** xref:jpa/glossary.adoc[]
1529
* xref:envers.adoc[]
16-
* xref:faq.adoc[]
17-
* xref:glossary.adoc[]
30+
** xref:envers/introduction.adoc[]
31+
** xref:envers/configuration.adoc[]
32+
** xref:envers/usage.adoc[]
33+
* https://github.com/spring-projects/spring-data-commons/wiki[Wiki]

src/main/antora/modules/ROOT/pages/jpa/auditing.adoc src/main/antora/modules/ROOT/pages/auditing.adoc

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
[[jpa.auditing]]
2-
= JPA Auditing
3-
4-
Spring Data JPA provides auditing based upon the foundation provided by {spring-data-commons-docs-url}/auditing.html[Spring Data Common's Auditing support].
5-
1+
include::{commons}@data-commons::page$auditing.adoc[]
62

73
There is also a convenience base class, `AbstractAuditable`, which you can extend to avoid the need to manually implement the interface methods. Doing so 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.
84

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include::{commons}@data-commons::page$upgrade.adoc[]
+3-202
Original file line numberDiff line numberDiff line change
@@ -1,204 +1,5 @@
11
[[envers]]
2-
= Spring Data Envers
2+
= Envers
3+
:page-section-summary-toc: 1
34

4-
[[envers.what.is.spring.data]]
5-
== What is Spring Data Envers?
6-
7-
Spring Data Envers makes typical Envers queries available in repositories for Spring Data JPA.
8-
It differs from other Spring Data modules in that it is always used in combination with another Spring Data Module: Spring Data JPA.
9-
10-
[[envers.what]]
11-
== What is Envers?
12-
13-
Envers is a https://hibernate.org/orm/envers/[Hibernate module] that adds auditing capabilities to JPA entities.
14-
This documentation assumes you are familiar with Envers, just as Spring Data Envers relies on Envers being properly configured.
15-
16-
[[envers.configuration]]
17-
== Configuration
18-
19-
As a starting point for using Spring Data Envers, you need a project with Spring Data JPA on the classpath and an additional `spring-data-envers` dependency:
20-
21-
====
22-
[source,xml,subs="+attributes"]
23-
----
24-
<dependencies>
25-
26-
<!-- other dependency elements omitted -->
27-
28-
<dependency>
29-
<groupId>org.springframework.data</groupId>
30-
<artifactId>spring-data-envers</artifactId>
31-
<version>{version}</version>
32-
</dependency>
33-
34-
</dependencies>
35-
----
36-
====
37-
38-
This also brings `hibernate-envers` into the project as a transient dependency.
39-
40-
To enable Spring Data Envers and Spring Data JPA, we need to configure two beans and a special `repositoryFactoryBeanClass`:
41-
42-
====
43-
[source,java]
44-
----
45-
@Configuration
46-
@EnableEnversRepositories
47-
@EnableTransactionManagement
48-
public class EnversDemoConfiguration {
49-
50-
@Bean
51-
public DataSource dataSource() {
52-
53-
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
54-
return builder.setType(EmbeddedDatabaseType.HSQL).build();
55-
}
56-
57-
@Bean
58-
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
59-
60-
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
61-
vendorAdapter.setGenerateDdl(true);
62-
63-
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
64-
factory.setJpaVendorAdapter(vendorAdapter);
65-
factory.setPackagesToScan("example.springdata.jpa.envers");
66-
factory.setDataSource(dataSource());
67-
return factory;
68-
}
69-
70-
@Bean
71-
public PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
72-
73-
JpaTransactionManager txManager = new JpaTransactionManager();
74-
txManager.setEntityManagerFactory(entityManagerFactory);
75-
return txManager;
76-
}
77-
}
78-
----
79-
====
80-
81-
To actually use Spring Data Envers, make one or more repositories into a {spring-data-commons-javadoc-base}/org/springframework/data/repository/history/RevisionRepository.html[`RevisionRepository`] by adding it as an extended interface:
82-
83-
====
84-
[source,java]
85-
----
86-
interface PersonRepository
87-
extends CrudRepository<Person, Long>,
88-
RevisionRepository<Person, Long, Long> // <1>
89-
{}
90-
----
91-
<1> The first type parameter (`Person`) denotes the entity type, the second (`Long`) denotes the type of the id property, and the last one (`Long`) is the type of the revision number.
92-
For Envers in default configuration, the revision number parameter should be `Integer` or `Long`.
93-
====
94-
95-
The entity for that repository must be an entity with Envers auditing enabled (that is, it must have an `@Audited` annotation):
96-
97-
====
98-
[source,java]
99-
----
100-
@Entity
101-
@Audited
102-
class Person {
103-
104-
@Id @GeneratedValue
105-
Long id;
106-
String name;
107-
@Version Long version;
108-
}
109-
----
110-
====
111-
112-
[[envers.usage]]
113-
== Usage
114-
115-
You can now use the methods from `RevisionRepository` to query the revisions of the entity, as the following test case shows:
116-
117-
====
118-
[source,java]
119-
----
120-
@ExtendWith(SpringExtension.class)
121-
@Import(EnversDemoConfiguration.class) // <1>
122-
class EnversIntegrationTests {
123-
124-
final PersonRepository repository;
125-
final TransactionTemplate tx;
126-
127-
EnversIntegrationTests(@Autowired PersonRepository repository, @Autowired PlatformTransactionManager tm) {
128-
this.repository = repository;
129-
this.tx = new TransactionTemplate(tm);
130-
}
131-
132-
@Test
133-
void testRepository() {
134-
135-
Person updated = preparePersonHistory();
136-
137-
Revisions<Long, Person> revisions = repository.findRevisions(updated.id);
138-
139-
Iterator<Revision<Long, Person>> revisionIterator = revisions.iterator();
140-
141-
checkNextRevision(revisionIterator, "John", RevisionType.INSERT);
142-
checkNextRevision(revisionIterator, "Jonny", RevisionType.UPDATE);
143-
checkNextRevision(revisionIterator, null, RevisionType.DELETE);
144-
assertThat(revisionIterator.hasNext()).isFalse();
145-
146-
}
147-
148-
/**
149-
* Checks that the next element in the iterator is a Revision entry referencing a Person
150-
* with the given name after whatever change brought that Revision into existence.
151-
* <p>
152-
* As a side effect the Iterator gets advanced by one element.
153-
*
154-
* @param revisionIterator the iterator to be tested.
155-
* @param name the expected name of the Person referenced by the Revision.
156-
* @param revisionType the type of the revision denoting if it represents an insert, update or delete.
157-
*/
158-
private void checkNextRevision(Iterator<Revision<Long, Person>> revisionIterator, String name,
159-
RevisionType revisionType) {
160-
161-
assertThat(revisionIterator.hasNext()).isTrue();
162-
Revision<Long, Person> revision = revisionIterator.next();
163-
assertThat(revision.getEntity().name).isEqualTo(name);
164-
assertThat(revision.getMetadata().getRevisionType()).isEqualTo(revisionType);
165-
}
166-
167-
/**
168-
* Creates a Person with a couple of changes so it has a non-trivial revision history.
169-
* @return the created Person.
170-
*/
171-
private Person preparePersonHistory() {
172-
173-
Person john = new Person();
174-
john.setName("John");
175-
176-
// create
177-
Person saved = tx.execute(__ -> repository.save(john));
178-
assertThat(saved).isNotNull();
179-
180-
saved.setName("Jonny");
181-
182-
// update
183-
Person updated = tx.execute(__ -> repository.save(saved));
184-
assertThat(updated).isNotNull();
185-
186-
// delete
187-
tx.executeWithoutResult(__ -> repository.delete(updated));
188-
return updated;
189-
}
190-
}
191-
----
192-
<1> This references the application context configuration presented earlier (in the xref:envers.adoc#envers.configuration[Configuration] section).
193-
====
194-
195-
[[envers.resources]]
196-
== Further Resources
197-
198-
You can download the https://github.com/spring-projects/spring-data-examples[Spring Data Envers example in the Spring Data Examples repository] and play around with to get a feel for how the library works.
199-
200-
You should also check out the {spring-data-commons-javadoc-base}/org/springframework/data/repository/history/RevisionRepository.html[Javadoc for `RevisionRepository`] and related classes.
201-
202-
You can ask questions at https://stackoverflow.com/questions/tagged/spring-data-envers[Stackoverflow by using the `spring-data-envers` tag].
203-
204-
The https://github.com/spring-projects/spring-data-jpa[source code and issue tracker for Spring Data Envers is hosted at GitHub] (as a module of Spring Data JPA).
5+
This chapter points out the specialties for repository support for Envers. This builds on the core repository support explained earlier. Make sure you have a sound understanding of the basic concepts explained there.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
[[envers.configuration]]
2+
= Configuration
3+
4+
As a starting point for using Spring Data Envers, you need a project with Spring Data JPA on the classpath and an additional `spring-data-envers` dependency:
5+
6+
====
7+
[source,xml,subs="+attributes"]
8+
----
9+
<dependencies>
10+
11+
<!-- other dependency elements omitted -->
12+
13+
<dependency>
14+
<groupId>org.springframework.data</groupId>
15+
<artifactId>spring-data-envers</artifactId>
16+
<version>{version}</version>
17+
</dependency>
18+
19+
</dependencies>
20+
----
21+
====
22+
23+
This also brings `hibernate-envers` into the project as a transient dependency.
24+
25+
To enable Spring Data Envers and Spring Data JPA, we need to configure two beans and a special `repositoryFactoryBeanClass`:
26+
27+
====
28+
[source,java]
29+
----
30+
@Configuration
31+
@EnableEnversRepositories
32+
@EnableTransactionManagement
33+
public class EnversDemoConfiguration {
34+
35+
@Bean
36+
public DataSource dataSource() {
37+
38+
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
39+
return builder.setType(EmbeddedDatabaseType.HSQL).build();
40+
}
41+
42+
@Bean
43+
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
44+
45+
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
46+
vendorAdapter.setGenerateDdl(true);
47+
48+
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
49+
factory.setJpaVendorAdapter(vendorAdapter);
50+
factory.setPackagesToScan("example.springdata.jpa.envers");
51+
factory.setDataSource(dataSource());
52+
return factory;
53+
}
54+
55+
@Bean
56+
public PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
57+
58+
JpaTransactionManager txManager = new JpaTransactionManager();
59+
txManager.setEntityManagerFactory(entityManagerFactory);
60+
return txManager;
61+
}
62+
}
63+
----
64+
====
65+
66+
To actually use Spring Data Envers, make one or more repositories into a {spring-data-commons-javadoc-base}/org/springframework/data/repository/history/RevisionRepository.html[`RevisionRepository`] by adding it as an extended interface:
67+
68+
====
69+
[source,java]
70+
----
71+
interface PersonRepository
72+
extends CrudRepository<Person, Long>,
73+
RevisionRepository<Person, Long, Long> // <1>
74+
{}
75+
----
76+
<1> The first type parameter (`Person`) denotes the entity type, the second (`Long`) denotes the type of the id property, and the last one (`Long`) is the type of the revision number.
77+
For Envers in default configuration, the revision number parameter should be `Integer` or `Long`.
78+
====
79+
80+
The entity for that repository must be an entity with Envers auditing enabled (that is, it must have an `@Audited` annotation):
81+
82+
====
83+
[source,java]
84+
----
85+
@Entity
86+
@Audited
87+
class Person {
88+
89+
@Id @GeneratedValue
90+
Long id;
91+
String name;
92+
@Version Long version;
93+
}
94+
----
95+
====
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[[envers.introduction]]
2+
= Introduction
3+
4+
[[envers.what.is.spring.data]]
5+
== What is Spring Data Envers?
6+
7+
Spring Data Envers makes typical Envers queries available in repositories for Spring Data JPA.
8+
It differs from other Spring Data modules in that it is always used in combination with another Spring Data Module: Spring Data JPA.
9+
10+
[[envers.what]]
11+
== What is Envers?
12+
13+
Envers is a https://hibernate.org/orm/envers/[Hibernate module] that adds auditing capabilities to JPA entities.
14+
This documentation assumes you are familiar with Envers, just as Spring Data Envers relies on Envers being properly configured.

0 commit comments

Comments
 (0)