All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.agileactors.crud.domain.AbstractUpdatable Maven / Gradle / Ivy

Go to download

This is a library that extends Spring Boot functionality and offers a convenient and easy way to expose a domain's CRUD (Create, Read, Update, Delete) operations.

The newest version!
package com.agileactors.crud.domain;

import java.io.Serializable;
import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.PreUpdate;
import lombok.Getter;
import lombok.Setter;

/**
 * Abstract base class for updatable entities. Introduces an updatedAt which is always updated upon
 * enity storage
 *
 * @author Alexis Panousis
 * @param  the type of the auditing type's identifier.
 */
@MappedSuperclass
@Getter
@Setter
public abstract class AbstractUpdatable extends AbstractPersistable {

  @Column(name = "updated_at")
  protected LocalDateTime updatedAt;

  public void onPrePersist() {
    super.onPrePersist();
    updatedAt = createdAt;
  }

  @PreUpdate
  public void onPreUpdate() {
    //TODO: Inject clock instance
    updatedAt = LocalDateTime.now();
  }
}