Auditing
Learn about Spring Data Cassandra’s auditing feature.
We'll cover the following...
We'll cover the following...
The auditing feature in Spring Data Cassandra automatically tracks and maintains metadata about data changes, including creation, modification, and deletion. It enhances data governance, traceability, and accountability in Cassandra-based applications, simplifying the implementation of audit trails.
Auditing metadata in the entity classes
First, let’s add a few properties in the POJOs that map the auditing metadata field in the database.
The Book entity
Let’s add properties like createdBy, dateCreated, updatedBy, and dateUpdated to the Book class. The underlying Spring Data Cassandra will take care of updating the database with the corresponding fields in the book table.
package com.smartdiscover.model;import lombok.Data;import org.springframework.data.annotation.CreatedBy;import org.springframework.data.annotation.CreatedDate;import org.springframework.data.annotation.LastModifiedBy;import org.springframework.data.annotation.LastModifiedDate;import org.springframework.data.cassandra.core.mapping.Column;import org.springframework.data.cassandra.core.mapping.PrimaryKey;import org.springframework.data.cassandra.core.mapping.Table;import java.util.Date;import java.util.UUID;@Data@Tablepublic class Book {@PrimaryKeyprivate UUID id;@Columnprivate String name;@Columnprivate String summary;@CreatedByprivate String createdBy;@CreatedDateprivate Date dateCreated;@LastModifiedByprivate String updatedBy;@LastModifiedDateprivate Date dateUpdated;@Overridepublic String toString() {return "Book{" +"id=" + id +", name='" + name + '\'' +", summary='" + summary + '\'' +", createdBy='" + createdBy + '\'' +", dateCreated='" + dateCreated + '\'' +", updatedBy='" + updatedBy + '\'' +", dateUpdated='" + dateUpdated +'}';}}
Here, we use the Spring Data annotations over the ...