
org.springframework.data.jpa.domain.GenericAuditableName Maven / Gradle / Ivy
package org.springframework.data.jpa.domain;
import java.io.Serializable;
import java.util.Date;
import java.util.Optional;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.joda.time.DateTime;
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.domain.Auditable;
/**
*
@Override
public Optional getCreatedBy() {
return Optional.ofNullable(createdBy);
}
@Override
public void setCreatedBy(U createdBy) {
this.createdBy = createdBy;
}
@Override
public Optional getCreatedDate() {
return null == createdDate ? Optional.empty() : Optional.of(LocalDateTime.ofInstant(createdDate.toInstant(), ZoneId.systemDefault()));
}
@Override
public void setCreatedDate(LocalDateTime createdDate) {
this.createdDate = Date.from(createdDate.atZone(ZoneId.systemDefault()).toInstant());
this.createdAddress = getRemoteAddress(null);
}
@Override
public Optional getLastModifiedBy() {
return Optional.ofNullable(lastModifiedBy);
}
@Override
public void setLastModifiedBy(U lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}
@Override
public Optional getLastModifiedDate() {
return null == lastModifiedDate ? Optional.empty() : Optional.of(LocalDateTime.ofInstant(lastModifiedDate.toInstant(), ZoneId.systemDefault()));
}
@Override
public void setLastModifiedDate(LocalDateTime lastModifiedDate) {
this.lastModifiedDate = Date.from(lastModifiedDate.atZone(ZoneId.systemDefault()).toInstant());
this.lastModifiedAddress = getRemoteAddress(null);
}
*
*/
@Access(AccessType.FIELD)
@MappedSuperclass
public abstract class GenericAuditableName extends GenericPersistable implements Auditable {
private static final long serialVersionUID = -1564212293184319064L;
/**
*
* @CreatedBy
* @Column(length = COLUMN_LENGTH_ID, updatable = false)
* private String createdBy;
*
*/
@CreatedBy
@Column(name = "createdBy", updatable = false)
protected String createdBy;
@CreatedDate
@Temporal(value = TemporalType.TIMESTAMP)
@Column(updatable = false)
protected Date createdDate;
@Column(length = COLUMN_LENGTH_ADDRESS, updatable = false)
protected String createdAddress;
/**
*
* @LastModifiedBy
* @Column(length = COLUMN_LENGTH_ID)
* private String lastModifiedBy;
*
*/
@LastModifiedBy
@Column(name = "lastModifiedBy")
protected String lastModifiedBy;
@LastModifiedDate
@Temporal(value = TemporalType.TIMESTAMP)
@Column
protected Date lastModifiedDate;
@Column(length = COLUMN_LENGTH_ADDRESS)
protected String lastModifiedAddress;
@Override
public String getCreatedBy() {
return createdBy;
}
@Override
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
@Override
public DateTime getCreatedDate() {
return null == createdDate ? null : new DateTime(createdDate);
}
@Override
public void setCreatedDate(DateTime createdDate) {
this.createdDate = null == createdDate ? null : createdDate.toDate();
this.createdAddress = getRemoteAddress(null);
}
public String getCreatedAddress() {
return createdAddress;
}
@Override
public String getLastModifiedBy() {
return lastModifiedBy;
}
@Override
public void setLastModifiedBy(String lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}
@Override
public DateTime getLastModifiedDate() {
return null == lastModifiedDate ? null : new DateTime(lastModifiedDate);
}
@Override
public void setLastModifiedDate(DateTime lastModifiedDate) {
this.lastModifiedDate = null == lastModifiedDate ? null : lastModifiedDate.toDate();
this.lastModifiedAddress = getRemoteAddress(null);
}
public String getLastModifiedAddress() {
return lastModifiedAddress;
}
public void setCreatedAddress(String createdAddress) {
this.createdAddress = createdAddress;
}
public void setLastModifiedAddress(String lastModifiedAddress) {
this.lastModifiedAddress = lastModifiedAddress;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy