Browse Source

DATAJDBC-154 - Polishing.

pull/24/merge
Greg Turnquist 8 years ago
parent
commit
0ef1a63bda
No known key found for this signature in database
GPG Key ID: CB2FA4D512B5C413
  1. 98
      README.adoc

98
README.adoc

@ -10,13 +10,14 @@ This means that it does rather little out of the box. But it offers plenty of pl
== Maven Coordinates == Maven Coordinates
```xml [source,xml]
----
<dependency> <dependency>
<groupId>org.springframework.data</groupId> <groupId>org.springframework.data</groupId>
<artifactId>spring-data-jdbc</artifactId> <artifactId>spring-data-jdbc</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version> <version>1.0.0.BUILD-SNAPSHOT</version>
</dependency> </dependency>
``` ----
== Features == Features
@ -24,31 +25,37 @@ This means that it does rather little out of the box. But it offers plenty of pl
In order use Spring Data JDBC you need the following: In order use Spring Data JDBC you need the following:
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. 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.
+
public class Person { [source,java]
@Id ----
Integer id; public class Person {
} @Id
Integer id;
2. A repository }
----
public interface PersonRepository extends CrudRepository<Person, Integer> {} +
1. A repository
3. Add `@EnableJdbcRepositories` to your application context configuration. +
[source,java]
4. Make sure your application context contains a bean of type `DataSource`. ----
public interface PersonRepository extends CrudRepository<Person, Integer> {}
----
+
1. Add `@EnableJdbcRepositories` to your application context configuration.
1. Make sure your application context contains a bean of type `DataSource`.
Now you can get an instance of the repository interface injected into your beans and use it: Now you can get an instance of the repository interface injected into your beans and use it:
```java [source,java]
@Autowired ----
private PersonRepository repository; @Autowired
private PersonRepository repository;
public void someMethod() { public void someMethod() {
Person person = repository.save(new Person()); Person person = repository.save(new Person());
} }
``` ----
=== Id generation === Id generation
@ -74,39 +81,40 @@ You can tweak that by providing a https://github.com/spring-projects/spring-data
Spring Data Jdbc triggers events which will get publish to any matching `ApplicationListener` in the application context. Spring Data Jdbc triggers events which will get publish to any matching `ApplicationListener` in the application context.
For example the following listener will get invoked before an aggregate gets saved. For example the following listener will get invoked before an aggregate gets saved.
``` java [source,java]
@Bean ----
public ApplicationListener<BeforeSave> timeStampingSaveTime() { @Bean
public ApplicationListener<BeforeSave> timeStampingSaveTime() {
return event -> {
return event -> {
Object entity = event.getEntity();
if (entity instanceof Category) { Object entity = event.getEntity();
Category category = (Category) entity; if (entity instanceof Category) {
category.timeStamp(); Category category = (Category) entity;
} category.timeStamp();
}; }
} };
``` }
----
.Available events .Available events
|=== |===
| Type | Published ... | Event | When It's Published
| https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/event/AfterDelete.java[`AfterDelete`]
| after an aggregate root got deleted.
| https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/event/BeforeDelete.java[`BeforeDelete`], | https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/event/BeforeDelete.java[`BeforeDelete`]
| before an aggregate root gets deleted. | before an aggregate root gets deleted.
| https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/event/AfterSave.java[`AfterSave`], | https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/event/AfterDelete.java[`AfterDelete`]
| after an aggregate root gets saved, i.e. inserted or updated. | after an aggregate root got deleted.
| https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/event/AfterDelete.java[`BeforeSave`], | https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/event/AfterDelete.java[`BeforeSave`]
| before an aggregate root gets saved, i.e. inserted or updated but after the decision was made if it will get updated or deleted. | before an aggregate root gets saved, i.e. inserted or updated but after the decision was made if it will get updated or deleted.
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. 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.
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. 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.
| https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/event/AfterSave.java[`AfterSave`]
| after an aggregate root gets saved, i.e. inserted or updated.
| https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/event/AfterDelete.java[`AfterCreation`] | https://github.com/spring-projects/spring-data-jdbc/blob/master/src/main/java/org/springframework/data/jdbc/mapping/event/AfterDelete.java[`AfterCreation`]
| after an aggregate root got created from a database `ResultSet` and all it's property set | after an aggregate root got created from a database `ResultSet` and all it's property set
|=== |===

Loading…
Cancel
Save