add missing doc to AbstractPersistableCustom & AbstractAuditableCustom
This commit is contained in:
committed by
Michael Vorburger ⛑️
parent
d0c8c6a012
commit
ae4117052b
+2
-49
@@ -35,9 +35,9 @@ import org.springframework.data.jpa.domain.AbstractAuditable;
|
||||
|
||||
/**
|
||||
* A custom copy of {@link AbstractAuditable} to override the column names used
|
||||
* on database.
|
||||
* on database. It also uses Instant instead of LocalDateTime for created and modified.
|
||||
*
|
||||
* Abstract base class for auditable entities. Stores the audition values in
|
||||
* Abstract base class for auditable entities. Stores the audit values in
|
||||
* persistent fields.
|
||||
*
|
||||
* @param <U>
|
||||
@@ -66,88 +66,41 @@ public abstract class AbstractAuditableCustom<U, PK extends Serializable> extend
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date lastModifiedDate;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.data.domain.Auditable#getCreatedBy()
|
||||
*/
|
||||
@Override
|
||||
public Optional<AppUser> getCreatedBy() {
|
||||
return Optional.ofNullable(this.createdBy);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.data.domain.Auditable#setCreatedBy(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public void setCreatedBy(final AppUser createdBy) {
|
||||
|
||||
this.createdBy = createdBy;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.data.domain.Auditable#getCreatedDate()
|
||||
*/
|
||||
@Override
|
||||
public Optional<Instant> getCreatedDate() {
|
||||
return null == this.createdDate ? Optional.empty() : Optional.of(this.createdDate.toInstant());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.data.domain.Auditable#setCreatedDate(T)
|
||||
*/
|
||||
@Override
|
||||
public void setCreatedDate(final Instant createdDate) {
|
||||
this.createdDate = null == createdDate ? null : Date.from(createdDate);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.data.domain.Auditable#getLastModifiedBy()
|
||||
*/
|
||||
@Override
|
||||
public Optional<AppUser> getLastModifiedBy() {
|
||||
return Optional.ofNullable(this.lastModifiedBy);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.data.domain.Auditable#setLastModifiedBy(java.lang
|
||||
* .Object)
|
||||
*/
|
||||
@Override
|
||||
public void setLastModifiedBy(final AppUser lastModifiedBy) {
|
||||
|
||||
this.lastModifiedBy = lastModifiedBy;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.data.domain.Auditable#getLastModifiedDate()
|
||||
*/
|
||||
@Override
|
||||
public Optional<Instant> getLastModifiedDate() {
|
||||
return null == this.lastModifiedDate ? Optional.empty() : Optional.of(this.lastModifiedDate.toInstant());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.data.domain.Auditable#setLastModifiedDate(T)
|
||||
*/
|
||||
@Override
|
||||
public void setLastModifiedDate(final Instant lastModifiedDate) {
|
||||
this.lastModifiedDate = null == lastModifiedDate ? null : Date.from(lastModifiedDate);
|
||||
|
||||
+26
-19
@@ -25,30 +25,37 @@ import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import org.springframework.data.domain.Persistable;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract base class for entities.
|
||||
*
|
||||
* Inspired by {@link org.springframework.data.jpa.domain.AbstractPersistable}, but
|
||||
* Id is always Long (and this class thus does not require generic parameterization),
|
||||
* and auto-generation is of strategy {@link javax.persistence.GenerationType#IDENTITY}.
|
||||
*
|
||||
* The {@link #equals(Object)} and {@link #hashCode()} methods are NOT implemented here,
|
||||
* which is untypical for JPA (it's usually implemented based on the Id), because
|
||||
* "we end up with issues on OpenJPA" (TODO clarify this).
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public abstract class AbstractPersistableCustom<PK extends Serializable> implements Persistable<Long>, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 9181640245194392646L;
|
||||
private static final long serialVersionUID = 9181640245194392646L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
protected void setId(final Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
protected void setId(final Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNew() {
|
||||
|
||||
return null == this.id;
|
||||
}
|
||||
|
||||
// We have removed toString(), hashCode() and equals() methods here, because by adding them here, we end up with issues on OpenJPA.
|
||||
@Override
|
||||
public boolean isNew() {
|
||||
return null == this.id;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user