DATACASS-4 - Add support for auditing.
We now support auditing using Spring's IsNewAwareAuditingHandler. Entities that are saved are processed before persisting these through auditing EntityCallbacks.
@Table
class Entity {
@Id Long id;
@CreatedDate
LocalDateTime created;
@LastModifiedDate
LocalDateTime modified;
// …
}
@EnableCassandraAuditing
@Configuration
class MyConfiguration extends AbstractReactiveCassandraConfiguration {
// …
}
This commit is contained in:
@@ -27,6 +27,8 @@ include::reference/converters.adoc[leveloffset=+1]
|
||||
include::reference/reactive-cassandra.adoc[leveloffset=+1]
|
||||
include::reference/cassandra-repositories.adoc[leveloffset=+1]
|
||||
include::reference/reactive-cassandra-repositories.adoc[leveloffset=+1]
|
||||
include::{spring-data-commons-docs}/auditing.adoc[leveloffset=+1]
|
||||
include::reference/cassandra-auditing.adoc[leveloffset=+1]
|
||||
include::reference/mapping.adoc[leveloffset=+1]
|
||||
|
||||
[[appendix]]
|
||||
|
||||
@@ -11,6 +11,7 @@ This chapter summarizes changes and new features for each release.
|
||||
* Lightweight transaction support via `DeleteOptions` using the Template API.
|
||||
* Filter conditions for lightweight transaction update and delete (`UPDATE … IF <condition>`, `DELETE … IF <condition>`).
|
||||
* Optimistic Locking support.
|
||||
* Auditing via `@EnableCassandraAuditing`.
|
||||
|
||||
[[new-features.2-1-0]]
|
||||
== What's new in Spring Data for Apache Cassandra 2.1
|
||||
|
||||
33
src/main/asciidoc/reference/cassandra-auditing.adoc
Normal file
33
src/main/asciidoc/reference/cassandra-auditing.adoc
Normal file
@@ -0,0 +1,33 @@
|
||||
[[cassandra.auditing]]
|
||||
== General Auditing Configuration for Cassandra
|
||||
|
||||
To activate auditing functionality, add the Spring Data for Apache Cassandra `auditing` namespace element to your configuration, as the following example shows:
|
||||
|
||||
.Activating auditing by using XML configuration
|
||||
====
|
||||
[source,xml]
|
||||
----
|
||||
<cassandra:auditing mapping-context-ref="customMappingContext" auditor-aware-ref="yourAuditorAwareImpl"/>
|
||||
----
|
||||
====
|
||||
|
||||
Alternatively, auditing can be enabled by annotating a configuration class with the `@EnableCassandraAuditing` annotation, as the following example shows:
|
||||
|
||||
.Activating auditing using JavaConfig
|
||||
====
|
||||
[source,java]
|
||||
----
|
||||
@Configuration
|
||||
@EnableCassandraAuditing
|
||||
class Config {
|
||||
|
||||
@Bean
|
||||
public AuditorAware<AuditableUser> myAuditorProvider() {
|
||||
return new AuditorAwareImpl();
|
||||
}
|
||||
}
|
||||
----
|
||||
====
|
||||
|
||||
If you expose a bean of type `AuditorAware` to the `ApplicationContext`, the auditing infrastructure picks it up automatically and uses it to determine the current user to be set on domain types.
|
||||
If you have multiple implementations registered in the `ApplicationContext`, you can select the one to be used by explicitly setting the `auditorAwareRef` attribute of `@EnableCassandraAuditing`.
|
||||
29
src/main/asciidoc/reference/cassandra-entity-callbacks.adoc
Normal file
29
src/main/asciidoc/reference/cassandra-entity-callbacks.adoc
Normal file
@@ -0,0 +1,29 @@
|
||||
= Store specific EntityCallbacks
|
||||
|
||||
Spring Data for Apache Cassandra uses the `EntityCallback` API for its auditing support and reacts on the following callbacks.
|
||||
|
||||
.Supported Entity Callbacks
|
||||
[%header,cols="4"]
|
||||
|===
|
||||
| Callback
|
||||
| Method
|
||||
| Description
|
||||
| Order
|
||||
|
||||
| Reactive/BeforeConvertCallback
|
||||
| onBeforeConvert(T entity, String collection)
|
||||
| Invoked before a domain object is converted to `org.bson.Document`.
|
||||
| `Ordered.LOWEST_PRECEDENCE`
|
||||
|
||||
| Reactive/AuditingEntityCallback
|
||||
| onBeforeConvert(Object entity, String collection)
|
||||
| Marks an auditable entity _created_ or _modified_
|
||||
| 100
|
||||
|
||||
| Reactive/BeforeSaveCallback
|
||||
| onBeforeSave(T entity, org.bson.Document target, String collection)
|
||||
| Invoked before a domain object is saved. +
|
||||
Can modify the target, to be persisted, `Document` containing all mapped entity information.
|
||||
| `Ordered.LOWEST_PRECEDENCE`
|
||||
|
||||
|===
|
||||
@@ -655,3 +655,6 @@ The `AbstractCassandraEventListener` has the following callback methods:
|
||||
* `onAfterConvert`: Called in the `CassandraTemplate.select(…)`, `.slice(…)`, and `.stream(…)` methods after converting a row retrieved from the database to a POJO.
|
||||
|
||||
NOTE: Lifecycle events are emitted only for root-level types. Complex types used as properties within an aggregate root are not subject to event publication.
|
||||
|
||||
include::../{spring-data-commons-docs}/entity-callbacks.adoc[leveloffset=+1]
|
||||
include::./cassandra-entity-callbacks.adoc[leveloffset=+2]
|
||||
|
||||
Reference in New Issue
Block a user