DateTime getCreatedDate();
void setCreated(final DateTime creationDate);
U getLastModifiedBy();
void setLastModifiedBy(final U lastModifiedBy);
DateTime getLastModifiedDate();
void setLastModified(final DateTime lastModifiedDate);
}
To show how it works, let's create a new table called CONTACT_AUDIT in our database schema, which
is based on the CONTACT table, with four audit-related columns added. Listing 10-37 shows the table
creation script (schema.sql).
Listing 10-37. The CONTACT_AUDIT Table
CREATE TABLE CONTACT_AUDIT (
ID INT NOT NULL AUTO_INCREMENT
, FIRST_NAME VARCHAR(60) NOT NULL
, LAST_NAME VARCHAR(40) NOT NULL
, BIRTH_DATE DATE
, VERSION INT NOT NULL DEFAULT 0
, CREATED_BY VARCHAR(20)
, CREATED_DATE TIMESTAMP
, LAST_MODIFIED_BY VARCHAR(20)
, LAST_MODIFIED_DATE TIMESTAMP
, UNIQUE UQ_CONTACT_AUDIT_1 (FIRST_NAME, LAST_NAME)
, PRIMARY KEY (ID)
);
In Listing 10-37, the four columns with bold characters indicate the audit-related columns. The next
step is to create the entity class called ContactAudit. It's basically the same as the Contact entity class; we
just added the mapping for the four audit columns. Also, the class implements the Auditable interface.
Listing 10-38 shows the code snippet that was added on top of the Contact class.
Listing 10-38. The ContactAudit Class
package com.apress.prospring3.ch10.domain;
// Import statements omitted
@Entity
@Table(name = "contact_audit")
public class ContactAudit implements Auditable<String, Long>, Serializable {
// other declaration mapping properties omitted
// Audit fields
private String createdBy;
private DateTime createdDate;
private String lastModifiedBy;
private DateTime lastModifiedDate;
@Column(name="CREATED_BY")
public String getCreatedBy() {
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home