You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by vo...@apache.org on 2020/04/07 21:46:29 UTC
[fineract] 01/04: add missing doc to AbstractPersistableCustom &
AbstractAuditableCustom
This is an automated email from the ASF dual-hosted git repository.
vorburger pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git
commit ae4117052bd3eb8965f88bd6b8d98ef17693d812
Author: Michael Vorburger <mi...@vorburger.ch>
AuthorDate: Mon Mar 23 01:31:23 2020 +0100
add missing doc to AbstractPersistableCustom & AbstractAuditableCustom
---
.../core/domain/AbstractAuditableCustom.java | 51 +---------------------
.../core/domain/AbstractPersistableCustom.java | 45 +++++++++++--------
2 files changed, 28 insertions(+), 68 deletions(-)
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractAuditableCustom.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractAuditableCustom.java
index 0328081..41a615f 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractAuditableCustom.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractAuditableCustom.java
@@ -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);
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractPersistableCustom.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractPersistableCustom.java
index 2e0586a..6a16c3d 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractPersistableCustom.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractPersistableCustom.java
@@ -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;
-
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private Long id;
-
- @Override
- public Long getId() {
- return id;
- }
+ private static final long serialVersionUID = 9181640245194392646L;
- protected void setId(final Long id) {
- this.id = id;
- }
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
- @Override
- public boolean isNew() {
+ @Override
+ public Long getId() {
+ return id;
+ }
- return null == this.id;
- }
+ protected void setId(final Long id) {
+ this.id = 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;
+ }
}