Skip to content

Commit 0ef1a63

Browse files
committed
DATAJDBC-154 - Polishing.
1 parent d5193e4 commit 0ef1a63

File tree

1 file changed

+53
-45
lines changed

1 file changed

+53
-45
lines changed

README.adoc

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,52 @@ This means that it does rather little out of the box. But it offers plenty of pl
1010

1111
== Maven Coordinates
1212

13-
```xml
13+
[source,xml]
14+
----
1415
<dependency>
1516
<groupId>org.springframework.data</groupId>
1617
<artifactId>spring-data-jdbc</artifactId>
1718
<version>1.0.0.BUILD-SNAPSHOT</version>
1819
</dependency>
19-
```
20+
----
2021

2122
== Features
2223

2324
=== CRUD operations
2425

2526
In order use Spring Data JDBC you need the following:
2627

27-
1. An entity with an attribute marked as _id_ using the spring datas https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/annotation/Id.html[`@Id`] annotation.
28-
29-
public class Person {
30-
@Id
31-
Integer id;
32-
}
33-
34-
2. A repository
35-
36-
public interface PersonRepository extends CrudRepository<Person, Integer> {}
37-
38-
3. Add `@EnableJdbcRepositories` to your application context configuration.
39-
40-
4. Make sure your application context contains a bean of type `DataSource`.
28+
1. An entity with an attribute marked as _id_ using the spring datas https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/annotation/Id.html[`@Id`] annotation.
29+
+
30+
[source,java]
31+
----
32+
public class Person {
33+
@Id
34+
Integer id;
35+
}
36+
----
37+
+
38+
1. A repository
39+
+
40+
[source,java]
41+
----
42+
public interface PersonRepository extends CrudRepository<Person, Integer> {}
43+
----
44+
+
45+
1. Add `@EnableJdbcRepositories` to your application context configuration.
46+
1. Make sure your application context contains a bean of type `DataSource`.
4147

4248
Now you can get an instance of the repository interface injected into your beans and use it:
4349

44-
```java
45-
@Autowired
46-
private PersonRepository repository;
50+
[source,java]
51+
----
52+
@Autowired
53+
private PersonRepository repository;
4754
48-
public void someMethod() {
49-
Person person = repository.save(new Person());
50-
}
51-
```
55+
public void someMethod() {
56+
Person person = repository.save(new Person());
57+
}
58+
----
5259

5360
=== Id generation
5461

@@ -74,39 +81,40 @@ You can tweak that by providing a https://github.com/spring-projects/spring-data
7481
Spring Data Jdbc triggers events which will get publish to any matching `ApplicationListener` in the application context.
7582
For example the following listener will get invoked before an aggregate gets saved.
7683

77-
``` java
78-
@Bean
79-
public ApplicationListener<BeforeSave> timeStampingSaveTime() {
80-
81-
return event -> {
82-
83-
Object entity = event.getEntity();
84-
if (entity instanceof Category) {
85-
Category category = (Category) entity;
86-
category.timeStamp();
87-
}
88-
};
89-
}
90-
```
84+
[source,java]
85+
----
86+
@Bean
87+
public ApplicationListener<BeforeSave> timeStampingSaveTime() {
88+
89+
return event -> {
90+
91+
Object entity = event.getEntity();
92+
if (entity instanceof Category) {
93+
Category category = (Category) entity;
94+
category.timeStamp();
95+
}
96+
};
97+
}
98+
----
9199

92100
.Available events
93101
|===
94-
| Type | Published ...
95-
96-
| https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/event/AfterDelete.java[`AfterDelete`]
97-
| after an aggregate root got deleted.
102+
| Event | When It's Published
98103

99-
| https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/event/BeforeDelete.java[`BeforeDelete`],
104+
| https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/event/BeforeDelete.java[`BeforeDelete`]
100105
| before an aggregate root gets deleted.
101106

102-
| https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/event/AfterSave.java[`AfterSave`],
103-
| after an aggregate root gets saved, i.e. inserted or updated.
107+
| https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/event/AfterDelete.java[`AfterDelete`]
108+
| after an aggregate root got deleted.
104109

105-
| https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/event/AfterDelete.java[`BeforeSave`],
110+
| https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/event/AfterDelete.java[`BeforeSave`]
106111
| before an aggregate root gets saved, i.e. inserted or updated but after the decision was made if it will get updated or deleted.
107112
The event has a reference to an https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/core/conversion/AggregateChange.java[`AggregateChange`] instance.
108113
The instance can be modified by adding or removing https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/core/conversion/DbAction.java[`DbAction`]s.
109114

115+
| https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/event/AfterSave.java[`AfterSave`]
116+
| after an aggregate root gets saved, i.e. inserted or updated.
117+
110118
| https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/event/AfterDelete.java[`AfterCreation`]
111119
| after an aggregate root got created from a database `ResultSet` and all it's property set
112120
|===

0 commit comments

Comments
 (0)