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
|
* 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.
|
* persistent fields.
|
||||||
*
|
*
|
||||||
* @param <U>
|
* @param <U>
|
||||||
@@ -66,88 +66,41 @@ public abstract class AbstractAuditableCustom<U, PK extends Serializable> extend
|
|||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
private Date lastModifiedDate;
|
private Date lastModifiedDate;
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.springframework.data.domain.Auditable#getCreatedBy()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<AppUser> getCreatedBy() {
|
public Optional<AppUser> getCreatedBy() {
|
||||||
return Optional.ofNullable(this.createdBy);
|
return Optional.ofNullable(this.createdBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.domain.Auditable#setCreatedBy(java.lang.Object)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void setCreatedBy(final AppUser createdBy) {
|
public void setCreatedBy(final AppUser createdBy) {
|
||||||
|
|
||||||
this.createdBy = createdBy;
|
this.createdBy = createdBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.springframework.data.domain.Auditable#getCreatedDate()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Instant> getCreatedDate() {
|
public Optional<Instant> getCreatedDate() {
|
||||||
return null == this.createdDate ? Optional.empty() : Optional.of(this.createdDate.toInstant());
|
return null == this.createdDate ? Optional.empty() : Optional.of(this.createdDate.toInstant());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.domain.Auditable#setCreatedDate(T)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void setCreatedDate(final Instant createdDate) {
|
public void setCreatedDate(final Instant createdDate) {
|
||||||
this.createdDate = null == createdDate ? null : Date.from(createdDate);
|
this.createdDate = null == createdDate ? null : Date.from(createdDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.springframework.data.domain.Auditable#getLastModifiedBy()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<AppUser> getLastModifiedBy() {
|
public Optional<AppUser> getLastModifiedBy() {
|
||||||
return Optional.ofNullable(this.lastModifiedBy);
|
return Optional.ofNullable(this.lastModifiedBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.domain.Auditable#setLastModifiedBy(java.lang
|
|
||||||
* .Object)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void setLastModifiedBy(final AppUser lastModifiedBy) {
|
public void setLastModifiedBy(final AppUser lastModifiedBy) {
|
||||||
|
|
||||||
this.lastModifiedBy = lastModifiedBy;
|
this.lastModifiedBy = lastModifiedBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.springframework.data.domain.Auditable#getLastModifiedDate()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Instant> getLastModifiedDate() {
|
public Optional<Instant> getLastModifiedDate() {
|
||||||
return null == this.lastModifiedDate ? Optional.empty() : Optional.of(this.lastModifiedDate.toInstant());
|
return null == this.lastModifiedDate ? Optional.empty() : Optional.of(this.lastModifiedDate.toInstant());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.domain.Auditable#setLastModifiedDate(T)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void setLastModifiedDate(final Instant lastModifiedDate) {
|
public void setLastModifiedDate(final Instant lastModifiedDate) {
|
||||||
this.lastModifiedDate = null == lastModifiedDate ? null : Date.from(lastModifiedDate);
|
this.lastModifiedDate = null == lastModifiedDate ? null : Date.from(lastModifiedDate);
|
||||||
|
|||||||
+26
-19
@@ -25,30 +25,37 @@ import javax.persistence.Id;
|
|||||||
import javax.persistence.MappedSuperclass;
|
import javax.persistence.MappedSuperclass;
|
||||||
import org.springframework.data.domain.Persistable;
|
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
|
@MappedSuperclass
|
||||||
public abstract class AbstractPersistableCustom<PK extends Serializable> implements Persistable<Long>, Serializable {
|
public abstract class AbstractPersistableCustom<PK extends Serializable> implements Persistable<Long>, Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 9181640245194392646L;
|
private static final long serialVersionUID = 9181640245194392646L;
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setId(final Long id) {
|
protected void setId(final Long id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNew() {
|
public boolean isNew() {
|
||||||
|
return null == this.id;
|
||||||
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.
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user